def setup_nodes(net: mininet.net.Mininet, configs): # hardcode some stuff here tcp_port1 = 9998 tcp_port2 = 9999 if configs.h2 else None h1 = net.get("h1") h3 = net.get("h3") h1_result = get_filename(h1, configs) h2_result = get_filename("h2", configs) # need to remove this file if already exists for filename in {h1_result, h2_result}: if os.path.exists(filename): os.remove(filename) h3_proc = multiprocessing.Process(target=setup_mininet_iperf_server, args=(h3, tcp_port1, tcp_port2, configs)) h1_proc = multiprocessing.Process(target=setup_client, args=(h1, h3, configs, tcp_port1, h1_result)) if configs.h2: h2 = net.get("h2") h2_proc = multiprocessing.Process(target=setup_client, args=(h2, h3, configs, tcp_port2, h2_result, configs.h2_cc)) else: h2_proc = None h3_proc.start() time.sleep(2 if configs.h2 else 0.5) h1_proc.start() if configs.h2: h2_proc.start() processes = [h3_proc, h1_proc, h2_proc] return processes
def start_attack(net, period, burst): mallory = net.get('mallory') bob = net.get('bob') print('UDP attack started from {} to {}.'.format(mallory.IP(), bob.IP())) return mallory.popen([ 'python', 'run_attacker.py', '--period', str(period), '--burst', str(burst), '--destination', bob.IP() ])
def set_interface(net, min_rto_ms): for host in ['alice', 'bob']: node = net.get(host) current_config = node.cmd('ip route show').strip() new_config = '%s rto_min %dms' % (current_config, min_rto_ms) node.cmd('ip route change %s' % new_config, shell=True) node.cmd('ethtool -K {}-eth0 tso off gso off gro off'.format(host))
def main(): "Create a simple network" get_ip_setting() topo = TwoServerClientAndRouterTopology() info('*** Creating network\n') net = mininet.net.Mininet(topo=topo, controller=mininet.node.RemoteController, ipBase=IPBASE) net.start() server1, server2, client, router = net.get('server1', 'server2', 'client', 'sw0') s1intf = server1.defaultIntf() s1intf.setIP('%s/8' % IP_SETTING['server1']) s2intf = server2.defaultIntf() s2intf.setIP('%s/8' % IP_SETTING['server2']) clintf = client.defaultIntf() clintf.setIP('%s/8' % IP_SETTING['client']) for host in server1, server2, client: set_default_route(host) # set_default_route_client(client) starthttp(server1) starthttp(server2) CLI(net) stophttp() net.stop()
def run_flow(net, ntcp, cwnd_file=None): alice = net.get('alice') bob = net.get('bob') print('Starting receiver on {}.'.format(bob.IP())) s = bob.popen('./run_receiver.sh', shell=True) # Wait for receiver to start listening. time.sleep(1.0) print('Starting sender on {}.'.format(alice.IP())) start = time.time() sender_cmd = './run_sender.sh -t {}'.format(bob.IP()) if cwnd_file is not None: sender_cmd += ' -p {}'.format(cwnd_file)+' -n {}'.format(ntcp) c = alice.popen(sender_cmd, shell=True) print('TCP flow started on Alice and Bob.') assert c.wait() == 0 assert s.wait() == 0 return time.time() - start
def set_interface(net, min_rto_ms): # From: https://serverfault.com/questions/529347/how-to-apply-rto-min-to-a-certain-host-in-centos for host in ['alice', 'bob']: node = net.get(host) current_config = node.cmd('ip route show').strip() new_config = '%s rto_min %dms' % (current_config, min_rto_ms) node.cmd('ip route change %s' % new_config, shell=True) node.cmd('ethtool -K {}-eth0 tso off gso off gro off'.format(host))
def cleanup_mininet(net: mininet.net.Mininet, processes): h3_proc, h1_proc, h2_proc = processes for p in {h1_proc, h2_proc}: if p is not None: p.join() h3_proc.kill() h3 = net.get("h3") # killall iperf3 instances h3.cmd("killall iperf3") mininet.clean.cleanup()
def main(): parser = argparse.ArgumentParser(description="TCP DoS simulator.") parser.add_argument( '--burst', '-b', help="Burst duration in seconds of each DoS attack.", type=float, default=0.15) parser.add_argument( '--cong', help="Congestion control algorithm to use.", default='reno') parser.add_argument( '--suffix', '-s', help="Suffix for output directory", type=str, default='default') parser.add_argument( '--period', '-p', help="Seconds between low-rate DoS attacks, e.g. 0.5", type=float, default=0.5) parser.add_argument( '--nc', '-n', help="Number of TCP connections, e.g. 1", type=int, default=1) parser.add_argument( '--rto', '-r', help="rto_min value, in ms", type=int, default=1000) args = parser.parse_args() # Initialize kernel parameters. subprocess.check_call( 'sysctl -q -w net.ipv4.tcp_congestion_control=%s' % args.cong, shell=True) subprocess.check_call('sysctl -q -w net.ipv4.tcp_sack=0', shell=True) subprocess.check_call('sysctl -q -w net.ipv4.tcp_dsack=0', shell=True) subprocess.check_call('sysctl -q -w net.ipv4.tcp_fack=0', shell=True) topo = Topo() net = mininet.net.Mininet( topo=topo, host=mininet.node.CPULimitedHost, link=mininet.link.TCLink) net.start() set_interface(net, args.rto) print('Alice\'s IP is {}.'.format(net.get('alice').IP())) print('Bob\'s IP is {}.'.format(net.get('bob').IP())) print('Mallory\'s IP is {}.'.format(net.get('mallory').IP())) print('') output_dir = 'results-{}'.format(args.suffix) if not os.path.isdir(output_dir): os.mkdir(output_dir) time_file = os.path.join(output_dir, 't-{}-{}.txt'.format( args.period, args.burst)) cwnd_file = os.path.join(output_dir, 'cwnd-{}-{}.txt'.format( args.period, args.burst)) print("NUmber of TCP connection(s) = {}\n".format(args.nc)) attack = start_attack(net, args.period, args.burst) t = run_flow(net, args.nc, cwnd_file=cwnd_file) print('Sending completed in %.4f seconds.' % t) with open(time_file, 'w') as f: f.write(str(t) + '\n') attack.terminate() net.stop()
import mininet.net net.get("host1").setIP("10.10.10.6", 24) net.get("host2").setIP("10.10.10.7", 24) net.get("host3").setIP("10.10.10.8", 24) net.get("host4").setIP("10.10.10.9", 24) net.get("host5").setIP("10.10.10.10", 24) net.get("host6").setIP("10.10.10.11", 24) net.get("host7").setIP("10.10.10.12", 24) net.get("host8").setIP("10.10.10.13", 24) net.get("host9").setIP("10.10.10.14", 24) net.get("server1").setIP("10.10.10.1", 24) net.get("server2").setIP("10.10.10.2", 24) net.get("server3").setIP("10.10.10.3", 24) net.get("server4").setIP("10.10.10.4", 24) net.get("server5").setIP("10.10.10.5", 24)
def main(args): "Create a simple network" get_ip_setting() topo = TwoServerClientAndRouterTopology() info( '*** Creating network\n' ) net = mininet.net.Mininet(topo=topo, controller=mininet.node.RemoteController, ipBase=IPBASE ) net.start() server1, server2, client, router = net.get( 'server1', 'server2', 'client', 'sw0') s1intf = server1.defaultIntf() s1intf.setIP('%s/8' % IP_SETTING['server1']) s2intf = server2.defaultIntf() s2intf.setIP('%s/8' % IP_SETTING['server2']) clintf = client.defaultIntf() clintf.setIP('%s/8' % IP_SETTING['client']) for host in server1, server2, client: set_default_route(host) # set_default_route_client(client) starthttp( server1 ) starthttp( server2 ) # CLI( net ,script="test.sh") # total credit credit = 85 strict_mode = False if(len(args)==2): if args[1]=='-s' or args[1]=='--strict': strict_mode = True print("Enable strict mode...") # test client ping router interface print("Start test ping...") deduction = test_ping("client ping 192.168.2.1",client,"192.168.2.1",strict_mode=strict_mode) credit-=deduction deduction = test_ping("client ping 172.64.3.1",client,"172.64.3.1",strict_mode=strict_mode) credit-=deduction deduction = test_ping("client ping 172.64.3.1",client,"10.0.1.1",strict_mode=strict_mode) credit-=deduction deduction = test_ping("client ping server1",client,server1.IP(),strict_mode=strict_mode) credit-=deduction deduction = test_ping("client ping server2",client,server2.IP(),strict_mode=strict_mode) credit-=deduction # test client ping error ip deduction = test_ping("client ping 192.168.2.3",client,"192.168.2.3",False,strict_mode=strict_mode) credit-=deduction # test client traceroute print("Start test traceroute...") deduction = test_traceroute("client traceroute 192.168.2.1",client,"192.168.2.1",["10.0.1.1"],strict_mode=strict_mode); credit-=deduction deduction = test_traceroute("client traceroute 172.64.3.1",client,"172.64.3.1",["10.0.1.1"],strict_mode=strict_mode); credit-=deduction deduction = test_traceroute("client traceroute 10.0.1.1",client,"10.0.1.1",["10.0.1.1"],strict_mode=strict_mode); credit-=deduction deduction = test_traceroute("client traceroute server1",client,server1.IP(),["10.0.1.1","192.168.2.2"],strict_mode=strict_mode); credit-=deduction deduction = test_traceroute("client traceroute server2",client,server2.IP(),["10.0.1.1","172.64.3.10"],strict_mode=strict_mode); credit-=deduction # test wget download file print("Start test wget...") deduction = test_wget("client wget http://192.168.2.2/index.html",client,"http://192.168.2.2/index.html",strict_mode=strict_mode) credit-=deduction deduction = test_wget("client wget http://172.64.3.10/index.html",client,"http://172.64.3.10/index.html",strict_mode=strict_mode) credit-=deduction print("Start test wget big file...") deduction = test_wget("client wget http://192.168.2.2/tmp",client,"http://192.168.2.2/tmp",strict_mode=strict_mode) credit-=deduction print("Congratulations: Your credit is {}".format(credit)) stophttp() net.stop()