source: ReferenceDesigns/w3_802.11/python/examples/log/log_capture_two_node_two_flow.py

Last change on this file was 6320, checked in by chunter, 5 years ago

1.8.0 release wlan-exp

File size: 8.7 KB
Line 
1"""
2------------------------------------------------------------------------------
3Mango 802.11 Reference Design Experiments Framework - Two Node Log capture
4------------------------------------------------------------------------------
5License:   Copyright 2014-2019, Mango Communications. All rights reserved.
6           Distributed under the WARP license (http://warpproject.org/license)
7------------------------------------------------------------------------------
8This script uses the 802.11 ref design and wlan_exp to create a log
9file that contains all data assocated with an experiment of head-to-head
10backlogged data transfer using the local traffic generators.
11
12Hardware Setup:
13  - Requires two WARP v3 nodes
14    - One node configured as AP using 802.11 Reference Design v1.5 or later
15    - One node configured as STA using 802.11 Reference Design v1.5 or later
16   - PC NIC and ETH B on WARP v3 nodes connected to common Ethernet switch
17
18Required Script Changes:
19  - Set NETWORK to the IP address of your host PC NIC network (eg X.Y.Z.0 for IP X.Y.Z.W)
20  - Set NODE_SERIAL_LIST to the serial numbers of your WARP nodes
21
22Description:
23  This script initializes two WARP v3 nodes, one AP and one STA. It usees
24wlan_exp commands to form any needed associations.  After initializing all of
25the experiment parameters, the script starts a traffic flow from the AP to
26the STA and while that flow is running will start and stop a traffic flow from
27the STA to the AP.  Finally, it resets the log, allows the experiment to run
28and then captures all the log data after the TRIAL_TIME.
29------------------------------------------------------------------------------
30"""
31import sys
32import time
33
34import wlan_exp.config as config
35import wlan_exp.util as util
36import wlan_exp.ltg as ltg
37
38
39#-----------------------------------------------------------------------------
40# Top Level Script Variables
41#-----------------------------------------------------------------------------
42# Change these values to match your experiment / network setup
43NETWORK              = '10.0.0.0'
44USE_JUMBO_ETH_FRAMES = False
45NODE_SERIAL_LIST     = ['W3-a-00001', 'W3-a-00002']
46
47AP_HDF5_FILENAME     = "ap_two_node_two_flow_capture.hdf5"
48STA_HDF5_FILENAME    = "sta_two_node_two_flow_capture.hdf5"
49
50# BSS parameters
51SSID                 = "WARP Log 2 Node 2 Flow Ex"
52CHANNEL              = 1
53BEACON_INTERVAL      = 100
54
55# Set the experiment duration (in seconds)
56TRIAL_TIME           = 60
57
58#-----------------------------------------------------------------------------
59# Local Helper Utilities
60#-----------------------------------------------------------------------------
61def write_log_file(filename, node, exp_name):
62    """Writes all the log data from the node to a HDF5 file."""
63
64    import datetime
65    import wlan_exp.log.util_hdf as hdf_util
66    import wlan_exp.log.util as log_util
67
68    data_buffer = node.log_get_all_new()
69
70    try:
71        print("    {0}".format(filename))
72
73        # Get the byte log_data out of the Buffer
74        data = data_buffer.get_bytes()
75
76        # Example Attribute Dictionary for the HDF5 file
77        attr_dict = {'exp_name'  : exp_name,
78                     'exp_time'  : log_util.convert_datetime_to_log_time_str(datetime.datetime.utcnow()),
79                     'node_desc' : node.description}
80
81        # Write the byte Log_data to the file
82        hdf_util.log_data_to_hdf5(log_data=data, filename=filename, attr_dict=attr_dict)
83    except AttributeError as err:
84        print("Error writing log file: {0}".format(err))
85
86#-----------------------------------------------------------------------------
87# Experiment Script
88#-----------------------------------------------------------------------------
89print("\nInitializing experiment\n")
90
91# Create an object that describes the network configuration of the host PC
92network_config = config.WlanExpNetworkConfiguration(network=NETWORK,
93                                                    jumbo_frame_support=USE_JUMBO_ETH_FRAMES)
94
95# Create an object that describes the WARP v3 nodes that will be used in this experiment
96nodes_config   = config.WlanExpNodesConfiguration(network_config=network_config,
97                                                  serial_numbers=NODE_SERIAL_LIST)
98
99# Initialize the Nodes
100#   This command will fail if either WARP v3 node does not respond
101nodes = util.init_nodes(nodes_config, network_config)
102
103# Set the time of all the nodes to zero
104util.broadcast_cmd_set_mac_time(0, network_config)
105
106# Extract the different types of nodes from the list of initialized nodes
107#     - This will work for both 'DCF' and 'NOMAC' mac_low projects
108n_ap_l  = util.filter_nodes(nodes=nodes, mac_high='AP',  serial_number=NODE_SERIAL_LIST)
109n_sta_l = util.filter_nodes(nodes=nodes, mac_high='STA', serial_number=NODE_SERIAL_LIST)
110
111# Check that setup is valid
112if len(n_ap_l) == 1 and len(n_sta_l) == 1:
113    # Extract the two nodes from the lists for easier referencing below
114    n_ap  = n_ap_l[0]
115    n_sta = n_sta_l[0]
116
117    # Configure the AP to reject authentication requests from wireless clients
118    #     - Uncomment this line to block any wireless associations during the experiment
119    # n_ap.set_authentication_address_filter(allow='NONE')
120
121    # Configure AP BSS
122    n_ap.configure_bss(ssid=SSID, channel=CHANNEL, beacon_interval=BEACON_INTERVAL)
123
124    # Establish the association state between nodes
125    #     - This will change the STA to the appropriate channel
126    n_ap.add_association(n_sta)
127else:
128    print("ERROR: Node configurations did not match requirements of script.\n")
129    print("    Ensure two nodes are ready, one using the AP design, one using the STA design\n")
130    sys.exit(0)
131
132# Check that the nodes are part of the same BSS.  Otherwise, the LTGs below will fail.
133if not util.check_bss_membership([n_ap, n_sta]):
134    print("\nERROR: Nodes are not part of the same BSS.")
135    util.check_bss_membership([n_ap, n_sta], verbose=True)
136    print("Ensure that both nodes are part of the same BSS.")
137    sys.exit(0)
138
139
140print("\nExperimental Setup:")
141
142# Set the rate of both nodes to 26 Mbps (mcs = 3, phy_mode = 'HTMF')
143mcs       = 3
144phy_mode  = util.phy_modes['HTMF']
145rate_info = util.get_rate_info(mcs, phy_mode)
146
147# Put each node in a known, good state
148for node in nodes:
149    node.set_tx_rate_data(mcs, phy_mode, device_list='ALL_UNICAST')
150    node.log_configure(log_full_payloads=False)
151    node.reset(log=True, txrx_counts=True, ltg=True, tx_queues=True) # Do not reset associations/bss_info
152    node.configure_bss(channel=CHANNEL)
153   
154    #Disable Ethernet portal to limit traffic to LTG
155    node.enable_ethernet_portal(enable=False)
156
157# Add the current time to all the nodes
158util.broadcast_cmd_write_time_to_logs(network_config)
159
160
161print("\nRun Experiment:")
162
163print("\nStart LTG - AP -> STA")
164# Start a flow from the AP's local traffic generator (LTG) to the STA
165#     - Set the flow to 1400 byte payloads, fully backlogged (0 usec between new pkts), run forever
166#     - Start the flow immediately
167ap_ltg_id  = n_ap.ltg_configure(ltg.FlowConfigCBR(dest_addr=n_sta.wlan_mac_address,
168                                                  payload_length=1400, 
169                                                  interval=0), auto_start=True)
170
171# Let the LTG flows run at the new rate
172time.sleep(TRIAL_TIME/3)
173
174
175print("\nStart LTG - STA -> AP")
176# Start a flow from the STA's local traffic generator (LTG) to the AP
177#     - Set the flow to 1400 byte payloads, fully backlogged (0 usec between new pkts), run forever
178#     - Start the flow immediately
179sta_ltg_id = n_sta.ltg_configure(ltg.FlowConfigCBR(dest_addr=n_ap.wlan_mac_address,
180                                                   payload_length=1400, 
181                                                   interval=0), auto_start=True)
182
183# Let the LTG flows run at the new rate
184time.sleep(TRIAL_TIME/3)
185
186print("\nStop  LTG - STA -> AP")
187
188# Stop the LTG flow and purge the transmit queue so that nodes are in a known, good state
189n_sta.ltg_stop(sta_ltg_id)
190n_sta.purge_tx_queues()
191
192# Let the LTG flows run at the new rate
193time.sleep(TRIAL_TIME/3)
194
195print("\nStop  LTG - AP -> STA")
196
197# Stop the LTG flow and purge the transmit queue so that nodes are in a known, good state
198n_ap.ltg_stop(ap_ltg_id)
199n_ap.purge_tx_queues()
200
201# Remove the LTGs so there are no memory leaks
202n_ap.ltg_remove(ap_ltg_id)
203n_sta.ltg_remove(sta_ltg_id)
204
205# Look at the final log sizes for reference
206ap_log_size  = n_ap.log_get_size()
207sta_log_size = n_sta.log_get_size()
208
209print("\nLog Sizes:  AP  = {0:10,d} bytes".format(ap_log_size))
210print("            STA = {0:10,d} bytes".format(sta_log_size))
211
212# Write Log Files for processing by other scripts
213print("\nWriting Log Files...")
214
215write_log_file(filename=STA_HDF5_FILENAME, node=n_sta, exp_name='STA: Two Node, Two Flow')
216write_log_file(filename=AP_HDF5_FILENAME, node=n_ap, exp_name='AP: Two Node, Two Flow')
217
218for node in nodes:
219    node.enable_ethernet_portal(enable=True)
220
221print("Done.")
Note: See TracBrowser for help on using the repository browser.