Repository navigation
Expand file tree
/
Copy pathlf_mixed_traffic.py
More file actions
executable file
·3761 lines (3506 loc) · 220 KB
/
Copy pathlf_mixed_traffic.py
File metadata and controls
executable file
·3761 lines (3506 loc) · 220 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_mixed_traffic.py
PURPOSE:
Mixed traffic test is designed to measure the access point performance and stability by running multiple traffic
on both virtual & real clients like Android, Linux, Windows, and IOS connected to the access point.
This test allows the user to choose multiple types of traffic like client ping test, qos test, ftp test, http test,
multicast test multicast test and run tests both serially and simultaneously.
EXAMPLE:
# CLI for Mixed Traffic Test: Run with Real Clients without connecting to a specified SSID
python3 lf_mixed_traffic.py --mgr 192.168.212.100 --tests 1 2 3 4 5 --target 10.0.0.10 --ping_interval 5 --upstream_port 1.1.eth1
--side_b_min_bps 3000000 --side_a_min 1000000 --side_b_min 1000000 --traffic_type lf_tcp --tos "VI"
--ftp_file_sizes 10MB --http_file_size 5MB --direction Download --mc_tos "BE" --real --qos_serial --mixed_traffic_loop 1
--ping_test_duration 1m --qos_test_duration 30s --ftp_test_duration 30s --http_test_duration 30s --multicast_test_duration 30s
--pre_cleanup --use_default_config
# CLI for Mixed Traffic Test: Run with Real Clients with parallel execution of tests
python3 lf_mixed_traffic.py --mgr 192.168.212.100
--twog_ssid NETGEAR-2G --twog_passwd Password@123 --twog_security wpa2 --twog_radio wiphy0 --twog_num_stations 5
--fiveg_ssid NETGEAR-5G --fiveg_passwd Password@123 --fiveg_security wpa2 --fiveg_radio wiphy1 --fiveg_num_stations 5
--band 2.4G,5G --tests 1 2 3 4 5 --target 10.0.0.10 --ping_interval 5 --upstream_port 1.1.eth1
--side_b_min_bps 3000000 --side_a_min 1000000 --side_b_min 1000000 --traffic_type lf_tcp --tos "VI"
--ftp_file_sizes 10MB --http_file_size 5MB --direction Download --mc_tos "BE" --real --mixed_traffic_loop 1
--ping_test_duration 1m --qos_test_duration 30s --ftp_test_duration 30s --http_test_duration 30s --multicast_test_duration 30s
--pre_cleanup --parallel --test_duration 1m
# CLI for Mixed Traffic Test: Run with Real Clients on 2.4GHz & 5GHz Bands, Single Iteration per Band.
python3 lf_mixed_traffic.py --mgr 192.168.212.100
--twog_ssid NETGEAR-2G --twog_passwd Password@123 --twog_security wpa2 --twog_radio wiphy0 --twog_num_stations 5
--fiveg_ssid NETGEAR-5G --fiveg_passwd Password@123 --fiveg_security wpa2 --fiveg_radio wiphy1 --fiveg_num_stations 5
--band 2.4G,5G --tests 1 2 3 4 5 --target 10.0.0.10 --ping_interval 5 --upstream_port 1.1.eth1
--side_b_min_bps 3000000 --side_a_min 1000000 --side_b_min 1000000 --traffic_type lf_tcp --tos "VI"
--ftp_file_sizes 10MB --http_file_size 5MB --direction Download --mc_tos "BE" --real --qos_serial --mixed_traffic_loop 1
--ping_test_duration 1m --qos_test_duration 30s --ftp_test_duration 30s --http_test_duration 30s --multicast_test_duration 30s
--pre_cleanup
# CLI for Mixed Traffic Test: Run on 2.4GHz & 5GHz Bands Simultaneously with Real Clients in a Single Iteration.
python3 lf_mixed_traffic.py --mgr 192.168.212.100
--twog_ssid NETGEAR-2G --twog_passwd Password@123 --twog_security wpa2 --twog_radio wiphy0 --twog_num_stations 5
--fiveg_ssid NETGEAR-5G --fiveg_passwd Password@123 --fiveg_security wpa2 --fiveg_radio wiphy1 --fiveg_num_stations 5
--band 2.4G,5G --tests 1 2 3 4 5 --target 10.0.0.10 --ping_interval 5 --upstream_port 1.1.eth1
--side_b_min_bps 3000000 --side_a_min 1000000 --side_b_min 1000000 --traffic_type lf_tcp --tos "VI"
--ftp_file_sizes 10MB --http_file_size 5MB --direction Download --mc_tos "BE" --real --qos_serial --mixed_traffic_loop 1
--ping_test_duration 1m --qos_test_duration 30s --ftp_test_duration 30s --http_test_duration 30s --multicast_test_duration 30s
--all_bands --pre_cleanup
# CLI for Mixed Traffic Test: Run with Virtual Clients on 2.4GHz & 5GHz Bands, Single Iteration per Band.
python3 lf_mixed_traffic.py --mgr 192.168.212.100
--twog_ssid NETGEAR-2G --twog_passwd Password@123 --twog_security wpa2 --twog_radio wiphy0 --twog_num_stations 5
--fiveg_ssid NETGEAR-5G --fiveg_passwd Password@123 --fiveg_security wpa2 --fiveg_radio wiphy1 --fiveg_num_stations 5
--band 2.4G,5G --tests 1 2 3 4 5 --target 10.0.0.10 --ping_interval 5 --upstream_port 1.1.eth1
--side_b_min_bps 3000000 --side_a_min 1000000 --side_b_min 1000000 --traffic_type lf_tcp --tos "VI"
--ftp_file_sizes 10MB --http_file_size 5MB --direction Download --mc_tos "BE" --virtual --qos_serial --mixed_traffic_loop 1
--ping_test_duration 1m --qos_test_duration 30s --ftp_test_duration 30s --http_test_duration 30s --multicast_test_duration 30s
--pre_cleanup
# CLI for Mixed Traffic Test: Run on 2.4GHz & 5GHz Bands Simultaneously with Virtual Clients in a Single Iteration.
python3 lf_mixed_traffic.py --mgr 192.168.212.100
--twog_ssid NETGEAR-2G --twog_passwd Password@123 --twog_security wpa2 --twog_radio wiphy0 --twog_num_stations 5
--fiveg_ssid NETGEAR-5G --fiveg_passwd Password@123 --fiveg_security wpa2 --fiveg_radio wiphy1 --fiveg_num_stations 5
--band 2.4G,5G --tests 1 2 3 4 5 --target 10.0.0.10 --ping_interval 5 --upstream_port 1.1.eth1
--side_b_min_bps 3000000 --side_a_min 1000000 --side_b_min 1000000 --traffic_type lf_tcp --tos "VI"
--ftp_file_sizes 10MB --http_file_size 5MB --direction Download --mc_tos "BE" --virtual --qos_serial --mixed_traffic_loop 1
--ping_test_duration 1m --qos_test_duration 30s --ftp_test_duration 30s --http_test_duration 30s --multicast_test_duration 30s
--all_bands --pre_cleanup
# Command Line Interface to run the Test along with IOT without device list (Series)
python3 lf_mixed_traffic.py --mgr 192.168.207.78 --upstream_port eth1 --test_name mixedtraffic --mixed_traffic_loop 1
--real --use_default_config --pre_cleanup --target www.google.com --ping_interval 5 --ping_test_duration 1m --side_a_min 0
--side_b_min 10000000 --traffic_type lf_tcp --tos VO,VI,BE,BK --qos_test_duration 1m --tests 1 2 --iot_test --iot_ip 127.0.0.1
--iot_port 8000 --iot_iterations 1 --iot_delay 5 --iot_testname "mixedtraffic_iot"
# Command Line Interface to run the Test along with IOT with device list (Parallel)
python3 lf_mixed_traffic.py --mgr 192.168.207.78 --upstream_port eth1 --device_list 1.20 --test_name mixedtraffics --mixed_traffic_loop 1
--real --use_default_config --pre_cleanup --parallel --test_duration 1m --target www.google.com --ping_interval 5 --side_a_min 0
--side_b_min 10000000 --traffic_type lf_tcp --tos VO,VI,BE,BK --ftp_file_sizes 5MB --direction Download --tests 1 2 3
--iot_test --iot_ip 127.0.0.1 --iot_port 8000 --iot_iterations 1 --iot_delay 5 --iot_device_list "switch.smart_plug_1_socket_1"
--iot_testname "mixedtraffics_iot_parallel"
SCRIPT_CLASSIFICATION: Multiples Tests, Creation, Report Generation (Both individual & Overall)
SCRIPT_CATEGORIES: Performance, Functional
NOTES:
The primary goal of the script is to execute a series of tests and group their individual test reports into a unified report.
STATUS: Functional
VERIFIED_ON: 02-May-2024
GUI Version: 5.4.8
Build Date : Sun Apr 21 01:42:42 PM PDT 2024
Kernel Version: 6.2.16+
LICENSE:
Free to distribute and modify. LANforge systems must be licensed.
Copyright (C) 2020-2026 Candela Technologies Inc
INCLUDE_IN_README: False
"""
import argparse
import asyncio
import importlib
import json
import logging
import platform
import sys
import os
import requests
import time
import datetime
import pandas as pd
from multiprocessing import Process, Pipe
import shutil
import threading
from collections import OrderedDict
# import traceback
if sys.version_info[0] != 3:
print("This script requires Python3")
exit(0)
sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../")))
realm = importlib.import_module("py-json.realm")
LFCliBase = realm.LFCliBase
Realm = realm.Realm
lf_kpi_csv = importlib.import_module("py-scripts.lf_kpi_csv")
lf_graph = importlib.import_module("py-scripts.lf_graph")
lf_report_pdf = importlib.import_module("py-scripts.lf_report")
lf_cleanup = importlib.import_module("py-scripts.lf_cleanup")
LFUtils = importlib.import_module("py-json.LANforge.LFUtils")
lf_logger_config = importlib.import_module("py-scripts.lf_logger_config")
lf_base_interop_profile = importlib.import_module("py-scripts.lf_base_interop_profile")
# importing scripts
ping_test = importlib.import_module("py-scripts.lf_interop_ping")
qos_test = importlib.import_module("py-scripts.lf_interop_qos")
qos_test_virtual = importlib.import_module("py-scripts.throughput_qos")
ftp_test = importlib.import_module("py-scripts.lf_ftp")
http_test = importlib.import_module("py-scripts.lf_webpage")
multicast_test = importlib.import_module("py-scripts.test_l3")
logger = logging.getLogger(__name__)
iot_scripts_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../local/interop-webGUI/IoT/scripts/"))
if os.path.exists(iot_scripts_path):
sys.path.insert(0, iot_scripts_path)
from test_automation import Automation # noqa: E402
class Mixed_Traffic(Realm):
def __init__(self,
host="",
port=8080,
lf_username="",
lf_password="",
real_client=False,
virtual_client=True,
selected_test_list="",
server_ip="",
ssid="",
passwd="",
security="",
twog_ssid="",
fiveg_ssid="",
sixg_ssid="",
twog_password="",
fiveg_password="",
sixg_password="",
twog_security="",
fiveg_security="",
sixg_security="",
twog_radio='',
fiveg_radio='',
sixg_radio='',
twog_mode='',
fiveg_mode='',
sixg_mode='',
twog_num_stations='',
fiveg_num_stations='',
sixg_num_stations='',
twog_start_id='',
fiveg_start_id='',
sixg_start_id='',
selected_bands="",
band="",
mode="",
# radio="",
number_template="0000",
# sta_list="",
num_stations=0,
upstream_port="",
qos_tos_list="",
dut_model="",
dut_firmware="",
test_duration="",
ping_test_duration="",
qos_test_duration="",
ftp_test_duration="",
http_test_duration="",
multicast_test_duration="",
qos_serial=False,
path='',
configure=True,
parallel=False,
target='192.168.1.3',
multicast_endp_types=None,
multicast_tos=None,
# for webui
dowebgui=False,
result_dir=None,
test_name=None,
device_list=None,
get_live_view: bool = False,
total_floors: int = 0,
debug=False):
super().__init__(lfclient_host=host,
lfclient_port=port)
self.report_path = None
self.lf_report_mt = None
self.test_duration1 = None
self.station_lists = []
self.wifi_mode_list = []
self.ssid_security_list = []
self.ssid_password_list = []
self.ssid_list = []
self.num_sta_per_radio_list = []
self.radio_name_list = []
self.mc_tos = None
self.endp_types = None
self.dataset2 = None
self.dataset = None
self.lis = []
self.data = {}
self.ping_test_obj = None
self.ftp_test_obj = None
self.http_obj = None
self.multicast_test_obj = None
self.interval = ""
self.target = ""
self.eid_list = []
self.windows_eids = []
self.windows_ports = []
self.hw_list = []
self.windows_list = []
self.linux_list = []
self.mac_list = []
self.android_list = []
self.user_query = []
# self.available_device_list = []
self.res = None
self.load = None
self.data_set = None
self.debug = debug
self.host = host
self.port = port
self.lf_username = lf_username
self.lf_password = lf_password
self.real = real_client
self.virtual = virtual_client
self.tests = selected_test_list
self.ssid = ssid
self.passwd = passwd
self.security = security
self.configure = configure
self.server_ip = server_ip
self.ssid_2g = twog_ssid
self.ssid_5g = fiveg_ssid
self.ssid_6g = sixg_ssid
self.passwd_2g = twog_password
self.passwd_5g = fiveg_password
self.passwd_6g = sixg_password
self.security_2g = twog_security
self.security_5g = fiveg_security
self.security_6g = sixg_security
self.radio_2g = twog_radio
self.radio_5g = fiveg_radio
self.radio_6g = sixg_radio
self.mode_2g = twog_mode
self.mode_5g = fiveg_mode
self.mode_6g = sixg_mode
self.num_stations_2g = twog_num_stations
self.num_stations_5g = fiveg_num_stations
self.num_stations_6g = sixg_num_stations
self.start_id_2g = twog_start_id
self.start_id_5g = fiveg_start_id
self.start_id_6g = sixg_start_id
self.selected_bands = selected_bands
self.band = ''
self.mode = mode
# self.radio = radio
self.number_template = number_template
self.station_list = []
self.num_staions = num_stations
self.upstream_port = upstream_port
self.dut_model = dut_model
self.dut_firmware = dut_firmware
self.test_duration = test_duration
self.ping_test_duration = ping_test_duration
self.qos_test_duration = qos_test_duration
self.ftp_test_duration = ftp_test_duration
self.http_test_duration = http_test_duration
self.multicast_test_duration = multicast_test_duration
self.path = path
self.station_profile = self.new_station_profile()
self.generic_endps_profile = self.new_generic_endp_profile()
self.station_profile.lfclient_url = self.lfclient_url
self.station_profile.ssid = self.ssid
self.station_profile.ssid_pass = self.passwd,
self.station_profile.security = self.security
self.station_profile.number_template_ = self.number_template
self.station_profile.mode = self.mode
# parallel test script status
self.ping_test_status = False
self.qos_test_status = False
self.ftp_test_status = False
self.http_test_status = False
self.multicast_test_status = False
self.qos_tos_list = qos_tos_list.split(',')
self.qos_serial_run = qos_serial
self.parallel = parallel
self.target = target
self.multicast_endp_types = multicast_endp_types
self.multicast_tos = multicast_tos
# for webui
self.dowebgui = dowebgui
self.device_list = device_list
self.result_dir = result_dir
self.test_name = test_name
self.api_url = 'http://{}:{}'.format(self.host, self.port)
self.ftp_device = []
self.http_dev = []
self.http_mac = []
self.rx_rate = []
self.get_live_view = get_live_view
self.total_floors = total_floors
if self.dowebgui:
self.stopped = False
self.ping_execution = False
self.qos_execution = False
self.ftp_execution = False
self.http_execution = False
self.mc_execution = False
# Base Profile obj
self.base_interop_profile = lf_base_interop_profile.RealDevice(manager_ip=self.host,
server_ip=self.server_ip,
ssid_2g=self.ssid_2g,
passwd_2g=self.passwd_2g,
encryption_2g=self.security_2g,
ssid_5g=self.ssid_5g,
passwd_5g=self.passwd_5g,
encryption_5g=self.security_5g,
ssid_6g=self.ssid_6g,
passwd_6g=self.passwd_6g,
encryption_6g=self.security_6g,
selected_bands=self.selected_bands)
# LF Cleanup obj
self.cleanup = lf_cleanup.lf_clean(host=self.host, port=self.port, resource='all')
# sorting out the test duration for each test
duration_suffixes = {'s': 1, 'S': 1, 'm': 60, 'M': 60, 'h': 3600, 'H': 3600}
if self.parallel:
if self.test_duration.endswith(tuple(duration_suffixes.keys())):
self.test_duration_suffix = self.test_duration[-1]
multiplier = duration_suffixes[self.test_duration_suffix]
self.test_duration = int(self.test_duration[:-1]) * multiplier
else:
self.test_duration = int(self.test_duration)
self.total_all_test_duration = self.test_duration
self.time_formate = self.format_duration_hms(self.total_all_test_duration)
else:
if self.test_duration:
if self.test_duration.endswith(tuple(duration_suffixes.keys())):
self.test_duration_suffix = self.test_duration[-1]
multiplier = duration_suffixes[self.test_duration_suffix]
self.test_duration = int(self.test_duration[:-1]) * multiplier
else:
self.test_duration = int(self.test_duration)
# Setting overall time formatting for report
if self.qos_serial_run:
self.total_all_test_duration = int(self.test_duration * (len(self.tests) - 1 + len(self.qos_tos_list)))
else:
self.total_all_test_duration = int(self.test_duration * len(self.tests))
self.time_formate = self.format_duration_hms(self.total_all_test_duration)
elif self.ping_test_duration or self.qos_test_duration or self.ftp_test_duration or self.http_test_duration or self.multicast_test_duration:
if self.ping_test_duration.endswith(tuple(duration_suffixes.keys())) or self.qos_test_duration.endswith(
tuple(duration_suffixes.keys())) or self.ftp_test_duration.endswith(
tuple(duration_suffixes.keys())) or self.http_test_duration.endswith(
tuple(duration_suffixes.keys())) or self.multicast_test_duration.endswith(
tuple(duration_suffixes.keys())):
# ping test duration
self.ping_test_duration_suffix = self.ping_test_duration[-1]
multiplier = duration_suffixes[self.ping_test_duration_suffix]
self.ping_test_duration = int(self.ping_test_duration[:-1]) * multiplier
# qos test duration
self.qos_test_duration_suffix = self.qos_test_duration[-1]
multiplier = duration_suffixes[self.qos_test_duration_suffix]
self.qos_test_duration = int(self.qos_test_duration[:-1]) * multiplier
# ftp test duration
self.ftp_test_duration_suffix = self.ftp_test_duration[-1]
multiplier = duration_suffixes[self.ftp_test_duration_suffix]
self.ftp_test_duration = int(self.ftp_test_duration[:-1]) * multiplier
# http test duration
self.http_test_duration_suffix = self.http_test_duration[-1]
multiplier = duration_suffixes[self.http_test_duration_suffix]
self.http_test_duration = int(self.http_test_duration[:-1]) * multiplier
# multicast test duration
self.multicast_test_duration_suffix = self.multicast_test_duration[-1]
multiplier = duration_suffixes[self.multicast_test_duration_suffix]
self.multicast_test_duration = int(self.multicast_test_duration[:-1]) * multiplier
else:
logger.error("Mixed traffic run requires a duration for at least one test scenario")
duration_by_test = {
'1': self.ping_test_duration,
'2': self.qos_test_duration * len(self.qos_tos_list) if self.qos_serial_run else self.qos_test_duration,
'3': self.ftp_test_duration,
'4': self.http_test_duration,
'5': self.multicast_test_duration,
}
self.total_all_test_duration = int(sum(duration_by_test[test_option] for test_option in self.tests))
self.time_formate = self.format_duration_hms(self.total_all_test_duration)
def report_obj(self, band, path):
if band is None:
band = 'all'
self.lf_report_mt = lf_report_pdf.lf_report(_output_pdf=f"mixed_traffic_test_{band}.pdf",
_output_html=f"mixed_traffic_test_{band}.html",
_path=path,
_results_dir_name=f"Mixed_Traffic_Test_Report_{band}")
self.report_path = self.lf_report_mt.get_path_date_time()
def pre_cleanup(self): # cleaning pre-existing stations and cross connections
if not self.real:
self.cleanup.sta_clean()
generic_url = '/generic?fields=name'
resp = self.json_get(generic_url)
if not resp:
logger.error("Failed to fetch generic endpoints for cleanup.\nRequested URL: '{}'\nResponse: {}".format(generic_url, resp))
endpoints = []
else:
endpoints = resp.get('endpoints', resp.get('endpoint', []))
if isinstance(endpoints, dict):
endpoints = [{endpoints['name']: endpoints}]
for i in endpoints:
if list(i.values())[0]['name']:
self.generic_endps_profile.created_cx.append('CX_' + list(i.values())[0]['name'])
self.generic_endps_profile.created_endp.append(list(i.values())[0]['name'])
self.generic_endps_profile.cleanup()
self.cleanup.cxs_clean()
self.cleanup.layer3_endp_clean()
self.cleanup.layer4_endp_clean()
def api_get(self, endp: str):
"""
Sends a GET request to fetch data
Args:
endp (str): API endpoint
Returns:
response: response code for the request
data: data returned in the response
"""
if endp[0] != '/':
endp = '/' + endp
response = requests.get(url=self.api_url + endp)
data = response.json()
return response, data
# function to exclude iOS devices
def filter_iOS_devices(self, device_list, rc_list, mac_list):
modified_device_list = device_list
if isinstance(device_list, str):
modified_device_list = device_list.split(',')
filtered_list = []
real_list = []
selected_macs = dict(zip(modified_device_list, mac_list))
for device in modified_device_list:
if device.count('.') == 1:
shelf, resource = device.split('.')
elif device.count('.') == 2:
shelf, resource, port = device.split('.')
elif device.count('.') == 0:
shelf, resource = 1, device
response_code, device_data = self.api_get('/resource/{}/{}'.format(shelf, resource))
if 'status' in device_data and device_data['status'] == 'NOT_FOUND':
logger.info("Device {} is not found".format(device))
continue
device_data = device_data['resource']
if 'Apple' in device_data['hw version'] and (device_data['app-id'] != '') and (device_data['app-id'] != '0' or device_data['kernel'] == ''):
logger.info("{} is an iOS device and currently we do not support iOS devices".format(device))
else:
filtered_list.append(device)
for j in rc_list:
for one_Dev in filtered_list:
if (j.split(' ')[0] == one_Dev.split('.')[0] + '.' + one_Dev.split('.')[1]):
real_list.append(j)
url = "/port/all"
response_port = self.json_get(url)
if response_port is None:
logger.error(
"Failed to fetch port data. Received empty response.\n"
f"Requested URL: '{url}'\n"
f"Response: {response_port}")
response_port = {}
mac_by_port = {}
for interface in response_port.get('interfaces', []):
for port, port_data in interface.items():
if port in filtered_list:
mac_by_port[port] = port_data['mac']
# Keep MACs in the selected device order, independent of API response order.
# Retain the selected MAC if a port disappears while the test is running.
mac_lists = [mac_by_port.get(device, selected_macs.get(device, 'NA'))
for device in filtered_list]
if isinstance(device_list, str):
filtered_list = ','.join(filtered_list)
self.device_list = filtered_list
return filtered_list, real_list, mac_lists
def virtual_client_creation(self, ssid, password, security, band, radio, num_stations, start_id, all_sta=False):
start_id = start_id
station_list = []
if start_id != 0:
start_id = int(start_id)
if (num_stations is not None) and (int(num_stations) > 0):
num_stations_converted = int(num_stations)
num_sta = num_stations_converted
station_list = LFUtils.port_name_series(prefix="sta",
start_id=start_id,
end_id=start_id + num_sta - 1,
padding_number=10000,
radio=radio)
# updating num stations and station list
if not all_sta:
self.station_list = station_list
self.num_staions = num_stations
self.radio = radio
logger.info("List of virtual stations for {band} : {station_list}".format(band=band, station_list=station_list))
if "2.4G" in band:
self.station_profile.mode = 13
elif "5G" in band:
self.station_profile.mode = 14
elif "6G" in band:
self.station_profile.mode = 15
# station build
self.station_profile.use_security(security, ssid, password)
self.station_profile.set_number_template("00")
logger.info("Creating virtual stations")
self.station_profile.set_command_flag("add_sta", "create_admin_down", 1)
self.station_profile.set_command_param("set_port", "report_timer", 1500)
self.station_profile.set_command_flag("set_port", "rpt_timer", 1)
if self.station_profile.create(radio=radio, sta_names_=station_list, debug=self.debug):
self._pass("Stations created successfully")
else:
self._fail("Stations not properly created")
self.station_profile.admin_up()
logger.info("Waiting for all station ports to come up (timeout: 300 seconds)")
if not LFUtils.wait_until_ports_admin_up(base_url=self.lfclient_url,
port_list=station_list,
debug_=self.debug):
self._fail("Unable to bring all stations up")
return
logger.info("Waiting for all stations to obtain IP addresses")
if Realm.wait_for_ip(self=self, station_list=station_list, 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("Station build failed", print_=True)
logger.error("Please re-check the configuration applied")
return station_list
def format_duration_hms(self, total_seconds):
hours, remainder = divmod(int(total_seconds), 3600)
minutes, seconds = divmod(remainder, 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"
def convert_seconds(self, seconds):
if seconds < 60:
return f"{seconds} sec"
elif 60 <= seconds < 3600:
minutes = seconds / 60
if minutes == 1.0:
return f"{str(round(abs(minutes), 1))} minute"
else:
return f"{str(round(abs(minutes), 1))} minutes"
else:
hours = seconds / 3600
if hours == 1.0:
return f"{str(round(abs(hours), 1))} hour"
else:
return f"{str(round(abs(hours), 1))} hours"
def selecting_devices_from_available(self):
selected_serial_list = self.base_interop_profile.query_all_devices_to_configure_wifi()
logger.info("Selected device list: {}".format(selected_serial_list))
return selected_serial_list
def select_real_devices(self, real_devices, real_sta_list=None, base_interop_obj=None):
self.real_sta_data_dict = {}
if real_sta_list is None:
if self.dowebgui:
self.user_query = real_devices.query_user(dowebgui=self.dowebgui, device_list=self.device_list)
self.real_sta_list = self.user_query[0]
else:
# Set flag=1 to include iOS devices in the DataFrame when capturing user input
self.user_query = real_devices.query_user(flag=1)
self.real_sta_list = self.user_query[0]
# fetching window's list
for port in self.user_query[0]:
if 'wlan0' not in port:
port = port + '.wlan0'
eid = self.name_to_eid(port)
self.eid_list.append(str(eid[0]) + '.' + str(eid[1]))
for eid in self.eid_list:
for device in self.user_query[1]:
if ("Win" in device) and (eid + ' ' in device):
self.windows_eids.append(eid)
for eid in self.windows_eids:
for port in self.user_query[0]:
if eid + '.' in port:
self.windows_ports.append(port)
else:
self.real_sta_list = real_sta_list
if base_interop_obj is not None:
self.base_interop_profile = base_interop_obj
# Need real stations to run interop test
if (len(self.real_sta_list) == 0):
logger.error("The test cannot proceed because the testbed contains no real devices")
exit(0)
logging.info("Real Station List: {}".format(*self.real_sta_list))
for sta_name in self.real_sta_list:
if sta_name not in real_devices.devices_data:
logger.error("Real station not in devices data")
raise ValueError('Real station not in devices data')
self.real_sta_data_dict[sta_name] = real_devices.devices_data[sta_name]
# Track number of selected devices
self.android = self.base_interop_profile.android
self.windows = self.base_interop_profile.windows
self.mac = self.base_interop_profile.mac
self.linux = self.base_interop_profile.linux
def real_client_wifi_config(self, selected_serial_list, all_devices=False):
self.user_query = []
logging.info(f"Ready for Connectivity: {selected_serial_list}")
if not all_devices:
self.base_interop_profile.selected_devices = []
self.base_interop_profile.report_labels = []
self.base_interop_profile.selected_macs = []
user_query_list = asyncio.run(self.base_interop_profile.configure_wifi(select_serials=selected_serial_list))
logger.info("Query Result: {}".format(user_query_list))
# removing the postfix name for the
for index, sublist in enumerate(user_query_list):
new_sublist = []
for item in sublist:
if index == 0:
if '.wlan0' not in item and '.wlan1' not in item and '.en0' not in item and '.sta0' not in item:
item += '.wlan0'
elif index == 1:
item = item.replace('.wlan0', '').replace('.en0', '').replace('.sta0', '').replace('wlan1', '')
new_sublist.append(item)
self.user_query.append(new_sublist)
logger.info("UPDATE: Query Result: {}".format(self.user_query))
# fetching window's list
for port in self.user_query[0]:
if 'wlan0' not in port:
port = port + '.wlan0'
eid = self.name_to_eid(port)
self.eid_list.append(str(eid[0]) + '.' + str(eid[1]))
for eid in self.eid_list:
for device in self.user_query[1]:
if ("Win" in device) and (eid + ' ' in device):
self.windows_eids.append(eid)
for eid in self.windows_eids:
for port in self.user_query[0]:
if eid + '.' in port:
self.windows_ports.append(port)
return self.user_query
def ping_test(self, ssid='', password='', security='', target='', interval='', _ping_test=ping_test,
all_bands=False, conn=None):
try:
# setting ping test duration & converting sec into minutes passing it float values for ping test
if self.test_duration:
minutes, seconds = divmod(self.test_duration, 60)
ping_test_duration = float(minutes)
else:
minutes, seconds = divmod(self.ping_test_duration, 60)
ping_test_duration = float(minutes)
self.target = target
self.interval = interval
# starting part of the ping test
self.ping_test_obj = ping_test.Ping(host=self.host, port=self.port, ssid=ssid, security=security,
password=password, lanforge_password="lanforge", target=self.target,
interval=self.interval, sta_list=[], virtual=self.virtual, real=self.real,
duration=ping_test_duration, result_dir=self.result_dir,
dowebgui=self.dowebgui, test_name=self.test_name)
if not self.ping_test_obj.check_tab_exists():
logger.error('Generic Tab is not available for Ping Test. Skipping the Ping Test.')
if (conn):
conn.send(['', False])
return
if self.real:
self.ping_test_obj.select_real_devices(real_devices=self.base_interop_profile,
real_sta_list=self.user_query[0],
base_interop_obj=self.base_interop_profile)
# removing the iOS devices from station list
self.ping_test_obj.real_sta_list, _, _ = self.filter_iOS_devices(self.user_query[0], self.user_query[1], self.user_query[2])
# removing the existing generic endpoints & cxs
if (len(self.ping_test_obj.real_sta_list) == 0):
logger.error("No device available to run the Ping Test. Skipping the Ping Test.")
if (conn):
conn.send(['', False])
return
self.ping_test_obj.cleanup()
self.ping_test_obj.sta_list = self.ping_test_obj.real_sta_list
elif self.virtual:
self.ping_test_obj.sta_list = self.station_list
print('Virtual Stations: {}'.format(self.station_list).replace('[', '').replace(']', '').replace('\'', ''))
self.ping_test_obj.cleanup()
# creating generic endpoints
self.ping_test_obj.create_generic_endp()
logger.info("Generic Cross-Connection List: {}".format(self.ping_test_obj.generic_endps_profile.created_cx))
logger.info("Starting running the Ping Test for {} minutes".format(ping_test_duration))
# start generate endpoint
self.ping_test_obj.start_generic()
time.sleep(10)
if self.dowebgui:
start_time = datetime.datetime.now()
end_time = start_time + datetime.timedelta(seconds=ping_test_duration * 60)
while (datetime.datetime.now() < end_time):
success = self.ping_test_obj.monitor_endp_availability(self.ping_test_obj.generic_endps_profile.created_endp)
if not success:
logger.error('All endpoints are not available. So exiting the monitor early.')
break
temp_json = []
for station in self.ping_test_obj.real_sta_list:
for ping_endp, ping_data in self.ping_test_obj.latest_results.items():
if ping_endp == 'generic-{}'.format(station):
temp_json.append({
'device': station,
'sent': ping_data['tx pkts'],
'recv': ping_data['rx pkts'],
'dropped': ping_data['dropped'],
'status': "Running",
'start_time': start_time.strftime("%d/%m %I:%M:%S %p"),
'end_time': end_time.strftime("%d/%m %I:%M:%S %p"),
"remaining_time": ""
})
df1 = pd.DataFrame(temp_json)
df1.to_csv('{}/ping_datavalues.csv'.format(self.result_dir), index=False)
try:
with open(self.result_dir + "/../../Running_instances/{}_{}_running.json".format(self.host, self.test_name), 'r') as file:
data = json.load(file)
if data["status"] != "Running":
logger.info('Test is stopped by the user')
break
except Exception as e:
logger.info("Error while checking running status during ping execution: {}".format(e))
time.sleep(3)
else:
start_time = time.time()
end_time = start_time + (ping_test_duration * 60)
while time.time() < end_time:
success = self.ping_test_obj.monitor_endp_availability(self.ping_test_obj.generic_endps_profile.created_endp)
if not success:
logger.error('All endpoints are not available. So exiting the monitor early.')
break
time.sleep(3)
logger.info("Stopping the Ping Test")
self.ping_test_obj.stop_generic()
# getting result dict
result_data = self.ping_test_obj.get_results()
result_json = {}
if self.virtual:
ports_url = '/ports/all/'
response = self.ping_test_obj.json_get(ports_url)
if not response:
logger.error("Failed to fetch ports. Received empty response.\nRequested URL: '{}'\nResponse: {}".format(ports_url, response))
raise RuntimeError('Failed to fetch port data from the LANforge.')
if 'interfaces' not in response:
logger.error("'interfaces' key not found in response.\nRequested URL: '{}'\nResponse: {}".format(ports_url, response))
raise RuntimeError('Failed to fetch port data from the LANforge.')
ports_data_dict = response['interfaces']
ports_data = {}
for ports in ports_data_dict:
port, port_data = list(ports.keys())[0], list(ports.values())[0]
ports_data[port] = port_data
for station in self.ping_test_obj.sta_list:
if station not in self.ping_test_obj.real_sta_list:
current_device_data = ports_data[station]
for ping_device in result_data:
ping_endp, ping_data = list(ping_device.keys())[0], list(ping_device.values())[0]
if station.split('.')[2] in ping_endp:
last_result_lines = []
try:
last_result_lines = ping_data['last results'].split('\n') if ping_data['last results'] else []
if len(last_result_lines) > 1:
last_result = last_result_lines[-2]
elif last_result_lines:
last_result = last_result_lines[-1]
else:
last_result = ""
if 'min/avg/max' in last_result:
rtt_values = last_result.split('min/avg/max:', 1)[1].strip().split()[0].split('/')
min_rtt, avg_rtt, max_rtt = self.ping_test_obj.validate_rtt(rtt_values[0], rtt_values[1], rtt_values[2])
else:
min_rtt, avg_rtt, max_rtt = 'NA', 'NA', 'NA'
result_json[station] = {
'command': ping_data['command'],
'sent': ping_data['tx pkts'],
'recv': ping_data['rx pkts'],
'dropped': ping_data['dropped'],
'min_rtt': min_rtt,
'avg_rtt': avg_rtt,
'max_rtt': max_rtt,
'mac': current_device_data['mac'],
'ssid': current_device_data['ssid'],
'channel': current_device_data['channel'],
'mode': current_device_data['mode'],
'name': station,
'os': 'Virtual',
'remarks': [],
'last_result': last_result}
result_json[station]['remarks'] = self.ping_test_obj.generate_remarks(result_json[station])
except Exception as error:
logger.error(
"Failed parsing the result for station %s. Error: %s\nLast result lines: %s",
station, error, last_result_lines)
if self.real:
for station in self.ping_test_obj.real_sta_list:
current_device_data = self.base_interop_profile.devices_data[station]
for ping_device in result_data:
ping_endp, ping_data = list(ping_device.keys())[0], list(ping_device.values())[0]
if station in ping_endp:
last_result_lines = []
try:
last_result_lines = ping_data['last results'].split('\n') if ping_data['last results'] else []
if len(last_result_lines) > 1:
last_result = last_result_lines[-2]
elif last_result_lines:
last_result = last_result_lines[-1]
else:
last_result = ""
if 'min/avg/max' in last_result:
rtt_values = last_result.split('min/avg/max:', 1)[1].strip().split()[0].split('/')
min_rtt, avg_rtt, max_rtt = self.ping_test_obj.validate_rtt(rtt_values[0], rtt_values[1], rtt_values[2])
else:
min_rtt, avg_rtt, max_rtt = 'NA', 'NA', 'NA'
result_json[station] = {
'command': ping_data['command'],
'sent': ping_data['tx pkts'],
'recv': ping_data['rx pkts'],
'dropped': ping_data['dropped'],
'min_rtt': min_rtt,
'avg_rtt': avg_rtt,
'max_rtt': max_rtt,
'mac': current_device_data['mac'],
'ssid': current_device_data['ssid'],
'channel': current_device_data['channel'],
'mode': current_device_data['mode'],
'name': [current_device_data['user'] if current_device_data['user'] != '' else current_device_data['hostname']][0],
'os': ['Windows' if 'Win' in current_device_data['hw version'] else 'Linux' if 'Linux' in current_device_data['hw version'] else 'Mac' if 'Apple' in current_device_data['hw version'] else 'Android'][0], # noqa: E501
'remarks': [],
'last_result': last_result}
result_json[station]['remarks'] = self.ping_test_obj.generate_remarks(result_json[station])
except Exception as error:
logger.error(
"Failed parsing the result for station %s. Error: %s\nLast result lines: %s",
station, error, last_result_lines)
if self.dowebgui:
temp_json = []
for station in result_json:
logging.debug('{} {}'.format(station, result_json[station]))
temp_json.append({'device': station,
'sent': result_json[station]['sent'],
'recv': result_json[station]['recv'],
'dropped': result_json[station]['dropped'],
'status': "Stopped",
'start_time': start_time.strftime("%d/%m %I:%M:%S %p"),
'end_time': end_time.strftime("%d/%m %I:%M:%S %p"),
"remaining_time": ""})
df1 = pd.DataFrame(temp_json)
df1.to_csv('{}/ping_datavalues.csv'.format(self.result_dir), index=False)
else:
logger.info("Final Result Json For Ping Test: {}".format(result_json))
if all_bands:
band = ''
else:
band = '_' + self.band
self.ping_test_obj.generate_report(result_json=result_json, result_dir=f'Ping_Test_Report{band}',
report_path=self.report_path)
# post cleanup this test's own generic endpoints only
self.ping_test_obj.generic_endps_profile.cleanup()
self.ping_test_status = True
if (conn):
conn.send([self.ping_test_obj, True])
except Exception as e:
# traceback.print_exc()
logging.exception(e)
if (conn):
conn.send(['', False])
def qos_test(self, ssid, password, security, ap_name, upstream, tos, traffic_type, side_a_min=0, side_b_min=0,
side_a_max=0, side_b_max=0, _qos_test=qos_test, _qos_test_virtual=qos_test_virtual, all_bands=False, conn=None):
try:
if self.test_duration:
self.qos_test_duration = self.test_duration
test_results = {'test_results': []}
# qos test for real clients
def qos_test_overall_real(qos_tos_real=None):
self.qos_test_obj = qos_test.ThroughputQOS(host=self.host,
port=self.port,
number_template="0000",
ap_name=ap_name,
name_prefix="TOS-",
tos=qos_tos_real if self.qos_serial_run else tos,
ssid=ssid,
password=password,
security=security,
upstream=upstream,
test_duration=self.qos_test_duration,
use_ht160=False,
side_a_min_rate=int(side_a_min),
side_b_min_rate=int(side_b_min),
side_a_max_rate=int(side_a_max),
side_b_max_rate=int(side_b_max),
traffic_type=traffic_type,
dowebgui="True" if self.dowebgui else "False",
test_name=self.test_name,
result_dir=self.result_dir,
ip=self.host,
_debug_on=False)
self.qos_test_obj.input_devices_list = self.user_query[0]
self.qos_test_obj.real_client_list = self.user_query[1]
self.qos_test_obj.real_client_list1 = self.user_query[1]
self.qos_test_obj.mac_id_list = self.user_query[2]
self.qos_test_obj.build()
if self.real:
self.qos_test_obj.monitor_cx()
self.qos_test_obj.start()
self.qos_test_obj.connections_download_avg = []
self.qos_test_obj.connections_upload_avg = []
self.qos_test_obj.avg_drop_a = []
self.qos_test_obj.avg_drop_b = []
time.sleep(10)
connections_download, connections_upload, drop_a_per, drop_b_per = {}, {}, [], []
try: