[6320] | 1 | """ |
---|
| 2 | ------------------------------------------------------------------------------ |
---|
| 3 | Mango 802.11 Reference Design Experiments Framework - Print Tx/Rx Stats |
---|
| 4 | ------------------------------------------------------------------------------ |
---|
| 5 | License: Copyright 2014-2019, Mango Communications. All rights reserved. |
---|
| 6 | Distributed under the WARP license (http://warpproject.org/license) |
---|
| 7 | ------------------------------------------------------------------------------ |
---|
| 8 | This module provides a simple wlan_exp example. |
---|
| 9 | |
---|
| 10 | Hardware Setup: |
---|
| 11 | - Requires 1+ WARP v3 node running 802.11 Reference Design v1.5 or later |
---|
| 12 | - PC NIC and ETH B on WARP v3 nodes connected to common Ethernet switch |
---|
| 13 | |
---|
| 14 | Required Script Changes: |
---|
| 15 | - Set NETWORK to the IP address of your host PC NIC network (eg X.Y.Z.0 for IP X.Y.Z.W) |
---|
| 16 | - Set NODE_SERIAL_LIST to the serial numbers of your WARP nodes |
---|
| 17 | |
---|
| 18 | Description: |
---|
| 19 | This script will initialize the given nodes; extract any APs from the |
---|
| 20 | initialized nodes; then for each AP, it will get the associations and counts |
---|
| 21 | and display them. |
---|
| 22 | ------------------------------------------------------------------------------ |
---|
| 23 | """ |
---|
| 24 | # Import Python modules |
---|
| 25 | import time |
---|
| 26 | |
---|
| 27 | # Import wlan_exp Framework |
---|
| 28 | import wlan_exp.config as config |
---|
| 29 | import wlan_exp.util as util |
---|
| 30 | |
---|
| 31 | # Change these values to match your experiment / network setup |
---|
| 32 | NETWORK = '10.0.0.0' |
---|
| 33 | USE_JUMBO_ETH_FRAMES = False |
---|
| 34 | NODE_SERIAL_LIST = ['W3-a-00001'] |
---|
| 35 | # Select whether the Tx/Rx counts should be printed for all known devices ('all') |
---|
| 36 | # or only devices which are associated with the node ('members') |
---|
| 37 | #STATIONS_TO_PRINT = 'members' |
---|
| 38 | STATIONS_TO_PRINT = 'all' |
---|
| 39 | |
---|
| 40 | nodes = [] |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | def initialize_experiment(): |
---|
| 44 | """Initialize the wlan_exp experiment.""" |
---|
| 45 | global nodes |
---|
| 46 | |
---|
| 47 | # Print initial message |
---|
| 48 | print("\nInitializing experiment\n") |
---|
| 49 | |
---|
| 50 | # Create an object that describes the network configuration of the host PC |
---|
| 51 | network_config = config.WlanExpNetworkConfiguration(network=NETWORK, |
---|
| 52 | jumbo_frame_support=USE_JUMBO_ETH_FRAMES) |
---|
| 53 | |
---|
| 54 | # Create an object that describes the WARP v3 nodes that will be used in this experiment |
---|
| 55 | nodes_config = config.WlanExpNodesConfiguration(network_config=network_config, |
---|
| 56 | serial_numbers=NODE_SERIAL_LIST) |
---|
| 57 | |
---|
| 58 | # Initialize the Nodes |
---|
| 59 | # This will initialize all of the networking and gather the necessary |
---|
| 60 | # information to control and communicate with the nodes |
---|
| 61 | nodes = util.init_nodes(nodes_config, network_config) |
---|
| 62 | |
---|
| 63 | def run_experiment(): |
---|
| 64 | """Run the experiment.""" |
---|
| 65 | global nodes |
---|
| 66 | |
---|
| 67 | # Print initial message |
---|
| 68 | print("\nRunning experiment (Use Ctrl-C to exit)\n") |
---|
| 69 | |
---|
| 70 | while(True): |
---|
| 71 | |
---|
| 72 | # For each of the APs, get the counts |
---|
| 73 | for node in nodes: |
---|
| 74 | if STATIONS_TO_PRINT == 'members': |
---|
| 75 | # Retreive the station_info/counts structs for all associated stations |
---|
| 76 | station_info_list = node.get_bss_members() |
---|
| 77 | else: |
---|
| 78 | # Retreive the station_info/counts structs for all known stations |
---|
| 79 | station_info_list = node.get_station_info_list() |
---|
| 80 | |
---|
| 81 | # Call the helper method to print this node's counts |
---|
| 82 | print_counts(node, station_info_list) |
---|
| 83 | |
---|
| 84 | print(92*"*") |
---|
| 85 | # Wait for 5 seconds |
---|
| 86 | time.sleep(5) |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | def print_counts(node, station_info_list): |
---|
| 90 | """Helper method to print the Tx/Rx counts retrieved from one node.""" |
---|
| 91 | print("-------------------- ----------------------------------- ----------------------------------- ") |
---|
| 92 | print(" Tx/Rx Counts at Node {0}".format(node.sn_str)) |
---|
| 93 | print(" Number of Packets Number of Bytes ") |
---|
| 94 | print("MAC Address Tx Data Tx Mgmt Rx Data Rx Mgmt Tx Data Tx Mgmt Rx Data Rx Mgmt ") |
---|
| 95 | print("-------------------- -------- -------- -------- -------- -------- -------- -------- -------- ") |
---|
| 96 | |
---|
| 97 | msg = "" |
---|
| 98 | for s in station_info_list: |
---|
| 99 | msg += "{0:<20} ".format(util.mac_addr_to_str(s['mac_addr'])) |
---|
| 100 | msg += "{0:8d} ".format(s['data_num_tx_packets_success']) |
---|
| 101 | msg += "{0:8d} ".format(s['mgmt_num_tx_packets_success']) |
---|
| 102 | msg += "{0:8d} ".format(s['data_num_rx_packets']) |
---|
| 103 | msg += "{0:8d} ".format(s['mgmt_num_rx_packets']) |
---|
| 104 | msg += "{0:8d} ".format(s['data_num_tx_bytes_success']) |
---|
| 105 | msg += "{0:8d} ".format(s['mgmt_num_tx_bytes_success']) |
---|
| 106 | msg += "{0:8d} ".format(s['data_num_rx_bytes']) |
---|
| 107 | msg += "{0:8d} ".format(s['mgmt_num_rx_bytes']) |
---|
| 108 | msg += "\n" |
---|
| 109 | print(msg) |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | def end_experiment(): |
---|
| 113 | """Experiment cleanup / post processing.""" |
---|
| 114 | global nodes |
---|
| 115 | print("\nEnding experiment\n") |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | if __name__ == '__main__': |
---|
| 120 | initialize_experiment() |
---|
| 121 | |
---|
| 122 | try: |
---|
| 123 | # Run the experiment |
---|
| 124 | run_experiment() |
---|
| 125 | except KeyboardInterrupt: |
---|
| 126 | pass |
---|
| 127 | |
---|
| 128 | end_experiment() |
---|
| 129 | print("\nExperiment Finished.") |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | |
---|