📄 run_expt.py
字号:
#!/usr/bin/env python# collect stats for each machine# ssh and start click# set up parameters, arp and routing table# set up flows# start flows and sleep# stop flows and collect stats# display throughputimport sys, os, math, string, traceback, getopt, timessh_str = "ssh -x -o LogLevel=QUIET -q -2"def wrt(handler, node):# print ('echo -n "%s " ; echo "write ' + handler + '" | nc -q 1 %s 7777') % (node, node) os.system(('echo -n "%s " ; echo "write ' + handler + '" | nc -q 1 %s 7777') % (node, node))def rd(handler, node): """ read and return the stripped output """ p = os.popen('echo "read ' + handler + '" | nc -q 1 %s 7777' % node) result = [] p.readline() # skips hello string if(p.readline().startswith("200")): p.readline() # skip DATA for l in p: result.append(l) p.close() return resultdef Rip(mac, prefix): """Converts MAC address to Roofnet IP address""" return ".".join([str(prefix)] + map(lambda(s) : str(int(s,16)), mac.split(':')[3:]))def get_node_info(node): out = os.popen("%s root@%s \"ifconfig ath0 up; ifconfig ath0 | grep HWaddr \" " % (ssh_str, node)).readlines() macaddr = string.strip(string.split(out[0])[4]) rip = Rip(macaddr, "5") nodes[node] = (node, macaddr, rip)def move_to_node(node): os.system("%s root@%s \"killall -9 click > /dev/null 2>&1\"" % (ssh_str, node)) print "moving files" os.system("scp ../../userlevel/click ./gen_config_cope_ls_norouting.pl ./cope_config_ls_norouting.click root@%s:/tmp/ 1>/dev/null" % (node))def start_click(node): print "starting click" os.system("%s root@%s \"killall -9 click > /dev/null 2>&1\"" % (ssh_str, node)) os.system("%s root@%s \"cd /tmp/; ./gen_config_cope_ls_norouting.pl --dev ath0 > test_full.click\"" % (ssh_str, node)) os.system("%s root@%s \"cd /tmp/; ./click test_full.click > /tmp/click.log 2>&1&\"" % (ssh_str, node)) print "started click"def set_common_params(node, coding): wrt("srcr/sendmgr.max_xmits 1", node) wrt("srcr/recvmgr.enable_acks false", node) wrt("srcr/scramble_q.enable_coding %s" % (coding), node) def set_arp(node): for neigh_node in nodes.keys(): wrt("srcr/arp.insert %s %s" % (nodes[neigh_node][2], nodes[neigh_node][1]), nodes[node][0]) print "srcr/arp.insert %s %s" % (nodes[neigh_node][2], nodes[neigh_node][1])def set_routing_table(alice, router, bob): # Alice wrt("srcr/set_sr.set_route %s %s %s" % (nodes[alice][2], nodes[router][2], nodes[bob][2]), alice) wrt("srcr/set_sr.set_route %s %s" % (nodes[alice][2], nodes[router][2]), alice) # Router wrt("srcr/set_sr.set_route %s %s" % (nodes[router][2], nodes[bob][2]), router) wrt("srcr/set_sr.set_route %s %s" % (nodes[router][2], nodes[alice][2]), router) # Bob wrt("srcr/set_sr.set_route %s %s %s" % (nodes[bob][2], nodes[router][2], nodes[alice][2]), bob) wrt("srcr/set_sr.set_route %s %s" % (nodes[bob][2], nodes[router][2]), bob)def set_flows(alice, bob): # Alice wrt("udpencap.flow %s 3456 %s 3457" % (nodes[alice][2], nodes[bob][2]), alice) # Bob wrt("udpencap.flow %s 3456 %s 3457" % (nodes[bob][2], nodes[alice][2]), bob)def start_flows(alice, bob): wrt("rsource.active true", alice) wrt("rsource.active true", bob)def kill_flows(alice, bob): wrt("rsource.active false", alice) wrt("rsource.active false", bob)def print_tput(alice, bob): # Alice cnt_res_alice = rd("pkcount.byte_count", alice) tot_recv_alice = int(string.strip(string.split(cnt_res_alice[0])[0])) # Bob cnt_res_bob = rd("pkcount.byte_count", bob) tot_recv_bob = int(string.strip(string.split(cnt_res_bob[0])[0])) print "\n \n ==============================================================================" print "Throughput from Alice to Bob (KB/s) : %f \n" % (tot_recv_alice/60000.0) print "Throughput from Bob to Alice (KB/s) : %f \n" % (tot_recv_bob/60000.0) print "Total throughput (KB/s): %f \n" % ((tot_recv_alice+tot_recv_bob)/60000.0)if (__name__ == '__main__'): try: optlist, args = getopt.getopt(sys.argv[1:], '', ['coding=']) for o,a in optlist: if o in ("--coding"): print "picked up coding" coding = a except: traceback.print_exc() print "Usage: python run.py <alice IP> <router IP> <bob IP> --coding=<1 or 0 to enable or disable coding >" sys.exit(1) try: alice = sys.argv[1] router = sys.argv[2] bob = sys.argv[3] coding = sys.argv[4] except: print "Usage: python run.py <alice IP> <router IP> <bob IP> <true or false to enable or disable coding >" print "You need to input the 3 IP addresses of the nodes simulating the Alice-Bob topology" sys.exit(1) nodes = {} get_node_info(alice) get_node_info(router) get_node_info(bob) for node in nodes.keys(): move_to_node(node) for node in nodes.keys(): start_click(node) for node in nodes.keys(): set_common_params(node, coding) for node in nodes.keys(): set_arp(node) set_routing_table(alice, router, bob) set_flows(alice, bob) start_flows(alice, bob) time.sleep(60) kill_flows(alice, bob) time.sleep(10) print_tput(alice, bob)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -