Example #1
0
    def start_networking(self):
        setLogLevel("info")
        net = Mininet(topo=self, \
                      controller=lambda name: RemoteController(name))
        net.start()

        # setup each switch
        for sw in net.switches:
            # set ofp version
            self.set_ofp_version(sw, ['OpenFlow10', 'OpenFlow13'])
            # if sw is bridge, set it up for normal SW
            swEntry = self.switchList[sw.name][1]
            isBridge = swEntry["bridge"]
            if isBridge:
                self.set_normalsw(sw)
            self.switchList[sw.name].append(sw)

        # setup each host
        for host in net.hosts:
            self.add_ipv6address(host)
            self.hostList[host.name].append(host)

        # execute pre_command
        if "pre_cmd_file" in self.jsonData:
            cmd_file = self.jsonData["pre_cmd_file"]
            self.exec_usercmd(cmd_file)

        CLI(net)

        # execute post_command
        if "post_cmd_file" in self.jsonData:
            cmd_file = self.jsonData["post_cmd_file"]
            self.exec_usercmd(cmd_file)

        net.stop()
Example #2
0
def run( n ):
    topo = OpticalTopo( n )
    net = Mininet( topo=topo, controller=RemoteController, autoSetMacs=True )
    net.start()
    #installStaticFlows( net )
    CLI( net )
    net.stop()
Example #3
0
def topology():

    "Create a network."
    net = Mininet( controller=Controller, link=TCLink, switch=OVSKernelSwitch )

    print "*** Creating nodes"
    sta1 = net.addStation( 'sta1', mac='00:00:00:00:00:02', ip='10.0.0.2/8', position='10,20,0' )
    sta2 = net.addStation( 'sta2', mac='00:00:00:00:00:03', ip='10.0.0.3/8', position='10,30,0' )
    ap1 = net.addBaseStation( 'ap1', ssid= 'new-ssid', mode= 'g', channel= '1', position='15,30,0' )
    c1 = net.addController( 'c1', controller=Controller )

    """uncomment to plot graph"""
    #net.plotGraph(max_x=60, max_y=60)

    print "*** Creating links"
    net.addLink(ap1, sta1)
    net.addLink(ap1, sta2)

    print "*** Starting network"
    net.build()
    c1.start()
    ap1.start( [c1] )

    print "*** Running CLI"
    CLI( net )

    print "*** Stopping network"
    net.stop()
Example #4
0
def test():
    topo = DssTopo()
    net = Mininet(topo, link=TCLink)
    net.start()

    pidList(net)

    global NPAUSE
    global NRESUME

    NPAUSE = 'sudo /home/kd/VirtualTimeKernel/test_virtual_time/freeze_all_procs -f -p %s'%pIDS
    NRESUME ='sudo /home/kd/VirtualTimeKernel/test_virtual_time/freeze_all_procs -u -p %s'%pIDS
    
    #block
    print(net.get('h1').cmd('ping -c 1 10.0.0.2'))

    net.get('h1').cmd('ping -c 40 10.0.0.2 > %sbl.test'% FileOut)
    
    #dont block
    net.get('h1').cmd('/home/kd/VirtualTimeKernel/iputils/ping -c 40 -D 10.0.0.2 > %svt.test &'% FileOut)
    time.sleep(5)

    for x in range(0,int(sys.argv[3])):
        print 'pausing'
        pause()
        time.sleep(stime)
	print 'resumed'
 
    time.sleep(30)
    net.stop()    
Example #5
0
    def build( self ):
        print "Build network based on our topology."

        net = Mininet( topo=None, build=False, link=TCLink, ipBase=self.minieditIpBase )
 
        net.controllers = self.addControllers()
        
        # Make nodes
        print "Getting Hosts and Switches."
        for widget in self.widgetToItem:
            name = widget[ 'text' ]
            tags = self.canvas.gettags( self.widgetToItem[ widget ] )
            nodeNum = int( name[ 1: ] )
            if 'Switch' in tags:
                net.addSwitch( name )
            elif 'Host' in tags:
                ipBaseNum, prefixLen = netParse( self.minieditIpBase )
                ip = ipAdd(i=nodeNum, prefixLen=prefixLen, ipBaseNum=ipBaseNum)
                net.addHost( name, ip=ip )
            else:
                raise Exception( "Cannot create mystery node: " + name )

        # Make links
        print "Getting Links."
        for link in self.links.values():
            ( src, dst, linkopts ) = link
            srcName, dstName = src[ 'text' ], dst[ 'text' ]
            src, dst = net.nameToNode[ srcName ], net.nameToNode[ dstName ]
            net.addLink(src, dst, **linkopts)

        self.printInfo()
        # Build network (we have to do this separately at the moment )
        net.build()

        return net
Example #6
0
def LowMnNet(n, nn, nnn):
	print "############ Instanitiate a mininet of topology LowMnTopo ###############\n"
	topo = LowMnTopo(n, nn, nnn)
	ctrl_port=6633
	net = Mininet(topo=topo, ipBase='10.0.0.0/8', autoSetMacs=True, host=CPULimitedHost, link=TCLink)
 	net.start()
	return net
Example #7
0
def main():

	# All b/w are in megabits
	max_bw = 1000

	# B/w of queue 1 and queue 2
	values = [3,1,4]

	topo = MyTopo(max_bw)

	net = Mininet(topo, link = TCLink, controller = partial(RemoteController, ip = '127.0.0.1', port = 6633))
	
	net.start()

	# Queue set in between h1 and s1
	cmd = 'ovs-vsctl -- set Port s2-eth4 [email protected] -- \
		[email protected] create QoS type=linux-htb other-config:max-rate=1000000000 [email protected],[email protected],[email protected],[email protected] -- \
		[email protected] create Queue other-config:min-rate=%d other-config:max-rate=%d -- \
		[email protected] create Queue other-config:min-rate=%d other-config:max-rate=%d -- \
		[email protected] create Queue other-config:min-rate=%d other-config:max-rate=%d -- \
		[email protected] create Queue other-config:min-rate=%d other-config:max-rate=%d' % \
		(max_bw * 10**6, max_bw * 10**6, \
		values[0] * 10**6, values[0] * 10**6, \
		values[1] * 10**6, values[1] * 10**6, \
		values[2] * 10**6, values[2] * 10**6)

	sp.call(cmd, shell = True)
	
	CLI(net)
	net.stop()
Example #8
0
def main():
    net = Mininet()
    # create hosts
    h1 = net.addHost('h1')
    h2 = net.addHost('h2')

    # create switch
    s1 = net.addSwitch('S1')

    # create controller
    c1 = net.addController('c1')

    # create links
    net.addLink(h1, s1)
    net.addLink(h2, s1)

    net.start()

    # start web server on h2
    print('starting web server...')
    h2.cmd('python -m SimpleHTTPServer 80 &')
    sleep(2)

    # use h1 as a web client
    print('accessing web server..')
    h1.cmd('curl', h2.IP())

    # CLI(net)
    print('kill web server..')
    h2.cmd('kill %python')

    print('finish.')
    net.stop()
Example #9
0
def multiping(netsize, chunksize, seconds):
    "Ping subsets of size chunksize in net of size netsize"

    # Create network and identify subnets
    topo = SingleSwitchTopo(netsize)
    net = Mininet(topo=topo)
    net.start()
    hosts = net.hosts
    subnets = chunks(hosts, chunksize)

    # Create polling object
    fds = [host.stdout.fileno() for host in hosts]
    poller = poll()
    for fd in fds:
        poller.register(fd, POLLIN)

    # Start pings
    for subnet in subnets:
        ips = [host.IP() for host in subnet]
        for host in subnet:
            startpings(host, ips)

    # Monitor output
    endTime = time() + seconds
    while time() < endTime:
        readable = poller.poll(1000)
        for fd, _mask in readable:
            node = Node.outToNode[fd]
            print "%s:" % node.name, node.monitor().strip()

    # Stop pings
    for host in hosts:
        host.cmd("kill %while")

    net.stop()
Example #10
0
def monitorTest( N=3, seconds=3 ):
    "Run pings and monitor multiple hosts"
    topo = SingleSwitchTopo( N )
    net = Mininet( topo )
    net.start()
    hosts = net.hosts
    info( "Starting test...\n" )
    server = hosts[ 0 ]
    outfiles, errfiles = {}, {}
    for h in hosts:
        # Create and/or erase output files
        outfiles[ h ] = '/tmp/%s.out' % h.name
        errfiles[ h ] = '/tmp/%s.err' % h.name
        h.cmd( 'echo >', outfiles[ h ] )
        h.cmd( 'echo >', errfiles[ h ] )
        # Start pings
        h.cmdPrint('ping', server.IP(),
                   '>', outfiles[ h ],
                   '2>', errfiles[ h ],
                   '&' )
    info( "Monitoring output for", seconds, "seconds\n" )
    for h, line in monitorFiles( outfiles, seconds, timeoutms=500 ):
        if h:
            info( '%s: %s\n' % ( h.name, line ) )
    for h in hosts:
        h.cmd('kill %ping')
    net.stop()
Example #11
0
def topoTest():
    "Create network and run simple performance test"
    topo = ITATopo()
    # topo = ITATopo(12, 10)
    net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink)

    net.interact()
Example #12
0
def main():
    # Defines the log level
    setLogLevel('info')

    # parses command line arguments
    parser = OptionParser()
    parser.add_option('-H', dest='hosts', default=5,
                      help='Number of hosts per switch')
    parser.add_option('-S', dest='switches', default=2,
                      help='Number of switches')
    (options, args) = parser.parse_args()

    # Build network topology (see mininet/topo.py)
    topo = LinearTopo(int(options.switches), int(options.hosts))

    # Creates the Network using a remote controller
    net = Mininet(topo,
                  controller=lambda a: RemoteController(a, ip='127.0.0.1'))

    # Starts the network
    net.start()
    # Run the mininet client
    CLI(net)
    # Stop the network
    net.stop()
Example #13
0
def run():
    "Create network and run the CLI"
    topo = InternetTopo()
    net = Mininet(topo=topo)
    net.start()
    CLI(net)
    net.stop()
Example #14
0
def emptyNet():

    net = Mininet(topo=None, build=False)
    c0 = Controller('c0', inNamespace=False)

    h1 = Host('h1')
    h2 = Host('h2')
    #intf1 = Intf("h1-eth1")
    #intf2 = Intf("h2-eth1")
    s1 = OVSSwitch('br0', inNamespace=False)    

    Link(h1, s1)
    Link(h2, s1)


    c0.start()
    s1.start([c0])

    net.start()    
    #s1.cmd('ovs-vsctl set bridge br0 protocols=OpenFlow13')
    CLI(net)

    net.stop()
    h1.stop()
    h2.stop()
    s1.stop()
    c0.stop()
Example #15
0
    def testLinkBandwidth( self ):
        "Verify that link bandwidths are accurate within a bound."
        if self.switchClass is UserSwitch:
            self.skipTest( 'UserSwitch has very poor performance -'
                           ' skipping for now' )
        BW = 5  # Mbps
        BW_TOLERANCE = 0.8  # BW fraction below which test should fail
        # Verify ability to create limited-link topo first;
        lopts = { 'bw': BW, 'use_htb': True }
        # Also verify correctness of limit limitng within a bound.
        mn = Mininet( SingleSwitchOptionsTopo( n=N, lopts=lopts ),
                      link=TCLink, switch=self.switchClass,
                      waitConnected=True )
        bw_strs = mn.run( mn.iperf, fmt='m' )
        loptsStr = ', '.join( '%s: %s' % ( opt, value )
                              for opt, value in lopts.items() )
        msg = ( '\nTesting link bandwidth limited to %d Mbps per link\n'
                'iperf results[ client, server ]: %s\n'
                'Topo = SingleSwitchTopo, %s hosts\n'
                'Link = TCLink\n'
                'lopts = %s\n'
                'host = default\n'
                'switch = %s\n'
                % ( BW, bw_strs, N, loptsStr, self.switchClass ) )

        # On the client side, iperf doesn't wait for ACKs - it simply
        # reports how long it took to fill up the TCP send buffer.
        # As long as the kernel doesn't wait a long time before
        # delivering bytes to the iperf server, its reported data rate
        # should be close to the actual receive rate.
        serverRate, _clientRate = bw_strs
        bw = float( serverRate.split(' ')[0] )
        self.assertWithinTolerance( bw, BW, BW_TOLERANCE, msg )
Example #16
0
def prev_get_default_net_hosts_switches(topo, listen_port, num_hosts, num_switches):
    net = Mininet(topo=topo, host=CPULimitedHost, controller=RemoteController,
                  listenPort=listen_port)
    net.start()
    hosts = get_hosts(net, num_hosts)
    switches = get_switches(net, num_switches)
    return (net, hosts, switches)
Example #17
0
def myNet():
    #OpenDayLight controller
    CONTROLLER1_IP='127.0.0.1'

    #Floodlight controller

    net = Mininet( topo=None, build=False)

    # Create nodes
    h1 = net.addHost( 'h1', mac='01:00:00:00:01:00', ip='192.168.0.1/24' )

    # Create switches
    s1 = net.addSwitch( 's1', listenPort=6634, mac='00:00:00:00:00:01' )
    
    print "*** Creating links"
    net.addLink(h1, s1 )
  

    # Add Controllers
    c0 = net.addController( 'c0', controller=RemoteController, ip=CONTROLLER1_IP, port=6633)

    net.build()

    # Connect each switch to a different controller
    s1.start([c0])

    s1.cmdPrint('ovs-vsctl show')
    
    CLI( net )
    net.stop()
Example #18
0
def get_default_net_hosts_switches(topo, listen_port):
    net = Mininet(topo=topo, host=CPULimitedHost, controller=RemoteController,
                  listenPort=listen_port)
    net.start()
    hosts = get_nodes(net, topo.hosts())
    switches = get_nodes(net, topo.switches())
    return (net, hosts, switches)
Example #19
0
def perfTest():
    topo = crazy_switches()
    net = Mininet(topo=topo, controller=lambda name: RemoteController( 'c0', '127.0.0.1' ),
                  host=CPULimitedHost, link=TCLink)
    net.start()
    CLI(net)
    net.stop()
Example #20
0
def simple():
	t=MyTopo();
	#c=Controller(name="c0",command="python ./pox/pox.py")
	#net=Mininet(t,controller=bridge);
	net=Mininet(topo=t,controller=lambda name:RemoteController(name,ip='127.0.0.1'))
	#net.addController(name="c0",port=6633);
	#mininet.node.RemoteController(port=6633)
	net.start();
	
	#print net.host;
	f=open("MacHost.txt","w");
	for i in net.hosts:
		print "i= ";
		print i;
		print Node.MAC(i);
		f.write(str(i)+" "+str(Node.MAC(i))+"\n");
	f.close();
	z=0
	f=open("/home/saumya/pox/output.txt","w")
	f.close()
	for i in net.hosts:
		for j in net.hosts:
			if(i!=j):
				time.sleep(10);
				net.ping([i,j])
				z=z+1;
				parse("/home/saumya/pox/output.txt");
				draw_graph();
Example #21
0
    def create_mininet(self, topo, tunnels=[],  switch=UserSwitch,
                       controller=None, STT=False):
        if(not self.net is None):
            self.logger.warn("running mininet instance detected!\
                              Shutting it down...")
            self.destroy_mininet()

        self.logger.info("Creating mininet instance")
        if controller:
            self.net = Mininet(topo=topo, intf=TCIntf, link=TCLink,
                               switch=switch, controller=controller)
        else:
            self.net = Mininet(topo=topo, intf=TCIntf, link=TCLink,
                               switch=switch)
        if STT:
            self.logger.info("Starting Mininet...")
            self.net.start()
        self.logger.info("Adding tunnels to mininet instance")
        for tunnel in tunnels:
            port = None
            cls = None
            if "port" in tunnel[2].keys():
                port = tunnel[2]["port"]
                del tunnel[2]["port"]
            if "cls" in tunnel[2].keys():
                cls = tunnel[2]["cls"]
                del tunnel[2]["cls"]
            self.addTunnel(tunnel[0], tunnel[1], port, cls, STT=STT, **tunnel[2])
        if not STT:
            self.logger.info("Starting Mininet...")
            self.net.start()
        self.logger.info("Startup complete.")
        self.x11popens = []
        return True
def startNetwork():
	topo = createTopo()
	global net
	net = Mininet(topo=topo, autoSetMacs=True)
	net.start()
	h1,h2,h3,h4,h5,h6,r1,r2,r3  = net.hosts
	h1.cmd('ifconfig h1-eth0 10.0.0.1 netmask 255.255.255.0')
	h1.cmd('route add default gw 10.0.0.3')
	h2.cmd('ifconfig h2-eth0 10.0.0.2 netmask 255.255.255.0')
	h2.cmd('route add default gw 10.0.0.3')
	h3.cmd('ifconfig h3-eth0 20.0.0.1 netmask 255.255.255.0')
	h3.cmd('route add default gw 20.0.0.3')
	h4.cmd('ifconfig h4-eth0 20.0.0.2 netmask 255.255.255.0')
	h4.cmd('route add default gw 20.0.0.3')
	h5.cmd('ifconfig h5-eth0 30.0.0.1 netmask 255.255.255.0')
	h5.cmd('route add default gw 30.0.0.3')
	h6.cmd('ifconfig h6-eth0 30.0.0.2 netmask 255.255.255.0')
	h6.cmd('route add default gw 30.0.0.3')

	r1.cmd('ifconfig r1-eth0 10.0.0.3 netmask 255.255.255.0')
	r2.cmd('ifconfig r2-eth0 20.0.0.3 netmask 255.255.255.0')
	r3.cmd('ifconfig r3-eth0 30.0.0.3 netmask 255.255.255.0')

	r1.cmd('ifconfig r1-eth1 110.0.0.1 netmask 255.255.255.0')
	r2.cmd('ifconfig r2-eth1 110.0.0.2 netmask 255.255.255.0')
	r1.cmd('ifconfig r1-eth2 120.0.0.1 netmask 255.255.255.0')
	r3.cmd('ifconfig r3-eth1 120.0.0.2 netmask 255.255.255.0')
	r2.cmd('ifconfig r2-eth2 130.0.0.1 netmask 255.255.255.0')
	r3.cmd('ifconfig r3-eth2 130.0.0.2 netmask 255.255.255.0')

	r1.cmd('echo 1 >> /proc/sys/net/ipv4/ip_forward')
	r2.cmd('echo 1 >> /proc/sys/net/ipv4/ip_forward')
	r3.cmd('echo 1 >> /proc/sys/net/ipv4/ip_forward')

	CLI(net)
def topology():
    "Create a network."
    net = Mininet( wirelessRadios=3, controller=Controller, link=TCLink, switch=OVSKernelSwitch )
    #wirelessRadios = Number of STAs + APs

    print "*** Creating nodes"
    sta1 = net.addStation( 'sta1' )
    sta2 = net.addStation( 'sta2' )
    ap1 = net.addBaseStation( 'ap1', ssid="simplewifi", mode="g", channel="5" )
    c0 = net.addController('c0', controller=Controller, ip='127.0.0.1', port=6633 )

    print "*** Adding Link"
    net.addLink(sta1, ap1)
    net.addLink(sta2, ap1)

    print "*** Starting network"
    net.build()
    c0.start()
    ap1.start( [c0] )

    print "*** Running CLI"
    CLI( net )

    print "*** Stopping network"
    net.stop()
Example #24
0
def on_topology(topology_gml_file):
    local_apps = 'ryuo.topology.topology'
    working_dir = '.'
    # Clean up environment
    mn_c = subprocess.Popen(['mn', '-c'])
    mn_c.wait()
    # Run Ryuo name server
    ryuo_ns = subprocess.Popen(['bin/ryuo-ns'])
    time.sleep(3)
    # Run Ryuo app
    ryuo_app = subprocess.Popen(['ryu-manager', 'ryuo.topology.app'],
                                cwd=working_dir, stdout=subprocess.PIPE)
    time.sleep(4)
    net = Mininet(topo=RyuoTopoFromTopoZoo(topology_gml_file,
                                           'OpenFlow13',
                                           working_dir,
                                           local_apps),
                  switch=RyuoOVSSwitch,
                  controller=RemoteController,
                  link=TCLink)
    net.start()
    time.sleep(10)
    net.stop()
    ryuo_app.kill()
    ryuo_ns.kill()
Example #25
0
def runMultiLink():
    "Create and run multiple link network"
    topo = simpleMultiLinkTopo( n=2 )
    net = Mininet( topo=topo )
    net.start()
    CLI( net )
    net.stop()
Example #26
0
 def __init__( self, *args, **kwargs ):
     """servers: a list of servers to use (note: include
        localhost or None to use local system as well)
        user: user name for server ssh
        placement: Placer() subclass"""
     params = { 'host': RemoteHost,
                'switch': RemoteOVSSwitch,
                'link': RemoteLink,
                'precheck': True }
     params.update( kwargs )
     servers = params.pop( 'servers', [ 'localhost' ] )
     servers = [ s if s else 'localhost' for s in servers ]
     self.servers = servers
     self.serverIP = params.pop( 'serverIP', {} )
     if not self.serverIP:
         self.serverIP = { server: RemoteMixin.findServerIP( server )
                           for server in self.servers }
     self.user = params.pop( 'user', findUser() )
     if params.pop( 'precheck' ):
         self.precheck()
     self.connections = {}
     self.placement = params.pop( 'placement', SwitchBinPlacer )
     # Make sure control directory exists
     self.cdir = os.environ[ 'HOME' ] + '/.ssh/mn'
     errRun( [ 'mkdir', '-p', self.cdir ] )
     Mininet.__init__( self, *args, **params )
 def testDefaultDpid( self ):
     """Verify that the default dpid is assigned using a valid provided
     canonical switchname if no dpid is passed in switch creation."""
     switch = Mininet( Topo(),
                       self.switchClass,
                       Host, Controller ).addSwitch( 's1' )
     self.assertEqual( switch.defaultDpid(), switch.dpid )
Example #28
0
def setup(num, hwintf, beg_ip):

    info( '*** Creating network\n' )
    #net = Mininet( topo=TestTopo( num ), switch=UserSwitch, controller=RemoteController)
    #net = Mininet( topo=TestTopo( num ), controller=RemoteController, listenPort=6634)
    net = Mininet( topo=TestTopo( num ), controller=RemoteController)
    #net = Mininet( topo=TestTopo( num ))

    os.environ['NOX_CORE_DIR'] = '/opt/nox/bin'
    #controller = net.addController(name='c0', controller=NOX, noxArgs='switchqos --threads=1')
    controller = net.addController(name='c0', controller=NOX, noxArgs='switchqos --threads=10')
    #controller = net.addController(name='c0', controller=NOX, noxArgs='switch --threads=10')

    #os.environ['NOX_CORE_DIR'] = '/usr/local/bin'
    #controller = net.addController(name='c0', controller=NOX, noxArgs='switchqos')

    # Add HW interface to root switch
    switch = net.switches[ 0 ]
    switch.addIntf(hwintf)

    ip = beg_ip.split('.')
    for n in range( N-1 ):
        h = net.hosts[n]
        i = h.intfs[0]
        h.setIP(i, '.'.join(ip), 24)
        #print "IP: " + `h.IP()`
        ip[3] = str(int(ip[3]) + 1)
        #print h.IP()

    #import networkx
    #networkx.draw(net.topo.g)
    #import pylab
    #pylab.show()

    return(net)
def setupNetwork():
    "Create network"
    topo = MyTopo()
    network = Mininet(topo=topo, autoSetMacs=True, controller=None)
    network.start()
    CLI( network )
    network.stop()
def genericTest(topo):
    net = Mininet(topo=topo, switch=SliceableSwitch,
        controller=RemoteController)
    net.start()
    run(net)
    CLI(net)
    net.stop()