-
Notifications
You must be signed in to change notification settings - Fork 25
/
create_station.py
executable file
·1054 lines (929 loc) · 52.3 KB
/
create_station.py
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
r"""
NAME: create_station.py
PURPOSE: Create and configure one or more of WiFi stations ports using the
specified parent radio.
NOTES: This script is intended to only create and configure stations. See other scripts
like 'test_l3.py' to create and run tests.
By default, the script will also attempt to connect the WiFi stations as configured
unless the '--create_admin_down' argument is specified.
--mode <mode_num>
Set the station WiFi mode (e.g. to configure a 802.11be radio as 802.11ax)
See the 'add_sta' command's mode option in the CLI documentation for
available mode settings. Link here: http://www.candelatech.com/lfcli_ug.php#add_sta
--station_flags <station_flags>
Comma-separated list of flags to configure the station with (e.g. 'ht160_enable,disable_sgi'
to enable 160MHz channel usage and disable 802.11ac short guard interval (SGI), respectively).
Note that other options like '--security' configure authentication-based station flags.
See the 'add_sta' command's 'flags' option in the CLI documentation for available options.
Link here: http://www.candelatech.com/lfcli_ug.php#add_sta
--country_code 840
United States : 840 | Dominican Rep : 214 | Japan (JE2) : 397 | Portugal : 620
Albania : 8 | Ecuador : 218 | Jordan : 400 | Pueto Rico : 630
Algeria : 12 | Egypt : 818 | Kazakhstan : 398 | Qatar : 634
Argentina : 32 | El Salvador : 222 | North Korea : 408 | Romania : 642
Bangladesh : 50 | Estonia : 233 | South Korea : 410 | Russia : 643
Armenia : 51 | Finland : 246 | South Korea : 411 | Saudi Arabia : 682
Australia : 36 | France : 250 | Kuwait : 414 | Singapore : 702
Austria : 40 | Georgia : 268 | Latvia : 428 | Slovak Republic : 703
Azerbaijan : 31 | Germany : 276 | Lebanon : 422 | Slovenia : 705
Bahrain : 48 | Greece : 300 | Liechtenstein : 438 | South Africa : 710
Barbados : 52 | Guatemala : 320 | Lithuania : 440 | Spain : 724
Belarus : 112 | Haiti : 332 | Luxembourg : 442 | Sweden : 752
Belgium : 56 | Honduras : 340 | Macau : 446 | Switzerland : 756
Belize : 84 | Hong Kong : 344 | Macedonia : 807 | Syria : 760
Bolivia : 68 | Hungary : 348 | Malaysia : 458 | Taiwan : 158
BiH : 70 | Iceland : 352 | Mexico : 484 | Thailand : 764
Brazil : 76 | India : 356 | Monaco : 492 | Trinidad &Tobago: 780
Brunei : 96 | Indonesia : 360 | Morocco : 504 | Tunisia : 788
Bulgaria : 100 | Iran : 364 | Netherlands : 528 | Turkey : 792
Canada : 124 | Ireland : 372 | Aruba : 533 | U.A.E. : 784
Chile : 152 | Israel : 376 | New Zealand : 554 | Ukraine : 804
China : 156 | Italy : 380 | Norway : 578 | United Kingdom : 826
Colombia : 170 | Jamaica : 388 | Oman : 512 | Uruguay : 858
Costa Rica : 188 | Japan : 392 | Pakistan : 586 | Uzbekistan : 860
Croatia : 191 | Japan (JP1) : 393 | Panama : 591 | Venezuela : 862
Cyprus : 196 | Japan (JP0) : 394 | Peru : 604 | Vietnam : 704
Czech Rep : 203 | Japan (JP1-1) : 395 | Philippines : 608 | Yemen : 887
Denmark : 208 | Japan (JE1) : 396 | Poland : 616 | Zimbabwe : 716
--no_pre_cleanup
Disables station cleanup before creation of stations. Default behavior will remove any existing stations.
--cleanup
Add this flag to clean up stations after creation
--eap_method <eap_method>
EAP method used by station in authentication.
See the 'set_wifi_extra' command's 'eap' option in the CLI documentation for available options.
Link here: http://www.candelatech.com/lfcli_ug.php#set_wifi_extra
--key_mgmt <protocol>
Key management protocol used by the station in authentication.
--pairwise_cipher <cipher>
Pairwise cipher used by station in authentication.
See the 'set_wifi_extra' command's 'pairwise' option in the CLI documentation for available options.
Link here: http://www.candelatech.com/lfcli_ug.php#set_wifi_extra
--groupwise_cipher <cipher>
Groupwise cipher used by station in authentication.
See the 'set_wifi_extra' command's 'groupwise' option in the CLI documentation for available options.
Link here: http://www.candelatech.com/lfcli_ug.php#set_wifi_extra
--eap_identity <eap_identity>
EAP identity (i.e. username) used by the station in authentication.
--eap_password <eap_password>
EAP password used by the station in authentication.
--pk_passwd <password>
Private key password used by the station in authentication. Required for TLS-based authentication.
--ca_cert <path_to_certificate>
Path to Certificate authority certificate used by the station in authentication.
Required for TLS-based authentication.
Note this is the path on the LANforge system where this station will be created.
--private_key <path_to_private_key>
Path to private key used by the station in authentication. Required for TLS-based authentication.
Note this is the path on the LANforge system where this station will be created.
EXAMPLE: # Create a single station
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--passwd <password> \
--security wpa2
# Create multiple stations
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--passwd <password> \
--security wpa2 \
--num_stations 10
# Create a multiple stations with specific numbering scheme
# In this example, create five stations with names of the format: "sta1000", "sta1001", "sta1002", etc.
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--passwd <password> \
--security wpa2 \
--start_id 1000 \
--num_stations 5
# Create a station, configuring radio settings like antenna, channel, etc.
# In this example, configure radio to use antennas (2x2 station) and channel 6
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--passwd <password> \
--security wpa2 \
--radio_antenna 2 \
--radio_channel 6
# Create a station, configuring the station to be a specific WiFi mode
# (e.g. configuring an 802.11ax-capable radio to create an 802.11ac station)
# See the 'add_sta' command's mode option in the CLI documentation for
# available mode settings. Link here: http://www.candelatech.com/lfcli_ug.php#add_sta
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--passwd <password> \
--security wpa2 \
--mode 6
# Create a station, configuring specific station flags
# In this example, enable 160MHz channels and disable 802.11ac short guard interval (SGI).
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--passwd <password> \
--security wpa2 \
--radio_antenna 2 \
--radio_channel 6 \
--station_flags "ht160_enable,disable_sgi"
# Create a station using TLS-based enterprise authentication
# Note that paths are paths on the LANforge system where the station will be created.
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--security <wpa2|wpa3> \
--key_mgmt <key_mgmt> \
--pairwise_cipher <cipher> \
--groupwise_cipher <cipher> \
--eap_method TLS \
--eap_identity <username> \
--eap_password <password> \
--pk_passwd <password> \
--private_key <path> \
--ca_cert <path>
# Create a station using TTLS-based enterprise authentication
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--security <wpa2|wpa3> \
--key_mgmt <TTLS|PEAP> \
--pairwise_cipher <cipher> \
--groupwise_cipher <cipher> \
--eap_method TTLS \
--eap_identity <username> \
--eap_password <password>
# Create station specifying a custom 'wpa_supplicant' config command
# In this example, specify a background scanning 'wpa_supplicant' command, useful for roaming.
# Here, the background scan is configured to a threshold of -65 dBm RSSI with a short and long interval of 50 and 300 seconds.
# See 'man wpa_supplicant.conf' for more information.
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--passwd <password> \
--security wpa2 \
--custom_wifi_cmd 'bgscan="simple:50:-65:300"'
SCRIPT_CLASSIFICATION:
Creation
SCRIPT_CATEGORIES:
Functional
STATUS: Functional
VERIFIED_ON:
9-JUN-2023,
GUI Version: 5.4.6
Kernel Version: 5.19.17+
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 pprint
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__ + "../../../")))
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")
lf_modify_radio = importlib.import_module("py-scripts.lf_modify_radio")
add_sta = importlib.import_module("py-json.LANforge.add_sta")
class CreateStation(Realm):
# Map values displayed in GUI to values accepted by the server
# Key is value displayed in GUI, value is value accepted by server
EAP_METHOD_MAP = {
"DEFAULT": "DEFAULT",
"EAP-MD5": "MD5",
"MSCHAPV2": "MSCHAPV2",
"EAP-OTP": "OTP",
"EAP-GTC": "GTC",
"EAP-TLS": "TLS",
"EAP-PEAP": "PEAP",
"EAP-TTLS": "TTLS",
"EAP-SIM": "SIM",
"EAP-AKA": "AKA",
"EAP-PSK": "PSK",
"EAP-IKEV2": "IKEV2",
"EAP-FAST": "FAST",
"WFA-UNAUTH-TLS": "WFA-UNAUTH-TLS",
"TTLS PEAP TLS": "TTLS PEAP TLS",
}
KEY_MGMT_MAP = {
"DEFAULT": "DEFAULT",
"NONE": "NONE",
"WPA-PSK": "WPA-PSK",
"FT-PSK (11r)": "FT-PSK",
"FT-EAP (11r)": "FT-EAP",
"FT-SAE (11r)": "FT-SAE",
"FT-SAE-EXT-KEY (11r)": "FT-SAE-EXT-KEY",
"FT-EAP-SHA384 (11r)": "FT-EAP-SHA-384",
"WPA-EAP": "WPA-EAP",
"OSEN": "OSEN",
"IEEE8021X": "IEEE8021X",
"WPA-PSK-SHA256": "WPA-PSK-SHA256",
"WPA-EAP-SHA256": "WPA-EAP-SHA256",
"PSK & EAP 128": "WPA-PSK WPA-EAP",
"PSK & EAP 256": "WPA-PSK-256 WPA-EAP-256",
"PSK & EAP 128/256": "WPA-PSK WPA-EAP WPA-PSK-256 WPA-EAP-256",
"SAE": "SAE",
"SAE-EXT-KEY": "SAE-EXT-KEY",
"WPA-EAP-SUITE-B": "WPA-EAP-SUITE-B",
"WPA-EAP-SUITE-B-192": "WPA-EAP-SUITE-B-192",
"FILS-SHA256": "FILS-SHA256",
"FILS-SHA384": "FILS-SHA384",
"OWE": "OWE",
}
PAIRWISE_CIPHER_MAP = {
"DEFAULT": "DEFAULT",
"CCMP": "CCMP",
"TKIP": "TKIP",
"NONE": "NONE",
"CCMP TKIP": "CCMP TKIP",
"CCMP-256": "CCMP-256",
"GCMP (wpa3)": "GCMP",
"GCMP-256 (wpa3)": "GCMP-256",
"CCMP/GCMP-256 (wpa3)": "GCMP-256 CCMP-256",
}
GROUPWISE_CIPHER_MAP = {
"DEFAULT": "DEFAULT",
"CCMP": "CCMP",
"WEP104": "WEP104",
"WEP40": "WEP40",
"GTK_NOT_USED": "GTK_NOT_USED",
"GCMP-256 (wpa3)": "GCMP-256",
"CCMP-256 (wpa3)": "CCMP-256",
"GCMP/CCMP-256 (wpa3)": "GCMP-256 CCMP-256",
"All": "CCMP TKIP WEP104 WEP40 CCMP-256 GCMP-256",
}
def __init__(self,
mgr,
mgr_port,
proxy,
debug,
up,
radio,
ssid,
bssid,
mode,
sta_list,
station_flags,
mac_pattern,
security,
password,
eap_method,
eap_identity,
eap_anonymous_identity,
eap_password,
eap_phase1,
eap_phase2,
pk_passwd,
ca_cert,
private_key,
key_mgmt,
pairwise_cipher,
groupwise_cipher,
set_txo_data,
custom_wifi_cmd,
**kwargs):
super().__init__(mgr,
mgr_port)
self.host = mgr
self.port = mgr_port
self.debug = debug
self.up = up
self.ssid = ssid
self.bssid = bssid
self.mode = mode
if mode:
if str.isalpha(mode):
self.mode = add_sta.add_sta_modes[mode]
self.sta_list = sta_list
self.sta_flags = station_flags
self.radio = radio
self.timeout = 120
self.security = security
self.password = password
# Translate from options displayed in the GUI to options
# that the server actually understands
if eap_method in self.EAP_METHOD_MAP:
self.eap_method = self.EAP_METHOD_MAP[eap_method]
else:
self.eap_method = eap_method
self.eap_identity = eap_identity
self.eap_anonymous_identity = eap_anonymous_identity
self.eap_password = eap_password
self.eap_phase1 = eap_phase1
self.eap_phase2 = eap_phase2
self.pk_passwd = pk_passwd
self.ca_cert = ca_cert
self.private_key = private_key
# Translate from options displayed in the GUI to options
# that the server actually understands
if key_mgmt in self.KEY_MGMT_MAP:
self.key_mgmt = self.KEY_MGMT_MAP[key_mgmt]
else:
self.key_mgmt = key_mgmt
if pairwise_cipher in self.PAIRWISE_CIPHER_MAP:
self.pairwise_cipher = self.PAIRWISE_CIPHER_MAP[pairwise_cipher]
else:
self.pairwise_cipher = pairwise_cipher
if groupwise_cipher in self.GROUPWISE_CIPHER_MAP:
self.groupwise_cipher = self.GROUPWISE_CIPHER_MAP[groupwise_cipher]
else:
self.groupwise_cipher = groupwise_cipher
self.set_txo_data = set_txo_data
self.custom_wifi_cmd = custom_wifi_cmd
self.station_profile = self.new_station_profile()
self.station_profile.lfclient_url = self.lfclient_url
self.station_profile.ssid = self.ssid
self.station_profile.bssid = self.bssid
self.station_profile.ssid_pass = self.password,
self.station_profile.security = self.security
self.station_profile.mode = self.mode
self.station_profile.set_command_param("add_sta", "mac", mac_pattern)
if self.sta_flags is not None:
_flags = self.sta_flags.split(',')
for flags in _flags:
logger.info(f"Selected Flags: '{flags}'")
self.station_profile.set_command_flag("add_sta", flags, 1)
logger.debug(pprint.pformat(self.sta_list))
def cleanup(self):
"""Remove any conflicting LANforge port(s)."""
for station in self.sta_list:
logger.info('Removing the station {} if exists'.format(station))
self.rm_port(station, check_exists=True)
if (not LFUtils.wait_until_ports_disappear(base_url=self.station_profile.lfclient_url, port_list=self.sta_list, debug=self.debug)):
logger.info('All stations are not removed or a timeout occurred. Aborting.')
exit(1)
def build(self):
"""Create LANforge port(s) as specified."""
self.station_profile.use_security(security_type=self.security,
ssid=self.ssid,
passwd=self.password)
logger.info("Creating stations")
self.station_profile.set_command_flag("add_sta", "create_admin_down", 1)
if not self.eap_method:
# Not 802.1X, but user may have specified other parameters
#
# When add support for other parameters, need to be careful here.
# Default from args is currently 'None' when unspecified
if self.key_mgmt:
# For whatever reason, setting the key mgmt here (using 'set_wifi_extra')
# clears the 'Key/Phrase' field set by 'add_sta'. Following workaround uses
# the 'set_wifi_extra' command's 'psk' parameter to set the 'WPA PSK'
# field in the 'Advanced Configuration' tab
#
# Hack to get around unfortunate argparse/initializer default settings which
# would result in 'null' password when password is not specified
if not self.password:
self.password = "[BLANK]"
# Have to set 'Advanced/802.1X' flag in order for 'psk' argument to take.
# This works around limitation in the GUI which does a check for 'Key/Phrase'
# length when WPA/WPA2/WPA3 enabled (but that field is sadly also cleared here)
self.station_profile.set_wifi_extra(key_mgmt=self.key_mgmt,
psk=self.password)
self.station_profile.set_command_flag(command_name="add_sta",
param_name="8021x_radius",
value=1) # Enable Advanced/802.1X flag
else:
# Configure station 802.1X settings
if self.eap_method == 'TLS':
self.station_profile.set_wifi_extra(key_mgmt=self.key_mgmt,
pairwise=self.pairwise_cipher,
group=self.groupwise_cipher,
eap=self.eap_method,
identity=self.eap_identity,
passwd=self.eap_password,
private_key=self.private_key,
ca_cert=self.ca_cert,
pk_password=self.pk_passwd,
phase1=self.eap_phase1,
phase2=self.eap_phase2)
elif self.eap_method == 'TTLS' or self.eap_method == 'PEAP':
self.station_profile.set_wifi_extra(key_mgmt=self.key_mgmt,
pairwise=self.pairwise_cipher,
group=self.groupwise_cipher,
eap=self.eap_method,
identity=self.eap_identity,
anonymous_identity=self.eap_anonymous_identity,
passwd=self.eap_password,
phase1=self.eap_phase1,
phase2=self.eap_phase2)
# Security type comes in one of following formats (possibly capitalized),
# so need to check if substring:
# 'type'
# '<type1|type2>'
if 'wpa3' in self.security or 'WPA3' in self.security:
self.station_profile.set_command_param("add_sta", "ieee80211w", 2)
self.desired_add_sta_flags = []
self.desired_add_sta_flags_mask = []
self.station_profile.set_command_flag(command_name="add_sta", param_name="8021x_radius", value=1) # enable 802.1x flag
# self.station_profile.set_command_flag(command_name="add_sta", param_name="80211r_pmska_cache", value=1) # enable 80211r_pmska_cache flag
# User may want to enable 802.11u, so need to double check (band-aid fix for now).
# If not specified, then disable it, as the StationProfile class enables it by default,
# and that may cause headaches.
#
# Note that station flags are also set in CreateStation constructor.
if not self.sta_flags or (self.sta_flags and "80211u_enable" not in self.sta_flags):
self.station_profile.set_command_flag(command_name="add_sta", param_name="80211u_enable", value=0)
self.station_profile.set_command_param(
"set_port", "report_timer", 1500)
self.station_profile.set_command_flag("set_port", "rpt_timer", 1)
if self.set_txo_data is not None:
self.station_profile.set_wifi_txo(
txo_ena=self.set_txo_data["txo_enable"],
tx_power=self.set_txo_data["txpower"],
pream=self.set_txo_data["pream"],
mcs=self.set_txo_data["mcs"],
nss=self.set_txo_data["nss"],
bw=self.set_txo_data["bw"],
retries=self.set_txo_data["retries"],
sgi=self.set_txo_data["sgi"],
)
if self.station_profile.create(radio=self.radio,
sta_names_=self.sta_list,
debug=self.debug,
up_=self.up):
self._pass("Stations created.")
else:
self._fail("Stations not properly created.")
# Custom Wifi setting
if self.custom_wifi_cmd:
for sta in self.sta_list:
self.set_custom_wifi(resource=int(sta.split('.')[1]),
station=str(sta.split('.')[2]),
cmd=self.custom_wifi_cmd)
if self.up:
self.station_profile.admin_up()
if not LFUtils.wait_until_ports_admin_up(base_url=self.lfclient_url,
port_list=self.station_profile.station_names,
debug_=self.debug,
timeout=10):
self._fail("Unable to bring all stations up")
return
if self.wait_for_ip(station_list=self.station_profile.station_names, timeout_sec=-1):
self._pass("All stations got IPs", print_=True)
self._pass("Station build finished", print_=True)
else:
self._fail("Stations failed to get IPs", print_=True)
self._fail("FAIL: Station build failed", print_=True)
logger.info("Please re-check the configuration applied")
def modify_radio(self, mgr, radio, antenna, channel, tx_power, country_code):
"""Configure LANforge WiFi radio port as specified."""
shelf, resource, radio, *nil = LFUtils.name_to_eid(radio)
modify_radio = lf_modify_radio.lf_modify_radio(lf_mgr=mgr)
modify_radio.set_wifi_radio(_resource=resource,
_radio=radio,
_shelf=shelf,
_antenna=antenna,
_channel=channel,
_txpower=tx_power,
_country_code=country_code)
def get_station_list(self):
"""Query LANforge system for list of all WiFi Station ports."""
response = super().json_get("/port/list?fields=_links,alias,device,port+type")
available_stations = []
for interface_name in response['interfaces']:
if 'sta' in list(interface_name.keys())[0]:
available_stations.append(list(interface_name.keys())[0])
return available_stations
def parse_args():
"""Parse CLI arguments."""
parser = LFCliBase.create_basic_argparse( # see create_basic_argparse in ../py-json/LANforge/lfcli_base.py
prog='create_station.py',
formatter_class=argparse.RawTextHelpFormatter,
epilog='''\
Create stations
''',
description="""\
NAME: create_station.py
PURPOSE: Create and configure one or more of WiFi stations ports using the
specified parent radio.
NOTES: This script is intended to only create and configure stations. See other scripts
like 'test_l3.py' to create and run tests.
By default, the script will also attempt to connect the WiFi stations as configured
unless the '--create_admin_down' argument is specified.
--mode <mode_num>
Set the station WiFi mode (e.g. to configure a 802.11be radio as 802.11ax)
See the 'add_sta' command's mode option in the CLI documentation for
available mode settings. Link here: http://www.candelatech.com/lfcli_ug.php#add_sta
--station_flags <station_flags>
Comma-separated list of flags to configure the station with (e.g. 'ht160_enable,disable_sgi'
to enable 160MHz channel usage and disable 802.11ac short guard interval (SGI), respectively).
Note that other options like '--security' configure authentication-based station flags.
See the 'add_sta' command's 'flags' option in the CLI documentation for available options.
Link here: http://www.candelatech.com/lfcli_ug.php#add_sta
--country_code 840
United States : 840 | Dominican Rep : 214 | Japan (JE2) : 397 | Portugal : 620
Albania : 8 | Ecuador : 218 | Jordan : 400 | Pueto Rico : 630
Algeria : 12 | Egypt : 818 | Kazakhstan : 398 | Qatar : 634
Argentina : 32 | El Salvador : 222 | North Korea : 408 | Romania : 642
Bangladesh : 50 | Estonia : 233 | South Korea : 410 | Russia : 643
Armenia : 51 | Finland : 246 | South Korea : 411 | Saudi Arabia : 682
Australia : 36 | France : 250 | Kuwait : 414 | Singapore : 702
Austria : 40 | Georgia : 268 | Latvia : 428 | Slovak Republic : 703
Azerbaijan : 31 | Germany : 276 | Lebanon : 422 | Slovenia : 705
Bahrain : 48 | Greece : 300 | Liechtenstein : 438 | South Africa : 710
Barbados : 52 | Guatemala : 320 | Lithuania : 440 | Spain : 724
Belarus : 112 | Haiti : 332 | Luxembourg : 442 | Sweden : 752
Belgium : 56 | Honduras : 340 | Macau : 446 | Switzerland : 756
Belize : 84 | Hong Kong : 344 | Macedonia : 807 | Syria : 760
Bolivia : 68 | Hungary : 348 | Malaysia : 458 | Taiwan : 158
BiH : 70 | Iceland : 352 | Mexico : 484 | Thailand : 764
Brazil : 76 | India : 356 | Monaco : 492 | Trinidad &Tobago: 780
Brunei : 96 | Indonesia : 360 | Morocco : 504 | Tunisia : 788
Bulgaria : 100 | Iran : 364 | Netherlands : 528 | Turkey : 792
Canada : 124 | Ireland : 372 | Aruba : 533 | U.A.E. : 784
Chile : 152 | Israel : 376 | New Zealand : 554 | Ukraine : 804
China : 156 | Italy : 380 | Norway : 578 | United Kingdom : 826
Colombia : 170 | Jamaica : 388 | Oman : 512 | Uruguay : 858
Costa Rica : 188 | Japan : 392 | Pakistan : 586 | Uzbekistan : 860
Croatia : 191 | Japan (JP1) : 393 | Panama : 591 | Venezuela : 862
Cyprus : 196 | Japan (JP0) : 394 | Peru : 604 | Vietnam : 704
Czech Rep : 203 | Japan (JP1-1) : 395 | Philippines : 608 | Yemen : 887
Denmark : 208 | Japan (JE1) : 396 | Poland : 616 | Zimbabwe : 716
--no_pre_cleanup
Disables station cleanup before creation of stations. Default behavior will remove any existing stations.
--cleanup
Add this flag to clean up stations after creation
--eap_method <eap_method>
EAP method used by station in authentication.
See the 'set_wifi_extra' command's 'eap' option in the CLI documentation for available options.
Link here: http://www.candelatech.com/lfcli_ug.php#set_wifi_extra
--key_mgmt <protocol>
Key management protocol used by the station in authentication.
--pairwise_cipher <cipher>
Pairwise cipher used by station in authentication.
See the 'set_wifi_extra' command's 'pairwise' option in the CLI documentation for available options.
Link here: http://www.candelatech.com/lfcli_ug.php#set_wifi_extra
--groupwise_cipher <cipher>
Groupwise cipher used by station in authentication.
See the 'set_wifi_extra' command's 'groupwise' option in the CLI documentation for available options.
Link here: http://www.candelatech.com/lfcli_ug.php#set_wifi_extra
--eap_identity <eap_identity>
EAP identity (i.e. username) used by the station in authentication.
--eap_password <eap_password>
EAP password used by the station in authentication.
--pk_passwd <password>
Private key password used by the station in authentication. Required for TLS-based authentication.
--ca_cert <path_to_certificate>
Path to Certificate authority certificate used by the station in authentication.
Required for TLS-based authentication.
Note this is the path on the LANforge system where this station will be created.
--private_key <path_to_private_key>
Path to private key used by the station in authentication. Required for TLS-based authentication.
Note this is the path on the LANforge system where this station will be created.
EXAMPLE: # Create a single station
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--passwd <password> \
--security wpa2
# Create multiple stations
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--passwd <password> \
--security wpa2 \
--num_stations 10
# Create a multiple stations with specific numbering scheme
# In this example, create five stations with names of the format: "sta1000", "sta1001", "sta1002", etc.
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--passwd <password> \
--security wpa2 \
--start_id 1000 \
--num_stations 5
# Create a station, configuring radio settings like antenna, channel, etc.
# In this example, configure radio to use antennas (2x2 station) and channel 6
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--passwd <password> \
--security wpa2 \
--radio_antenna 2 \
--radio_channel 6
# Create a station, configuring the station to be a specific WiFi mode
# (e.g. configuring an 802.11ax-capable radio to create an 802.11ac station)
# See the 'add_sta' command's mode option in the CLI documentation for
# available mode settings. Link here: http://www.candelatech.com/lfcli_ug.php#add_sta
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--passwd <password> \
--security wpa2 \
--mode 6
# Create a station, configuring specific station flags
# In this example, enable 160MHz channels and disable 802.11ac short guard interval (SGI).
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--passwd <password> \
--security wpa2 \
--radio_antenna 2 \
--radio_channel 6 \
--station_flags "ht160_enable,disable_sgi"
# Create a station using TLS-based enterprise authentication
# Note that paths are paths on the LANforge system where the station will be created.
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--security <wpa2|wpa3> \
--key_mgmt <key_mgmt> \
--pairwise_cipher <cipher> \
--groupwise_cipher <cipher> \
--eap_method TLS \
--eap_identity <username> \
--eap_password <password> \
--pk_passwd <password> \
--private_key <path> \
--ca_cert <path>
# Create a station using TTLS-based enterprise authentication
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--security <wpa2|wpa3> \
--key_mgmt <TTLS|PEAP> \
--pairwise_cipher <cipher> \
--groupwise_cipher <cipher> \
--eap_method TTLS \
--eap_identity <username> \
--eap_password <password>
# Create station specifying a custom 'wpa_supplicant' config command
# In this example, specify a background scanning 'wpa_supplicant' command, useful for roaming.
# Here, the background scan is configured to a threshold of -65 dBm RSSI with a short and long interval of 50 and 300 seconds.
# See 'man wpa_supplicant.conf' for more information.
./create_station.py \
--mgr <lanforge ip> \
--radio 1.1.wiphy1 \
--ssid <ssid> \
--passwd <password> \
--security wpa2 \
--custom_wifi_cmd 'bgscan="simple:50:-65:300"'
SCRIPT_CLASSIFICATION:
Creation
SCRIPT_CATEGORIES:
Functional
STATUS: Functional
VERIFIED_ON:
9-JUN-2023,
GUI Version: 5.4.6
Kernel Version: 5.19.17+
LICENSE: Free to distribute and modify. LANforge systems must be licensed.
Copyright 2023 Candela Technologies Inc
INCLUDE_IN_README:
False
""")
required = parser.add_argument_group('required arguments')
required.add_argument('--start_id',
type=int,
help='Specify the station starting id \n e.g: --start_id <value> default 0',
default=0)
optional = parser.add_argument_group('Optional arguments')
optional.add_argument("--prefix",
type=str,
help="Station prefix. Default: \'sta\'",
default="sta")
optional.add_argument("--create_admin_down",
help='Create ports in admin down state.',
action='store_true')
optional.add_argument("--bssid",
type=str,
help="AP BSSID. For example, \"00:00:00:00:00:00\".",
default="DEFAULT") # TODO: Fix 'null' when not set issue (REST server-side issue)
optional.add_argument('--mode',
help='Mode for your station (as a number)',
default=0)
optional.add_argument('--station_flags',
'--station_flag',
dest='station_flags',
help='station flags to add. eg: --station_flags ht40_disable',
required=False,
default=None)
optional.add_argument("--mac_pattern",
help="MAC randomization pattern for created stations. "
"In full MAC address pattern, the \'*\' indicates "
"randomizable characters. Most users will not adjust "
"this option. Note that this does not explicitly set "
"the locally-administered address bit.",
default="xx:xx:xx:*:*:xx")
optional.add_argument("--radio_antenna",
help='Number of spatial streams: \n'
' default = -1 \n'
' 0 Diversity (All) \n'
' 1 Fixed-A (1x1) \n'
' 4 AB (2x2) \n'
' 7 ABC (3x3) \n'
' 8 ABCD (4x4) \n'
' 9 (8x8) \n',
default='0')
optional.add_argument("--radio_channel",
help='Radio Channel: \n'
' default: AUTO \n'
' e.g: --radio_channel 6 (2.4G) \n'
'\t--radio_channel 36 (5G) \n',
default='AUTO')
optional.add_argument("--radio_tx_power",
help='Radio tx-power \n'
' default: AUTO system defaults',
default='AUTO')
optional.add_argument("--country_code",
help='Radio Country Code:\n'
'e.g: \t--country_code 840')
optional.add_argument("--eap_method",
type=str,
help='Enter EAP method e.g: TLS')
optional.add_argument("--eap_identity",
"--radius_identity",
dest="eap_identity",
type=str,
help="This is synonymous with the RADIUS username.")
optional.add_argument("--eap_anonymous_identity",
type=str,
help="",
default="[BLANK]") # TODO: Fix root cause of 'null' when not set issue (REST server-side issue)
optional.add_argument("--eap_password",
"--radius_passwd",
dest="eap_password",
type=str,
help="This is synonymous with the RADIUS user's password.")
optional.add_argument("--eap_phase1",
type=str,
help="EAP Phase 1 (outer authentication, i.e. TLS tunnel) parameters.\n"
"For example, \"peapver=0\" or \"peapver=1 peaplabel=1\".\n"
"Some WPA Enterprise setups may require \"auth=MSCHAPV2\"",
default="[BLANK]") # TODO: Fix root cause of 'null' when not set issue (REST server-side issue)
optional.add_argument("--eap_phase2",
type=str,
help="EAP Phase 2 (inner authentication) parameters.\n"
"For example, \"autheap=MSCHAPV2 autheap=MD5\" for EAP-TTLS.",
default="[BLANK]") # TODO: Fix root cause of 'null' when not set issue (REST server-side issue)
optional.add_argument("--pk_passwd",
type=str,
help='Enter the private key password')
optional.add_argument("--ca_cert",
type=str,
help='Enter path for certificate e.g: /home/lanforge/ca.pem')
optional.add_argument("--private_key",
type=str,
help='Enter private key path e.g: /home/lanforge/client.p12')
optional.add_argument("--key_mgmt",
type=str,
help="Authentication key management. Combinations are supported.\n")
optional.add_argument("--pairwise_cipher",
help='Pairwise Ciphers\n'
'DEFAULT\n'
'CCMP\n'
'TKIP\n'
'NONE\n'
'CCMP-TKIP\n'
'CCMP-256\n'
'GCMP\n'
'GCMP-256\n'
'CCMP/GCMP-256',
default='[BLANK]')
optional.add_argument("--groupwise_cipher",
help='Groupwise Ciphers\n'
'DEFAULT\n'
'CCMP\n'
'TKIP\n'
'WEP104\n'
'WEP40\n'
'GTK_NOT_USED\n'
'GCMP-256\n'
'CCMP-256\n'
'GCMP/CCMP-256\n'
'ALL',
default='[BLANK]')
optional.add_argument("--no_pre_cleanup",
help='Add this flag to stop cleaning up before station creation',
action='store_true')
optional.add_argument("--cleanup",
help='Add this flag to clean up stations after creation',
action='store_true')
optional.add_argument("--custom_wifi_cmd",
help="Mention the custom wifi command.")
return parser.parse_args()
def validate_args(args):
"""Validate CLI arguments."""
if args.radio is None:
logger.error("--radio required")
exit(1)
# TODO: Revisit these requirements. May have made some incorrect assumptions
if args.eap_method is not None:
if args.eap_identity is None:
logger.error("--eap_identity required")
exit(1)
elif args.eap_password is None:
logger.error("--eap_password required")
exit(1)
elif args.key_mgmt is None:
logger.error("--key_mgmt required")
exit(1)
elif args.eap_method == 'TLS':
if args.pk_passwd is None:
logger.error("--pk_passwd required")
exit(1)
elif args.ca_cert is None:
logger.error('--ca_cert required')
exit(1)
elif args.private_key is None:
logger.error('--private_key required')
exit(0)
# Only need to check WPA3 ciphers because user requests 802.1X authentication.
# Personal WPA3 always uses SAE, so default '[BLANK]' is fine if ciphers
# aren't specified.
#
# Security type comes in one of following formats (possibly capitalized),
# so need to check if substring:
# 'type'
# '<type1|type2>'
if 'wpa3' in args.security or 'WPA3' in args.security:
if args.pairwise_cipher == '[BLANK]':
logger.error('--pairwise_cipher required')
exit(1)
elif args.groupwise_cipher == '[BLANK]':
logger.error('--groupwise_cipher required')
exit(1)
def main():
"""Create LANforge WiFi station port(s) using specified options."""
args = parse_args()
help_summary = "This script will create and configure one or more WiFi station ports " \
"using the single specified WiFi radio parent port."
if args.help_summary:
print(help_summary)
exit(0)
validate_args(args)
# Configure logging