-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathlf_roam_test.py
More file actions
executable file
·2036 lines (1868 loc) · 125 KB
/
lf_roam_test.py
File metadata and controls
executable file
·2036 lines (1868 loc) · 125 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
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
"""
NAME: lf_roam_test.py
PURPOSE: lf_hard_rome_test.py works on both roaming methods i.e. hard/forced roaming and also attenuation based roaming
(soft roam) specific or purely based to 11r.
- By default, this script executes a hard roaming process and provides the results of the 11r roam test pdf,
as well as all the packet captures generated after the roam test. However, to perform a soft roam, the soft_roam
parameter must be set to true.
Hard Roam
EXAMPLE: For a single station and a single iteration
python3 lf_roam_test.py --mgr 192.168.100.221 --ap1_bssid "68:7d:b4:5f:5c:3b" --ap2_bssid "14:16:9d:53:58:cb"
--fiveg_radios "1.1.wiphy1" --band "fiveg" --sniff_radio "wiphy2" --num_sta 1 --ssid_name "RoamAP5g" --security "wpa2"
--security_key "something" --duration None --upstream "eth2" --iteration 1 --channel "40" --option "ota"
--dut_name ["AP1","AP2"] --traffic_type "lf_udp" --log_file False --debug False --iteration_based
EXAMPLE: For a single station and multiple iteration
python3 lf_roam_test.py --mgr 192.168.100.221 --ap1_bssid "68:7d:b4:5f:5c:3b" --ap2_bssid "14:16:9d:53:58:cb"
--fiveg_radios "1.1.wiphy1" --band "fiveg" --sniff_radio "wiphy2" --num_sta 1 --ssid_name "RoamAP5g" --security "wpa2"
--security_key "something" --duration None --upstream "eth2" --iteration 10 --channel "40" --option "ota"
--dut_name ["AP1","AP2"] --traffic_type "lf_udp" --log_file False --debug False --iteration_based
EXAMPLE: For multiple station and a single iteration
python3 lf_roam_test.py --mgr 192.168.100.221 --ap1_bssid "68:7d:b4:5f:5c:3b" --ap2_bssid "14:16:9d:53:58:cb"
--fiveg_radios "1.1.wiphy1" --band "fiveg" --sniff_radio "wiphy2" --num_sta 10 --ssid_name "RoamAP5g" --security "wpa2"
--security_key "something" --duration None --upstream "eth2" --iteration 1 --channel "40" --option "ota"
--dut_name ["AP1","AP2"] --traffic_type "lf_udp" --log_file False --debug False --iteration_based
EXAMPLE: For multiple station and multiple iteration
python3 lf_roam_test.py --mgr 192.168.100.221 --ap1_bssid "68:7d:b4:5f:5c:3b" --ap2_bssid "14:16:9d:53:58:cb"
--fiveg_radios "1.1.wiphy1" --band "fiveg" --sniff_radio "wiphy2" --num_sta 10 --ssid_name "RoamAP5g" --security "wpa2"
--security_key "something" --duration None --upstream "eth2" --iteration 10 --channel "40" --option "ota"
--dut_name ["AP1","AP2"] --traffic_type "lf_udp" --log_file False --debug False --iteration_based
EXAMPLE: For multiple station and multiple iteration with multicast traffic enable
python3 lf_roam_test.py --mgr 192.168.100.221 --ap1_bssid "10:f9:20:fd:f3:4b" --ap2_bssid "14:16:9d:53:58:cb"
--fiveg_radios "1.1.wiphy1" --band "fiveg" --sniff_radio "wiphy2" --num_sta 2 --ssid_name "RoamAP5g" --security "wpa2"
--security_key "something" --duration None --upstream "eth2" --iteration 1 --channel "36" --option "ota"
--dut_name ["AP1","AP2"] --traffic_type "lf_udp" --log_file False --debug False --iteration_based --sta_type normal --multicast True
Soft Roam
EXAMPLE: For a single station and a single iteration
python3 lf_roam_test.py --mgr 192.168.100.221 --ap1_bssid "68:7d:b4:5f:5c:3b" --ap2_bssid "14:16:9d:53:58:cb"
--fiveg_radios "1.1.wiphy1" --band "fiveg" --sniff_radio "wiphy2" --num_sta 1 --ssid_name "RoamAP5g" --security "wpa2"
--security_key "something" --duration None --upstream "eth2" --iteration 1 --channel "40" --option "ota"
--dut_name ["AP1","AP2"] --traffic_type "lf_udp" --log_file False --debug False --iteration_based --soft_roam True
EXAMPLE: For a single station and multiple iteration
python3 lf_roam_test.py --mgr 192.168.100.221 --ap1_bssid "68:7d:b4:5f:5c:3b" --ap2_bssid "14:16:9d:53:58:cb"
--fiveg_radios "1.1.wiphy1" --band "fiveg" --sniff_radio "wiphy2" --num_sta 1 --ssid_name "RoamAP5g" --security "wpa2"
--security_key "something" --duration None --upstream "eth2" --iteration 10 --channel "40" --option "ota"
--dut_name ["AP1","AP2"] --traffic_type "lf_udp" --log_file False --debug False --iteration_based --soft_roam True
EXAMPLE: For multiple station and a single iteration
python3 lf_roam_test.py --mgr 192.168.100.221 --ap1_bssid "68:7d:b4:5f:5c:3b" --ap2_bssid "14:16:9d:53:58:cb"
--fiveg_radios "1.1.wiphy1" --band "fiveg" --sniff_radio "wiphy2" --num_sta 10 --ssid_name "RoamAP5g" --security "wpa2"
--security_key "something" --duration None --upstream "eth2" --iteration 1 --channel "40" --option "ota"
--dut_name ["AP1","AP2"] --traffic_type "lf_udp" --log_file False --debug False --iteration_based --soft_roam True
EXAMPLE: For multiple station and multiple iteration
python3 lf_roam_test.py --mgr 192.168.100.221 --ap1_bssid "68:7d:b4:5f:5c:3b" --ap2_bssid "14:16:9d:53:58:cb"
--fiveg_radios "1.1.wiphy1" --band "fiveg" --sniff_radio "wiphy2" --num_sta 10 --ssid_name "RoamAP5g" --security "wpa2"
--security_key "something" --duration None --upstream "eth2" --iteration 10 --channel "40" --option "ota"
--dut_name ["AP1","AP2"] --traffic_type "lf_udp" --log_file False --debug False --iteration_based --soft_roam True
SCRIPT_CLASSIFICATION: Test
NOTES:
The primary focus of this script is to enable seamless roaming of clients/stations between two access points (APs).
The test can be conducted with a single or multiple stations, with single or multiple iterations.
The script will create stations/clients with advanced/802.1x and 11r key management. By default, it will create a
single station/client. Once the stations are created, the script will generate CX traffic between the upstream port and
the stations and run the traffic before roam.
Packet captures will be taken for each station/client in two scenarios:
(i) While the station/client is connected to an AP
(ii) While the station/client roams from one AP to another AP
These packet captures will be used to analyze the performance and stability of the roaming process.
Overall, this script is designed to provide a comprehensive test of the roaming functionality of the APs and the
stability of the network when clients move between APs.
The following are the criteria for PASS the test:
1. The BSSID of the station should change after roaming from one AP to another
2 The station should not experience any disconnections during/after the roaming process.
3. The duration of the roaming process should be less than 50 ms.
The following are the criteria for FAIL the test:
1. The BSSID of the station remains unchanged after roaming from one AP to another.
2. No roaming occurs, as all stations are connected to the same AP.
3. The captured packet does not contain a Reassociation Response Frame.
4. The station experiences disconnection during/after the roaming process.
5. The duration of the roaming process exceeds 50 ms.
STATUS: BETA RELEASE (MORE TESTING ONLY WITH MULTICAST)
VERIFIED_ON: 15-MAY-2023, Underdevelopment
LICENSE:
Free to distribute and modify. LANforge systems must be licensed.
Copyright (C) 2020-2026 Candela Technologies Inc
INCLUDE_IN_README: False
"""
import sys
import os
import importlib
import logging
import time
import datetime
from datetime import datetime # noqa: F811
import pandas as pd
import paramiko
from itertools import chain
import argparse
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")
cv_test_reports = importlib.import_module("py-json.cv_test_reports")
lf_report = cv_test_reports.lanforge_reports
lf_report_pdf = importlib.import_module("py-scripts.lf_report")
lf_csv = importlib.import_module("py-scripts.lf_csv")
lf_pcap = importlib.import_module("py-scripts.lf_pcap")
lf_graph = importlib.import_module("py-scripts.lf_graph")
sniff_radio = importlib.import_module("py-scripts.lf_sniff_radio")
sta_connect = importlib.import_module("py-scripts.sta_connect2")
lf_clean = importlib.import_module("py-scripts.lf_cleanup")
series = importlib.import_module("cc_module_9800_3504")
attenuator = importlib.import_module("py-scripts.attenuator_serial")
modify = importlib.import_module("py-scripts.lf_atten_mod_test")
multicast_profile = importlib.import_module("py-json.multicast_profile")
TIME_FORMAT = '%y %b %d %H:%M:%S'
class HardRoam(Realm):
def __init__(self, lanforge_ip=None,
lanforge_port=None,
lanforge_ssh_port=None,
c1_bssid=None,
c2_bssid=None,
fiveg_radio=None,
twog_radio=None,
sixg_radio=None,
band=None,
sniff_radio_=None,
num_sta=None,
security=None,
security_key=None,
ssid=None,
upstream=None,
duration=None,
iteration=None,
channel=None,
option=None,
duration_based=None,
iteration_based=None,
dut_name=None,
traffic_type="lf_udp",
roaming_delay=None,
path="../",
scheme="ssh",
dest="localhost",
user="admin",
passwd="Cisco123",
prompt="WLC2",
series_cc="9800",
ap="AP687D.B45C.1D1C",
port="8888",
band_cc="5g",
timeout="10",
identity=None,
ttls_pass=None,
log_file=False,
debug=False,
soft_roam=False,
sta_type=None,
multicast=None,
**kwargs):
super().__init__(lanforge_ip,
lanforge_port)
self.lanforge_ip = lanforge_ip
self.lanforge_port = lanforge_port
self.lanforge_ssh_port = lanforge_ssh_port
self.c1_bssid = c1_bssid
self.c2_bssid = c2_bssid
self.fiveg_radios = fiveg_radio
self.twog_radios = twog_radio
self.sixg_radios = sixg_radio
self.band = band
self.sniff_radio = sniff_radio_
self.num_sta = num_sta
self.ssid_name = ssid
self.security = security
self.security_key = security_key
self.upstream = upstream
self.duration = duration
self.iteration = iteration
self.channel = channel
self.option = option
self.iteration_based = iteration_based
self.duration_based = duration_based
self.local_realm = realm.Realm(lfclient_host=self.lanforge_ip, lfclient_port=self.lanforge_port)
self.staConnect = sta_connect.StaConnect2(host=self.lanforge_ip, port=self.lanforge_port,
outfile="sta_connect2.csv")
self.final_bssid = []
self.pcap_obj_2 = None
self.pcap_name = None
self.test_duration = None
self.client_list = []
self.dut_name = dut_name
self.pcap_obj = lf_pcap.LfPcap()
self.lf_csv_obj = lf_csv.lf_csv()
self.traffic_type = traffic_type
self.roam_delay = roaming_delay
self.sta_type = sta_type
self.cx_profile = self.local_realm.new_l3_cx_profile()
self.cc = None
self.cc = series.create_controller_series_object(
scheme=scheme,
dest=dest,
user=user,
passwd=passwd,
prompt=prompt,
series=series_cc,
ap=ap,
port=port,
band=band_cc,
timeout=timeout)
self.cc.pwd = path
self.start_time = None
self.end_time = None
self.identity = identity
self.ttls_pass = ttls_pass
self.log_file = log_file
self.debug = debug
self.mac_data = None
self.soft_roam = soft_roam
self.multicast = multicast
# logging.basicConfig(filename='roam.log', filemode='w', level=logging.INFO, force=True)
self.multi_cast_profile = multicast_profile.MULTICASTProfile(self.lanforge_ip, self.lanforge_port,
local_realm=self)
# Start debugger of controller
def start_debug_(self, mac_list):
mac = mac_list
for i in mac:
y = self.cc.debug_wireless_mac_cc(mac=str(i))
print(y)
# Stop debugger of controller
def stop_debug_(self, mac_list):
mac = mac_list
for i in mac:
y = self.cc.no_debug_wireless_mac_cc(mac=str(i))
print(y)
# Get trace file names from controller
def get_ra_trace_file(self):
ra = self.cc.get_ra_trace_files__cc()
print(ra)
ele_list = [y for y in (x.strip() for x in ra.splitlines()) if y]
print(ele_list)
return ele_list
# Get trace file names from controller with respect to number of clients
def get_file_name(self, client):
file_name = []
if not self.debug:
for i in range(client):
file_name.append("debug disabled")
else:
file = self.get_ra_trace_file()
indices = [i for i, s in enumerate(file) if 'dir bootflash: | i ra_trace' in s]
# print(indices)
y = indices[-1]
if client == 1:
z = file[y + 1]
list_ = [z]
m = list_[0].split(" ")
print(m)
print(len(m))
print(m[-1])
if m[-1].isnumeric():
print("Log file not Available")
file_name.append("file not found")
file_name.append(m[-1])
else:
z = file[y + (int(0) + 1)]
list_ = [z]
m = list_[0].split(" ")
print(m)
print(len(m))
print(m[-1])
if m[-1].isnumeric():
print("Log file not Available")
for i in range(client):
file_name.append("file not found")
else:
for i in range(client):
z = file[y + (int(i) + 1)]
list_ = [z]
m = list_[0].split(" ")
print(m)
print(len(m))
print(m[-1])
if m[-1].isnumeric():
print("Log file not Available")
file_name.append("file not found")
file_name.append(m[-1])
print("File_name", file_name)
file_name.reverse()
return file_name
# delete trace file from controller
def delete_trace_file(self, file):
# file = self.get_file_name()
self.cc.del_ra_trace_file_cc(file=file)
# get station list from lf
def get_station_list(self):
sta = self.staConnect.station_list()
if sta == "no response":
return "no response"
sta_list = []
for i in sta:
for j in i:
sta_list.append(j)
return sta_list
def create_stations(self, radio):
local_realm = realm.Realm(lfclient_host=self.lanforge_ip, lfclient_port=self.lanforge_port)
station_profile = local_realm.new_station_profile()
if self.band == "twog":
radio = self.twog_radios
elif self.band == "fiveg":
radio = self.fiveg_radios
else:
radio = self.sixg_radios
logger.info(f"Using LANforge radio(s) {radio} for test station(s)")
station_list = LFUtils.portNameSeries(prefix_="sta",
start_id_=0,
end_id_=self.num_sta - 1,
padding_number_=10000,
radio=radio)
if not self.soft_roam:
logger.info("Soft roam disabled")
station_profile.set_command_flag("add_sta", "disable_roam", 1)
else:
logger.info("Soft roam enabled")
if self.option == "otds":
logger.info("Enabling 802.11r FT-DS")
station_profile.set_command_flag("add_sta", "ft-roam-over-ds", 1)
if self.sta_type == "11r-sae-802.1x":
self.security_key = "[BLANK]"
# Settings for all stations
station_profile.use_security(self.security, self.ssid_name, self.security_key)
station_profile.set_command_flag("add_sta", "create_admin_down", 1)
station_profile.set_command_param("set_port", "report_timer", 1500)
station_profile.set_command_flag("add_sta", "80211u_enable", 0)
# WPA3 requires PMF (802.11w)
if "sae" in self.sta_type:
station_profile.set_command_flag("add_sta", "ieee80211w", 2)
if self.sta_type == "11r" or self.sta_type == "11r-sae":
if self.sta_type == "11r":
key_mgmt = "FT-PSK"
else:
key_mgmt = "FT-SAE"
# 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)
station_profile.set_wifi_extra(key_mgmt=key_mgmt,
psk=self.security_key)
station_profile.set_command_flag(command_name="add_sta",
param_name="8021x_radius",
value=1) # Enable Advanced/802.1X flag
elif self.sta_type == "11r-sae-802.1x":
station_profile.set_command_flag(command_name="add_sta",
param_name="8021x_radius",
value=1) # Enable Advanced/802.1X flag
station_profile.set_wifi_extra(key_mgmt="FT-EAP",
eap="TTLS",
identity=self.identity,
passwd=self.ttls_pass)
# Create stations
logger.info(f"Creating {self.num_sta} test stations configurated for test AP SSID {self.ssid_name}")
logger.debug(f"Creating stations: {station_list}")
station_profile.create(radio=radio, sta_names_=station_list)
logger.info("Waiting stations to initialize")
local_realm.wait_until_ports_appear(sta_list=station_list)
if self.soft_roam:
bgscan_config = 'bgscan="simple:30:-65:300"'
logger.info(f"Enabling background scanning for test stations: {bgscan_config}")
for sta_name in station_list:
logger.debug(f"Enabling background scanning for station {sta_name}")
sta = sta_name.split(".")[2] # TODO: Use name_to_eid
bgscan = {
"shelf": 1,
"resource": 1, # TODO: Do not hard-code resource, get it from radio eid I think.
"port": str(sta),
"type": 'NA',
"text": bgscan_config,
}
self.local_realm.json_post("/cli-json/set_wifi_custom", bgscan)
# Bring up stations
logger.info("Setting stations to active state")
station_profile.admin_up()
# Wait for stations to connect
logger.info("Waiting for stations to connect (associate and configure IP)")
if local_realm.wait_for_ip(station_list):
logger.info("All stations connected")
# exit()
return True
else:
logger.error(f"One or more stations did not connect to test AP SSID {self.ssid_name}")
return False
# create a multicast profile
def mcast_tx(self):
# set 1mbps tx rate
self.multi_cast_profile.side_b_min_bps = 1000000
self.multi_cast_profile.create_mc_tx("mc_udp", self.upstream)
def mcast_rx(self, sta_list):
self.multi_cast_profile.side_a_min_bps = 0
print("Station List :", sta_list)
self.multi_cast_profile.create_mc_rx("mc_udp", sta_list)
def mcast_start(self):
self.multi_cast_profile.start_mc()
def mcast_stop(self):
self.multi_cast_profile.stop_mc()
# Create layer-3 traffic on clients
def create_layer3(self, side_a_min_rate, side_a_max_rate, side_b_min_rate, side_b_max_rate, side_a_min_pdu,
side_b_min_pdu, traffic_type, sta_list):
logger.info("Station List : ", str(sta_list))
logger.info(str(self.upstream))
self.cx_profile.host = self.lanforge_ip
self.cx_profile.port = self.lanforge_port
self.cx_profile.side_a_min_bps = side_a_min_rate
self.cx_profile.side_a_max_bps = side_a_max_rate
self.cx_profile.side_b_min_bps = side_b_min_rate
self.cx_profile.side_b_max_bps = side_b_max_rate
self.cx_profile.side_a_min_pdu = side_a_min_pdu,
self.cx_profile.side_b_min_pdu = side_b_min_pdu,
# Create layer3 end points & run traffic
logger.info("Creating Endpoints")
self.cx_profile.create(endp_type=traffic_type, side_a=sta_list, side_b=self.upstream, sleep_time=0)
self.cx_profile.start_cx()
# Get layer3 values
def get_layer3_values(self, cx_name=None, query=None):
url = f"/cx/{cx_name}"
response = self.json_get(_req_url=url)
result = response[str(cx_name)][str(query)]
return result
# Get cross-connect names
def get_cx_list(self):
layer3_result = self.local_realm.cx_list()
layer3_names = [item["name"] for item in layer3_result.values() if "_links" in item]
print("Layer-3 Names :", layer3_names)
return layer3_names
# Get Endpoint values
def get_endp_values(self, endp="A", cx_name="niki", query="tx bytes"):
# self.get_cx_list()
# self.json_get("http://192.168.100.131:8080/endp/Unsetwlan000-0-B?fields=rx%20rate")
url = f"/endp/{cx_name}-{endp}?fields={query}"
response = self.json_get(_req_url=url)
if (response is None) or ("endpoint" not in response):
print("Incomplete response:")
exit(1)
final = response["endpoint"][query]
return final
# Pre-Cleanup on lanforge
def precleanup(self):
obj = lf_clean.lf_clean(host=self.lanforge_ip, port=self.lanforge_port, clean_cxs=True, clean_endp=True)
obj.resource = "all"
obj.sta_clean()
obj.cxs_clean()
obj.layer3_endp_clean()
# Get client data from lf
def station_data_query(self, station_name="wlan0", query="channel"):
url = f"/port/{1}/{1}/{station_name}?fields={query}"
response = self.local_realm.json_get(_req_url=url)
if (response is None) or ("interface" not in response):
print("Station_list: incomplete response:")
# pprint(response)
exit(1)
y = response["interface"][query]
return y
# Start packet capture on lf
# TODO: Check if other monitor ports exist on this radio already. If so, delete those
# before adding new monitor port (or) just use the existing monitor port without creating
# a new one. --Ben
def start_sniffer(self, radio_channel=None, radio=None, test_name="sniff_radio", duration=60):
self.pcap_name = test_name + str(datetime.now().strftime("%Y-%m-%d-%H-%M")).replace(':', '-') + ".pcap"
self.pcap_obj_2 = sniff_radio.SniffRadio(lfclient_host=self.lanforge_ip, lfclient_port=self.lanforge_port,
radio=radio, channel=radio_channel, monitor_name="monitor",
channel_bw="20")
self.pcap_obj_2.setup(0, 0, 0)
time.sleep(5)
self.pcap_obj_2.monitor.admin_up()
time.sleep(5)
self.pcap_obj_2.monitor.start_sniff(capname=self.pcap_name, duration_sec=duration)
# Stop packet capture and get file name
def stop_sniffer(self):
print("In Stop Sniffer")
directory = None
directory_name = "pcap"
if directory_name:
directory = os.path.join("", str(directory_name))
try:
if not os.path.exists(directory):
os.mkdir(directory)
except Exception as x:
print(x)
self.pcap_obj_2.monitor.admin_down()
self.pcap_obj_2.cleanup()
lf_report.pull_reports(hostname=self.lanforge_ip, port=self.lanforge_ssh_port, username="lanforge",
password="lanforge", report_location="/home/lanforge/" + self.pcap_name,
report_dir="pcap")
return self.pcap_name
# Generate csv files at the beginning
def generate_csv(self):
file_name = []
for i in range(self.num_sta):
file = 'test_client_' + str(i) + '.csv'
if self.multicast == "True":
lf_csv_obj = lf_csv.lf_csv(_columns=['Iterations', 'bssid1', 'bssid2', "PASS/FAIL", "Remark"], _rows=[],
_filename=file)
else:
lf_csv_obj = lf_csv.lf_csv(_columns=['Iterations', 'bssid1', 'bssid2', "Roam Time(ms)", "PASS/FAIL",
"Pcap file Name", "Log File", "Remark"], _rows=[], _filename=file)
# "Packet loss",
file_name.append(file)
lf_csv_obj.generate_csv()
return file_name
# Get journal ctl logs/ kernel logs
def journal_ctl_logs(self, file):
jor_lst = []
name = "kernel_log" + file + ".txt"
jor_lst.append(name)
try:
ssh = paramiko.SSHClient()
command = "journalctl --since '5 minutes ago' > kernel_log" + file + ".txt"
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=self.lanforge_ip, port=self.lanforge_ssh_port, username="lanforge",
password="lanforge", banner_timeout=600)
stdin, stdout, stderr = ssh.exec_command(str(command))
stdout.readlines()
ssh.close()
kernel_log = "/home/lanforge/kernel_log" + file + ".txt"
lf_report.pull_reports(hostname=self.lanforge_ip, port=self.lanforge_ssh_port, username="lanforge",
password="lanforge", report_location=kernel_log, report_dir=".")
except Exception as e:
print(e)
return jor_lst
# Gives wlan management status of pcap file
def get_wlan_mgt_status(self, file_name,
pyshark_filter="(wlan.fc.type_subtype eq 3 && wlan.fixed.status_code == 0x0000 && wlan.tag.number == 55)"):
query_reasso_response = self.pcap_obj.get_wlan_mgt_status_code(pcap_file=str(file_name), filter=pyshark_filter)
print("Query", query_reasso_response)
return query_reasso_response
# Get attenuator serial number
def attenuator_serial(self):
obj = attenuator.AttenuatorSerial(lfclient_host=self.lanforge_ip, lfclient_port=self.lanforge_port)
val = obj.show()
return val
# To modify the attenuators
def attenuator_modify(self, serno, idx, val):
atten_obj = modify.CreateAttenuator(self.lanforge_ip, self.lanforge_port, serno, idx, val)
atten_obj.build()
# This is where the main roaming functionality begins
def run(self, file_n=None):
try:
logger.info("Setting both attenuators to zero attenuation at the beginning.")
ser_no = self.attenuator_serial()
logger.info("Available attenuators :" + str(ser_no[0]) + " , " + str(ser_no[1]))
ser_1 = ser_no[0].split(".")[2]
ser_2 = ser_no[1].split(".")[2]
self.attenuator_modify(ser_1, "all", 0)
self.attenuator_modify(ser_2, "all", 0)
except Exception as e:
logger.warning(str(e))
finally:
kernel_log = []
message = None, None
# Start Timer
self.start_time = datetime.now().strftime(TIME_FORMAT)
logger.debug(f"Test start time: {self.start_time}")
# Getting two BSSID's for roam
self.final_bssid.extend([self.c1_bssid, self.c2_bssid])
logger.info(f"Roaming target BSSIDs: {self.final_bssid}")
# If 'Soft Roam' is selected, initially set the attenuator to zero.
if self.soft_roam:
logger.info("Setting both attenuators to zero attenuation at the beginning for 'soft roam'")
ser_no = self.attenuator_serial()
logger.info("Available attenuators :" + str(ser_no[0]) + " , " + str(ser_no[1]))
ser_1 = ser_no[0].split(".")[2]
ser_2 = ser_no[1].split(".")[2]
self.attenuator_modify(ser_1, "all", 0)
self.attenuator_modify(ser_2, "all", 0)
# Start sniffer & Create clients with respect to bands
logger.info("Begin sniffing to establish the initial connection.")
self.start_sniffer(radio_channel=self.channel, radio=self.sniff_radio,
test_name="roam_" + str(self.sta_type) + "_" + str(self.option) + "start" + "_",
duration=3600)
if self.band == "twog":
self.local_realm.reset_port(self.twog_radios)
self.create_stations(radio=self.twog_radios)
elif self.band == "fiveg":
self.local_realm.reset_port(self.fiveg_radios)
self.create_stations(radio=self.fiveg_radios)
else:
self.local_realm.reset_port(self.sixg_radios)
self.create_stations(radio=self.sixg_radios)
# Check if all stations have ip or not
sta_list = self.get_station_list()
logger.info("Checking for IP and station list :" + str(sta_list))
if sta_list == "no response":
logger.info("No response from station")
else: # if all stations got ip check mac address for stations
val = self.wait_for_ip(sta_list)
mac_list = []
for sta_name in sta_list:
sta = sta_name.split(".")[2] # use name_to_eid
mac = self.station_data_query(station_name=str(sta), query="mac")
mac_list.append(mac)
logger.info("List of MAC addresses for all stations :" + str(mac_list))
self.mac_data = mac_list
logger.info("Stop Sniffer")
file_name_ = self.stop_sniffer()
file_name = "./pcap/" + str(file_name_)
logger.info("pcap file name : " + str(file_name))
if val: # if all station got an ip, then check all station are connected to single AP
logger.info("All stations got ip")
logger.info("Check if all stations are connected single ap")
# get BSSID'S of all stations
logger.info("Get BSSID's of all stations")
check = []
for sta_name in sta_list:
sta = sta_name.split(".")[2]
bssid = self.station_data_query(station_name=str(sta), query="ap")
logger.info(str(bssid))
check.append(bssid)
logger.info(str(check))
# Check if all the stations in the BSSID list have the same BSSID.
logger.info("Verifying whether all BSSID's are identical or not.")
result = all(element == check[0] for element in check)
# if all BSSID's are identical / same, run layer3 traffic b/w station to upstream
if result:
if self.multicast == "True":
print("multicast is true")
self.mcast_tx()
self.mcast_rx(sta_list=sta_list)
self.mcast_start()
else:
self.create_layer3(side_a_min_rate=1000000, side_a_max_rate=0, side_b_min_rate=1000000,
side_b_max_rate=0, sta_list=sta_list, traffic_type=self.traffic_type,
side_a_min_pdu=1250, side_b_min_pdu=1250)
else:
# if BSSID's are not identical / same, try to move all clients to one ap
logger.info("Attempt to ensure that all clients are connected to the same AP before "
"initiating a roaming process.")
count1 = check.count(self.c1_bssid.upper())
count2 = check.count(self.c2_bssid.upper())
checker, new_sta_list, checker2 = None, [], None
if count1 > count2:
logger.info("Station connected mostly to ap1")
checker = self.c2_bssid.upper()
checker2 = self.c1_bssid.upper()
else:
checker = self.c1_bssid.upper()
checker2 = self.c2_bssid.upper()
index_count = [i for i, x in enumerate(check) if x == checker]
logger.info(str(index_count))
for i in index_count:
new_sta_list.append(sta_list[i])
logger.info("new_sta_list " + str(new_sta_list))
for sta_name in new_sta_list:
eid = self.name_to_eid(sta_name)
# sta = sta_name.split(".")[2] # TODO: use name-to-eid
sta = eid[2]
logger.info(sta)
wpa_cmd = "roam " + str(checker2)
wifi_cli_cmd_data1 = {
"shelf": eid[0],
"resource": eid[1], # TODO: do not hard-code
"port": str(sta),
"wpa_cli_cmd": 'scan trigger freq 5180 5300'
}
wifi_cli_cmd_data = {
"shelf": eid[0],
"resource": eid[1],
"port": str(sta),
"wpa_cli_cmd": wpa_cmd
}
logger.info(str(wifi_cli_cmd_data))
self.local_realm.json_post("/cli-json/wifi_cli_cmd", wifi_cli_cmd_data1)
# TODO: LANforge sta on same radio will share scan results, so you only need to scan on one STA per
# radio, and then sleep should be 5 seconds, then roam every station that needs to roam.
# You do not need this sleep and scan for each STA.
self.local_realm.json_post("/cli-json/wifi_cli_cmd", wifi_cli_cmd_data)
if self.multicast == "True":
print("multicast is true")
self.mcast_tx()
self.mcast_rx(sta_list=sta_list)
self.mcast_start()
else:
self.create_layer3(side_a_min_rate=1000000, side_a_max_rate=0, side_b_min_rate=1000000,
side_b_max_rate=0, sta_list=sta_list, traffic_type=self.traffic_type,
side_a_min_pdu=1250, side_b_min_pdu=1250)
timeout, variable, iterable_var = None, None, None
if self.duration_based is True:
timeout = time.time() + 60 * float(self.duration)
# iteration_dur = 50000000
iterable_var = 50000000
variable = -1
if self.iteration_based:
variable = self.iteration
iterable_var = self.iteration
# post_bssid = None
while variable: # The iteration loop for roaming begins at this point.
if self.multicast == "True":
if variable == 1:
print("ignore")
else:
print("wait for 5 mins for next roam process")
time.sleep(120)
logger.info("Value of the Variable :" + str(variable))
iterations, number, ser_1, ser_2 = self.iteration, None, None, None
if variable != -1:
iterations = iterable_var - variable
variable = variable - 1
if variable == -1:
# need to write duration iteration logic
# iterations = iterable_var - iteration_dur
if self.duration is not None:
if time.time() > timeout:
break
# Get the serial number of attenuators from lf
ser_no = self.attenuator_serial()
logger.info(str(ser_no[0]))
ser_1 = ser_no[0].split(".")[2]
ser_2 = ser_no[1].split(".")[2]
if self.soft_roam:
if iterations % 2 == 0:
logger.info("even set c1 to lowest and c2 to highest attenuation ")
number = "even"
logger.info("number " + str(number))
# set attenuation to zero in first attenuator and high in second attenuator
self.attenuator_modify(ser_1, "all", 700)
self.attenuator_modify(ser_2, "all", 0)
else:
logger.info("odd, c1 is already at highest and c2 is at lowest")
self.attenuator_modify(ser_1, "all", 0)
self.attenuator_modify(ser_2, "all", 700) # 700 == 300/400 bgscan 15:-70:300
number = "odd"
logger.info("number " + str(number))
try:
# Define row list per iteration
row_list = []
sta_list = self.get_station_list()
logger.info("Station list :" + str(sta_list))
if sta_list == "no response":
logger.info("No response")
pass
else:
station = self.wait_for_ip(sta_list)
if self.debug:
logger.info("Start debug")
self.start_debug_(mac_list=mac_list)
if station:
logger.info("All stations got ip")
# Get bssid's of all stations currently connected
bssid_list = []
for sta_name in sta_list:
sta = sta_name.split(".")[2]
bssid = self.station_data_query(station_name=str(sta), query="ap")
bssid_list.append(bssid)
print("BSSID of the current connected stations : ", bssid_list)
logger.info(str(bssid_list))
pass_fail_list = []
pcap_file_list = []
roam_time1 = []
# packet_loss_lst = []
remark = []
log_file = []
# Check if all element of bssid list has same bssid's
result = all(element == bssid_list[0] for element in bssid_list)
if not result:
# Attempt to connect the client to the same AP for each iteration
logger.info("Giving a try to connect")
logger.info("Move all clients to one AP")
count3 = bssid_list.count(self.c1_bssid.upper())
count4 = bssid_list.count(self.c2_bssid.upper())
logger.info("Count3 " + str(count3))
logger.info("Count4 " + str(count4))
checker, new_sta_list, checker2 = None, [], None
if count3 > count4:
logger.info("Station connected mostly to AP-1")
checker = self.c2_bssid.upper()
checker2 = self.c1_bssid.upper()
else:
checker = self.c1_bssid.upper()
checker2 = self.c2_bssid.upper()
index_count = [i for i, x in enumerate(bssid_list) if x == checker]
logger.info(str(index_count))
for i in index_count:
new_sta_list.append(sta_list[i])
logger.info("new_sta_list " + str(new_sta_list))
for sta_name in new_sta_list:
# sta = sta_name.split(".")[2]
eid = self.name_to_eid(sta_name)
sta = eid[2]
logger.info(str(sta))
wpa_cmd = "roam " + str(checker2)
wifi_cli_cmd_data1 = {
"shelf": eid[0],
"resource": eid[1],
"port": str(sta),
"wpa_cli_cmd": 'scan trigger freq 5180 5300'
}
wifi_cli_cmd_data = {
"shelf": eid[0],
"resource": eid[1],
"port": str(sta),
"wpa_cli_cmd": wpa_cmd
}
logger.info(str(wifi_cli_cmd_data))
self.local_realm.json_post("/cli-json/wifi_cli_cmd", wifi_cli_cmd_data1)
self.local_realm.json_post("/cli-json/wifi_cli_cmd", wifi_cli_cmd_data)
# check bssid before
before_bssid = []
for sta_name in sta_list:
sta = sta_name.split(".")[2]
before_bss = self.station_data_query(station_name=str(sta), query="ap")
logger.info(str(before_bss))
before_bssid.append(before_bss)
logger.info("BSSID of the current connected stations : " + str(before_bssid))
if before_bssid[0] == str(self.c1_bssid.upper()):
post_bssid = self.c2_bssid.upper()
else:
post_bssid = self.c1_bssid.upper()
logger.info(
"After roaming, the stations will connect to " + str(post_bssid) + "the BSSID")
result1 = all(element == before_bssid[0] for element in before_bssid)
if result1:
logger.info("All stations connected to same AP")
for i in before_bssid:
local_row_list = [str(iterations + 1), i]
logger.info(str(local_row_list))
row_list.append(local_row_list)
logger.info(str(row_list))
# if all bssid are equal then do check to which ap it is connected
formated_bssid = before_bssid[0].lower()
station_before = ""
if formated_bssid == self.c1_bssid:
logger.info("Station connected to chamber1 AP")
station_before = formated_bssid
elif formated_bssid == self.c2_bssid:
logger.info("Station connected to chamber 2 AP")
station_before = formated_bssid
logger.info(str(station_before))
# After checking all conditions start roam and start snifffer
logger.info("Starting sniffer")
self.start_sniffer(radio_channel=self.channel, radio=self.sniff_radio,
test_name="roam_" + str(self.sta_type) + "_" + str(
self.option) + "_iteration_" + str(
iterations) + "_", duration=3600)
if self.soft_roam:
ser_num = None
ser_num2 = None
if number == "even":
ser_num = ser_1
ser_num2 = ser_2
logger.info("even " + str(ser_num))
elif number == "odd":
ser_num = ser_2
ser_num2 = ser_1
logger.info("odd " + str(ser_num))
# logic to decrease c2 attenuation till 10 db using 1dbm steps
status = None
logger.info("checking attenuation")
logger.info("ser num " + str(ser_num))
for atten_val2 in range(700, -10, -10):
self.attenuator_modify(int(ser_num), "all", atten_val2)
# TODO: You are changing in 1db increments. So, sleep for only 4 seconds
# should be enough.
logger.info("wait for 4 secs")
# query bssid's of all stations
bssid_check = []
for sta_name in sta_list:
sta = sta_name.split(".")[2]
bssid = self.station_data_query(station_name=str(sta), query="ap")
# if bssid == "NA":
# time.sleep(10)
bssid_check.append(bssid)
logger.info(str(bssid_check))
# check if all are equal
resulta = all(element == bssid_check[0] for element in bssid_check)
if resulta:
station_after = bssid_check[0].lower()
if station_after == "N/A" or station_after == "na":
status = "station did not roamed"
logger.info("station did not roamed")
continue
if station_after == station_before:
status = "station did not roamed"
logger.info("station did not roamed")
continue
elif station_after != station_before:
logger.info("client performed roam")
break
if status == "station did not roamed":
# set c1 to high
for atten_val1 in (range(0, 700, 10)):
logger.info(str(atten_val1))
self.attenuator_modify(int(ser_num2), "all", atten_val1)
# TODO: You are changing in 1db increments. So, sleep for only 4 seconds
# should be enough.
# TODO: Add attenuation step to logs to make it more obvious what script is doing.
logger.info("wait for 4 secs")
bssid_check2 = []
for sta_name in sta_list:
sta = sta_name.split(".")[2]
bssid = self.station_data_query(station_name=str(sta),
query="ap")
# if bssid == "NA":
# time.sleep(10)
bssid_check2.append(bssid)
logger.info(str(bssid_check2))