-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathcreate_l3.py
More file actions
executable file
·379 lines (308 loc) · 15.1 KB
/
create_l3.py
File metadata and controls
executable file
·379 lines (308 loc) · 15.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#!/usr/bin/env python3
"""
NAME: create_l3.py
PURPOSE: This script is used to create the user-specified Layer-3 cross-connection.
EXAMPLE:
(If the specified endpoints are not present in the port manager,the cross-connects will be in a PHANTOM state.)
# For layer-3 cx creation on LANforge:
./create_l3.py --mgr localhost --endp_a eth1 --endp_b eth2 --min_rate_a 56000 --min_rate_b 40000 --no_cleanup
# For regression (script will create the layer-3 cx, check if it was successful, and then remove the layer-3 cx):
./create_l3.py --mgr localhost --endp_a 1.1.sta0000 --endp_b 1.2.sta0000 --min_rate_a 56000 --min_rate_b 40000 --no_cleanup
# For remote layer-3 cx creation:
./create_l3.py --mgr localhost --endp_a sta0000,sta0001 --endp_b eth2 --min_rate_a 56000 --min_rate_b 40000 --cx_type lf_udp
--multi_conn_a 1 --multi_conn_b 1 --no_cleanup
# With tos & pkts_to_send cross-connections
./create_l3.py --mgr localhost --endp_a sta00 --endp_b eth2 --min_ip_port_a 1000 --tos VI --pkts_to_send 10 --no_cleanup
# For batch creation functionality:
./create_l3.py --mgr 192.168.200.93 --endp_a 1.1.eth1 --endp_b 1.1.wlan2 --min_rate_a 6200000 --min_rate_b 6200000
--batch_quantity 10 --endp_a_increment 0 --endp_b_increment 1 --min_ip_port_a 1000 --min_ip_port_b 2000
--ip_port_increment_a 1 --ip_port_increment_b 1 --multi_conn_a 1 --multi_conn_b 1 --no_cleanup
SCRIPT_CLASSIFICATION: Creation
SCRIPT_CATEGORIES: Functional
NOTES:
Create Layer-3 Cross Connection Using LANforge JSON API : https://www.candelatech.com/cookbook.php?vol=fire&book=scripted+layer-3+test
Written by Candela Technologies Inc.
* Supports only creating user-specified Layer-3 cross-connection.
* Supports regression testing for QA
* If the specified ports used for creating endpoints are not present in the port manager, the cross-connects will be in a PHANTOM state.
STATUS: Functional
VERIFIED_ON: 20-JUN-2023,
Build Version: 5.4.6
Kernel Version: 6.2.14+
LICENSE:
Free to distribute and modify. LANforge systems must be licensed.
Copyright 2023 Candela Technologies Inc
INCLUDE_IN_README: False
"""
import sys
import os
import importlib
import argparse
import logging
logger = logging.getLogger(__name__)
if sys.version_info[0] != 3:
logger.critical("This script requires Python 3")
exit(1)
sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../")))
LANforge = importlib.import_module("py-json.LANforge")
lfcli_base = importlib.import_module("py-json.LANforge.lfcli_base")
LFCliBase = lfcli_base.LFCliBase
LFUtils = importlib.import_module("py-json.LANforge.LFUtils")
realm = importlib.import_module("py-json.realm")
Realm = realm.Realm
lf_logger_config = importlib.import_module("py-scripts.lf_logger_config")
class CreateL3(Realm):
def __init__(self,
name_prefix,
endp_b,
endp_a,
cx_type,
tos=None,
pkts_to_send=None,
host="localhost", port=8080,
min_rate_a=56, max_rate_a=0,
min_rate_b=56, max_rate_b=0,
_debug_on=False,
_exit_on_error=False,
_exit_on_fail=False,
_quantity=None,
_endp_a_increment=None,
_endp_b_increment=None,
_ip_port_increment_a=None,
_ip_port_increment_b=None,
_min_ip_port_a=None,
_min_ip_port_b=None,
_multi_conn_a=None,
_multi_conn_b=None,
ep_pairs=None):
super().__init__(host, port)
self.host = host
self.port = port
self.endp_b = endp_b
if endp_a:
self.endp_a = endp_a[0].split(',')
self.cx_type = cx_type
self.tos = tos
self.pkts_to_send = pkts_to_send
self.name_prefix = name_prefix
self.cx_profile = self.new_l3_cx_profile()
self.cx_profile.host = self.host
self.cx_profile.port = self.port
self.cx_profile.name_prefix = self.name_prefix
self.cx_profile.side_a_min_bps = min_rate_a
self.cx_profile.side_a_max_bps = max_rate_a
self.cx_profile.side_b_min_bps = min_rate_b
self.cx_profile.side_b_max_bps = max_rate_b
self.cx_profile.mconn_A = _multi_conn_a
self.cx_profile.mconn_B = _multi_conn_b
# for batch creation window automation attributes
self.batch_quantity = _quantity
self.port_increment_a = _endp_a_increment
self.port_increment_b = _endp_b_increment
self.ip_port_increment_a = _ip_port_increment_a
self.ip_port_increment_b = _ip_port_increment_b
self.min_ip_port_a = _min_ip_port_a
self.min_ip_port_b = _min_ip_port_b
# this overrides endp_a and endp_b
if ep_pairs:
self.endp_a = []
self.endp_b = []
logger.info("CreateL3: filling endpoint pair lists...")
for pair in list(ep_pairs):
ep_a = None
ep_b = None
if str(pair).find(',') < 1:
raise ValueError(f"Endpoint pair does not appear to be two ports [{pair}]")
# print(f" P A I R {pair}")
ep_a, ep_b = str(pair).split(",")
self.endp_a.append(ep_a)
self.endp_b.append(ep_b)
logger.info(f"filled {len(self.endp_a)} pairs")
def pre_cleanup(self):
self.cx_profile.cleanup_prefix()
def build(self):
# check for test_group
if self.cx_profile.create(endp_type=self.cx_type,
side_a=self.endp_a,
side_b=self.endp_b,
sleep_time=0,
tos=self.tos,
pkts_to_send=self.pkts_to_send,
ip_port_a=self.min_ip_port_a,
ip_port_b=self.min_ip_port_b,
batch_quantity=self.batch_quantity,
port_increment_a=self.port_increment_a,
port_increment_b=self.port_increment_b,
ip_port_increment_a=self.ip_port_increment_a,
ip_port_increment_b=self.ip_port_increment_b
):
self._pass("Cross-connect build finished")
else:
self._fail("Cross-connect build did not succeed.")
def parse_args():
parser = LFCliBase.create_bare_argparse(
prog='create_l3.py',
formatter_class=argparse.RawTextHelpFormatter,
epilog='''\
Used for creating layer-3 cross connections
''',
description='''\
NAME: create_l3.py
PURPOSE: This script is used to create the user-specified Layer-3 cross-connection.
EXAMPLE:
(If the specified endpoints are not present in the port manager,the cross-connects will be in a PHANTOM state.)
# For layer-3 cx creation on LANforge:
./create_l3.py --mgr localhost --endp_a eth1 --endp_b eth2 --min_rate_a 56000 --min_rate_b 40000 --no_cleanup
# For regression (script will create the layer-3 cx, check if it was successful, and then remove the layer-3 cx):
./create_l3.py --mgr localhost --endp_a 1.1.sta0000 --endp_b 1.2.sta0000 --min_rate_a 56000 --min_rate_b 40000 --no_cleanup
# For remote layer-3 cx creation:
./create_l3.py --mgr localhost --endp_a sta0000,sta0001 --endp_b eth2 --min_rate_a 56000 --min_rate_b 40000 --cx_type lf_udp
--multi_conn_a 1 --multi_conn_b 1 --no_cleanup
# With tos & pkts_to_send cross-connections
./create_l3.py --mgr localhost --endp_a sta00 --endp_b eth2 --min_ip_port_a 1000 --tos VI --pkts_to_send 10 --no_cleanup
# For batch creation functionality:
./create_l3.py --mgr 192.168.200.93 --endp_a 1.1.eth1 --endp_b 1.1.wlan2 --min_rate_a 6200000 --min_rate_b 6200000
--batch_quantity 10 --endp_a_increment 0 --endp_b_increment 1 --min_ip_port_a 1000 --min_ip_port_b 2000
--ip_port_increment_a 1 --ip_port_increment_b 1 --multi_conn_a 1 --multi_conn_b 1 --no_cleanup
SCRIPT_CLASSIFICATION: Creation
SCRIPT_CATEGORIES: Functional
NOTES:
Create Layer-3 Cross Connection Using LANforge JSON API : https://www.candelatech.com/cookbook.php?vol=fire&book=scripted+layer-3+test
Written by Candela Technologies Inc.
* Supports only creating user-specified Layer-3 cross-connection.
* Supports regression testing for QA
* If the specified ports used for creating endpoints are not present in the port manager, the cross-connects will be in a PHANTOM state.
STATUS: Functional
VERIFIED_ON: 20-JUN-2023,
Build Version: 5.4.6
Kernel Version: 6.2.14+
LICENSE:
Free to distribute and modify. LANforge systems must be licensed.
Copyright 2023 Candela Technologies Inc
INCLUDE_IN_README: False
''')
parser.add_argument('--cleanup',
help='Cleanup before exit',
action='store_true')
parser.add_argument('--no_cleanup',
help='Deprecated option. This script does not cleanup by default.',
action='store_true')
parser.add_argument("--no_pre_cleanup",
help="do not remove connections at start",
action="store_true")
# CX/endpoint naming
parser.add_argument('--cx_prefix',
help='phrase to begin CX names with',
default="VT")
# Endpoint port selection/configuration
parser.add_argument('--endp_a',
help='--endp_a station list',
default=[],
action="append",
required=False)
parser.add_argument('--endp_b',
help='--upstream port',
default="eth2",
required=False)
parser.add_argument("--ep_pairs",
help="--ep_pairs is a list of ports in a,b format, like eth1#0,eth2#0 eth1#1,eth2#1",
default=None,
required=False,
nargs='*')
parser.add_argument('--min_ip_port_a',
help='min ip port range for endp-a',
default=-1)
parser.add_argument('--min_ip_port_b',
help='min ip port range for endp-b',
default=-1)
# CX/endpoint basic configuration
parser.add_argument('--cx_type',
help='specify the traffic type for cx eg : lf_udp | lf_tcp',
default="lf_udp")
parser.add_argument('--min_rate_a',
help='--min_rate_a bps rate minimum for side_a',
default=56000)
parser.add_argument('--min_rate_b',
help='--min_rate_b bps rate minimum for side_b',
default=56000)
# CX/endpoint advanced configuration
parser.add_argument('--tos',
help='specify tos for endpoints eg : BK | BE | VI | VO | Voice | Video')
parser.add_argument('--pkts_to_send',
help='specify the pkts to send to the endpoints eg :One - 1 | Ten - 10 | (100) - 100 | (1000) - 1000')
parser.add_argument('--multi_conn_a', '--multi_con_a',
help='modify multi connection endpoint-a for cx',
default=0,
type=int)
parser.add_argument('--multi_conn_b', '--multi_con_b',
default=0,
type=int,
help='modify multi connection endpoint-b for cx')
# Batch creation settings
parser.add_argument('--batch_quantity',
help='No of cx endpoints to batch-create',
default=1)
parser.add_argument('--endp_a_increment',
help='End point - A port increment',
default=0)
parser.add_argument('--endp_b_increment',
help='End point - B port increment',
default=0)
parser.add_argument('--ip_port_increment_a',
help='ip port increment for endp-a',
default=1)
parser.add_argument('--ip_port_increment_b',
help='ip port increment for endp-b',
default=1)
return parser.parse_args()
def main():
args = parse_args()
help_summary = '''\
This script is made to set up/ crate a Layer-3 cross-connections. It allows running traffic from the upstream port
(eth1/eth2) to the station and vice versa. Additionally, it supports running traffic directly between stations.
The script also has a useful feature for batch modifying or batch creation functionality.
The script will create CX only, will not run/start traffic and will not generate any report.
'''
# help summary
if args.help_summary:
print(help_summary)
exit(0)
logger_config = lf_logger_config.lf_logger_config()
# set the logger level to requested value
logger_config.set_level(level=args.log_level)
logger_config.set_json(json_file=args.lf_logger_config_json)
ip_var_test = CreateL3(host=args.mgr,
port=args.mgr_port,
name_prefix=args.cx_prefix,
endp_a=args.endp_a,
endp_b=args.endp_b,
tos=args.tos,
cx_type=args.cx_type,
pkts_to_send=args.pkts_to_send,
min_rate_a=args.min_rate_a,
min_rate_b=args.min_rate_b,
_debug_on=args.debug,
_quantity=args.batch_quantity,
_endp_a_increment=args.endp_a_increment,
_endp_b_increment=args.endp_b_increment,
_ip_port_increment_a=args.ip_port_increment_a,
_ip_port_increment_b=args.ip_port_increment_b,
_min_ip_port_a=args.min_ip_port_a,
_min_ip_port_b=args.min_ip_port_b,
_multi_conn_a=args.multi_conn_a,
_multi_conn_b=args.multi_conn_b,
ep_pairs=args.ep_pairs)
if not args.no_pre_cleanup:
ip_var_test.pre_cleanup()
ip_var_test.build()
# TODO: Delete the thing just created, unless --no_cleanup option was added.
# Similar to how the create_bond.py does it.
if args.cleanup:
ip_var_test.pre_cleanup()
if ip_var_test.passes():
logger.info("Cross Connects created successfully.")
ip_var_test.exit_success()
else:
ip_var_test.exit_fail()
if __name__ == "__main__":
main()