bitrate_test.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 import sys
00004 import time
00005 import subprocess
00006 
00007 import roslib; roslib.load_manifest('network_monitor_udp')
00008 import rospy
00009 from network_monitor_udp.linktest import UdpmonsourceHandle
00010 from network_monitor_udp.linktest import LinkTest
00011 from network_monitor_udp.msg import LinktestGoal
00012 import dynamic_reconfigure.client
00013 
00014 AP_PREFIX="/ap_atheros/"
00015 HOSTAPD_NODE=AP_PREFIX+"ap_control"
00016 AP_SINK_IP="192.168.69.1"
00017 AP_SINK_PORT=12345
00018 
00019 STA_PREFIX="/sta/"
00020 STA_IFACE="eth1"
00021 STA_SINK_IP="192.168.69.2"
00022 STA_SINK_PORT=12345
00023 
00024 bitrates = [ int(rate*10**6) for rate in [ 1, 2, 5.5, 6, 9, 11, 12, 18, 24, 36, 48, 54 ] ]
00025 
00026 DEFAULT_PACKET_SIZE = 1500
00027 
00028 def run_link_capacity_test(direction = "down", rate = bitrates[0]):
00029     if direction == "up":
00030         ret = subprocess.call(["iwconfig", STA_IFACE, "rate", str(rate)])
00031         if ret != 0:
00032             raise IOError("iwconfig could not set bitrate on " + STA_IFACE)
00033         return sta_source.get_link_capacity(sink_ip=AP_SINK_IP, sink_port=AP_SINK_PORT, rostopic_prefix=AP_PREFIX, pktsize=pktsize)
00034     elif direction == "down":
00035         config = dynclient.update_configuration({"bitrate": rate})
00036         if config["status"] != "OK":
00037             raise ValueError(config["errmsg"])
00038         return ap_source.get_link_capacity(sink_ip=STA_SINK_IP, sink_port=STA_SINK_PORT, rostopic_prefix=STA_PREFIX, pktsize=pktsize)
00039         
00040 def setup_hostapd_ap():        
00041     config = dynclient.update_configuration({"enabled": True, "ssid": "testnet", "mode": "g"})
00042     if config["status"] != "OK":
00043         raise ValueError(config["errmsg"])
00044 
00045 if __name__ == '__main__':
00046     pktsize = DEFAULT_PACKET_SIZE
00047     if len(sys.argv) == 2:
00048         pktsize = int(sys.argv[1])
00049 
00050     rospy.init_node('testnode')
00051 
00052     dynclient = dynamic_reconfigure.client.Client(HOSTAPD_NODE)
00053     
00054     ap_source = UdpmonsourceHandle('/ap_atheros/performance_test') 
00055     sta_source = UdpmonsourceHandle('/sta/performance_test') 
00056     ap_source.cancel_all_tests()
00057     sta_source.cancel_all_tests()
00058 
00059     setup_hostapd_ap()
00060 
00061     print "# Link capacity test"
00062     print "# Packet size: %d bytes"%(pktsize)
00063     print "# bitrate uplink_capacity downlink_capacity"
00064     for rate in bitrates:
00065         print rate, run_link_capacity_test("up", rate), run_link_capacity_test("down", rate)
00066 


network_control_tests
Author(s): Catalin Drula
autogenerated on Wed Sep 16 2015 04:38:36