#!/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()
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()
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()
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