def simpleTest(hosts): net = TreeNet(depth=1, fanout=hosts, autoSetMacs=True, controller=partial(RemoteController, ip='127.0.0.1', port=6633)) net.items() #print(net.items()) host = net.items()[0][0] #print(net.get(host).MAC()) for i in net.items(): string1 = i[0] string2 = 'h' if cmp(string1[0:1], string2[0:1]) == 0: db = MySQLdb.connect("localhost", "root", "44123429", "mininet") cursor = db.cursor() sql = "INSERT IGNORE INTO HOSTS(MAC, TEAM) VALUES ('%s', '%s')" % ( net.get(i[0]).MAC(), 0) #try: cursor.execute(sql) db.commit() #except: #db.rollback() db.close() print(net.get(i[0]).MAC()) #print(net.get(host).MAC()) # Configure and start NATted connectivity rootnode = connectToInternet(net) print "*** Hosts are running and should have internet connectivity" print "*** Type 'exit' or control-D to shut down network" CLI(net) # Shut down NAT stopNAT(rootnode) net.stop()
def simpleTest(hosts): net = TreeNet( depth=1, fanout=hosts, autoSetMacs=True, controller=partial(RemoteController, ip='127.0.0.1', port=6633 )) net.items() #print(net.items()) host=net.items()[0][0] #print(net.get(host).MAC()) for i in net.items(): string1 = i[0] string2 = 'h' if cmp(string1[0:1],string2[0:1]) == 0: db = MySQLdb.connect("localhost","root","44123429","mininet" ) cursor = db.cursor() sql = "INSERT IGNORE INTO HOSTS(MAC, TEAM) VALUES ('%s', '%s')" % (net.get(i[0]).MAC(), 0) #try: cursor.execute(sql) db.commit() #except: #db.rollback() db.close() print(net.get(i[0]).MAC()) #print(net.get(host).MAC()) # Configure and start NATted connectivity rootnode = connectToInternet( net ) print "*** Hosts are running and should have internet connectivity" print "*** Type 'exit' or control-D to shut down network" CLI( net ) # Shut down NAT stopNAT( rootnode ) net.stop()
def run_mininet(depth_val): for i in depth_val: network = TreeNet( depth=i, fanout=2, switch=OVSKernelSwitch ) network.start() all_topos[i]=network.pingAllFull() all_perf[i]=network.iperf(fmt='g') proc_ping(i) proc_iperf(i) network.stop()
def treePing64(): "Run ping test on 64-node tree networks." results = {} switches = { 'reference user': UserSwitch, 'Open vSwitch kernel': OVSKernelSwitch } for name in switches: info( "*** Testing", name, "datapath\n" ) switch = switches[ name ] network = TreeNet( depth=2, fanout=8, switch=switch, waitConnected=True ) result = network.run( network.pingAll ) results[ name ] = result info( "\n*** Tree network ping results:\n" ) for name in switches: info( "%s: %d%% packet loss\n" % ( name, results[ name ] ) ) info( '\n' )
def treePing64(): "Run ping test on 64-node tree networks." results = {} switches = { # 'reference kernel': KernelSwitch, 'reference user': UserSwitch, 'Open vSwitch kernel': OVSKernelSwitch } for name in switches: info( "*** Testing", name, "datapath\n" ) switch = switches[ name ] network = TreeNet( depth=2, fanout=8, switch=switch ) result = network.run( network.pingAll ) results[ name ] = result info( "\n*** Tree network ping results:\n" ) for name in switches: info( "%s: %d%% packet loss\n" % ( name, results[ name ] ) ) info( '\n' )
def treePing64(): "Run ping test on 64-node tree networks." results = {} switches = { # 'reference kernel': KernelSwitch, 'reference user': UserSwitch, 'Open vSwitch kernel': OVSKernelSwitch } for name in switches: print "*** Testing", name, "datapath" switch = switches[ name ] network = TreeNet( depth=2, fanout=8, switch=switch ) result = network.run( network.pingAll ) results[ name ] = result print print "*** Tree network ping results:" for name in switches: print "%s: %d%% packet loss" % ( name, results[ name ] ) print
def simpleTest(): print("infection hosts rate:") inf_rate = eval(input()) print("k:") k = eval(input()) grow_time = 20 atck_time = 40 test_time = 50 max = grow_time * k controller = RemoteController('Runos', ip='127.0.0.1', port=6653) switch = partial(OVSKernelSwitch, protocols='OpenFlow13') net = TreeNet(depth=2, fanout=3, controller=controller, switch=switch, cleanup=True) net.start() sleep(3) hosts = net.topo.hosts() inf_amount = round(inf_rate * len(hosts)) inf_hosts = [] while inf_amount: num = randint(0, 8) if inf_amount and not (hosts[num] in inf_hosts): inf_hosts.append(hosts[num]) inf_amount -= 1 print(inf_hosts) general_capacity_per_sec = max / len(inf_hosts) connection_interval = grow_time / len(inf_hosts) send_delay_for_host = round(1000 / general_capacity_per_sec) print(send_delay_for_host) infection_sequence = numpy.arange(len(inf_hosts)) numpy.random.shuffle(infection_sequence) start = monotonic() childs = [] for i in range(len(hosts)): try: pid = os.fork() except: print('error: create child process') sys.exit(33) if pid == 0: host = net.get(hosts[i]) if hosts[i] in inf_hosts: index = inf_hosts.index(hosts[i]) host_turn = connection_interval * infection_sequence[index] ping_pair = net.get(hosts[i - 1]) curr_time = monotonic() - start interval = ( 2.5 + host_turn - curr_time) if (2.5 + host_turn - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) ping_pair = net.get(hosts[i - 2]) curr_time = monotonic() - start interval = ( 5 + host_turn - curr_time) if (5 + host_turn - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) curr_time = monotonic() - start sleep_time = 5 + host_turn - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start interval = 5 + atck_time - curr_time if (5 + atck_time - curr_time) >= 1 else 1 print("curr_time=%s :: %s start attack" % (curr_time, host.IP())) host.cmd( "./runos/src/apps/ddos-defender/scripts/atckWithOpts.sh %s %s %s %s" % (host.MAC(), host.IP(), interval, send_delay_for_host)) while curr_time < test_time + 5: curr_time = monotonic() - start interval = ( 5 + test_time - curr_time) if (5 + test_time - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) sleep(0.5) file_name = "atck_duration_" + str(i) + ".txt" handle = open(file_name, "w") handle.write("'%s' : [%s, %s]" % (net.get( hosts[i]).IP(), 5 + host_turn + 6, 5 + atck_time + 6)) handle.close() else: ping_pair = net.get(hosts[i - 1]) curr_time = monotonic() - start interval = (5 - curr_time) if (5 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) ping_pair = net.get(hosts[i - 2]) curr_time = monotonic() - start interval = (25 - curr_time) if (25 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) ping_pair = net.get(hosts[i - 3]) curr_time = monotonic() - start interval = ( test_time + 5 - curr_time) if (test_time + 5 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) sys.exit(3) if pid > 0: childs.append(pid) for p in childs: pid, status = os.wait() print('childs end') host = net.get(hosts[0]) handleResult = open("runos/src/apps/ddos-defender/tests/infectedMACs.txt", "w") handleResult.write("{") for i in range(len(hosts)): if hosts[i] in inf_hosts: file_name = "atck_duration_" + str(i) + ".txt" handle = open(file_name, "r") result = handle.read() handleResult.write(result) if i < (len(hosts) - 1): handleResult.write(", ") handle.close() cmnd = "sudo rm " + file_name host.cmd(cmnd) handleResult.write("}") handleResult.close() CLI(net) net.stop()
# Create link between root NS and switch link = network.addLink(root, switch) link.intf1.setIP(rootip, prefixLen) # Start network that now includes link to root namespace network.start() # Start NAT and establish forwarding startNAT(root) # Establish routes from end hosts for host in network.hosts: host.cmd('ip route flush root 0/0') host.cmd('route add -net', subnet, 'dev', host.defaultIntf()) host.cmd('route add default gw', rootip) return root if __name__ == '__main__': lg.setLogLevel('info') net = TreeNet(depth=1, fanout=4) # Configure and start NATted connectivity rootnode = connectToInternet(net) print " *** Hosts are running and should have internet connectivity" print " *** Type 'exit' or control-D to shut down network" CLI(net) # Shut down NAT stopNAT(rootnode) net.stop()
def simpleTest(): print("infection hosts rate:") inf_rate = eval(input()) print("amplituda (packets per second):") max = eval(input()) print("period T:") grow_time = eval(input()) / 2 atck_time = 40 test_time = 50 controller = RemoteController('Runos', ip='127.0.0.1', port=6653) switch = partial(OVSKernelSwitch, protocols='OpenFlow13') net = TreeNet(depth=2, fanout=3, controller=controller, switch=switch, cleanup=True) net.start() sleep(3) hosts = net.topo.hosts() inf_amount = round(inf_rate * len(hosts)) inf_hosts = [] while inf_amount: num = randint(0, 8) if inf_amount and not (hosts[num] in inf_hosts): inf_hosts.append(hosts[num]) inf_amount -= 1 hosts = net.topo.hosts() general_capacity_per_sec = max / len(inf_hosts) num_intervals = round(grow_time / 2) offset_delay = round((1000 / general_capacity_per_sec) / num_intervals) print(hosts) start = monotonic() childs = [] for i in range(len(hosts)): try: pid = os.fork() except: print('error: create child process') sys.exit(33) if pid == 0: host = net.get(hosts[i]) if hosts[i] in inf_hosts: ping_pair = net.get(hosts[i - 1]) curr_time = monotonic() - start interval = (2.5 - curr_time) if (2.5 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) ping_pair = net.get(hosts[i - 2]) curr_time = monotonic() - start interval = (5 - curr_time) if (5 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) k = 0 while curr_time < atck_time + 5: curr_time = monotonic() - start sleep_time = grow_time * 2 * k + 5 - curr_time if sleep_time > 0: sleep(sleep_time) send_delay = 0 for j in range(num_intervals): curr_time = monotonic() - start send_delay += offset_delay if (curr_time + 2 < atck_time + 5): print("curr_time=%s :: %s start attack" % (curr_time, host.IP())) host.cmd( "./runos/src/apps/ddos-defender/scripts/atckWithOpts.sh %s %s %s %s" % (host.MAC(), host.IP(), 2, send_delay)) for j in range(num_intervals): curr_time = monotonic() - start if (curr_time + 2 < atck_time + 5): print("curr_time=%s :: %s start attack" % (curr_time, host.IP())) host.cmd( "./runos/src/apps/ddos-defender/scripts/atckWithOpts.sh %s %s %s %s" % (host.MAC(), host.IP(), 2, send_delay)) send_delay -= offset_delay k += 1 while curr_time < test_time + 5: curr_time = monotonic() - start interval = ( 5 + test_time - curr_time) if (5 + test_time - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) sleep(0.5) file_name = "atck_duration_" + str(i) + ".txt" handle = open(file_name, "w") handle.write("'%s' : [%s, %s]" % (net.get(hosts[i]).IP(), 5, 45)) handle.close() else: ping_pair = net.get(hosts[i - 1]) curr_time = monotonic() - start interval = (5 - curr_time) if (5 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) ping_pair = net.get(hosts[i - 2]) curr_time = monotonic() - start interval = (25 - curr_time) if (25 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) ping_pair = net.get(hosts[i - 3]) curr_time = monotonic() - start interval = ( test_time + 5 - curr_time) if (test_time + 5 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), ping_pair.IP(), interval)) host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (ping_pair.IP(), interval)) sys.exit(3) if pid > 0: childs.append(pid) for p in childs: pid, status = os.wait() print('childs end') host = net.get(hosts[0]) handleResult = open("runos/src/apps/ddos-defender/tests/infectedMACs.txt", "w") handleResult.write("{") for i in range(len(hosts)): if hosts[i] in inf_hosts: file_name = "atck_duration_" + str(i) + ".txt" handle = open(file_name, "r") result = handle.read() handleResult.write(result) if i < (len(hosts) - 1): handleResult.write(", ") handle.close() cmnd = "sudo rm " + file_name host.cmd(cmnd) handleResult.write("}") handleResult.close() CLI(net) net.stop()
"Stop everything and quit." self.stop(wait=False) Frame.quit(self) # Make it easier to construct and assign objects def assign(obj, **kwargs): "Set a bunch of fields in an object." obj.__dict__.update(kwargs) class Object(object): "Generic object you can stuff junk into." def __init__(self, **kwargs): assign(self, **kwargs) if __name__ == '__main__': setLogLevel('info') c = RemoteController('c', '143.54.12.113', 6633) network = TreeNet(depth=2, fanout=5) network.addController(c) #network.addNAT().configDefault() network.start() app = ConsoleApp(network, width=4) app.mainloop() network.stop()
all_outputs.append((node, dest, outputs)) output(('%s ' % dest.name) if received else 'X ') output('\n') output("*** Results: \n") for outputs in all_outputs: src, dest, ping_outputs = outputs sent, received, rttmin, rttavg, rttmax, rttdev = ping_outputs output(" %s->%s: %s/%s, " % (src, dest, sent, received)) output("rtt min/avg/max/mdev %0.3f/%0.3f/%0.3f/%0.3f ms\n" % (rttmin, rttavg, rttmax, rttdev)) return all_outputs if __name__ == '__main__': setLogLevel('info') temp_list = [i for i in range(2, 10)] for i in temp_list: network = TreeNet(depth=i, fanout=2, switch=OVSKernelSwitch) info('** Dumping host processes\n') # for host in network.hosts: # host.cmdPrint("") # network.run( CLI, network ) "Perform a complete start/test/stop cycle." network.start() info('*** Running test\n') network.iperf((network.hosts[0], network.hosts[-1])) # customPingFull(hosts=[network.hosts[0], network.hosts[-1]]) # result = test( *args, **kwargs ) CLI(network) network.stop()
def simpleTest(): controller = RemoteController('Runos', ip='192.168.56.102', port=6653) switch = partial(OVSKernelSwitch, protocols='OpenFlow13') net = TreeNet(depth=2, fanout=3, controller=controller, switch=switch, cleanup=True) net.start() sleep(3) start = monotonic() results = [] childs = [] for hostName in net.topo.hosts(): try: pid = os.fork() except: print('error: create child process') sys.exit(33) if pid == 0: host = net.get(hostName) if hostName == "h1": pingPair = net.get("h4") curr_time = monotonic() - start interval = (12 - curr_time) if (12 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start sleep_time = 12.5 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start print("curr_time=%s :: %s start attack" % (curr_time, host.IP())) result = host.cmd("./atck.sh %s %s 25" % (host.MAC(), host.IP())) print("%s end attack" % host.IP()) if hostName == "h2": pingPair = net.get("h1") curr_time = monotonic() - start interval = (4 - curr_time) if (4 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start print('curr_time=%s :: %s changed IP with DHCP' % (curr_time, host.IP())) host.cmd('dhclient -r') host.cmd('dhclient') sleep(0.5) newIP = host.cmd( "ifconfig | grep 'inet 10.' | cut -f2 -d't' | cut -f1 -d'n'" ) splitnewIP = newIP.split(' ') host.setIP(splitnewIP[1]) pingPair = net.get("h3") pingPair.setIP("10.0.0.20") curr_time = monotonic() - start sleep_time = 6 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start interval = (12 - curr_time) if (12 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start sleep_time = 12.5 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start print("curr_time=%s :: %s start attack" % (curr_time, host.IP())) result = host.cmd("./atck.sh %s %s 25" % (host.MAC(), host.IP())) print("%s end attack" % host.IP()) if hostName == "h3": pingPair = net.get("h9") curr_time = monotonic() - start interval = (4 - curr_time) if (4 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start print( 'curr_time=%s :: %s changed IP STATIC (%s -> 10.0.0.20)' % (curr_time, host.IP(), host.IP())) host.cmd('ifconfig h3-eth0 10.0.0.20 netmask 255:0:0:0') host.setIP("10.0.0.20") sleep(0.5) pingPair = net.get("h9") curr_time = monotonic() - start sleep_time = 6 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start interval = (17 - curr_time) if (17 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) pingPair = net.get("h4") curr_time = monotonic() - start interval = (25 - curr_time) if (25 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) result = host.cmd("./png.sh %s %s" % (pingPair.IP(), interval)) handle = open("outputH3-H4.txt", "w") handle.write(result) handle.close() pingPair = net.get("h7") curr_time = monotonic() - start interval = (40 - curr_time) if (40 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) pingPair = net.get("h6") curr_time = monotonic() - start interval = (50 - curr_time) if (50 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) if hostName == "h4": pingPair = net.get("h5") curr_time = monotonic() - start interval = (17 - curr_time) if (17 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) pingPair = net.get("h6") curr_time = monotonic() - start interval = (25 - curr_time) if (25 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) result = host.cmd("./png.sh %s %s" % (pingPair.IP(), interval)) handle = open("outputH4-H6.txt", "w") handle.write(result) handle.close() curr_time = monotonic() - start print('curr_time=%s :: %s changed IP with DHCP' % (curr_time, host.IP())) host.cmd('dhclient -r') host.cmd('dhclient') sleep(0.5) newIP = host.cmd( "ifconfig | grep 'inet 10.' | cut -f2 -d't' | cut -f1 -d'n'" ) splitnewIP = newIP.split(' ') host.setIP(splitnewIP[1]) pingPair = net.get("h6") curr_time = monotonic() - start sleep_time = 27.5 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start interval = (50 - curr_time) if (50 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) if hostName == "h5": pingPair = net.get("h6") curr_time = monotonic() - start interval = (6 - curr_time) if (6 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) pingPair = net.get("h8") curr_time = monotonic() - start interval = (12 - curr_time) if (12 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start sleep_time = 12.5 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start print("curr_time=%s :: %s start attack" % (curr_time, host.IP())) result = host.cmd("./atck.sh %s %s 35" % (host.MAC(), host.IP())) print("%s end attack" % host.IP()) if hostName == "h6": pingPair = net.get("h7") curr_time = monotonic() - start interval = (6 - curr_time) if (6 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) pingPair = net.get("h8") curr_time = monotonic() - start interval = (27.5 - curr_time) if (27.5 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) pingPair = net.get("h7") curr_time = monotonic() - start interval = (50 - curr_time) if (50 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) if hostName == "h7": pingPair = net.get("h9") curr_time = monotonic() - start interval = (6 - curr_time) if (6 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start sleep_time = 10 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start print('curr_time=%s :: %s move from s4 to s2' % (curr_time, host.IP())) hostIP = host.IP() moveHost(host, net.get('s4'), net.get('s2'), None, net) host = net.get(hostName) host.setIP(hostIP) curr_time = monotonic() - start sleep_time = 17 - curr_time if sleep_time > 0: sleep(sleep_time) pingPair = net.get("h8") curr_time = monotonic() - start interval = (27.5 - curr_time) if (27.5 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) result = host.cmd("./png.sh %s %s" % (pingPair.IP(), interval)) handle = open("outputH7-H8.txt", "w") handle.write(result) handle.close() pingPair = net.get("h9") curr_time = monotonic() - start interval = (50 - curr_time) if (50 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) if hostName == "h8": pingPair = net.get("h9") curr_time = monotonic() - start interval = (15 - curr_time) if (15 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start interval = (27.5 - curr_time) if (27.5 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping 10.0.0.20 for %s sec" % (curr_time, host.IP(), interval)) print(hostName, host.cmd("./png.sh 10.0.0.20 %s" % interval)) curr_time = monotonic() - start sleep_time = 30 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start print('curr_time=%s :: %s move from s4 to s1' % (curr_time, host.IP())) hostIP = host.IP() moveHost(host, net.get('s4'), net.get('s1'), None, net) host = net.get(hostName) host.setIP(hostIP) curr_time = monotonic() - start sleep_time = 37.5 - curr_time if sleep_time > 0: sleep(sleep_time) pingPair = net.get("h9") curr_time = monotonic() - start interval = (50 - curr_time) if (50 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) if hostName == "h9": pingPair = net.get("h6") curr_time = monotonic() - start interval = (50 - curr_time) if (50 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print(hostName, host.cmd("./png.sh %s %s" % (pingPair.IP(), interval))) sys.exit(3) if pid > 0: childs.append(pid) curr_time = monotonic() - start sleep_time = 27.5 - curr_time if sleep_time > 0: sleep(sleep_time) print('"curr_time=%s :: switch s2 off' % curr_time) SwitchOff(net.get('s2'), net) curr_time = monotonic() - start sleep_time = 40 - curr_time if sleep_time > 0: sleep(sleep_time) print('"curr_time=%s :: switch s2 up' % curr_time) SwitchUp(net.get('s2'), net) for p in childs: pid, status = os.wait() print('childs end') handleResult = open("outputRTT.txt", "w") handle = open("outputH3-H4.txt", "r") result = handle.read() handleResult.write(result) handle.close() handle = open("outputH4-H6.txt", "r") result = handle.read() handleResult.write(result) handle.close() handle = open("outputH7-H8.txt", "r") result = handle.read() handleResult.write(result) handle.close() handleResult.close() try: pid = os.fork() except: print('error: create child process') sys.exit(33) if pid == 0: host = net.get("h1") host.cmd("sudo rm outputH3-H4.txt outputH4-H6.txt outputH7-H9.txt") sys.exit(3) pid, status = os.wait() CLI(net) net.stop() """
console.waitOutput() self.setOutputHook( None ) # Shut down any iperfs that might still be running quietRun( 'killall -9 iperf' ) def quit( self ): "Stop everything and quit." self.stop( wait=False) Frame.quit( self ) # Make it easier to construct and assign objects def assign( obj, **kwargs ): "Set a bunch of fields in an object." obj.__dict__.update( kwargs ) class Object( object ): "Generic object you can stuff junk into." def __init__( self, **kwargs ): assign( self, **kwargs ) if __name__ == '__main__': setLogLevel( 'info' ) network = TreeNet( depth=2, fanout=4 ) network.start() app = ConsoleApp( network, width=4 ) app.mainloop() network.stop()
# Add hosts and switches leftHost = self.addHost( 'h1' ) rightHost = self.addHost( 'h2' ) leftHost2 = self.addHost( 'h3' ) rightHost2 = self.addHost( 'h4' ) leftSwitch = self.addSwitch( 's1' ) #rightSwitch = self.addSwitch( 's4' ) # Add links self.addLink( leftHost, leftSwitch ) self.addLink( rightHost, leftSwitch ) #self.addLink( rightSwitch, rightHost ) self.addLink( leftHost2, leftSwitch ) self.addLink( rightHost2, leftSwitch ) #self.addLink( leftSwitch, rightSwitch ) self.switch = leftSwitch def get( self, switch ): return self.switch if __name__ == '__main__': lg.setLogLevel( 'info') net = TreeNet( depth=1, fanout=4, controller=lambda name: RemoteController( name, ip='127.0.0.1' ) ) #topos = { 'mytopo': ( lambda: MyTopo() ) } #net = MyTopo() connectToInternet( net ) net.stop()
from mininet.cli import CLI from mininet.log import lg, info from mininet.topolib import TreeNet net = TreeNet(depth=1,fanout=7) net.start() net.hosts[6].cmd('cd http') net.hosts[6].cmd('python server.py &') for h in net.hosts: if h.name != 'h7': h.cmd('cd '+h.name); h.cmd('../Onion 10.0.0.7 &') CLI(net); net.stop()
#Librerie API importate: from mininet.net import Mininet from mininet.node import Controller, RemoteController from mininet.cli import CLI from mininet.link import Intf from mininet.log import setLogLevel, info from mininet.link import Link, TCLink #from mininet.util import irange, dumpNodeConnections import time from mininet.topolib import TreeNet if __name__ == '__main__': #Avvio tempo info('Tempo iniziale') start_time = time.time() print("--- %s seconds ---" % (time.time() - start_time)) setLogLevel('info') #Creazione rete net = TreeNet(depth=4, fanout=2, controller=RemoteController, link=TCLink) #Avvio rete info('*** Avvio rete\n') net.start() mid_time = time.time() print("--- %s seconds ---" % (mid_time - start_time)) info('*** Testing network connectivity\n') #time.sleep(10) #Verifica %CPU e %MEM tramite comando TOP CLI(net) info('*** Stopping network\n') net.stop()
def simpleTest(): controller = RemoteController('Runos', ip='127.0.0.1', port=6653) switch = partial(OVSKernelSwitch, protocols='OpenFlow13') net = TreeNet(depth=2, fanout=3, controller=controller, switch=switch, cleanup=True) net.start() sleep(3) start = monotonic() attack_hosts = ["h1", "h2", "h5"] childs = [] for hostName in net.topo.hosts(): try: pid = os.fork() except: print('error: create child process') sys.exit(33) if pid == 0: host = net.get(hostName) if hostName == "h1": pingPair = net.get("h4") curr_time = monotonic() - start interval = (12 - curr_time) if (12 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start sleep_time = 12.5 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start print("curr_time=%s :: %s start attack" % (curr_time, host.IP())) start_attack = curr_time result = host.cmd( "./runos/src/apps/ddos-defender/scripts/atck.sh %s %s 25" % (host.MAC(), host.IP())) curr_time = monotonic() - start end_attack = curr_time print("curr_time=%s :: %s end attack" % (curr_time, host.IP())) pingPair = net.get("h3") pingPair.setIP("10.0.0.20") while (curr_time < 50): curr_time = monotonic() - start interval = (50 - curr_time) if (50 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) sleep(0.5) file_name = "atck_duration_" + attack_hosts[0] + ".txt" handle = open(file_name, "w") handle.write("'%s' : [%s, %s]" % (host.IP(), start_attack, end_attack)) handle.close() if hostName == "h2": pingPair = net.get("h1") curr_time = monotonic() - start interval = (4 - curr_time) if (4 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start print('curr_time=%s :: %s changed IP with DHCP' % (curr_time, host.IP())) host.cmd('dhclient -r') host.cmd('dhclient') sleep(0.5) newIP = host.cmd( "ifconfig | grep 'inet 10.' | cut -f2 -d't' | cut -f1 -d'n'" ) splitnewIP = newIP.split(' ') host.setIP(splitnewIP[1]) pingPair = net.get("h3") pingPair.setIP("10.0.0.20") curr_time = monotonic() - start sleep_time = 6 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start interval = (12 - curr_time) if (12 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start sleep_time = 12.5 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start print("curr_time=%s :: %s start attack" % (curr_time, host.IP())) start_attack = curr_time result = host.cmd( "./runos/src/apps/ddos-defender/scripts/atck.sh %s %s 35" % (host.MAC(), host.IP())) curr_time = monotonic() - start end_attack = curr_time print("curr_time=%s :: %s end attack" % (curr_time, host.IP())) pingPair = net.get("h7") while curr_time < 50: curr_time = monotonic() - start interval = (50 - curr_time) if (50 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) sleep(0.5) file_name = "atck_duration_" + attack_hosts[1] + ".txt" handle = open(file_name, "w") handle.write("'%s' : [%s, %s]" % (host.IP(), start_attack, end_attack)) handle.close() if hostName == "h3": pingPair = net.get("h4") curr_time = monotonic() - start interval = (4 - curr_time) if (4 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start print( 'curr_time=%s :: %s changed IP STATIC (%s -> 10.0.0.20)' % (curr_time, host.IP(), host.IP())) host.cmd('ifconfig h3-eth0 10.0.0.20 netmask 255:0:0:0') host.setIP("10.0.0.20") sleep(0.5) pingPair = net.get("h4") curr_time = monotonic() - start sleep_time = 6 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start interval = (25 - curr_time) if (25 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) pingPair = net.get("h7") curr_time = monotonic() - start interval = (40 - curr_time) if (40 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) pingPair = net.get("h6") curr_time = monotonic() - start interval = (50 - curr_time) if (50 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) if hostName == "h4": pingPair = net.get("h5") curr_time = monotonic() - start interval = (12.5 - curr_time) if (12.5 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) pingPair = net.get("h9") curr_time = monotonic() - start interval = (25 - curr_time) if (25 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start print('curr_time=%s :: %s changed IP with DHCP' % (curr_time, host.IP())) host.cmd('dhclient -r') host.cmd('dhclient') sleep(0.5) newIP = host.cmd( "ifconfig | grep 'inet 10.' | cut -f2 -d't' | cut -f1 -d'n'" ) splitnewIP = newIP.split(' ') host.setIP(splitnewIP[1]) pingPair = net.get("h6") curr_time = monotonic() - start sleep_time = 27.5 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start interval = (40 - curr_time) if (40 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start sleep_time = 45 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start interval = (50 - curr_time) if (50 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) if hostName == "h5": pingPair = net.get("h6") curr_time = monotonic() - start interval = (6 - curr_time) if (6 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) pingPair = net.get("h8") curr_time = monotonic() - start interval = (12 - curr_time) if (12 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start sleep_time = 12.5 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start print("curr_time=%s :: %s start attack" % (curr_time, host.IP())) start_attack = curr_time result = host.cmd( "./runos/src/apps/ddos-defender/scripts/atck.sh %s %s 25" % (host.MAC(), host.IP())) curr_time = monotonic() - start end_attack = curr_time print("curr_time=%s :: %s end attack" % (curr_time, host.IP())) pingPair = net.get("h8") curr_time = monotonic() - start interval = (40 - curr_time) if (40 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start sleep_time = 46 - curr_time if sleep_time > 0: sleep(sleep_time) while curr_time < 50: curr_time = monotonic() - start interval = (50 - curr_time) if (50 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) sleep(0.5) file_name = "atck_duration_" + attack_hosts[2] + ".txt" handle = open(file_name, "w") handle.write("'%s' : [%s, %s]" % (host.IP(), start_attack, end_attack)) handle.close() if hostName == "h6": pingPair = net.get("h7") curr_time = monotonic() - start interval = (6 - curr_time) if (6 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) pingPair = net.get("h8") curr_time = monotonic() - start interval = (27.5 - curr_time) if (27.5 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) pingPair = net.get("h7") curr_time = monotonic() - start interval = (40 - curr_time) if (40 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start sleep_time = 45 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start interval = (50 - curr_time) if (50 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) if hostName == "h7": pingPair = net.get("h9") curr_time = monotonic() - start interval = (6 - curr_time) if (6 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start sleep_time = 10 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start print('curr_time=%s :: %s move from s4 to s2' % (curr_time, host.IP())) hostIP = host.IP() moveHost(host, net.get('s4'), net.get('s2'), None, net) host = net.get(hostName) host.setIP(hostIP) curr_time = monotonic() - start sleep_time = 17.5 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start interval = (50 - curr_time) if (50 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) if hostName == "h8": pingPair = net.get("h9") curr_time = monotonic() - start interval = (15 - curr_time) if (15 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) curr_time = monotonic() - start interval = (27.5 - curr_time) if (27.5 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping 10.0.0.20 for %s sec" % (curr_time, host.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh 10.0.0.20 %s" % interval)) curr_time = monotonic() - start sleep_time = 30 - curr_time if sleep_time > 0: sleep(sleep_time) curr_time = monotonic() - start print('curr_time=%s :: %s move from s4 to s1' % (curr_time, host.IP())) hostIP = host.IP() moveHost(host, net.get('s4'), net.get('s1'), None, net) host = net.get(hostName) host.setIP(hostIP) curr_time = monotonic() - start sleep_time = 37.5 - curr_time if sleep_time > 0: sleep(sleep_time) pingPair = net.get("h9") curr_time = monotonic() - start interval = (50 - curr_time) if (50 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) if hostName == "h9": pingPair = net.get("h6") curr_time = monotonic() - start interval = (50 - curr_time) if (50 - curr_time) >= 1 else 1 print("curr_time=%s :: %s start ping %s for %s sec" % (curr_time, host.IP(), pingPair.IP(), interval)) print( hostName, host.cmd( "./runos/src/apps/ddos-defender/scripts/png.sh %s %s" % (pingPair.IP(), interval))) sys.exit(3) if pid > 0: childs.append(pid) for p in childs: pid, status = os.wait() curr_time = monotonic() - start print("curr_time=%s :: childs end" % curr_time) handleResult = open("runos/src/apps/ddos-defender/tests/infectedMACs.txt", "w") handleResult.write("{") for i in range(len(attack_hosts)): host = net.get(attack_hosts[i]) file_name = "atck_duration_" + attack_hosts[i] + ".txt" handle = open(file_name, "r") result = handle.read() handleResult.write(result) if i < (len(attack_hosts) - 1): handleResult.write(", ") handle.close() cmnd = "sudo rm " + file_name host.cmd(cmnd) handleResult.write("}") handleResult.close() CLI(net) net.stop()
#!/usr/bin/python """ Example to create a Mininet topology and connect it to the internet via NAT """ from mininet.cli import CLI from mininet.log import lg, info from mininet.topolib import TreeNet if __name__ == '__main__': lg.setLogLevel( 'info') net = TreeNet( depth=1, fanout=4, waitConnected=True ) # Add NAT connectivity net.addNAT().configDefault() net.start() info( "*** Hosts are running and should have internet connectivity\n" ) info( "*** Type 'exit' or control-D to shut down network\n" ) CLI( net ) # Shut down NAT net.stop()
def main(): lg.setLogLevel('info') net = TreeNet(depth=2, fanout=4) # Add NAT connectivity net.addNAT().configDefault() net.start() h1 = net.get('h1') h2 = net.get('h2') h3 = net.get('h3') h4 = net.get('h4') h5 = net.get('h5') h6 = net.get('h6') h7 = net.get('h7') h8 = net.get('h8') h9 = net.get('h9') h10 = net.get('h10') h11 = net.get('h11') h12 = net.get('h12') h13 = net.get('h13') h14 = net.get('h14') h15 = net.get('h15') h16 = net.get('h16') p1 = h1.popen('node ../server/server.js %s & ' % h1.IP()) p16 = h16.popen('node ../server/server.js %s & ' % h16.IP()) sleep(2) p2 = h2.popen('python3 ../mininet/test_company.py 1 %s &' % h1.IP()) p3 = h3.popen('python3 ../mininet/test_company.py 2 %s &' % h1.IP()) p4 = h4.popen('python3 ../mininet/test_company.py 3 %s &' % h1.IP()) p5 = h5.popen('python3 ../mininet/test_company.py 4 %s &' % h1.IP()) p6 = h6.popen('python3 ../mininet/test_company.py 5 %s &' % h16.IP()) p7 = h7.popen('python3 ../mininet/test_company.py 6 %s &' % h16.IP()) p8 = h8.popen('python3 ../mininet/test_company.py 7 %s &' % h1.IP()) p9 = h9.popen('python3 ../mininet/test_company.py 8 %s &' % h1.IP()) p10 = h10.popen('python3 ../mininet/test_company.py 9 %s &' % h1.IP()) p11 = h11.popen('python3 ../mininet/test_company.py 10 %s &' % h16.IP()) p12 = h12.popen('python3 ../mininet/test_company.py 11 %s &' % h16.IP()) p13 = h13.popen('python3 ../mininet/test_company.py 12 %s &' % h16.IP()) p14 = h14.popen('python3 ../mininet/test_company.py 13 %s &' % h16.IP()) p15 = h15.popen('python3 ../mininet/test_company.py 14 %s &' % h16.IP()) process2 = {h2: p2} process3 = {h3: p3} process4 = {h4: p4} process5 = {h5: p5} process6 = {h6: p6} process7 = {h7: p7} process8 = {h8: p8} process9 = {h9: p9} process10 = {h10: p10} process11 = {h11: p11} process12 = {h12: p12} process13 = {h13: p13} process14 = {h14: p14} process15 = {h15: p15} printToConsole(process2) p2.terminate() printToConsole(process3) p3.terminate() printToConsole(process4) p4.terminate() printToConsole(process5) p5.terminate() printToConsole(process6) p6.terminate() printToConsole(process7) p7.terminate() printToConsole(process8) p8.terminate() printToConsole(process9) p9.terminate() printToConsole(process10) p10.terminate() printToConsole(process11) p11.terminate() printToConsole(process12) p12.terminate() printToConsole(process13) p13.terminate() printToConsole(process14) p14.terminate() printToConsole(process15) p15.terminate() p1.terminate() p16.terminate() net.stop()
experiment = raw_input("Input experiment title: ") fanout_num = int(raw_input("Indicate number of hosts: ")) # Creating folder foldername = '/home/fastflux/experiments/{}/'.format(experiment) print(foldername) if not os.path.exists(os.path.dirname(foldername)): try: os.makedirs(os.path.dirname(foldername)) except OSError as exc: if exc.errno != errno.EEXIST: raise setLogLevel('info') # Number of hosts = fanout^depth # Number of switches = fanout + 1 network = TreeNet(depth=1, fanout=fanout_num, switch=OVSSwitch) network.addNAT().configDefault() network.start() # Wait for tcpdump before starting #print('Do tcpdump now....') # network.mn.terms += makeTerms([h1], term = term) #network.terms += makeTerm(h1) time.sleep(60) scriptit(experiment, fanout_num) CLI(network) network.stop()
# quietRun( 'killall -9 iperf3' ) def quit(self): "Stop everything and quit." self.stop(wait=False) Frame.quit(self) # Make it easier to construct and assign objects def assign(obj, **kwargs): "Set a bunch of fields in an object." obj.__dict__.update(kwargs) class Object(object): "Generic object you can stuff junk into." def __init__(self, **kwargs): assign(self, **kwargs) if __name__ == '__main__': setLogLevel('info') network = TreeNet(depth=2, fanout=4) network.start() app = ConsoleApp(network, width=4) app.mainloop() network.stop()
output( ( '%s ' % dest.name ) if received else 'X ' ) output( '\n' ) output( "*** Results: \n" ) for outputs in all_outputs: src, dest, ping_outputs = outputs sent, received, rttmin, rttavg, rttmax, rttdev = ping_outputs output( " %s->%s: %s/%s, " % (src, dest, sent, received ) ) output( "rtt min/avg/max/mdev %0.3f/%0.3f/%0.3f/%0.3f ms\n" % (rttmin, rttavg, rttmax, rttdev) ) return all_outputs if __name__ == '__main__': setLogLevel( 'info' ) temp_list = [i for i in range(2, 10)] for i in temp_list: network = TreeNet( depth=i, fanout=2, switch=OVSKernelSwitch, controller=None ) CONTROLLER_IP = "0.0.0.0" CONTROLLER_PORT = 6633 network.addController( 'controller',controller=RemoteController,ip=CONTROLLER_IP,port=CONTROLLER_PORT) info('** Dumping host processes\n') # for host in network.hosts: # host.cmdPrint("") # network.run( CLI, network ) "Perform a complete start/test/stop cycle." network.start() info( '*** Running test\n' ) network.iperf((network.hosts[0], network.hosts[-1])) network.pingFull(hosts=[network.hosts[0], network.hosts[-1]]) # result = test( *args, **kwargs ) # CLI(network) network.stop()
#!/usr/bin/python """ Create a 1024-host network, and run the CLI on it. If this fails because of kernel limits, you may have to adjust them, e.g. by adding entries to /etc/sysctl.conf and running sysctl -p. Check util/sysctl_addon. """ from mininet.cli import CLI from mininet.log import setLogLevel from mininet.node import OVSSwitch from mininet.topolib import TreeNet if __name__ == '__main__': setLogLevel( 'info' ) network = TreeNet( depth=2, fanout=32, switch=OVSSwitch ) network.run( CLI, network )
#!/usr/bin/python """ Create a 1024-host network, and run the CLI on it. If this fails because of kernel limits, you may have to adjust them, e.g. by adding entries to /etc/sysctl.conf and running sysctl -p. Check util/sysctl_addon. """ from mininet.cli import CLI from mininet.log import setLogLevel from mininet.node import OVSSwitch from mininet.topolib import TreeNet if __name__ == '__main__': setLogLevel('info') network = TreeNet(depth=2, fanout=32, switch=OVSSwitch) network.run(CLI, network)
#!/usr/bin/python """ Example to create a Mininet topology and connect it to the internet via NAT """ from mininet.cli import CLI from mininet.log import lg from mininet.topolib import TreeNet if __name__ == '__main__': lg.setLogLevel( 'info') net = TreeNet( depth=1, fanout=4 ) # Add NAT connectivity net.addNAT().configDefault() net.start() print "*** Hosts are running and should have internet connectivity" print "*** Type 'exit' or control-D to shut down network" CLI( net ) # Shut down NAT net.stop()
#!/usr/bin/python """ Create a 1024-host network, and run the CLI on it. If this fails because of kernel limits, you may have to adjust them, e.g. by adding entries to /etc/sysctl.conf and running sysctl -p. Check util/sysctl_addon. """ from mininet.cli import CLI from mininet.log import setLogLevel from mininet.node import OVSSwitch from mininet.topolib import TreeNet from mininet.examples.treeping64 import HostV4 if __name__ == '__main__': setLogLevel( 'info' ) network = TreeNet( depth=2, fanout=32, host=HostV4, switch=OVSSwitch, waitConnected=True) network.run( CLI, network )
# Create link between root NS and switch link = network.addLink(root, switch) link.intf1.setIP(rootip, prefixLen) # Start network that now includes link to root namespace network.start() # Start NAT and establish forwarding startNAT(root) # Establish routes from end hosts for host in network.hosts: host.cmd('ip route flush root 0/0') host.cmd('route add -net', subnet, 'dev', host.defaultIntf()) host.cmd('route add default gw', rootip) return root if __name__ == '__main__': lg.setLogLevel('info') net = TreeNet(depth=2, fanout=3) # Configure and start NATted connectivity rootnode = connectToInternet(net) print "*** Hosts are running and should have internet connectivity" print "*** Type 'exit' or control-D to shut down network" CLI(net) # Shut down NAT stopNAT(rootnode) net.stop()
def emulated_web(parsed_objects='./parsed-objects', url_list='./url_list'): ''' parsed_objects: a directory storing objects under 'hostname' subfolder url_list: each line is a url to visit ''' hosts = [] objects_for_hosts_dict = {} source_files = {} # get hostnames and hostname:objects pairs in dict for i, (root, folders, files) in enumerate(os.walk(parsed_objects)): if i == 0: hosts = folders else: objects_for_hosts_dict[hosts[i - 1]] = files source_files[root] = files # print(hosts, objects_for_hosts_dict) # list servable-content if not os.path.exists("./servable-content/"): os.mkdir("./servable-content/") # make dir for host, objects_list in objects_for_hosts_dict.iteritems(): with open("./servable-content/" + host, "w+") as f: for i in objects_list: f.write(i + '\n') # each line contains one object # to simply the topo, use default method of tree structure with one level, n leaves server_num = len(hosts) host_server_match = {} for i in range(server_num): host_server_match['h' + str(i + 2)] = hosts[i] # one client as 'h1', with server_num of servers fron 'h2' to 'hn' net = TreeNet(depth=1, fanout=server_num + 1) # Add NAT connectivity net.addNAT().configDefault() net.start() # test this net dumpNodeConnections(net.hosts) # see connectivity print(net.pingAll()) # ping to test connectivity # set up simple http server for num, host in host_server_match.iteritems(): print(str(os.path.join(parsed_objects, host))) net.get(num).cmd('cd %s' % str(os.path.join(parsed_objects, host))) net.get(num).cmd('python -m SimpleHTTPServer 80 &') # test each server http client = net.get('h1') time.sleep(2) # magic, don't delete, otherwise wget doesn't work for num, host in host_server_match.iteritems(): # test for LAN # print(client.cmd('ping -c1 %s' % net.get(num).IP())) print(client.cmd('ping -c1 8.8.8.8')) # test for real print(client.cmd('wget -o - %s' % net.get(num).IP())) # print(client.cmd('wget -o - http://www.google.com')) time.sleep(1) # magic, don't delete, otherwise wget doesn't work if not os.path.exists("./get-responses/"): os.mkdir("./get-responses/") # make dir pass # not finished here