def stop_network(): logging.getLogger(__name__).info('Stopping simulated network...') # stop apache instances logging.getLogger(__name__).info('Stopping apache...') try: reset_apache(get_server_ip_list()) restart_apache() except Exception as e: logging.getLogger(__name__).error(e) # Stop traffic shaping logging.getLogger(__name__).info('Disabling traffic shaping...') try: check_output('%s stop' % TC_SETUP) except Exception as e: logging.getLogger(__name__).error(e) # Destroy fake NICs logging.getLogger(__name__).info('Destroying network interfaces...') try: check_both('killall -9 click', shouldPrint=False) time.sleep(0.1) except: pass logging.getLogger(__name__).info('Network stopped.')
def setUp(self): check_both('killall -9 proxy', False, False) check_both('killall -9 nameserver', False, False) self.start_netsim() self.proxyport1 = random.randrange(1025, 60000) self.proxyport2 = random.randrange(1025, 60000) self.dnsport = random.randrange(1025, 60000)
def run_proxy(self, log, alpha, listenport, fakeip, dnsip, dnsport, serverip=''): check_both('rm %s' % log, False, False) run_bg('%s %s %s %s %s %s %s %s'\ % (PROXY, log, alpha, listenport, fakeip, dnsip, dnsport, serverip))
def test_proxy_alpha(self): log_switch = [] log_switch.append(self.run_alpha_test('0.1', 30)) check_both('killall -9 proxy', True, False) self.proxyport1 = random.randrange(1025, 6000) log_switch.append(self.run_alpha_test('0.5', 10)) check_both('killall -9 proxy', True, False) self.proxyport1 = random.randrange(1025, 6000) log_switch.append(self.run_alpha_test('0.9', 10)) print log_switch self.assertTrue(log_switch[0] >= log_switch[1]) self.assertTrue(log_switch[1] >= log_switch[2]) print 'done test_proxy_alpha'
def stop(): out = check_both('%s qdisc del dev %s root' % (TC, args.interface), shouldPrint=False, check=False) if out[1] != 0 and 'RTNETLINK answers: No such file or directory' not in out[ 0][0]: raise Exception("Error stopping traffic shaping")
def stop_servers(): logging.getLogger(__name__).info('Stopping simulated network...') # stop apache instances logging.getLogger(__name__).info('Stopping apache...') if args.topology == 'servers': servers = [] with open(args.servers) as servers_file: for line in strip_comments(servers_file): servers.append(int(line)) servers_file.closed try: reset_apache(servers) restart_apache() except Exception as e: logging.getLogger(__name__).error(e) else: if args.topology == 'onelink': try: reset_apache(['127.0.0.1:8080']) restart_apache() except Exception as e: logging.getLogger(__name__).error(e) else: try: reset_apache(['127.0.0.1:8080', '127.0.0.1:8081']) restart_apache() except Exception as e: logging.getLogger(__name__).error(e) # Destroy fake NICs logging.getLogger(__name__).info('Destroying bandwidth shaper...') try: check_both('killall -9 click', shouldPrint=False) time.sleep(0.1) except: pass logging.getLogger(__name__).info('Network stopped.')
def tearDown(self): check_both('killall -9 proxy', False, False) check_both('killall -9 nameserver', False, False) self.stop_netsim()
def get_curl(self, url): return check_both("curl -f -s %s" % url, shouldPrint=False)[0][0]
def is_tc_configured(): return 'htb' in check_both('%s show'\ % (TC_SETUP), shouldPrint=False, check=False)[0][0]
def is_click_running(): return 'click' in check_both('ps -e | grep click | grep -v grep'\ , shouldPrint=False, check=False)[0][0]
def stop(): out = check_both('%s qdisc del dev %s root' % (TC, args.interface), shouldPrint=False, check=False) if out[1] is not 0 and 'RTNETLINK answers: No such file or directory' not in out[0][0]: raise Exception("Error stopping traffic shaping")
def terminate_counters(): check_both('killall tcpdump', False, False)
def is_tc_configured(): return "htb" in check_both("%s show" % (TC_SETUP), shouldPrint=False, check=False)[0][0]
def is_click_running(): return "click" in check_both("ps -e | grep click | grep -v grep", shouldPrint=False, check=False)[0][0]