mirror of
				https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
				synced 2025-10-31 18:58:01 +00:00 
			
		
		
		
	tos-plus: Add fixes from Pankaj.
This commit is contained in:
		
							
								
								
									
										110
									
								
								tos_plus_auto.py
									
									
									
									
									
								
							
							
						
						
									
										110
									
								
								tos_plus_auto.py
									
									
									
									
									
								
							| @@ -25,13 +25,28 @@ import pprint | |||||||
| import telnetlib | import telnetlib | ||||||
| import argparse | import argparse | ||||||
| import pexpect | import pexpect | ||||||
|  | import subprocess | ||||||
|  |  | ||||||
| ptype="QCA" | ptype="QCA" | ||||||
|  | FORMAT = '%(asctime)s %(name)s %(levelname)s: %(message)s' | ||||||
|  |  | ||||||
| def usage(): | def usage(): | ||||||
|    print("$0 used connect to automated a test case using cisco controller and LANforge tos-plus script:") |    print("$0 used connect to automated a test case using cisco controller and LANforge tos-plus script:") | ||||||
|    print("-p|--ptype:  AP Hardware type") |    print("-p|--ptype:  AP Hardware type") | ||||||
|    print("-h|--help") |    print("-h|--help") | ||||||
|  |    print("-l|--log file: log messages here") | ||||||
|  |  | ||||||
|  | # see https://stackoverflow.com/a/13306095/11014343 | ||||||
|  | class FileAdapter(object): | ||||||
|  |     def __init__(self, logger): | ||||||
|  |         self.logger = logger | ||||||
|  |     def write(self, data): | ||||||
|  |         # NOTE: data can be a partial line, multiple lines | ||||||
|  |         data = data.strip() # ignore leading/trailing whitespace | ||||||
|  |         if data: # non-blank | ||||||
|  |            self.logger.info(data) | ||||||
|  |     def flush(self): | ||||||
|  |         pass  # leave it to logging to flush properly | ||||||
|  |  | ||||||
| def main(): | def main(): | ||||||
|    global ptype |    global ptype | ||||||
| @@ -39,42 +54,99 @@ def main(): | |||||||
|  |  | ||||||
|    parser = argparse.ArgumentParser(description="TOS Plus automation script") |    parser = argparse.ArgumentParser(description="TOS Plus automation script") | ||||||
|    parser.add_argument("-p", "--ptype",    type=str, help="AP Hardware type") |    parser.add_argument("-p", "--ptype",    type=str, help="AP Hardware type") | ||||||
|  |    parser.add_argument("-l", "--log",     type=str, help="logfile for messages, stdout means output to console") | ||||||
|     |     | ||||||
|    args = None |    args = None | ||||||
|    try: |    try: | ||||||
|       args = parser.parse_args() |       args = parser.parse_args() | ||||||
|       if (args.ptype != None): |       if (args.ptype != None): | ||||||
|          ptype = args.ptype |          ptype = args.ptype | ||||||
|  |       logfile = args.log | ||||||
|        |        | ||||||
|    except Exception as e: |    except Exception as e: | ||||||
|       logging.exception(e); |       logging.exception(e); | ||||||
|       usage() |       usage() | ||||||
|       exit(2); |       exit(2); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |    console_handler = logging.StreamHandler() | ||||||
|  |    formatter = logging.Formatter(FORMAT) | ||||||
|  |    logg = logging.getLogger(__name__) | ||||||
|  |    logg.setLevel(logging.DEBUG) | ||||||
|  |    file_handler = None | ||||||
|  |    if (logfile is not None): | ||||||
|  |        if (logfile != "stdout"): | ||||||
|  |            file_handler = logging.FileHandler(logfile, "w") | ||||||
|  |            file_handler.setLevel(logging.DEBUG) | ||||||
|  |            file_handler.setFormatter(formatter) | ||||||
|  |            logg.addHandler(file_handler) | ||||||
|  |            logging.basicConfig(format=FORMAT, handlers=[file_handler]) | ||||||
|  |        else: | ||||||
|  |            # stdout logging | ||||||
|  |            logging.basicConfig(format=FORMAT, handlers=[console_handler])  | ||||||
|  |  | ||||||
|    # Set up cisco controller.  For now, variables are hard-coded. |    # Set up cisco controller.  For now, variables are hard-coded. | ||||||
|    dest = 172.19.27.95 |    dest = '172.19.27.95' | ||||||
|    port = 2013 |    port = '2013' | ||||||
|    ap = AxelMain |    port_ap = '2014' | ||||||
|    user = cisco |    ap = 'AxelMain' | ||||||
|    passwd = Cisco123 |    user = 'cisco' | ||||||
|  |    passwd = 'Cisco123' | ||||||
|  |    user_ap = 'cisco' | ||||||
|  |    passwd_ap = 'Cisco123' | ||||||
|  |    wlan = 'wlan_open' | ||||||
|  |    wlanID = '6' | ||||||
|  |  | ||||||
|    subprocess.run("python3 cisco_wifi_ctl.py -d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s -w wlan_open -i 6 --action wlan"%(dest, port, ap, user, passwd)) |    subprocess.run(["./cisco_wifi_ctl.py", "-d", dest, "-o", port, "-s", "telnet", "-l", "stdout", "-a", ap, "-u", "cisco", "-p", "Cisco123", "-w", wlan, "-i", wlanID, | ||||||
|    subprocess.run("python3 cisco_wifi_ctl.py -d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s -w wlan_open -i 6 --action wlan_qos --value platinum"%(dest, port, ap, user, passwd)) |                   "--action", "wlan"], capture_output=True) | ||||||
|    subprocess.run("python3 cisco_wifi_ctl.py -d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s --action show --value \"wlan summary\""%(dest, port, ap, user, passwd)) |    subprocess.run(["./cisco_wifi_ctl.py", "-d", dest, "-o", port, "-s", "telnet", "-l", "stdout", "-a", ap, "-u", "cisco", "-p", "Cisco123", "-w", wlan, "-i", wlanID, | ||||||
|    subprocess.run("python3 cisco_wifi_ctl.py -d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s -b b --action disable"%(dest, port, ap, user, passwd)) |                   "--action", "wlan_security"], capture_output=True) | ||||||
|    subprocess.run("python3 cisco_wifi_ctl.py -d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s -b a --action disable"%(dest, port, ap, user, passwd)) |    subprocess.run(["./cisco_wifi_ctl.py", "-d", dest, "-o", port, "-s", "telnet", "-l", "stdout", "-a", ap, "-u", "cisco", "-p", "Cisco123", "-w", wlan, "-i", wlanID, | ||||||
|    subprocess.run("python3 cisco_wifi_ctl.py -d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s -b a --action channel --value 149"%(dest, port, ap, user, passwd)) |                   "--action", "wlan_qos", "--value", "platinum"], capture_output=True) | ||||||
|    subprocess.run("python3 cisco_wifi_ctl.py -d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s -b a --action bandwidth --value 80"%(dest, port, ap, user, passwd)) |    subprocess.run(["./cisco_wifi_ctl.py", "-d", dest, "-o", port, "-s", "telnet", "-l", "stdout", "-a", ap, "-u", "cisco", "-p", "Cisco123", "-w", wlan, "-i", wlanID, | ||||||
|    subprocess.run("python3 cisco_wifi_ctl.py -d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s -b a --action enable"%(dest, port, ap, user, passwd)) |                   "--action", "enable_wlan"], capture_output=True) | ||||||
|  |    output01 = subprocess.run(["./cisco_wifi_ctl.py", "-d", dest, "-o", port, "-s", "telnet", "-l", "stdout", "-a", ap, "-u", "cisco", "-p", "Cisco123", "--action", "show",  | ||||||
|  |                   "--value", "wlan summary"], capture_output=True) | ||||||
|  |    #pss = output01.stdout.decode('utf-8', 'ignore'); | ||||||
|  |    #print(pss) | ||||||
|  |    print(output01) | ||||||
|  |    subprocess.run(["./cisco_wifi_ctl.py", "-d", dest, "-o", port, "-s", "telnet", "-l", "stdout", "-a", ap, "-u", "cisco", "-p", "Cisco123", "-b", "b", "--action",  | ||||||
|  |                   "disable"], capture_output=True) | ||||||
|  |    subprocess.run(["./cisco_wifi_ctl.py", "-d", dest, "-o", port, "-s", "telnet", "-l", "stdout", "-a", ap, "-u", "cisco", "-p", "Cisco123", "-b", "a", "--action",  | ||||||
|  |                   "disable"], capture_output=True) | ||||||
|  |    subprocess.run(["./cisco_wifi_ctl.py", "-d", dest, "-o", port, "-s", "telnet", "-l", "stdout", "-a", ap, "-u", "cisco", "-p", "Cisco123", "-b", "a", "--action",  | ||||||
|  |                   "channel", "--value", "149"], capture_output=True) | ||||||
|  |    subprocess.run(["./cisco_wifi_ctl.py", "-d", dest, "-o", port, "-s", "telnet", "-l", "stdout", "-a", ap, "-u", "cisco", "-p", "Cisco123", "-b", "a", "--action",  | ||||||
|  |                   "bandwidth", "--value", "80"], capture_output=True) | ||||||
|  |    subprocess.run(["./cisco_wifi_ctl.py", "-d", dest, "-o", port, "-s", "telnet", "-l", "stdout", "-a", ap, "-u", "cisco", "-p", "Cisco123", "-b", "a", "--action",  | ||||||
|  |                   "enable"], capture_output=True) | ||||||
|  |    #subprocess.run("python3 cisco_wifi_ctl.py -d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s -w %s -i %s --action wlan"%(dest, port, ap, user, passwd, wlan, wlanID)) | ||||||
|  |    #subprocess.run("./cisco_wifi_ctl.py", "-d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s -w %s -i %s --action wlan_qos --value platinum"%(dest, port, ap, user, passwd, wlan, wlanID)) | ||||||
|  |    #subprocess.run("python3 cisco_wifi_ctl.py -d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s --action show --value \"wlan summary\""%(dest, port, ap, user, passwd)) | ||||||
|  |    #subprocess.run("python3 cisco_wifi_ctl.py -d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s -b b --action disable"%(dest, port, ap, user, passwd)) | ||||||
|  |    #subprocess.run("python3 cisco_wifi_ctl.py -d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s -b a --action disable"%(dest, port, ap, user, passwd)) | ||||||
|  |    #subprocess.run("python3 cisco_wifi_ctl.py -d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s -b a --action channel --value 149"%(dest, port, ap, user, passwd)) | ||||||
|  |    #subprocess.run("python3 cisco_wifi_ctl.py -d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s -b a --action bandwidth --value 80"%(dest, port, ap, user, passwd)) | ||||||
|  |    #subprocess.run("python3 cisco_wifi_ctl.py -d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s -b a --action enable"%(dest, port, ap, user, passwd)) | ||||||
|  |  | ||||||
|  |    #Clear Stormbreaker stats on AP | ||||||
|  |    subprocess.run(["./cisco_ap.py", "-d", dest, "-o", port_ap, "-s", "telnet", "-l", "stdout", "-a", ap, "-u", "cisco", "-p", "Cisco123", "--action", "clear_counter"], capture_output=True) | ||||||
|     |     | ||||||
|    # Run the tos plus script to generate traffic and grab capture files. |    # Run the tos plus script to generate traffic and grab capture files. | ||||||
|    # You may edit this command as needed for different behaviour. |    # You may edit this command as needed for different behaviour. | ||||||
|    subprocess.run("./lf_tos_plus_test.py --dur 1 --lfmgr localhost --ssid 11ax-open --radio \"1.wiphy0 2 0\" --txpkts 10000 --wait_sniffer 1   --cx \"1.wiphy0 1.wlan0 anAX 1.eth2 udp 1024 10000 50000000 184\" --sniffer_radios \"1.wiphy2\"") |    os.system('python3 ./lf_tos_plus_test.py --dur 1 --lfmgr localhost --ssid wlan_open --radio "1.wiphy0 2 0" --txpkts 9999 --wait_sniffer 1  --cx "1.wiphy0 1.wlan0 anAX 1.eth2 udp 1024 10000 5000000000 184" --sniffer_radios "1.wiphy2"') | ||||||
|  |    #output02 = subprocess.run(["./lf_tos_plus_test.py", "--dur", "1", "--lfmgr", "localhost", "--ssid", wlan, "--radio", "1.wiphy0 2 0", "--txpkts", "10000",  | ||||||
|  |    #               "--wait_sniffer", "1", "--cx", "1.wiphy0 1.wlan0 anAX 1.eth2 udp 1024 10000 50000000 184", "--sniffer_radios", "1.wiphy2"], capture_output=True) | ||||||
|  |  | ||||||
|  |    #Read Stormbreaker exported stats after the test | ||||||
|  |    output02 = subprocess.run(["./cisco_ap.py", "-d", dest, "-o", port_ap, "-s", "telnet", "-l", "stdout", "-a", ap, "-u", "cisco", "-p", "Cisco123", "--action", "show",  | ||||||
|  |                   "--value", "interfaces dot11Radio 1 traffic distribution periodic data exported"], capture_output=True) | ||||||
|  |    print(output02) | ||||||
|  |  | ||||||
|    file1 = open('TOS_PLUS.sh', 'r')  |    file1 = open('TOS_PLUS.sh', 'r')  | ||||||
|    lines = file1.readlines() |    lines = file1.readlines() | ||||||
|  |  | ||||||
|  |  | ||||||
|    csv_file = "" |    csv_file = "" | ||||||
|    capture_dir = "" |    capture_dir = "" | ||||||
|    # Strips the newline character  |    # Strips the newline character  | ||||||
| @@ -82,14 +154,15 @@ def main(): | |||||||
|        tok_val = line.split("=", 1) |        tok_val = line.split("=", 1) | ||||||
|        if tok_val[0] == "CAPTURE_DIR": |        if tok_val[0] == "CAPTURE_DIR": | ||||||
|            capture_dir = tok_val[1] |            capture_dir = tok_val[1] | ||||||
|        else if tok_val[0] == "CSV_FILE": |        elif tok_val[0] == "CSV_FILE": | ||||||
|            capture_dir = tok_val[1] |            capture_dir = tok_val[1] | ||||||
|  |  | ||||||
|    # Remove  third-party tool's tmp file tmp file |    # Remove  third-party tool's tmp file tmp file | ||||||
|    os.unlink("stormbreaker.log") |    os.unlink("stormbreaker.log") | ||||||
|  |  | ||||||
|    # Run third-party tool to process the capture files. |    # Run third-party tool to process the capture files. | ||||||
|    subprocess.run("python3 sb -p %s -subdir %s"%(ptype, capture_dir)) |    os.system('python3 sb -p %s -subdir %s'%(ptype, capture_dir)) | ||||||
|  |  | ||||||
|    |    | ||||||
|    # Print out one-way latency reported by LANforge |    # Print out one-way latency reported by LANforge | ||||||
|    file2 = open(csv_file, 'r') |    file2 = open(csv_file, 'r') | ||||||
| @@ -101,8 +174,9 @@ def main(): | |||||||
|        # Print out endp-name and avg latency |        # Print out endp-name and avg latency | ||||||
|        print("%s\t%s"%(cols[1], cols[15])) |        print("%s\t%s"%(cols[1], cols[15])) | ||||||
|  |  | ||||||
|  |    subprocess.run(["./cisco_wifi_ctl.py", "-d", dest, "-o", port, "-s", "telnet", "-l", "stdout", "-a", ap, "-u", "cisco", "-p", "Cisco123", "-w", wlan, "-i", wlanID, | ||||||
|    subprocess.run("python3 cisco_wifi_ctl.py -d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s -w wlan_open -i 6 --action delete_wlan"%(dest, port, ap, user, passwd)) |                   "--action", "delete_wlan"], capture_output=True) | ||||||
|  |      #subprocess.run("python3 cisco_wifi_ctl.py -d %s  -o %s -s telnet -l stdout -a %s -u %s -p %s -w wlan_open -i 6 --action delete_wlan"%(dest, port, ap, user, passwd)) | ||||||
|  |  | ||||||
| # ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- | # ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- | ||||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Ben Greear
					Ben Greear