-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathlf_ftp.py
More file actions
executable file
·3728 lines (3369 loc) · 181 KB
/
lf_ftp.py
File metadata and controls
executable file
·3728 lines (3369 loc) · 181 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_ftp.py
PURPOSE:
lf_ftp.py will verify that N clients are connected on a specified band and can simultaneously download/upload
some amount of file data from the FTP server while measuring the time taken by clients to download/upload the file.
EXAMPLE-1:
Command Line Interface to run download scenario for Real clients
python3 lf_ftp.py --ssid Netgear-5g --passwd sharedsecret --file_sizes 10MB --mgr 192.168.200.165 --traffic_duration 1m
--security wpa2 --directions Download --clients_type Real --ap_name Netgear --bands 5G --upstream_port eth1
EXAMPLE-2:
Command Line Interface to run upload scenario on 6GHz band for Virtual clients
python3 lf_ftp.py --ssid Netgear-6g --passwd sharedsecret --file_sizes 10MB --mgr 192.168.200.165 --traffic_duration 1m
--security wpa3 --fiveg_radio wiphy2 --directions Upload --clients_type Virtual --ap_name Netgear --bands 6G --num_stations 2
--upstream_port eth1
EXAMPLE-3:
Command Line Interface to run download scenario on 5GHz band for Virtual clients
python3 lf_ftp.py --ssid Netgear-5g --passwd sharedsecret --file_sizes 10MB --mgr 192.168.200.165 --traffic_duration 1m
--security wpa2 --fiveg_radio wiphy2 --directions Download --clients_type Virtual --ap_name Netgear --bands 5G --num_stations 2
--upstream_port eth1
EXAMPLE-4:
Command Line Interface to run upload scenario for Real clients
python3 lf_ftp.py --ssid Netgear-2g --passwd sharedsecret --file_sizes 10MB --mgr 192.168.200.165 --traffic_duration 1m
--security wpa2 --directions Download --clients_type Real --ap_name Netgear --bands 2.4G --upstream_port eth1
EXAMPLE-5:
Command Line Interface to run upload scenario on 2.4GHz band for Virtual clients
python3 lf_ftp.py --ssid Netgear-2g --passwd sharedsecret --file_sizes 10MB --mgr 192.168.200.165 --traffic_duration 1m
--security wpa2 --twog_radio wiphy1 --directions Upload --clients_type Virtual --ap_name Netgear --bands 2.4G --num_stations 2
--upstream_port eth1
EXAMPLE-6:
Command Line Interface to run download scenario for Real clients with device list
python3 lf_ftp.py --ssid Netgear-2g --passwd sharedsecret --file_sizes 10MB --mgr 192.168.214.219 --traffic_duration 1m --security wpa2
--directions Download --clients_type Real --ap_name Netgear --bands 2.4G --upstream_port eth1 --device_list 1.12,1.22
EXAMPLE-7:
Command Line Interface to run download scenario by setting the same expected Pass/Fail value for all devices
python3 lf_ftp.py --file_sizes 1MB --mgr 192.168.213.218 --traffic_duration 1m --directions Download --clients_type Real --bands 5G
--upstream_port eth1 --expected_passfail_value 4
EXAMPLE-8:
Command Line Interface to run download scenario by setting device specific Pass/Fail values in the csv file
python3 lf_ftp.py --file_sizes 1MB --mgr 192.168.204.74 --traffic_duration 1m --directions Download --clients_type Real --bands 5G
--upstream_port eth1 --device_csv_name device.csv
EXAMPLE-9:
Command Line Interface to run download scenario by Configuring Real Devices with SSID, Password, and Security
python3 lf_ftp.py --file_sizes 1MB --mgr 192.168.213.218 --traffic_duration 1m --directions Download --clients_type Real --bands 5G
--upstream_port eth1 --ssid NETGEAR_5G --passwd Password@123 --security wpa2 --config
EXAMPLE-10:
Command Line Interface to run download scenario by setting the same expected Pass/Fail value for all devices with configuration
python3 lf_ftp.py --file_sizes 1MB --mgr 192.168.213.218 --traffic_duration 1m --directions Download --clients_type Real --bands 5G
--upstream_port eth1 --ssid NETGEAR_2G --passwd Password@123 --security wpa2 --expected_passfail_value 4 --config
EXAMPLE-11:
Command Line Interface to run download scenario by setting device specific Pass/Fail values in the csv file without configuration
python3 lf_ftp.py --file_sizes 1MB --mgr 192.168.213.218 --traffic_duration 1m --directions Download --clients_type Real --bands 5G
--upstream_port eth1 --ssid NETGEAR_2G --passwd Password@123 --security wpa2 --device_csv_name device.csv
EXAMPLE-12:
Command Line Interface to run download scenario by Configuring Devices in Groups with Specific Profiles
python3 lf_ftp.py --file_sizes 1MB --mgr 192.168.213.218 --traffic_duration 1m --directions Download --clients_type Real --bands 5G
--upstream_port eth1 --file_name g219 --group_name grp1 --profile_name Open3
EXAMPLE-13:
Command Line Interface to run download scenario by Configuring Devices in Groups with Specific Profiles and expected Pass/Fail values
python3 lf_ftp.py --file_sizes 1MB --mgr 192.168.213.218 --traffic_duration 1m --directions Download --clients_type Real --bands 5G
--upstream_port eth1 --file_name g219 --group_name grp1 --profile_name Open3 --expected_passfail_value 3 --wait_time 30
EXAMPLE-14:
Command Line Interface to run the Test along with IOT without device list
python3 lf_ftp.py --ssid Netgear-5g --passwd sharedsecret --file_sizes 10MB --mgr 192.168.207.78 --traffic_duration 1m --security wpa2
--directions Download --clients_type Real --ap_name Netgear --bands 5G --upstream_port eth1 --iot_test --iot_testname "IotTest"
EXAMPLE-15:
Command Line Interface to run the Test along with IOT with device list
python3 lf_ftp.py --ssid Netgear-5g --passwd sharedsecret --file_sizes 10MB --mgr 192.168.207.78 --traffic_duration 1m --security wpa2
--directions Download --clients_type Real --ap_name Netgear --bands 5G --upstream_port eth1 --iot_test --iot_testname "IotTest" --iot_device_list "switch.smart_plug_1_socket_1"
EXAMPLE-16:
Command Line Interface to run download scenario for Real clients with only coordinates
python3 lf_ftp.py --ssid Netgear-5g --passwd sharedsecret --file_sizes 10MB --mgr 192.168.207.78 --traffic_duration 1m
--security wpa2 --directions Download --clients_type Real --ap_name Netgear --bands 5G --upstream_port eth1 --robot_test --robot_ip 192.168.204.101 --coordinate 3,4
EXAMPLE-17:
Command Line Interface to run download scenario for Real clients with coordinates and rotations
python3 lf_ftp.py --ssid Netgear-5g --passwd sharedsecret --file_sizes 10MB --mgr 192.168.207.78 --traffic_duration 1m
--security wpa2 --directions Download --clients_type Real --ap_name Netgear --bands 5G --upstream_port eth1 --robot_test --robot_ip 192.168.204.101 --coordinate 3,4 --rotation 30,45
SCRIPT_CLASSIFICATION : Test
SCRIPT_CATEGORIES: Performance, Functional, Report Generation
NOTES:
After passing cli, a list will be displayed on terminal which contains available resources to run test.
The following sentence will be displayed
Enter the desired resources to run the test:
Please enter the port numbers seperated by commas ','.
Example:
Enter the desired resources to run the test:1.10,1.11,1.12,1.13,1.202,1.203,1.303
STATUS : Functional
VERIFIED_ON:
26-JULY-2024,
GUI Version: 5.4.8
Kernel Version: 6.2.16+
LICENSE :
Copyright 2023 Candela Technologies Inc
Free to distribute and modify. LANforge systems must be licensed.
INCLUDE_IN_README: False
"""
import sys
import importlib
import paramiko
import argparse
from datetime import datetime, timedelta
import time
import os
import requests
import json
import matplotlib.patches as mpatches
import pandas as pd
import logging
import shutil
from lf_graph import lf_bar_graph_horizontal
from typing import List, Optional
import asyncio
import csv
import traceback
import threading
from collections import OrderedDict
from lf_base_robo import RobotClass
if sys.version_info[0] != 3:
print("This script requires Python 3")
exit(1)
sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../")))
LFUtils = importlib.import_module("py-json.LANforge.LFUtils")
lfcli_base = importlib.import_module("py-json.LANforge.lfcli_base")
LFCliBase = lfcli_base.LFCliBase
realm = importlib.import_module("py-json.realm")
Realm = realm.Realm
# Importing DeviceConfig to apply device configurations for ADB devices and laptops
DeviceConfig = importlib.import_module("py-scripts.DeviceConfig")
lf_report = importlib.import_module("py-scripts.lf_report")
lf_graph = importlib.import_module("py-scripts.lf_graph")
lf_kpi_csv = importlib.import_module("py-scripts.lf_kpi_csv")
logger = logging.getLogger(__name__)
lf_logger_config = importlib.import_module("py-scripts.lf_logger_config")
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 FtpTest(LFCliBase):
def __init__(self, lfclient_host="localhost", lfclient_port=8080, sta_prefix="sta", start_id=0, num_sta=0, radio="",
dut_ssid=None, dut_security=None, dut_passwd=None, file_size=None, band=None, twog_radio=None,
file_name=None,
profile_name=None, group_name=None,
sixg_radio=None, fiveg_radio=None, upstream="eth1", _debug_on=False, _exit_on_error=False, _exit_on_fail=False, ap_name="",
direction=None, duration=None, traffic_duration=None, ssh_port=None, kpi_csv=None, kpi_results=None,
lf_username="lanforge", lf_password="lanforge", clients_type="Virtual", dowebgui=False, device_list=None, test_name=None, result_dir=None,
eap_method=None,
eap_identity=None,
ieee80211=None,
ieee80211u=None,
ieee80211w=None,
enable_pkc=None,
bss_transition=None,
power_save=None,
disable_ofdma=None,
roam_ft_ds=None,
key_management=None,
pairwise=None,
private_key=None,
ca_cert=None,
client_cert=None,
wait_time=60,
pk_passwd=None,
pac_file=None,
expected_passfail_val=None,
get_live_view=False,
total_floors=0,
config=False,
csv_name=None,
robot_test=False,
robot_ip=None,
coordinate=None,
rotation=None,
):
super().__init__(lfclient_host, lfclient_port, _debug=_debug_on, _exit_on_fail=_exit_on_fail)
if not device_list:
device_list = []
logger.info("Test is about to start")
self.ssid_list = []
self.host = lfclient_host
self.port = lfclient_port
# self.radio = radio
self.profile_name = profile_name
self.file_name = file_name
self.group_name = group_name
self.ap_name = ap_name
self.result_dir = result_dir
self.test_name = test_name
self.upstream = upstream
self.sta_prefix = sta_prefix
self.sta_start_id = start_id
self.num_sta = num_sta
self.ssid = dut_ssid
self.security = dut_security
self.password = dut_passwd
self.requests_per_ten = 600
self.band = band
self.lf_username = lf_username
self.lf_password = lf_password
self.kpi_csv = kpi_csv
self.kpi_results = kpi_results
self.file_size = file_size
self.direction = direction
self.twog_radio = twog_radio
self.fiveg_radio = fiveg_radio
self.sixg_radio = sixg_radio
self.duration = duration
self.dowebgui = dowebgui
self.device_list = device_list
self.traffic_duration = traffic_duration
self.ssh_port = ssh_port
self.local_realm = realm.Realm(lfclient_host=self.host, lfclient_port=self.port)
self.station_profile = self.local_realm.new_station_profile()
self.cx_profile = self.local_realm.new_http_profile()
self.port_util = realm.PortUtils(self.local_realm)
self.cx_profile.requests_per_ten = self.requests_per_ten
self.clients_type = clients_type
self.real_client_list = []
self.working_resources_list = []
self.hw_list = []
self.windows_list = []
self.windows_eid_list = []
self.windows_ports = []
self.mac_list = []
self.linux_list = []
self.android_list = []
self.eid_list = []
self.devices_available = []
self.user_list = []
self.input_devices_list = []
self.mac_id1_list = []
self.mac_id_list = []
self.real_client_list1 = []
self.uc_avg = []
self.failed_cx = []
self.tracking_map = {}
self.uc_min = []
self.uc_max = []
self.url_data = []
self.bytes_rd = []
self.rx_rate = []
self.total_err = []
self.channel_list = []
self.mode_list = []
self.cx_list = []
self.rssi_list = []
self.tx_rate = []
self.port_rx_rate = []
self.individual_device_csv_names = []
self.eap_method = eap_method
self.eap_identity = eap_identity
self.ieee80211 = ieee80211
self.ieee80211u = ieee80211u
self.ieee80211w = ieee80211w
self.enable_pkc = enable_pkc
self.bss_transition = bss_transition
self.power_save = power_save
self.disable_ofdma = disable_ofdma
self.roam_ft_ds = roam_ft_ds
self.key_management = key_management
self.pairwise = pairwise
self.private_key = private_key
self.ca_cert = ca_cert
self.client_cert = client_cert
self.pk_passwd = pk_passwd
self.pac_file = pac_file
self.expected_passfail_val = expected_passfail_val
self.csv_name = csv_name
self.wait_time = wait_time
self.config = config
self.group_device_map = {}
self.pass_fail_list = []
self.test_input_list = []
self.api_url = 'http://{}:{}'.format(self.host, self.port)
self.get_live_view = get_live_view
self.total_floors = total_floors
# Robot related variables
self.robot_test = robot_test
self.robot_ip = robot_ip
self.coordinate = coordinate
self.rotation = rotation
self.rotation_enabled = False
if self.robot_test:
self.coordinate_list = coordinate.split(',')
self.rotation_list = rotation.split(',')
self.current_coordinate = ""
self.current_angle = ""
self.robot_data = {}
self.robot_obj = {}
logger.info("Test is Initialized")
def query_realclients(self):
config_devices = {}
obj = DeviceConfig.DeviceConfig(lanforge_ip=self.host, file_name=self.file_name, wait_time=self.wait_time)
upstream = self.change_port_to_ip(self.upstream)
config_dict = {
'ssid': self.ssid,
'passwd': self.password,
'enc': self.security,
'eap_method': self.eap_method,
'eap_identity': self.eap_identity,
'ieee80211': self.ieee80211,
'ieee80211u': self.ieee80211u,
'ieee80211w': self.ieee80211w,
'enable_pkc': self.enable_pkc,
'bss_transition': self.bss_transition,
'power_save': self.power_save,
'disable_ofdma': self.disable_ofdma,
'roam_ft_ds': self.roam_ft_ds,
'key_management': self.key_management,
'pairwise': self.pairwise,
'private_key': self.private_key,
'ca_cert': self.ca_cert,
'client_cert': self.client_cert,
'pk_passwd': self.pk_passwd,
'pac_file': self.pac_file,
'server_ip': upstream,
}
# Case 1: Group name, file name, and profile name are provided, but device list is empty
if self.group_name and self.file_name and self.device_list == [] and self.profile_name:
selected_groups = self.group_name.split(',')
selected_profiles = self.profile_name.split(',')
for i in range(len(selected_groups)):
config_devices[selected_groups[i]] = selected_profiles[i]
obj.initiate_group()
self.group_device_map = obj.get_groups_devices(data=selected_groups, groupdevmap=True)
# Configure devices in the selected group with the selected profile
self.device_list = asyncio.run(obj.connectivity(config_devices, upstream=upstream))
# Case 2: Device list is already provided
elif self.device_list != []:
all_devices = obj.get_all_devices()
# self.device_list can be a string like "dev1,dev2" or a list; convert to list if it's a string
if isinstance(self.device_list, str):
self.device_list = self.device_list.split(',')
# If config is false, the test will exclude all inactive devices
if self.config:
# If config is True, attempt to bring up all devices in the list and perform tests on those that become active
# Configure devices in the device list with the provided SSID, Password and Security
self.device_list = asyncio.run(obj.connectivity(device_list=self.device_list, wifi_config=config_dict))
# Case 3: Device list is empty but config flag is True — prompt the user to input device details for configuration
elif self.device_list == [] and self.config:
all_devices = obj.get_all_devices()
device_list = []
for device in all_devices:
if device["type"] == 'laptop':
device_list.append(device["shelf"] + '.' + device["resource"] + " " + device["hostname"])
else:
device_list.append(device["eid"] + " " + device["serial"])
logger.info(f"Available devices: {device_list}")
self.device_list = input("Enter the desired resources to run the test:").split(',')
# If config is false, the test will exclude all inactive devices
if self.config:
# If config is True, attempt to bring up all devices in the list and perform tests on those that become active
# Configure devices entered by the user with the provided SSID, Password and Security
self.device_list = asyncio.run(obj.connectivity(device_list=self.device_list, wifi_config=config_dict))
response = self.json_get("/resource/all")
for key, value in response.items():
if key == "resources":
for element in value:
for _, b in element.items():
self.hw_list.append(b['hw version'])
for hw_version in self.hw_list:
if "Win" in hw_version:
self.windows_list.append(hw_version)
elif "Linux" in hw_version:
self.linux_list.append(hw_version)
elif "Apple" in hw_version:
self.mac_list.append(hw_version)
else:
if hw_version != "":
self.android_list.append(hw_version)
port_eid_list, same_eid_list, original_port_list = [], [], []
response = self.json_get("/resource/all")
for key, value in response.items():
if key == "resources":
for element in value:
for _, b in element.items():
if b['phantom'] is False:
self.working_resources_list.append(b["hw version"])
if "Win" in b['hw version']:
self.eid_list.append(b['eid'])
self.windows_list.append(b['hw version'])
self.windows_eid_list.append(b['eid'])
# self.hostname_list.append(b['eid']+ " " +b['hostname'])
self.devices_available.append(b['eid'] + " " + 'Win' + " " + b['hostname'])
elif "Linux" in b['hw version']:
if ('ct' not in b['hostname']):
if ('lf' not in b['hostname']):
self.eid_list.append(b['eid'])
self.linux_list.append(b['hw version'])
# self.hostname_list.append(b['eid']+ " " +b['hostname'])
self.devices_available.append(b['eid'] + " " + 'Lin' + " " + b['hostname'])
elif 'Apple' in b['hw version'] and (b['app-id'] != '') and (b['app-id'] != '0' or b['kernel'] == ''):
continue
elif "Apple" in b['hw version']:
self.eid_list.append(b['eid'])
self.mac_list.append(b['hw version'])
# self.hostname_list.append(b['eid']+ " " +b['hostname'])
self.devices_available.append(b['eid'] + " " + 'Mac' + " " + b['hostname'])
else:
self.eid_list.append(b['eid'])
self.android_list.append(b['hw version'])
# self.username_list.append(b['eid']+ " " +b['user'])
self.devices_available.append(b['eid'] + " " + 'android' + " " + b['user'])
# print("hostname list :",self.hostname_list)
# print("username list :", self.username_list)
# print("Available resources in resource tab :", self.devices_available)
# print("eid_list : ",self.eid_list)
# All the available resources are fetched from resource mgr tab ----
response_port = self.json_get("/port/all")
# print(response_port)
for interface in response_port['interfaces']:
for port, port_data in interface.items():
if 'p2p0' not in port:
if (not port_data['phantom'] and not port_data['down'] and port_data['parent dev'] == "wiphy0"):
for id in self.eid_list:
if (id + '.' in port):
original_port_list.append(port)
port_eid_list.append(str(LFUtils.name_to_eid(port)[0]) + '.' + str(LFUtils.name_to_eid(port)[1]))
self.mac_id1_list.append(str(LFUtils.name_to_eid(port)[0]) + '.' + str(LFUtils.name_to_eid(port)[1]) + ' ' + port_data['mac'])
# print("port eid list",port_eid_list)
for i in range(len(self.eid_list)):
for j in range(len(port_eid_list)):
if self.eid_list[i] == port_eid_list[j]:
same_eid_list.append(self.eid_list[i])
same_eid_list = [_eid + ' ' for _eid in same_eid_list]
# print("same eid list",same_eid_list)
# print("mac_id list",self.mac_id_list)
# All the available ports from port manager are fetched from port manager tab ---
for eid in same_eid_list:
for device in self.devices_available:
if eid in device:
print(eid + ' ' + device)
self.user_list.append(device)
logger.info("AVAILABLE DEVICES TO RUN TEST: %s", self.user_list)
logging.info(self.user_list)
# Case 4: Config is False, no device list is provided, and no group is selected
if not self.config and len(self.device_list) == 0 and self.group_name is None:
logger.info("AVAILABLE DEVICES TO RUN TEST : {}".format(self.user_list))
# Prompt the user to manually input devices for running the test
self.device_list = input("Enter the desired resources to run the test:").split(',')
if len(self.device_list) != 0:
devices_list = self.device_list
available_list = []
not_available = []
for input_device in devices_list:
found = False
for device in self.devices_available:
if input_device + " " in device:
available_list.append(input_device)
found = True
break
if found is False:
not_available.append(input_device)
logging.warning(device + " is not available to run test")
if len(available_list) > 0:
logging.info("Test is initiated on devices: %s", available_list)
devices_list = ','.join(available_list)
else:
devices_list = ""
logging.warning("Test can not be initiated on any selected devices hence aborting the test")
df1 = pd.DataFrame({
"client": self.client_list,
"url_data": 0,
"bytes_rd": 0,
"uc_min": 0,
"uc_max": 0,
"uc_avg": 0,
'status': 'Stopped'
}
)
df1.to_csv('{}/ftp_datavalues.csv'.format(self.result_dir), index=False)
raise ValueError("No Device is available to run the test hence aborting the test")
logging.info("device got from webui are: %s", devices_list)
else:
devices_list = ""
# print("devices list",devices_list)
resource_eid_list = devices_list.split(',')
resource_eid_list2 = [eid + ' ' for eid in resource_eid_list]
resource_eid_list1 = [resource + '.' for resource in resource_eid_list]
# print("resource eid list",resource_eid_list)
if devices_list == "" or devices_list == ",":
logger.warning(f"Can't run test on the selected devices. devices_list: '{devices_list}'")
exit(1)
# User desired eids are fetched ---
for eid in resource_eid_list1:
for ports_m in original_port_list:
if eid in ports_m and 'p2p0' not in ports_m:
self.input_devices_list.append(ports_m)
logging.info("INPUT DEVICES LIST %s", self.input_devices_list)
# user desired real client list 1.1 wlan0 ---
for port in self.input_devices_list:
for eid in self.windows_eid_list:
if eid + '.' in port:
self.windows_ports.append(port)
for i in resource_eid_list2:
for j in range(len(self.user_list)):
if i in self.user_list[j]:
self.real_client_list.append(self.user_list[j])
self.real_client_list1.append((self.user_list[j]))
print("REAL CLIENT LIST", self.real_client_list)
# print("REAL CLIENT LIST1", self.real_client_list1)
for eid in resource_eid_list2:
for i in self.mac_id1_list:
if eid in i:
self.mac_id_list.append(i.strip(eid + ' '))
logging.info("MAC ID LIST %s", self.mac_id_list)
return self.real_client_list, config_devices
def set_values(self):
'''This method will set values according user input'''
if self.band == "6G":
self.radio = [self.sixg_radio]
elif self.band == "5G":
self.radio = [self.fiveg_radio]
elif self.band == "2.4G":
self.radio = [self.twog_radio]
elif self.band == "Both":
self.radio = [self.fiveg_radio, self.twog_radio]
# if Both then number of stations are half for 2.4G and half for 5G
self.num_sta = self.num_sta // 2
# converting minutes into time stamp
self.pass_fail_duration = self.duration
# self.duration = self.convert_min_in_time(self.duration)
# self.traffic_duration = self.convert_min_in_time(self.traffic_duration)
# file size in Bytes
self.file_size_bytes = int(self.convert_file_size_in_Bytes(self.file_size))
# Converts an upstream port name to its corresponding IP address if it's not already in IP format.
def change_port_to_ip(self, upstream_port):
if upstream_port.count('.') != 3:
target_port_list = LFUtils.name_to_eid(upstream_port)
shelf, resource, port, _ = target_port_list
try:
target_port_ip = self.json_get(f'/port/{shelf}/{resource}/{port}?fields=ip')['interface']['ip']
upstream_port = target_port_ip
except BaseException: # noqa: B036
logging.warning(f'The upstream port is not an ethernet port. Proceeding with the given upstream_port {upstream_port}.')
logging.info(f"Upstream port IP {upstream_port}")
else:
logging.info(f"Upstream port IP {upstream_port}")
return upstream_port
def precleanup(self):
self.count = 0
# delete everything in the GUI before starting the script
'''try:
self.local_realm.load("BLANK")
except:
print("Couldn't load 'BLANK' Test configurations")'''
for rad in self.radio:
if rad == self.sixg_radio:
self.station_profile.mode = 15
self.count = self.count + 1
elif rad == self.fiveg_radio:
# select mode(All stations will connects to 5G)
self.station_profile.mode = 14
self.count = self.count + 1
elif rad == self.twog_radio:
# select mode(All stations will connects to 2.4G)
self.station_profile.mode = 13
self.count = self.count + 1
# check Both band if both band then for 2G station id start with 20
if self.count == 2:
self.sta_start_id = self.num_sta
self.num_sta = 2 * (self.num_sta)
# if Both band then first 20 stations will connects to 5G
self.station_profile.mode = 14
self.cx_profile.cleanup()
# create station list with sta_id 20
self.station_list1 = LFUtils.portNameSeries(prefix_=self.sta_prefix, start_id_=self.sta_start_id,
end_id_=self.num_sta - 1, padding_number_=10000,
radio=rad)
# cleanup station list which started sta_id 20
self.station_profile.cleanup(self.station_list1, debug_=self.debug)
LFUtils.wait_until_ports_disappear(base_url=self.lfclient_url,
port_list=self.station_list,
debug=self.debug)
# clean layer4 ftp traffic
self.cx_profile.cleanup()
self.station_list = LFUtils.portNameSeries(prefix_=self.sta_prefix, start_id_=self.sta_start_id,
end_id_=self.num_sta - 1, padding_number_=10000,
radio=rad)
# cleans stations
self.station_profile.cleanup(self.station_list, delay=1.5, debug_=self.debug)
LFUtils.wait_until_ports_disappear(base_url=self.lfclient_url,
port_list=self.station_list,
debug=self.debug)
time.sleep(1)
logger.info("precleanup done")
def build(self):
# set ftp
# self.port_util.set_ftp(port_name=self.local_realm.name_to_eid(self.upstream)[2], resource=2, on=True)
rv = self.local_realm.name_to_eid(self.upstream)
# rv[0]=shelf, rv[1]=resource, rv[2]=port
self.port_util.set_ftp(port_name=rv[2], resource=rv[1], on=True)
# self.port_util.set_ftp(port_name=rv, resource=rv[1], on=True)
eth_list = []
# list of upstream port
eth_list.append(self.upstream)
if (self.clients_type == "Virtual"):
if self.band == "2.4G":
self.station_profile.mode = 13
elif self.band == "5G":
self.station_profile.mode = 14
elif self.band == "6G":
self.station_profile.mode = 15
for rad in self.radio:
# station build
self.station_profile.use_security(self.security, self.ssid, self.password)
self.station_profile.set_number_template("00")
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)
self.station_profile.create(radio=rad, sta_names_=self.station_list, debug=self.debug)
self.local_realm.wait_until_ports_appear(sta_list=self.station_list)
self.station_profile.admin_up()
if self.local_realm.wait_for_ip(self.station_list):
self._pass("All stations got IPs")
else:
self._fail("Stations failed to get IPs")
# exit(1)
# building layer4
logger.info("Build Layer4")
self.cx_profile.direction = "dl"
self.cx_profile.dest = "/dev/null"
logger.info('Direction: %s', self.direction)
if self.direction == "Download":
# data from GUI for find out ip addr of upstream port
data = self.json_get("ports/list?fields=IP")
rv = self.local_realm.name_to_eid(self.upstream)
# rv[0]=shelf, rv[1]=resource, rv[2]=port
ip_upstream = None
for i in data["interfaces"]:
for j in i:
# if "1.1." + self.upstream == j:
# ip_upstream = i["1.1." + self.upstream]['ip']
interface = "{shelf}.{resource}.{port}".format(shelf=rv[0], resource=rv[1], port=rv[2])
if interface == j:
ip_upstream = i[interface]['ip']
# print("ip_upstream:{ip_upstream}".format(ip_upstream=ip_upstream))
'''
elif self.upstream == j:
ip_upstream = i[self.upstream]['ip']
'''
if ip_upstream is not None:
# print("station:{station_names}".format(station_names=self.station_profile.station_names))
# print("ip_upstream:{ip_upstream}".format(ip_upstream=ip_upstream))
self.cx_profile.create(ports=self.station_profile.station_names, ftp_ip=ip_upstream +
"/ftp_test.txt",
sleep_time=.5, debug_=self.debug, suppress_related_commands_=True, timeout=1000, ftp=True,
user=self.lf_username,
passwd=self.lf_password, source="", proxy_auth_type=0x200)
elif self.direction == "Upload":
dict_sta_and_ip = {}
# data from GUI for find out ip addr of each station
data = self.json_get("ports/list?fields=IP")
# This loop for find out proper ip addr and station name
for i in self.station_list:
for j in data['interfaces']:
for k in j:
if i == k:
dict_sta_and_ip[k] = j[i]['ip']
# list of ip addr of all stations
ip = list(dict_sta_and_ip.values())
# print("build() - ip:{ip}".format(ip=ip))
client_list = []
# list of all stations
for i in range(len(self.station_list)):
client_list.append(self.station_list[i][4:])
# create layer four connection for upload
for client_num in range(len(self.station_list)):
self.cx_profile.create(ports=eth_list, ftp_ip=ip[client_num] + "/ftp_test.txt", sleep_time=.5,
debug_=self.debug, suppress_related_commands_=True, timeout=1000, ftp=True,
user=self.lf_username, passwd=self.lf_password,
source="", upload_name=client_list[client_num], proxy_auth_type=0x200)
# check Both band present then build stations with another station list
if self.count == 2:
self.station_list = self.station_list1
# if Both band then another 20 stations will connects to 2.4G
self.station_profile.mode = 6
if self.clients_type == "Real":
if self.direction == "Download":
# data from GUI for find out ip addr of upstream port
data = self.json_get("ports/list?fields=IP")
rv = self.local_realm.name_to_eid(self.upstream)
# rv[0]=shelf, rv[1]=resource, rv[2]=port
ip_upstream = None
for i in data["interfaces"]:
for j in i:
# if "1.1." + self.upstream == j:
# ip_upstream = i["1.1." + self.upstream]['ip']
interface = "{shelf}.{resource}.{port}".format(shelf=rv[0], resource=rv[1], port=rv[2])
if interface == j:
ip_upstream = i[interface]['ip']
# print("ip_upstream:{ip_upstream}".format(ip_upstream=ip_upstream))
'''
elif self.upstream == j:
ip_upstream = i[self.upstream]['ip']
'''
if ip_upstream is not None:
# print("station:{station_names}".format(station_names=self.station_profile.station_names))
# print("ip_upstream:{ip_upstream}".format(ip_upstream=ip_upstream))
self.cx_profile.create(ports=self.input_devices_list, ftp_ip=ip_upstream +
"/ftp_test.txt",
sleep_time=.5, debug_=self.debug, suppress_related_commands_=True, interop=True, timeout=1000, ftp=True,
user=self.lf_username,
passwd=self.lf_password, source="", proxy_auth_type=0x200, windows_list=self.windows_ports)
elif self.direction == "Upload":
# list of upstream port
# data from GUI for find out ip addr of each station
data = self.json_get("ports/list?fields=IP")
dict_sta_and_ip = {}
# This loop for find out proper ip addr and station name
for i in self.input_devices_list:
for j in data['interfaces']:
for k in j:
if i == k:
dict_sta_and_ip[k] = j[i]['ip']
# list of ip addr of all stations
ip = list(dict_sta_and_ip.values())
# print("build() - ip:{ip}".format(ip=ip))
# create layer four connection for upload
for client in range(len(self.input_devices_list)):
self.cx_profile.create(ports=eth_list, ftp_ip=ip[client] + "/ftp_test.txt", sleep_time=.5,
debug_=self.debug, suppress_related_commands_=True, timeout=1000, interop=True, ftp=True,
user=self.lf_username, passwd=self.lf_password,
source="", upload_name=self.input_devices_list[client], proxy_auth_type=0x200)
# check Both band present then build stations with another station list
# if self.count == 2:
# self.station_list = self.station_list1
# # if Both band then another 20 stations will connects to 2.4G
# self.station_profile.mode = 6
self.cx_list = list(self.cx_profile.created_cx.keys())
logger.info("Test Build done")
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
def start(self, print_pass=False, print_fail=False):
for _ in self.radio:
self.cx_profile.start_cx()
logger.info("Test Started")
def stop(self):
self.cx_profile.stop_cx()
self.station_profile.admin_down()
# To update status of devices and remaining_time in ftp_datavalues.csv file to stopped and 0 respectively.
if self.clients_type == 'Real':
if not self.robot_test:
self.data["status"] = ["STOPPED"] * len(self.mac_id_list)
self.data["remaining_time"] = ["0"] * len(self.mac_id_list)
df1 = pd.DataFrame(self.data)
df1.to_csv("ftp_datavalues.csv", index=False)
if self.robot_test:
# Storing data in robot_data dictionary for each coordinate and angle
if self.rotation_enabled:
self.robot_data.setdefault(self.current_coordinate, {})[self.current_angle] = {
"mac_id_list": self.mac_id_list,
"channel_list": self.channel_list,
"ssid_list": self.ssid_list,
"mode_list": self.mode_list,
"url_data": self.url_data,
"uc_avg": self.uc_avg,
"bytes_rd": self.bytes_rd,
"rx_rate": self.rx_rate,
"total_err": self.total_err,
"uc_min": self.uc_min,
"uc_max": self.uc_max,
}
else:
self.robot_data[self.current_coordinate] = {
"mac_id_list": self.mac_id_list,
"channel_list": self.channel_list,
"ssid_list": self.ssid_list,
"mode_list": self.mode_list,
"url_data": self.url_data,
"uc_avg": self.uc_avg,
"bytes_rd": self.bytes_rd,
"rx_rate": self.rx_rate,
"total_err": self.total_err,
"uc_min": self.uc_min,
"uc_max": self.uc_max
}
if self.dowebgui:
df1.to_csv(f"{self.result_dir}/{self.current_coordinate}_ftp_datavalues.csv", index=False)
else:
df1.to_csv(f"{self.current_coordinate}_ftp_datavalues.csv", index=False)
def update_stop_status_robot(self):
# To update status of devices in csv file to stopped.
self.data["status"] = ["STOPPED"] * len(self.mac_id_list)
df1 = pd.DataFrame(self.data)
df1.to_csv("ftp_datavalues.csv", index=False)
if self.dowebgui:
df1.to_csv(f"{self.result_dir}/{self.current_coordinate}_ftp_datavalues.csv", index=False)
else:
df1.to_csv(f"{self.current_coordinate}_ftp_datavalues.csv", index=False)
def postcleanup(self):
self.cx_profile.cleanup()
# self.local_realm.load("BLANK")
self.station_profile.cleanup(self.station_profile.station_names, delay=1.5, debug_=self.debug)
LFUtils.wait_until_ports_disappear(base_url=self.lfclient_url, port_list=self.station_profile.station_names,
debug=self.debug)
def filter_iOS_devices(self, device_list):
modified_device_list = device_list
if type(device_list) is str:
modified_device_list = device_list.split(',')
filtered_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 %s is not found.", device)
continue
device_data = device_data['resource']
# print(device_data)
if 'Apple' in device_data['hw version'] and (device_data['app-id'] != '') and (device_data['app-id'] != '0' or device_data['kernel'] == ''):
logger.info("%s is an iOS device. Currently, we do not support iOS devices.", device)
else:
filtered_list.append(device)
if type(device_list) is str:
filtered_list = ','.join(filtered_list)
self.device_list = filtered_list
return filtered_list
def file_create(self):
'''This method will Create file for given file size'''
ip = self.host
entity_id = self.local_realm.name_to_eid(self.upstream)
# entity_id[0]=shelf, entity_id[1]=resource, entity_id[2]=port
user = "root"
pswd = "lanforge"
port = self.ssh_port
ssh = paramiko.SSHClient() # creating shh client object we use this object to connect to router
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # automatically adds the missing host key
# get upstream port ip-address from test ftp server
if entity_id[1] > 1:
resource_val = str(entity_id[1])
ftp_resource_url = self.json_get("ports/1/" + resource_val + "/0/list?fields=IP")
ftp_server_ip = ftp_resource_url["interface"]["ip"]
ip = ftp_server_ip
ssh.connect(ip, port=port, username=user, password=pswd, banner_timeout=600)
cmd = '[ -f /home/lanforge/ftp_test.txt ] && echo "True" || echo "False"'
stdin, stdout, stderr = ssh.exec_command(str(cmd))
output = stdout.readlines()
logger.info(output)
if output == ["True\n"]:
cmd1 = "rm /home/lanforge/ftp_test.txt"
stdin, stdout, stderr = ssh.exec_command(str(cmd1))
output = stdout.readlines()
time.sleep(10)
cmd2 = "sudo fallocate -l " + self.file_size + " /home/lanforge/ftp_test.txt"
stdin, stdout, stderr = ssh.exec_command(str(cmd2))
logger.info("File creation done %s", self.file_size)
output = stdout.readlines()
else:
cmd2 = "sudo fallocate -l " + self.file_size + " /home/lanforge/ftp_test.txt"
stdin, stdout, stderr = ssh.exec_command(str(cmd2))
logger.info("File creation done %s", self.file_size)
output = stdout.readlines()
ssh.close()
time.sleep(1)
return output
def convert_file_size_in_Bytes(self, size):
'''convert file size MB or GB into Bytes'''
'''
if (size.endswith("MB")) or (size.endswith("Mb")) or (size.endswith("GB")) or (size.endswith("Gb")):
if (size.endswith("MB")) or (size.endswith("Mb")):
return float(size[:-2]) * 10 ** 6
elif (size.endswith("GB")) or (size.endswith("Gb")):
return float(size[:-2]) * 10 ** 9
'''
upper = size.upper()
if upper.endswith("MB"):
return float(upper[:-2]) * 10 ** 6
elif upper.endswith("GB"):
return float(upper[:-2]) * 10 ** 9
# assume data is MB if no designator is on end of str
else:
return float(upper[:-2]) * 10 ** 6
def get_all_l4_data(self):
"""
Fetches the complete set of Layer-4 data and writes it to a dictionary
Returns:
dict: A dictionary mapping each Layer 4 field to a list of values in the order of CXs.
"""
fields = [