Example #1
0
def simpleTopo():

    # Check arguments passed

    nHosts = False

    if (len(sys.argv) > 1 and sys.argv[1].isdigit()):
        topo = SimpleTopo(sys.argv[1])
        nHosts = True
    else:
        topo = SimpleTopo()

    net = Mininet(topo)
    if ((len(sys.argv) == 2 and sys.argv[1] == 'c')
            or (len(sys.argv) > 2 and sys.argv[2] == 'c')):
        net.addNAT().configDefault()
    else:
        if (nHosts == False and len(sys.argv) >= 2):
            print "*** Wrong parameters ***"
            print "*** Usage: python simpleTopo.py [n] [c] ***"
            print "*** with n integer number of hosts (optional) that can be 2 or 3"
            print "*** and c to give internet access to the topology. ***"
            print "*** Starting topology with 2 hosts and no internet access ***"

    net.start()
    CLI(net)
    net.stop()
Example #2
0
    def run(self):
        '''Run the lab 3 simulation environment'''

        localJitter = 10 # ms, the evolution of the time between two consecutive packets
        # We create the topology
        topology = Lab3Topology(nbOfServersPerRegion, nbOfClientsPerRegion, nbOfRegions)
        # We create the simulation
        # Set the topology, the class for links and interfaces, the mininet environment must be cleaned up before launching, we should build now the topology
        simulation = Mininet(topo = topology, link = TCLink, intf = TCIntf, cleanup = True, build = True, ipBase='10.1.0.0/24')
        # We connect the network to Internet
        simulation.addNAT().configDefault()
        # We can start the simulation
        print "Starting the simulation..."
        simulation.start()
        # For each host
        for host in simulation.hosts:
            # We set the jitter (It can only be done after the simulation was started, not from the Topology)
            host.defaultIntf().config(jitter = ("%dms" % localJitter))
        # for each server
        for server in simulation.hosts:
            if "vessel" in server.name:
                # We open a xterm and start the server
                self.startServer(server)
        makeTerm(node=simulation.getNodeByName("client1"), cmd="firefox")
        # We also start the Command Line Interface of Mininet
        CLI(simulation)
        # Once the CLI is closed (with exit), we can stop the simulation
        print "Stopping the simulation NOW!"
        # We close the xterms (mininet.term.cleanUpScreens)
        cleanUpScreens()
        simulation.stop()
Example #3
0
def perform_tests():

    topo = TreeTopo(depth=3)
    net = Mininet(topo, link=TCLink)
    net.addNAT().configDefault()
    net.start()
    # print ("Dumping host connections")
    # dumpNodeConnections(net.hosts)
    # datbase_ip = net.get('nat0').IP()
    # app_servers = ['h33', 'h34']
    # for app_server in app_servers:
    #     s = net.get(app_server)
    #     p = s.popen('./start_app.sh', s.IP(), datbase_ip, stdout = subprocess.PIPE)
    # time.sleep(2)
    # instructor = net.get('h1')
    # print("[*] Creating Instructor")
    # p = instructor.popen("python3", "instructor.py", net.get('h33').IP(), stdout = subprocess.PIPE)
    # output, error = p.communicate()
    # p.wait()
    # print(output, error)
    # students = [net.get('h2'), net.get('h3'), net.get('h4')]
    # for i in range(len(students)):
    #     print("[*] Creating student no: {}".format(i+1))
    #     student_no = i+1
    #     p = students[i].popen("python3", "student.py", net.get('h33').IP(), str(student_no))
    #     output, error = p.communicate()
    #     print(error)
    #     p.wait()
    CLI(net)
    net.stop()
Example #4
0
def myNet():
    net = Mininet(topo=MyTopo(),
                  controller=lambda name: RemoteController(name, ip='127.0.0.1'))
    net.addNAT().configDefault()
    net.start()
    CLI(net)
    net.stop()
Example #5
0
def run():
    "Test linux router"
    topo = NetworkTopo()
    net = Mininet(topo=topo)  # controller is used by s1-s3
    #c0 = net.addController( 'c0',controller=RemoteController,ip=CONTROLLER_IP,port=6633)
    net.addController('c0', port=6633)
    net.addNAT(ip='100.0.0.250').configDefault()
    net.start()

    info('*** Routing Table on Router:\n')
    # Add routing for reaching networks that aren't directly connected
    info(net['r1'].cmd('ip route add 10.1.0.0/24 via 10.100.0.2 dev r1-eth2'))
    info(net['r2'].cmd('ip route add 10.0.0.0/24 via 10.100.0.1 dev r2-eth2'))
    #r1.cmd("ip route add 10.1.0.0/24 via 10.100.0.2 dev r1-eth2")
    #r2.cmd("ip route add 10.0.0.0/24 via 10.100.0.1 dev r2-eth2")
    info(net['r1'].cmd('route'))
    info(net['r2'].cmd('route'))

    info(os.system('date'))
    info(os.system('ip addr add 10.1.0.99/24 dev s1'))
    info(os.system('ip link set s1 up'))

    #info( net[ 'm3' ].cmd( 'python3 hello.py' ) )

    #sudo nice -n17 python3 suball.py

    CLI(net)
    net.stop()
Example #6
0
def spoofDHCP():
    topo = DHCPTopo()
    privateDirs = [('/var', '/tmp/%(name)s/var')]
    host = partial(Host, privateDirs=privateDirs)
    net = Mininet(topo=topo,
                  switch=LinuxBridge,
                  host=host,
                  link=TCLink,
                  xterms=True)
    net.addNAT().configDefault()
    h1, dhcp, evil, nat, switch = net.get('h1', 'dhcp', 'evil', 'nat0', 's1')
    setupPrivateFS([h1, evil], '/tmp/%s/etc', '/tmp/%s/var')
    net.start()
    raw_input(
        "Press return after you've started dhcp_server on evil and wireshark on s1"
    )
    startGoodDHCPserver(dhcp, gw=nat.IP(), dns='8.8.8.8')
    # Let the client connect
    startDHCPclient(h1, '/tmp/%s/etc' % h1)
    waitForIP(h1)
    CLI(net)
    stopGoodDHCPserver(dhcp)
    stopDHCPclient(h1)
    removePrivateFS([h1, evil], '/tmp/%s/etc', '/tmp/%s/var')
    net.stop()
def emptyNet():

    NODE2_IP='10.0.0.40' # Remote computer IP

    net = Mininet( topo=None,
                   build=False, switch=OVSSwitch, link=TCLink)

    net.addController( 'c0',
                      controller=RemoteController)

    h3 = net.addHost( 'h3' )
    
    h4 = net.addHost( 'h4' )
    h5 = net.addHost( 'h5' )

    s2 = net.addSwitch( 's2' )
  
    net.addLink( h4, s2 , bw = 10)
    net.addLink( h3, s2 , bw = 10)
    

    net.addNAT().configDefault()
    net.start()

    #GRE tunnel
    s2.cmd('ovs-vsctl add-port s2 s2-gre1 -- set interface s2-gre1 type=gre options:remote_ip='+NODE2_IP)

    CLI( net )
    net.stop()
Example #8
0
def setup():

    topo = SingleSwitchTopo(k=4)
    net = Mininet(topo=topo, xterms=True)
    net.addNAT().configDefault()
    net.start()  #neccessary for nat to work.

    controller = net.get('c0')
    #DISCO = controller.cmd('${ETCD_DISCOVERY:-$(curl https://discovery.etcd.io/new?size=3)}')
    DISCO = controller.cmd('curl https://discovery.etcd.io/new?size=3')

    print("DISCO %s" % DISCO)
    nodes = net.keys()
    print("nodes are %s" % nodes)
    for key in net.__iter__():
        if 'h' in key:
            node = net.get(key)
            result = node.cmd('ifconfig')
            node.cmd('export ETCD_DISCOVERY=%s' % DISCO)
            print("node.cmd: %s" % node.cmd('echo $ETCD_DISCOVERY'))
            print(result)
    # h1 = net.get('h1')
    # result = h1.cmd('ifconfig')
    # print (result)
    CLI(net)  #opens mn in terminal. Also is a kind of pause
    net.stop()  #shuts everything down.
Example #9
0
def emptyNet():

    NODE2_IP = '10.0.0.50'  #Remote host IP

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

    net.addController('c0', controller=RemoteController)

    h1 = net.addHost('h1')

    h2 = net.addHost('h2')

    s1 = net.addSwitch('s1')

    net.addLink(h1, s1)
    net.addLink(h2, s1)

    net.addNAT().configDefault()

    net.start()

    #GRE tunnel
    s1.cmd(
        'ovs-vsctl add-port s1 s1-gre1 -- set interface s1-gre1 type=gre options:remote_ip='
        + NODE2_IP)

    CLI(net)
    net.stop()
Example #10
0
def startMini():
    """
    Start Mininet with mounted directories
    :return:
    """
    setLogLevel('info')
    topo = CassTopo()
    privateDirs = [('~/raft/data', '~/raft/data/%(name)s')]
    host = partial(Host, privateDirs=privateDirs)
    # net = Mininet(topo=topo, host=host)
    net = Mininet(topo=topo, host=host, link=TCLink)
    net.addNAT().configDefault()
    net.start()
    net.pingAll()

    hs = [
        net.get('h{0}'.format(i + 1))
        for i in range(num_of_cass + num_of_client)
    ]

    # change network interface cards' names to suit cassandra.yaml
    for i in range(num_of_cass):
        hs[i].intf('h{0}-eth0'.format(i + 1)).rename('eth0')

    dumpNodeConnections(net.hosts)
    # net.stop()
    return net, hs
Example #11
0
 def run(self):
     '''Run the simulation environment'''
     # We create the topology
     topology = DistributedTopology(self.nb_of_servers)
     # We create the simulation
     # Set the topology, the class for links and interfaces, the mininet environment must be cleaned up before launching, we should build now the topology
     simulation = Mininet(topo=topology,
                          link=TCLink,
                          intf=TCIntf,
                          cleanup=True,
                          build=True,
                          ipBase='10.1.0.0/24')
     # We connect the network to Internet
     simulation.addNAT().configDefault()
     terms = []
     # We can start the simulation
     print "Starting the simulation..."
     simulation.start()
     for srv in simulation.hosts:
         if "server" in srv.name:
             # We open a xterm and start the server
             terms.append(self.startServer(srv)[0])
     # We also start the Command Line Interface of Mininet
     CLI(simulation)
     # Once the CLI is closed (with exit), we can stop the simulation
     print "Stopping the simulation NOW!"
     # We close the xterms (mininet.term.cleanUpScreens)
     cleanUpScreens()
     for term in terms:
         os.kill(term.pid, signal.SIGKILL)
     simulation.stop()
Example #12
0
def run(num_worker, loss, delay):
    topo = SimpleTopo(num_worker, loss, delay)
    net = Mininet( topo=topo, link=TCLink)
    net.addNAT().configDefault()
    net.start()
    
    CLI( net )
Example #13
0
def dhcp():

    topo = DHCPTopo()
    net = Mininet(topo=topo, link=TCLink)
    net.addNAT().configDefault()
    net.start()
    CLI(net)
    net.stop()
Example #14
0
def create_topo():
    topo=MutiController()
    net = Mininet(topo=topo,switch=MultiSwitch,build=False,link=TCLink,controller=RemoteController)
    net.build()
    net.addNAT().configDefault()
    net.start()
    CLI(net)
    net.stop()
Example #15
0
def myNetwork():

    net = Mininet( topo=None,
                   build=False,
                   ipBase='10.0.0.0/8')

    info( '*** Adding controller\n' )
    c0=net.addController(name='c0',
                      controller=RemoteController,
                      ip='127.0.0.1',
                      protocol='tcp',
                      port=6633)

    info( '*** Add switches\n')
    s4 = net.addSwitch('s4', cls=OVSKernelSwitch)
    s3 = net.addSwitch('s3', cls=OVSKernelSwitch)
    s5 = net.addSwitch('s5', cls=OVSKernelSwitch)
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch)

    info( '*** Add hosts\n')
    h6 = net.addHost('h6', cls=Host, ip='10.0.0.6', defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
    h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None)
    h5 = net.addHost('h5', cls=Host, ip='10.0.0.5', defaultRoute=None)
    h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
    h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)

    info( '*** Add links\n')
    net.addLink(h1, s1)
    net.addLink(h2, s1)
    net.addLink(s2, s1)
    net.addLink(s2, s3)
    net.addLink(s3, s4)
    net.addLink(s3, s5)
    net.addLink(s5, h5)
    net.addLink(s5, h6)
    net.addLink(s4, h4)
    net.addLink(s4, h3)

    info( '*** Starting network\n')
    net.build()
    info( '*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()

    info( '*** Starting switches\n')
    net.get('s4').start([c0])
    net.get('s3').start([c0])
    net.get('s5').start([c0])
    net.get('s2').start([c0])
    net.get('s1').start([c0])

    info( '*** Post configure switches and hosts\n')

    net.addNAT().configDefault()
    CLI(net)
    net.stop()
Example #16
0
def myNetwork():

    net = Mininet( topo=None,
                   listenPort=6633,
                   build=False,
                   ipBase='10.0.0.0/8',
		   link=TCLink,
		   )

    info( '*** Adding controller\n' )
    c0=net.addController(name='c0',
                      controller=RemoteController,
		      protocols='OpenFlow13',
		      ip='127.0.0.1'
                     )

    info( '*** Add switches\n')
    s1 = net.addSwitch('s3', cls=OVSSwitch, mac='00:00:00:00:00:06', protocols='OpenFlow13')
    s2 = net.addSwitch('s2', cls=OVSSwitch, mac='00:00:00:00:00:05', protocols='OpenFlow13')
    s3 = net.addSwitch('s1', cls=OVSSwitch, mac='00:00:00:00:00:04', protocols='OpenFlow13')

    info( '*** Add hosts\n')
    h1 = net.addHost('h3', cls=Host, ip='10.0.0.3', mac='00:00:00:00:00:03', defaultRoute='via 10.0.0.4')
    h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', mac='00:00:00:00:00:02', defaultRoute='via 10.0.0.4')
    h3 = net.addHost('h1', cls=Host, ip='10.0.0.1', mac='00:00:00:00:00:01', defaultRoute='via 10.0.0.4')
    # La ruta por defecto de los host es la de NAT (10.0.0.4 en este caso)

    info('*** Add NAT\n')
    net.addNAT().configDefault()


    info( '*** Add links\n')
    net.addLink(s1, s2, bw=10, delay='0.2ms')
    net.addLink(s1, s3, bw=10, delay='0.2ms')
    #net.addLink(s2, s1, bw=10, delay='0.2ms') #Esta linea con este controlador provoca errores.
    net.addLink(s1, h1, bw=10, delay='0.2ms')
    net.addLink(s2, h2, bw=10, delay='0.2ms')
    net.addLink(s3, h3, bw=10, delay='0.2ms')


    info( '*** Starting network\n')
    net.build()
    net.start()
    info( '*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()


    info( '*** Starting switches\n')
    net.get('s3').start([c0])
    net.get('s2').start([c0])
    net.get('s1').start([c0])

    info( '*** Post configure switches and hosts\n')

    CLI(net)
    net.stop()
Example #17
0
def setUpTopology(switches, hosts):
    topo = TreeTopology(switches=switches, hosts=hosts)
    net = Mininet(topo=topo,
                  link=TCLink,
                  host=CPULimitedHost,
                  controller=Controller)
    net.addNAT().configDefault()
    net.start()
    return net
Example #18
0
def myNetwork():

    net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8')

    info('*** Adding controller\n')
    c3 = net.addController(name='c3',
                           controller=Controller,
                           protocol='tcp',
                           port=6633)

    c1 = net.addController(name='c1',
                           controller=Controller,
                           protocol='tcp',
                           port=6633)

    c2 = net.addController(name='c2',
                           controller=Controller,
                           protocol='tcp',
                           port=6633)

    info('*** Add switches\n')
    s5 = net.addSwitch('s5', cls=OVSKernelSwitch)
    s4 = net.addSwitch('s4', cls=OVSKernelSwitch)
    s3 = net.addSwitch('s3', cls=OVSKernelSwitch)

    info('*** Add hosts\n')
    h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)

    info('*** Add links\n')
    h1s3 = {'bw': 10, 'delay': '1', 'loss': 0, 'max_queue_size': 10}
    net.addLink(h1, s3, cls=TCLink, **h1s3)
    h2s4 = {'bw': 10, 'delay': '1', 'loss': 0, 'max_queue_size': 10}
    net.addLink(h2, s4, cls=TCLink, **h2s4)
    s4s5 = {'bw': 10, 'delay': '10000', 'loss': 0, 'max_queue_size': 10}
    net.addLink(s4, s5, cls=TCLink, **s4s5)
    s3s5 = {'bw': 10, 'delay': '10000', 'loss': 0, 'max_queue_size': 10}
    net.addLink(s3, s5, cls=TCLink, **s3s5)

    info('*** Starting network\n')
    net.build()
    info('*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()

    info('*** Starting switches\n')
    net.get('s5').start([c1])
    net.get('s4').start([c3])
    net.get('s3').start([c2])
    net.addNAT().configDefault()
    net.start()
    info('*** Post configure switches and hosts\n')

    CLI(net)
    net.stop()
Example #19
0
def runTopo():
    topo = MyTopo()
    net = Mininet(
        topo=topo,
        controller=lambda name: RemoteController(name, ip='127.0.0.1'),
        switch=OVSSwitch,
        autoSetMacs=True)
    net.addNAT().configDefault()
    net.start()
    CLI(net)
    net.stop()
Example #20
0
def simpleTest():
    "Crete and teste a simple network"
    topo = MyTopo()
    net = Mininet(topo, controller=RemoteController, link=TCLink)
    net.addNAT().configDefault()
    net.start()
    #linkdown = net.configLinkStatus('s1','s3','down')
    #print linkdown
    dumpNodeConnections(net.hosts)
    CLI(net)
    net.stop()
def configure():
    topo = MyTopo()
    net = Mininet(topo=topo)
    # Add NAT connectivity
    net.addNAT().configDefault()
    net.start()
    h1, h2, h3 = net.get('h1', 'h2', 'h3')

    CLI(net)

    net.stop()
Example #22
0
def startMini():
    setLogLevel('info')
    topo = RedisTopo()
    net = Mininet(topo=topo)
    # net = Mininet(topo=topo, link=TCLink)
    net.addNAT().configDefault()
    net.start()
    net.pingAll()
    hs = [net.get('h{0}'.format(i + 1)) for i in range(num_of_hosts)]
    dumpNodeConnections(net.hosts)
    return net, hs
def myNetwork():

    net = Mininet( topo=None,
                   build=False,
                   ipBase='10.0.0.0/8')

    info( '*** Adding controller\n' )
    c0=net.addController(name='c0',
                      controller=RemoteController,
                      ip='192.168.1.10',
                      protocol='tcp',
                      port=6633)

    info( '*** Add switches\n')
    #s4 = net.addSwitch('s4', cls=OVSKernelSwitch)
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
    s4 = net.addSwitch('s4', cls=OVSKernelSwitch)
    s3 = net.addSwitch('s3', cls=OVSKernelSwitch)
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch)

    info( '*** Add hosts\n')
    h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)

    info( '*** Add links\n')
    net.addLink(h1, s1)
    net.addLink(s1, s2)
    net.addLink(s1, s3)
    net.addLink(s2, s4)
    net.addLink(s3, s4)
    net.addLink(s4, h2)

    info( '*** Starting network\n')
    net.build()
    info( '*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()

    info( '*** Starting switches\n')
    net.get('s4').start([c0])
    net.get('s2').start([c0])
    net.get('s3').start([c0])
    net.get('s1').start([c0])

    info( '*** Post configure switches and hosts\n')
  
    info( '*** Add NAT connectivity\n')
    net.addNAT().configDefault()
    info( '*** Hosts are running and should have internet connectivity\n')
    net.start()
    CLI(net)
    net.stop()
def run(num_worker, work_split, loss, delay, num_iteration):
    topo = SimpleTopo(num_worker, loss, delay)
    net = Mininet( topo=topo, link=TCLink)
    net.addNAT().configDefault()
    net.start()
    
    net['main'].cmd('python tcpPiMain.py ' + str(num_worker) + ' ' + str(work_split) + ' ' + str(num_iteration) + ' &')
    time.sleep(1)
    for i in range(num_worker):
        worker_name = 'h' + str(i)
        net[worker_name].cmd('python tcpPiWorker.py &')
    
    CLI( net )
def run(num_worker, work_split, loss, delay, infile1, infile2, out_file):
    topo = SimpleTopo(num_worker, loss, delay)
    net = Mininet( topo=topo, link=TCLink)
    net.addNAT().configDefault()
    net.start()
    
    net['main'].cmd('python tcpMatrixMain.py ' + str(num_worker) + ' ' + str(work_split) + ' ' + infile1 + ' ' + infile2 + ' ' + out_file + ' &')
    time.sleep(1)
    for i in range(num_worker):
        worker_name = 'h' + str(i)
        net[worker_name].cmd('python tcpMatrixWorker.py &')
    
    CLI( net )
Example #26
0
def main():
    setLogLevel('info')
    tp = MyTopo()
    net = Mininet(tp,
                  controller=RemoteController(ip='127.0.0.1',
                                              name='RyuController'),
                  autoStaticArp=True)
    net.addNAT().configDefault()
    net.start()

    dumpNodeConnections(net.hosts)
    net.staticArp()  # Not needed if autoStaticArp=True
    CLI(net)
    net.stop()
Example #27
0
def myNetwork():

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


    info( '*** Adding controller\n' )
    net.addController(name='c0', controller=RemoteController, ip='127.0.0.1', port=6633)

    info( '*** Add switches\n')
    s1 = net.addSwitch('s1')
    Intf( 'eth1', node=s1 )
    net.addNAT().configDefault()
    s2 = net.addSwitch('s2')

    s3 = net.addSwitch('s3')


    info( '*** Add hosts\n')
    h1 = net.addHost('h1', ip='0.0.0.0')
    h2 = net.addHost('h2', ip='0.0.0.0')
    h3 = net.addHost('h3', ip='0.0.0.0')
    h4 = net.addHost('h4', ip='0.0.0.0')
#    h1 = net.addHost('h1', ip='10.0.3.16')
#    h2 = net.addHost('h2', ip='10.0.3.18')
#    h3 = net.addHost('h3', ip='10.0.3.19')
#    h4 = net.addHost('h4', ip='10.0.3.20')
#    h1 = net.addHost('h1')

    

    info( '*** Add links\n')
    net.addLink(h1, s2)
    net.addLink(h2, s2)
    net.addLink(h3, s3)
    net.addLink(h4, s3)
    net.addLink(s1, s2)
    net.addLink(s2, s3)
    net.addLink(s1, s3)
#    net.addLink(h1, s1)

    info( '*** Starting network\n')
    net.start()
    h1.cmdPrint('dhclient '+h1.defaultIntf().name)
    h2.cmdPrint('dhclient '+h2.defaultIntf().name)
    h3.cmdPrint('dhclient '+h3.defaultIntf().name)
    h4.cmdPrint('dhclient '+h4.defaultIntf().name)
    CLI(net)
    net.stop()
Example #28
0
def create_topo():
    topo=MutiController()
    net = Mininet(topo=topo,switch=MultiSwitch,build=False,link=TCLink,controller=RemoteController)
    #  pdb.set_trace()
    #  net.addLink(topo.switch_list[0],h15)
    net.build()
    #  self.hopts={'defaultRoute':'via 10.0.0.254'}
    #  nat1=net.hosts[-1]
    #  net.addLink(nat1,net.switches[0])
    net.addNAT().configDefault()
    net.start()
    #  os.popen('ovs-vsctl add-port s7 enp0s3')
    #  h15.cmdPrint('dhclient '+h15.defaultIntf().name)
    CLI(net)
    net.stop()
Example #29
0
def startMini():
    setLogLevel('info')
    if '-s' in argv or '--single' in argv:
        topo = RedisTopoSingleSwitch()
    elif '-l1' in argv or '--linear1' in argv or '-l2' in argv or '--linear2' in argv:
        topo = RedisTopoLinear()
    else:
        return
    # net = Mininet(topo=topo)
    net = Mininet(topo=topo, link=TCLink)
    net.addNAT().configDefault()
    net.start()
    net.pingAll()
    hs = [net.get('h{0}'.format(i + 1)) for i in range(num_of_hosts)]
    dumpNodeConnections(net.hosts)
    return net, hs
Example #30
0
def myNetwork():

    net = Mininet( topo=None,
                   listenPort=6633,
                   build=False,
                   ipBase='10.0.0.0/8',
		   link=TCLink,
		   )

    info( '*** Adding controller\n' )
    c0=net.addController(name='c0',
                      controller=RemoteController,
		      protocols='OpenFlow13',
		      ip='127.0.0.1'
                     )
    info( '*** Add switches\n')
    s1 = net.addSwitch('s1', cls=OVSSwitch, mac='00:00:00:00:00:10', protocols='OpenFlow13')

    info( '*** Add hosts\n')
    h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', mac='00:00:00:00:00:01', defaultRoute='via 10.0.0.2') # defaultRoute es la ip del nat

    info('*** Add NAT\n')
    net.addNAT().configDefault()

    net.addLink(s1, h1, bw=10, delay='0.2ms')

    info( '*** Starting network\n')
    net.build()
    net.start()
    info( '*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()


    info( '*** Starting switches\n')
    net.get('s1').start([c0])

    info( '*** Post configure switches and hosts\n')

    CLI(net)
    net.stop()
Example #31
0
 def run(self, amount=''):
     "Run the lab 1 simulation environment"
     # local variables
     if amount:
         nbOfServersPerRegion = int(amount)
     else:
         nbOfServersPerRegion = 4
     nbOfClientsPerRegion = 2
     nbOfRegions = 1
     localJitter = 10  # ms, the evolution of the time between two consecutive packets
     # We create the topology
     topology = Lab1Topology(nbOfServersPerRegion,
                             nbOfClientsPerRegion, nbOfRegions)
     # We create the simulation
     # Set the topology, the class for links and interfaces, the mininet environment must be cleaned up before launching, we should build now the topology
     simulation = Mininet(topo=topology, link=TCLink, intf=TCIntf,
                          cleanup=True, build=True, ipBase='10.1.0.0/24')
     # We connect the network to Internet
     simulation.addNAT().configDefault()
     # We can start the simulation
     print "Starting the simulation..."
     simulation.start()
     # For each host
     for host in simulation.hosts:
         # We set the jitter (It can only be done after the simulation was started, not from the Topology)
         host.defaultIntf().config(jitter=("%dms" % localJitter))
     # we create a dictionnary to store the popen
     popens = {}
     # for each server
     for server in simulation.hosts:
         if "vessel" in server.name:
             # We open a xterm and start the server
             self.startServer(server, nbOfServersPerRegion * nbOfRegions)
     # We also start the Command Line Interface of Mininet
     CLI(simulation)
     # Once the CLI is closed (with exit), we can stop the simulation
     print "Stopping the simulation NOW!"
     simulation.stop()
     # We close the xterms (mininet.term.cleanUpScreens)
     cleanUpScreens()
Example #32
0
def emptyNet():

    NODE2_IP = '192.168.144.134'
    CONTROLLER_IP = '192.168.144.126'

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

    #c0 = net.addController( 'c0',controller=RemoteController,ip=CONTROLLER_IP,port=6633)
    net.addController('c0', port=6633)

    h1 = net.addHost('h1', ip='10.0.0.1')
    h2 = net.addHost('h2', ip='10.0.0.2')
    s1 = net.addSwitch('s1')
    net.addLink(h1, s1, 1, 1)
    net.addLink(h2, s1, 1, 2)
    net.build()
    net.addNAT(ip='10.0.0.5').configDefault()
    net.start()
    #net.addNAT().configDefault()
    #s1.start([c0])
    #s1.cmdPrint('ovs-vsctl set bridge s1 protocols=OpenFlow13')
    # Configure the GRE tunnel
    s1.cmdPrint(
        'ovs-vsctl add-port s1 s1-gre1 -- set interface s1-gre1 type=gre ofport_request=5 options:remote_ip='
        + NODE2_IP)
    s1.cmdPrint('ovs-vsctl show')
    #s1.cmdPrint('ovs-vsctl set bridge s1 protocols=OpenFlow13')
    #os.system('ovs-ofctl add-flow s1 eth_type=2048,ip_dst=10.0.1.3,action=output:5')
    #os.system('ovs-ofctl add-flow s1 eth_type=2048,ip_dst=10.0.1.4,action=output:5')
    #os.system('ovs-ofctl add-flow s1 eth_type=2054,ip_dst=10.0.1.3,action=output:5')
    #os.system('ovs-ofctl add-flow s1 eth_type=2054,ip_dst=10.0.1.4,action=output:5')
    h1.cmdPrint('ip link set mtu 1454 dev h1-eth1')
    h2.cmdPrint('ip link set mtu 1454 dev h2-eth1')
    nat = net.get('nat0')
    nat.cmdPrint('ip link set mtu 1454 dev nat0-eth0')
    #net.addNAT().configDefault()
    CLI(net)
    net.stop()
Example #33
0
class Application(Topo):
  def syn_flood(self):
    for h in self.net.hosts[:10]:
      h.cmd("python /home/fschardong/escape/other/scapy-2.3.1/syn_flood.py -d 10.0.0.17 -p 8000 -c x &")


    

  def __init__(self, **opts):
    topo = TreeTopo(depth=2,fanout=4)

    http = topo.addHost('http')
    http_switch = topo.addSwitch('s0')
    topo.addLink(http, http_switch)
    topo.addLink(topo.root, http_switch)

    self.net = Mininet(topo, controller = OVSController)
    self.net.addNAT().configDefault()
    self.net.start()

    self.net.switches[0].cmd("ifconfig s0 10.0.0.253")

    #self.net.hosts[100].cmd("cvlc -vvv small.mp4 --sout '#standard{access=http,mux=asf,dst=:8080}' --repeat >& /tmp/stream.log &")
    #self.net.hosts[100].cmd("cd other; python -m SimpleHTTPServer >& /tmp/http.log &")

    #for h in self.net.hosts[20:50]:
    #  h.cmd("python networkUser.py &")

    self.net.hosts[16].cmd("/home/fschardong/escape/other/orchestrator.sh > /tmp/orchestrator.log &")

    t = Timer(1, self.syn_flood)
    t.start()

   # t = Timer(90, self.syn_flood)
   # t.start()

    t = Timer(600, self.net.stop)
    t.start()
Example #34
0
def emptyNet():

    NODE2_IP='192.168.144.134'
    CONTROLLER_IP='192.168.144.126'

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

    #c0 = net.addController( 'c0',controller=RemoteController,ip=CONTROLLER_IP,port=6633)
    net.addController('c0', port=6633)

    h1 = net.addHost( 'h1', ip='10.0.0.1' )
    h2 = net.addHost( 'h2', ip='10.0.0.2' )
    s1 = net.addSwitch( 's1' )
    net.addLink( h1, s1,1,1)
    net.addLink( h2, s1,1,2)
    net.build()
    net.addNAT(ip='10.0.0.5').configDefault()
    net.start()
    #net.addNAT().configDefault()
    #s1.start([c0])
    #s1.cmdPrint('ovs-vsctl set bridge s1 protocols=OpenFlow13')
    # Configure the GRE tunnel
    s1.cmdPrint('ovs-vsctl add-port s1 s1-gre1 -- set interface s1-gre1 type=gre ofport_request=5 options:remote_ip='+NODE2_IP)
    s1.cmdPrint('ovs-vsctl show')
    #s1.cmdPrint('ovs-vsctl set bridge s1 protocols=OpenFlow13')
    #os.system('ovs-ofctl add-flow s1 eth_type=2048,ip_dst=10.0.1.3,action=output:5')
    #os.system('ovs-ofctl add-flow s1 eth_type=2048,ip_dst=10.0.1.4,action=output:5')
    #os.system('ovs-ofctl add-flow s1 eth_type=2054,ip_dst=10.0.1.3,action=output:5')
    #os.system('ovs-ofctl add-flow s1 eth_type=2054,ip_dst=10.0.1.4,action=output:5')
    h1.cmdPrint('ip link set mtu 1454 dev h1-eth1')
    h2.cmdPrint('ip link set mtu 1454 dev h2-eth1')
    nat = net.get('nat0')
    nat.cmdPrint('ip link set mtu 1454 dev nat0-eth0')
    #net.addNAT().configDefault()
    CLI( net )
    net.stop()
Example #35
0
def run():
    ''' Method used to configure network '''
    # Create network
    net = Mininet(topo=SimpleTopology(4),
                  controller=FloodlightController(name='floodlight',
                                                  ip=get_ip()),
                  autoSetMacs=True)
    # Add NAT connectivity
    net.addNAT().configDefault()

    # Start Network
    net.start()

    nat = net.get('nat0')
    print "*** NAT with mac address %s and ip address %s." % (nat.MAC(),
                                                              nat.IP())

    # Deploy interactive client
    CLI(net)

    # Shutdown network
    net.stop()
    # Cleanup
    cleanup()
Example #36
0
 def startControlNet( cls ):
     "Start control net if necessary and return it"
     cnet = cls.cnet
     if not cnet:
         info( '### Starting control network\n' )
         cnet = Mininet( ipBase=cls.ipBase )
         cswitch = cnet.addSwitch( 'ovsbr0', cls=OVSBridge )
         # Add NAT - note this can conflict with data network NAT
         info( '### Adding NAT for control and data networks'
               ' (use --nat flush=0 for data network)\n' )
         cls.cnet = cnet
         cls.nat = cnet.addNAT( 'ovsdbnat0')
         cnet.start()
         info( '### Control network started\n' )
     return cnet
Example #37
0
    setLogLevel( 'info')
    net = Mininet( controller=RemoteController )
   
    info( '*** Adding controller\n' ) 
  
    net.addController( 'c1',controller=RemoteController,ip="10.161.68.127",port=6653 )

    info( '*** Adding hosts\n' )
    h1 = net.addHost( 'h1', ip="12.0.0.1" )
    h2 = net.addHost( 'h2', ip="12.0.0.2" )

    info( '*** Adding switch\n' )
    s1 = net.addSwitch( 's1', mac="00:00:00:00:00:01" )

    info( '*** Creating links\n' )
   

    net.addLink( h1, s1 )
    net.addLink( h2, s1 )
    net.addNAT().configDefault()

    info( '*** Starting network\n')
    net.start()

   
    info( '*** Running CLI\n' )
    CLI( net )

    info( '*** Stopping network' )
    net.stop()
Example #38
0
def multiControllerNet():
    "Create a network from semi-scratch with multiple controllers."

    CONTROLLER_IP='192.168.144.149'
    #CONTROLLER_IP='127.0.0.1'
    #net = Mininet( controller=Controller,host=CPULimitedHost)
    net = Mininet(controller=Controller)
    print "*** Creating (reference) controllers"
    #c1 = net.addController( 'c1', port=6633)
    c1 = net.addController('c1', controller=RemoteController,ip=CONTROLLER_IP,port=6633)
    #c2 = net.addController( 'c2', port=6634 )
    c2 = net.addController('c2', controller=RemoteController,ip=CONTROLLER_IP,port=6634)
    #c3 = net.addController( 'c3', port=6635 )
    c3 = net.addController('c3', controller=RemoteController,ip=CONTROLLER_IP,port=6635)

    layer = 5
    tmp = 1<<layer
    print "*** Creating switches"
    sdn_switch = [net.addSwitch('S%d'%(n),dpid = str(n+1).zfill(16)) for n in range(1)]
    left_switch = [net.addSwitch('L%d'%(n+1),dpid = str(n+1+100).zfill(16)) for n in range(tmp-1)]
    right_switch = [net.addSwitch('R%d'%(n+tmp),dpid = str(n+1+200).zfill(16)) for n in range(tmp-1)]
    #f = open('switch_list','w')
    switch_name = [n.name for n in sdn_switch]
    #switch_name = switch_name + [n.name for n in right_switch]
    #switch_name = switch_name + [n.name for n in sdn_switch]
    with open('switch_list','w') as f:
        f.write(' '.join(switch_name)) 
    print 'Finish writing switch_list'
       
    print "*** Creating hosts"
    hosts1 = [ net.addHost( 'h%d' % (n+1) ,ip='10.0.0.%s'%(n+1),mac='00:00:00:00:00:%s'%(hex(n+1)[2:])) for n in range(tmp) ]
    hosts2 = [ net.addHost( 'h%d' % (n+1+tmp) ,ip='10.0.0.%s'%(100+n+1),mac='00:00:00:00:01:%s'%(hex(n+1)[2:])) for n in range(tmp) ]

    print "*** Creating links"
    for i in range(len(left_switch)/2):
        net.addLink(left_switch[i],left_switch[(i+1)*2-1],2,1)
        net.addLink(left_switch[i],left_switch[(i+1)*2],3,1)
    for i in range(len(right_switch)/2):
        net.addLink(right_switch[i],right_switch[(i+1)*2-1],2,1)
        net.addLink(right_switch[i],right_switch[(i+1)*2],3,1)
    for i in range(len(sdn_switch)):
        net.addLink(sdn_switch[i],left_switch[0],2,1)
        net.addLink(sdn_switch[i],right_switch[0],3,1)
  
    ''' 
    for i in range(4): 
        for j in range(2):
            net.addLink(left_switch[i+3],hosts1[2*i+j])
            net.addLink(right_switch[i+3],hosts2[2*i+j])
    '''
    tmp >>= 1
    for i in range(tmp):
        for j in range(2):
            net.addLink(left_switch[i+tmp-1],hosts1[2*i+j],2+j,1)
            net.addLink(right_switch[i+tmp-1],hosts2[2*i+j],2+j,1)
    tmp <<= 1
    print "*** Starting network"
    net.build()
    net.addNAT(ip='10.0.0.254',mac='00:00:00:00:00:FF').configDefault()
    #net.build()
    c1.start()
    c2.start()
    c3.start()
    
    for k in left_switch:
        k.start([c3])
        k.cmd('ovs-vsctl set bridge '+k.name+' protocols=OpenFlow13')
    for k in right_switch:
        k.start([c2])
        k.cmd('ovs-vsctl set bridge '+k.name+' protocols=OpenFlow13')
    for k in sdn_switch:
        k.start([c1])
        k.cmd('ovs-vsctl set bridge '+k.name+' protocols=OpenFlow13')
    print 'Finish bridges setting'
    
    ovs_url = 'http://'+CONTROLLER_IP+':8080/v1.0/conf/switches/'+str(1).zfill(16)+'/ovsdb_addr'
    queue_url = 'http://'+CONTROLLER_IP+':8080/qos/queue/status/'+str(1).zfill(16)
    rule_url = 'http://'+CONTROLLER_IP+':8080/qos/rules/'+str(1).zfill(16)
    

    #connect ovsdb
    sdn_switch[0].cmdPrint('ovs-vsctl set-manager ptcp:6632')
    payload = "tcp:"+'192.168.144.134'+":6632"
    response = requests.put(ovs_url,data=json.dumps(payload))
    print response,response.text
    #c1.cmdPrint('curl -X PUT -d \'"tcp:127.0.0.1:6632"\' http://localhost:8080/v1.0/conf/switches/0000000000000001/ovsdb_addr') 
    
    #local queue setting
    times = tmp**2+tmp+1
    print 'Add ',times,'queues to S0-eth2 and S0-eth3'
    q1 = []
    q2 = []
    for i in range(times):
        q1.append(str(i)+'=@q'+str(i))
        q2.append('-- --id=@q'+str(i)+' create Queue other-config:max-rate='+str(1000*1000*8))
    q1 = ','.join(q1)
    q2 = ' '.join(q2)
    CMD = 'ovs-vsctl'
    sdn_switch[0].cmd(CMD+' -- set Port S0-eth2 qos=@newqos -- --id=@newqos create Qos type=linux-htb other-config:max-rate=1000000000 queues='+q1+' '+q2)
    sdn_switch[0].cmd(CMD+' -- set Port S0-eth3 qos=@newqos -- --id=@newqos create Qos type=linux-htb other-config:max-rate=1000000000 queues='+q1+' '+q2)
    '''
    times = tmp<<1+1
    print 'Add ',times,'queues to S0-eth4'
    q1 = []
    q2 = []
    for i in range(times):
        q1.append(str(i)+'=@q'+str(i))
        q2.append('-- --id=@q'+str(i)+' create Queue other-config:max-rate=1000000000')
    q1 = ','.join(q1)
    q2 = ' '.join(q2)
    sdn_switch[0].cmd(CMD+' -- set Port S0-eth4 qos=@newqos -- --id=@newqos create Qos type=linux-htb other-config:max-rate=100000000 queues='+q1+' '+q2)
    '''

    '''
    time.sleep(1) 
    #queue setting using request, but it only afford about 500 queue

    #payload = {"port_name":"S0-eth2","type":"linux-htb","max_rate":"10000000","queues":[{"max_rate":"1000000"},{"min_rate":"500000"}]}
    unlimit_speed = {'max_rate':'1000000000'}
    payload = {"type": "linux-htb", "queues": [unlimit_speed]*(2)}
    payloads = json.dumps(payload)
    print len(payloads)
    t1 = time.time()
    try:
        response = requests.post(url,data=payloads)
    except:
        print 'timeout'
    print time.time()-t1
    print response
    print 'Queue estabish'
    #Queue setting using curl, but it only afford about 1500 queue 
    #If you want to use curl, the item in the dictionary must like "a":"1". But str(payload) looks like 'a':'1', so it won't work.
    #However, the output of json.dumps is appropriate for this
    #c1.cmdPrint("curl -X POST -d '"+json.dumps(payload)+"' "+url)
    '''
    print 'Add matching flow'
    source_provider = '192.168.144.149'
    for i in range(tmp):
        for j in range(tmp):
            payload = {'match':{'nw_src':'10.0.0.%s'%(i+1),'nw_dst':'10.0.0.%s'%(100+j+1),'nw_proto':'UDP'},'actions':{'queue':str(i*tmp+j+1)}}
            response = requests.post(rule_url,data=json.dumps(payload))
            if response.status_code!=200:
                print response,response.text
            payload = {'match':{'nw_src':'10.0.0.%s'%(i+1+100),'nw_dst':'10.0.0.%s'%(j+1),'nw_proto':'UDP'},'actions':{'queue':str(i*tmp+j+1)}}
            response = requests.post(rule_url,data=json.dumps(payload))
            if response.status_code!=200:
                print response,response.text
            
    for i in range(tmp):
        payload = {'match':{'nw_src':source_provider,'nw_dst':'10.0.0.%s'%(i+1),'nw_proto':'UDP'},'actions':{'queue':str(tmp*tmp+i+1)}}
        response = requests.post(rule_url,data=json.dumps(payload))
        if response.status_code!=200:
            print response,response.text
        payload = {'match':{'nw_src':source_provider,'nw_dst':'10.0.0.%s'%(i+1+100),'nw_proto':'UDP'},'actions':{'queue':str(tmp*tmp+i+1)}}
        response = requests.post(rule_url,data=json.dumps(payload))
        if response.status_code!=200:
            print response,response.text
    print 'Finish adding flow'    
    
    for k in sdn_switch: 
        for i in range(tmp):
            print i,'round'
            k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=2,udp,ip_src='+source_provider+',ip_dst=10.0.0.%s,action=output:2'%(i+1))
            k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=2,tcp,ip_src='+source_provider+',ip_dst=10.0.0.%s,action=output:2'%(i+1))
            k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=1,eth_type=2048,ip_src='+source_provider+',ip_dst=10.0.0.%s,action=output:2'%(i+1))
            k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=2,udp,ip_src='+source_provider+',ip_dst=10.0.0.%s,action=output:3'%(i+1+100))
            k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=2,tcp,ip_src='+source_provider+',ip_dst=10.0.0.%s,action=output:3'%(i+1+100))
            k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=1,eth_type=2048,ip_src='+source_provider+',ip_dst=10.0.0.%s,action=output:3'%(i+1+100))
            k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=2,udp,ip_src=10.0.0.%s,ip_dst='%(i+1)+source_provider+',action=output:4')
            k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=2,tcp,ip_src=10.0.0.%s,ip_dst='%(i+1)+source_provider+',action=output:4')
            k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=1,eth_type=2048,ip_src=10.0.0.%s,ip_src='%(i+1)+source_provider+',action=output:4')
            k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=2,udp,ip_src=10.0.0.%s,ip_dst='%(i+1+100)+source_provider+',action=output:4')
            k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=2,tcp,ip_src=10.0.0.%s,ip_dst='%(i+1+100)+source_provider+',action=output:4')
            k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=1,eth_type=2048,ip_src=10.0.0.%s,ip_src='%(i+1+100)+source_provider+',action=output:4')
            
            for j in range(tmp):
                k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=2,udp,ip_src=10.0.0.%s,ip_dst=10.0.0.%s,action=output:2'%(j+1+100,i+1))
                k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=2,tcp,ip_src=10.0.0.%s,ip_dst=10.0.0.%s,action=output:2'%(j+1+100,i+1))
                k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=1,eth_type=2048,ip_src=10.0.0.%s,ip_dst=10.0.0.%s,action=output:2'%(j+1+100,i+1))
                k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=2,udp,ip_src=10.0.0.%s,ip_dst=10.0.0.%s,action=output:3'%(j+1,i+1+100))
                k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=2,tcp,ip_src=10.0.0.%s,ip_dst=10.0.0.%s,action=output:3'%(j+1,i+1+100))
                k.cmd('ovs-ofctl -O OpenFlow13 add-flow '+k.name+' table=1,priority=1,eth_type=2048,ip_src=10.0.0.%s,ip_dst=10.0.0.%s,action=output:3'%(j+1,i+1+100))
    
    '''
    for i in range(tmp<<1):
        sdn_switch[0].cmdPrint('ovs-ofctl -O OpenFlow13 add-flow S15 priority=2,udp,ip_dst=10.0.0.%s,action=output:2'%(i+1))
        sdn_switch[0].cmdPrint('ovs-ofctl -O OpenFlow13 add-flow S15 priority=2,tcp,ip_dst=10.0.0.%s,action=output:2'%(i+1))
        #sdn_switch[0].cmdPrint('ovs-ofctl -O OpenFlow13 add-flow S15 priority=2,eth_type=2054,ip_dst=10.0.0.%s,action=output:2'%(i+1))
        sdn_switch[0].cmdPrint('ovs-ofctl -O OpenFlow13 add-flow S15 priority=1,eth_type=2048,ip_dst=10.0.0.%s,action=output:2'%(i+1))
        sdn_switch[0].cmdPrint('ovs-ofctl -O OpenFlow13 add-flow S15 priority=2,udp,ip_dst=10.0.0.%s,action=output:3'%(100+i+1))
        sdn_switch[0].cmdPrint('ovs-ofctl -O OpenFlow13 add-flow S15 priority=2,tcp,ip_dst=10.0.0.%s,action=output:3'%(100+i+1))
        #sdn_switch[0].cmdPrint('ovs-ofctl -O OpenFlow13 add-flow S15 priority=2,eth_type=2054,ip_dst=10.0.0.%s,action=output:3'%(100+i+1))  
        sdn_switch[0].cmdPrint('ovs-ofctl -O OpenFlow13 add-flow S15 priority=1,eth_type=2048,ip_dst=10.0.0.%s,action=output:3'%(100+i+1))
    '''
    print "*** Testing network"
    #net.pingAll()
     
    popens = {}
    for i in range(tmp):
        print 'activate',i
        #popens[hosts1[i]] = hosts1[i].popen('python client.py 1 1 %s user1 > %s &'%(i,'user1'+str(i)))
        #popens[hosts2[i]] = hosts2[i].popen('python client.py 1 2 %s user1 > %s &'%(i,'user2'+str(i)))
        hosts1[i].cmd('nohup python client.py 1 1 %s 200s/4/user1%s > %s &'%(i,str(i+1).zfill(2),'user1'+str(i+1).zfill(2)+'.txt'))
        #time.sleep(1)
        hosts2[i].cmd('nohup python client.py 1 2 %s 200s/4/user2%s > %s &'%(i,str(i+1).zfill(2),'user2'+str(i+1).zfill(2)+'.txt'))
        #time.sleep(1)
    
        #hosts1[i].cmd('nohup python client.py 1 1 %s test3/user1%s > %s &'%(i,i,'user1'+str(i)+'.txt'))
        #hosts2[i].cmd('nohup python client.py 1 2 %s test3/user2%s > %s &'%(i,i,'user2'+str(i)+'.txt'))
    
    '''
    for host,line in pmonitor(popens):
        if host:
            print "<%s>: %s" % ( host.name, line.strip() )
    '''
    '''
    print 'host1'
    hosts1[0].cmd('python client.py 1 1 1 user1 > a &')
    print 'host2'
    hosts1[1].cmd('python client.py 1 1 2 user1 > b &')
    print "*** Running CLI"
    '''
    CLI( net )
    print "*** Stopping network"
    net.stop()
    print 'destroy qos setting'
    os.system('ovs-vsctl --all destroy qos')
    os.system('ovs-vsctl --all destroy queue')
    print 'stop ovsdb manager'
    os.system('ovs-vsctl del-manager')
Example #39
0
class ONOSCluster( Controller ):
    "ONOS Cluster"
    def __init__( self, *args, **kwargs ):
        """name: (first parameter)
           *args: topology class parameters
           ipBase: IP range for ONOS nodes
           forward: default port forwarding list,
           topo: topology class or instance
           nodeOpts: ONOSNode options
           **kwargs: additional topology parameters"""
        args = list( args )
        name = args.pop( 0 )
        topo = kwargs.pop( 'topo', None )
        nat = kwargs.pop( 'nat', 'nat0' )
        nodeOpts = kwargs.pop( 'nodeOpts', {} )
        # Default: single switch with 1 ONOS node
        if not topo:
            topo = SingleSwitchTopo
            if not args:
                args = ( 1, )
        if not isinstance( topo, Topo ):
            topo = RenamedTopo( topo, *args, hnew='onos', **kwargs )
        self.ipBase = kwargs.pop( 'ipBase', '192.168.123.0/24' )
        self.forward = kwargs.pop( 'forward',
                                   [ KarafPort, GUIPort, OpenFlowPort ] )
        super( ONOSCluster, self ).__init__( name, inNamespace=False )
        fixIPTables()
        self.env = initONOSEnv()
        self.net = Mininet( topo=topo, ipBase=self.ipBase,
                            host=partial( ONOSNode, **nodeOpts ),
                            switch=LinuxBridge,
                            controller=None )
        if nat:
            self.net.addNAT( nat ).configDefault()
        updateNodeIPs( self.env, self.nodes() )
        self._remoteControllers = []

    def start( self ):
        "Start up ONOS cluster"
        info( '*** ONOS_APPS = %s\n' % ONOS_APPS )
        self.net.start()
        for node in self.nodes():
            node.start( self.env, self.nodes() )
        info( '\n' )
        self.configPortForwarding( ports=self.forward, action='A' )
        self.waitStarted()
        return

    def waitStarted( self ):
        "Wait until all nodes have started"
        startTime = time.time()
        for node in self.nodes():
            info( node )
            node.waitStarted()
        info( '*** Waited %.2f seconds for ONOS startup' %
              ( time.time() - startTime ) )

    def stop( self ):
        "Shut down ONOS cluster"
        self.configPortForwarding( ports=self.forward, action='D' )
        for node in self.nodes():
            node.stop()
        self.net.stop()

    def nodes( self ):
        "Return list of ONOS nodes"
        return [ h for h in self.net.hosts if isinstance( h, ONOSNode ) ]

    def defaultIntf( self ):
        "Call ip route to determine default interface"
        result = quietRun( 'ip route | grep default', shell=True ).strip()
        match = search( r'dev\s+([^\s]+)', result )
        if match:
            intf = match.group( 1 )
        else:
            warn( "Can't find default network interface - using eth0\n" )
            intf = 'eth0'
        return intf

    def configPortForwarding( self, ports=[], intf='', action='A' ):
        """Start or stop forwarding on intf to all nodes
           action: A=add/start, D=delete/stop (default: A)"""
        if not intf:
            intf = self.defaultIntf()
        for port in ports:
            for index, node in enumerate( self.nodes() ):
                ip, inport = node.IP(), port + index
                # Configure a destination NAT rule
                cmd = ( 'iptables -t nat -{action} PREROUTING -t nat '
                        '-i {intf} -p tcp --dport {inport} '
                        '-j DNAT --to-destination {ip}:{port}' )
                self.cmd( cmd.format( **locals() ) )
Example #40
0
class ONOSCluster( Controller ):
    "ONOS Cluster"
    def __init__( self, *args, **kwargs ):
        """name: (first parameter)
           *args: topology class parameters
           ipBase: IP range for ONOS nodes
           forward: default port forwarding list,
           topo: topology class or instance
           **kwargs: additional topology parameters"""
        args = list( args )
        name = args.pop( 0 )
        topo = kwargs.pop( 'topo', None )
        # Default: single switch with 1 ONOS node
        if not topo:
            topo = SingleSwitchTopo
            if not args:
                args = ( 1, )
        if not isinstance( topo, Topo ):
            topo = RenamedTopo( topo, *args, hnew='onos', **kwargs )
        self.ipBase = kwargs.pop( 'ipBase', '192.168.123.0/24' )
        self.forward = kwargs.pop( 'forward',
                                   [ KarafPort, GUIPort, OpenFlowPort ] )
        super( ONOSCluster, self ).__init__( name, inNamespace=False )
        fixIPTables()
        self.env = initONOSEnv()
        self.net = Mininet( topo=topo, ipBase=self.ipBase,
                            host=ONOSNode, switch=LinuxBridge,
                            controller=None )
        self.net.addNAT().configDefault()
        updateNodeIPs( self.env, self.nodes() )
        self._remoteControllers = []

    def start( self ):
        "Start up ONOS cluster"
        killprocs( 'karaf.jar' )
        info( '*** ONOS_APPS = %s\n' % ONOS_APPS )
        self.net.start()
        for node in self.nodes():
            node.start( self.env )
        info( '\n' )
        self.configPortForwarding( ports=self.forward, action='A' )
        self.waitStarted()
        return

    def waitStarted( self ):
        "Wait until all nodes have started"
        startTime = time.time()
        for node in self.nodes():
            info( node )
            node.waitStarted()
        info( '*** Waited %.2f seconds for ONOS startup' %
              ( time.time() - startTime ) )

    def stop( self ):
        "Shut down ONOS cluster"
        self.configPortForwarding( ports=self.forward, action='D' )
        for node in self.nodes():
            node.stop()
        self.net.stop()

    def nodes( self ):
        "Return list of ONOS nodes"
        return [ h for h in self.net.hosts if isinstance( h, ONOSNode ) ]

    def configPortForwarding( self, ports=[], intf='eth0', action='A' ):
        """Start or stop ports on intf to all nodes
           action: A=add/start, D=delete/stop (default: A)"""
        for port in ports:
            for index, node in enumerate( self.nodes() ):
                ip, inport = node.IP(), port + index
                # Configure a destination NAT rule
                cmd = ( 'iptables -t nat -{action} PREROUTING -t nat '
                        '-i {intf} -p tcp --dport {inport} '
                        '-j DNAT --to-destination {ip}:{port}' )
                self.cmd( cmd.format( **locals() ) )
Example #41
0
    """
    net = Mininet(controller=RemoteController)

    c0 = net.addController('c0')

    s1 = net.addSwitch('s1')
    s2 = net.addSwitch('s2')
    s3 = net.addSwitch('s3')

    h1 = net.addHost('h1', mac='00:00:00:00:00:01')
    h2 = net.addHost('h2', mac='00:00:00:00:00:02')
    h3 = net.addHost('h3', mac='00:00:00:00:00:03')
    h4 = net.addHost('h4', mac='00:00:00:00:00:04')
    h5 = net.addHost('h5', mac='00:00:00:00:00:05')

    nat0 = net.addNAT(name='nat0', connect=False)

    print "Links: ",
    links = [(s1, h1), (s1, h2), (s2, h3), (s3, h4), (s3, h5), (s1, s2),
             (s2, s3), (nat0, s2)]
    for node1, node2 in links:
        print '({0}, {1})'.format(node1.name, node2.name),
        Link(node1, node2)
    print

    net.build()
    c0.start()
    s1.start([c0])
    s2.start([c0])
    s3.start([c0])
    #print "Setting protocols..."
Example #42
0
def multiControllerNet():
    "Create a network from semi-scratch with multiple controllers."

    NODE1_IP='192.168.144.126'
    NODE2_IP='192.168.144.134'
    CONTROLLER_IP='192.168.144.126'
    #net = Mininet( controller=Controller,host=CPULimitedHost)
    net = Mininet(controller=Controller)
    print "*** Creating (reference) controllers"
    c1 = net.addController( 'c1', port=6633 )
    #c1 = net.addController('c1', controller=RemoteController,ip='127.0.0.1',port=6633)
    #c2 = net.addController( 'c2', port=6634 )
    #c2 = net.addController('c2', controller=RemoteController,ip='127.0.0.1',port=6634)
    #c3 = net.addController( 'c3', port=6635 )
    #c3 = net.addController('c3', controller=RemoteController,ip='127.0.0.1',port=6635)

    layer = 3
    tmp = 1<<layer
    print "*** Creating switches"
    sdn_switch = [net.addSwitch('S%d'%(n)) for n in range(15,16)]
    left_switch = [net.addSwitch('L%d'%(n+1)) for n in range(tmp-1)]
    #right_switch = [net.addSwitch('R%d'%(n+tmp)) for n in range(tmp-1)]
    #f = open('switch_list','w')
    switch_name = [n.name for n in left_switch]
    #switch_name = switch_name + [n.name for n in right_switch]
    switch_name = switch_name + [n.name for n in sdn_switch]
    '''
    with open('switch_list','w') as f:
        f.write(' '.join(switch_name)) 
    print 'Finish writing switch_list'
    '''   
    print "*** Creating hosts"
    hosts1 = [ net.addHost( 'h%d' % (n+1) ,ip='10.0.0.%s'%(n+1)) for n in range(tmp) ]
    #hosts2 = [ net.addHost( 'h%d' % (n+1+tmp) ) for n in range(tmp) ]

    print "*** Creating links"
    for i in range(len(left_switch)/2):
        net.addLink(left_switch[i],left_switch[(i+1)*2-1])
        net.addLink(left_switch[i],left_switch[(i+1)*2])
    #for i in range(len(right_switch)/2):
    #    net.addLink(right_switch[i],right_switch[(i+1)*2-1])
    #    net.addLink(right_switch[i],right_switch[(i+1)*2])
    for i in range(len(sdn_switch)):
        #net.addLink(sdn_switch[i],right_switch[0])
        net.addLink(sdn_switch[i],left_switch[0])
    #net.addLink(sdn_switch[0],sdn_switch[1])
  
    ''' 
    for i in range(4): 
        for j in range(2):
            net.addLink(left_switch[i+3],hosts1[2*i+j])
            net.addLink(right_switch[i+3],hosts2[2*i+j])
    '''
    tmp >>= 1
    for i in range(tmp):
        for j in range(2):
            net.addLink(left_switch[i+tmp-1],hosts1[2*i+j])
            #net.addLink(right_switch[i+tmp-1],hosts2[2*i+j])

    print "*** Starting network"
    net.build()
    net.addNAT(ip='10.0.0.254').configDefault()
    #nat = net.addNAT(connect=None)
    #net.addLink(nat,sdn_switch[0])
    #nat.configDefault()
    #net.build()
    c1.start()
    #c2.start()
    #c3.start()
    for k in left_switch:
        k.start([c1])
    #for k in right_switch:
    #    k.start([c2])
    for k in sdn_switch:
        k.start([c1])
    
    sdn_switch[0].cmdPrint('ovs-vsctl add-port '+sdn_switch[0].name+' '+sdn_switch[0].name+'-gre1 -- set interface '+sdn_switch[0].name+'-gre1 type=gre options:remote_ip='+NODE2_IP)
    for k in hosts1:
        k.cmdPrint('ip link set mtu 1454 dev '+k.name+'-eth0')
    nat = net.get('nat0')
    nat.cmdPrint('ip link set mtu 1454 dev nat0-eth0')
    print "*** Testing network"
    #net.pingAll()
    out = {}
    popens = {}
    count = {}
    for i in range(tmp<<1):
        print 'activate',i
        #popens[hosts1[i]] = hosts1[i].popen('python client.py 1 1 %s user1 > %s &'%(i,'user1'+str(i)))
        popens[hosts1[i]] = hosts1[i].popen('python client.py 1 1 %s user1'%(i))
        #popens[hosts2[i]] = hosts2[i].popen('python client.py 1 2 %s user1 > %s &'%(i,'user2'+str(i)))
        #hosts1[i].cmdPrint('python client.py 1 1 %s user1 > %s &'%(i,'user1'+str(i)))
        #hosts2[i].cmd('python client.py 1 2 %s user1 > %s &'%(i,'user2'+str(i)))
        out[hosts1[i].name] = open('user1'+str(i),'w')
        count[hosts1[i].name] = 0
    
    for host,line in pmonitor(popens):
        if host:
            out[host.name].write(line.strip()+'\n')
            count[host.name] += 1
            print count
            #print "<%s>: %s" % ( host.name, line.strip() )
    
    '''
    print 'host1'
    hosts1[0].cmd('python client.py 1 1 1 user1 > a &')
    print 'host2'
    hosts1[1].cmd('python client.py 1 1 2 user1 > b &')
    print "*** Running CLI"
    '''
    CLI( net )
    print count
    print "*** Stopping network"
    net.stop()
def myNetwork():

    net = Mininet( topo=None,
                   build=False,
                   ipBase='10.0.0.0/8')

    info( '*** Adding controller\n' )
    c0=net.addController(name='c0',
                      controller=RemoteController,
                      protocol='tcp',
                      port=6633)

    info( '*** Add switches\n')
    s3 = net.addSwitch('s3', cls=OVSKernelSwitch, protocols="OpenFlow13")
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch, protocols="OpenFlow13")
    s4 = net.addSwitch('s4', cls=OVSKernelSwitch, protocols="OpenFlow13")
    s5 = net.addSwitch('s5', cls=OVSKernelSwitch, protocols="OpenFlow13")
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch, protocols="OpenFlow13")
    s6 = net.addSwitch('s6', cls=OVSKernelSwitch, protocols="OpenFlow13")
    s7 = net.addSwitch('s7', cls=OVSKernelSwitch, protocols="OpenFlow13")

    info( '*** Add hosts\n')
    #Endpoints
    h1 = net.addHost('h1', cls=Host, mac='3a:20:45:92:93:fc', ip='10.0.0.1', defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, mac='4e:f0:8b:08:4f:07', ip='10.0.0.2', defaultRoute=None)
    h3 = net.addHost('h3', cls=Host, mac='b2:67:ff:f4:e4:18', ip='10.0.0.3', defaultRoute=None)
    h4 = net.addHost('h4', cls=Host, mac='ba:a1:a6:16:e0:91', ip='10.0.0.4', defaultRoute=None)
    h5 = net.addHost('h5', cls=Host, mac='52:e7:7c:5c:02:66', ip='10.0.0.5', defaultRoute=None)
    h6 = net.addHost('h6', cls=Host, mac='36:35:11:54:5f:95', ip='10.0.0.6', defaultRoute=None)
    h7 = net.addHost('h7', cls=Host, mac='22:bf:70:06:90:ec', ip='10.0.0.7', defaultRoute=None)
    h8 = net.addHost('h8', cls=Host, mac='02:76:81:72:1e:16', ip='10.0.0.8', defaultRoute=None)
    
    #Switch 'Hosts'
    h9 = net.addHost('h9', cls=Host, ip='10.0.0.9', defaultRoute=None)
    h10 = net.addHost('h10', cls=Host, ip='10.0.0.10', defaultRoute=None)
    h11 = net.addHost('h11', cls=Host, ip='10.0.0.11', defaultRoute=None)
    h12 = net.addHost('h12', cls=Host, ip='10.0.0.12', defaultRoute=None)
    h13 = net.addHost('h13', cls=Host, ip='10.0.0.13', defaultRoute=None)
    h14 = net.addHost('h14', cls=Host, ip='10.0.0.14', defaultRoute=None)
    h15 = net.addHost('h15', cls=Host, ip='10.0.0.15', defaultRoute=None)
    
    #External
    h16 = net.addHost('h16', cls=Host, mac='f6:52:56:1a:37:1f', ip='10.0.0.16', defaultRoute=None)

    info( '*** Add links\n')
    net.addLink(s1, h16)
    net.addLink(s1, h15)
    net.addLink(s1, s2)
    net.addLink(s1, s3)
    net.addLink(s3, s7)
    net.addLink(s3, s6)
    net.addLink(s6, h5)
    net.addLink(s6, h6)
    net.addLink(s7, h7)
    net.addLink(s7, h8)
    net.addLink(s5, h4)
    net.addLink(s5, h3)
    net.addLink(s4, h2)
    net.addLink(s4, h1)
    net.addLink(s5, h13)
    net.addLink(s5, s2)
    net.addLink(s2, s4)
    net.addLink(s2, h12)
    net.addLink(s3, h11)
    net.addLink(s7, h9)
    net.addLink(s4, h14)
    net.addLink(s6, h10)

    info( '*** Starting network\n')
    net.addNAT().configDefault()
    net.build()
    info( '*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()

    info( '*** Starting switches\n')
    net.get('s3').start([c0])
    net.get('s2').start([c0])
    net.get('s4').start([c0])
    net.get('s5').start([c0])
    net.get('s1').start([c0])
    net.get('s6').start([c0])
    net.get('s7').start([c0])

    info( '*** Post configure switches and hosts\n')

    CLI(net)
    
    net.stop()
Example #44
0
class ONOSCluster( Controller ):
    "ONOS Cluster"
    def __init__( self, *args, **kwargs ):
        """name: (first parameter)
           *args: topology class parameters
           ipBase: IP range for ONOS nodes
           forward: default port forwarding list,
           topo: topology class or instance
           nodeOpts: ONOSNode options
           **kwargs: additional topology parameters"""
        args = list( args )
        name = args.pop( 0 )
        topo = kwargs.pop( 'topo', None )
        self.nat = kwargs.pop( 'nat', 'nat0' )
        nodeOpts = kwargs.pop( 'nodeOpts', {} )
        # Default: single switch with 1 ONOS node
        if not topo:
            topo = SingleSwitchTopo
            if not args:
                args = ( 1, )
        if not isinstance( topo, Topo ):
            topo = RenamedTopo( topo, *args, hnew='onos', **kwargs )
        self.ipBase = kwargs.pop( 'ipBase', '192.168.123.0/24' )
        self.forward = kwargs.pop( 'forward',
                                   [ KarafPort, GUIPort, OpenFlowPort ] )
        super( ONOSCluster, self ).__init__( name, inNamespace=False )
        fixIPTables()
        self.env = initONOSEnv()
        self.net = Mininet( topo=topo, ipBase=self.ipBase,
                            host=partial( ONOSNode, **nodeOpts ),
                            switch=LinuxBridge,
                            controller=None )
        if self.nat:
            self.net.addNAT( self.nat ).configDefault()
        updateNodeIPs( self.env, self.nodes() )
        self._remoteControllers = []

    def start( self ):
        "Start up ONOS cluster"
        info( '*** ONOS_APPS = %s\n' % ONOS_APPS )
        self.net.start()
        for node in self.nodes():
            node.start( self.env, self.nodes() )
        info( '\n' )
        self.configPortForwarding( ports=self.forward, action='A' )
        self.waitStarted()
        return

    def waitStarted( self ):
        "Wait until all nodes have started"
        startTime = time.time()
        for node in self.nodes():
            info( node )
            node.waitStarted()
        info( '*** Waited %.2f seconds for ONOS startup' %
              ( time.time() - startTime ) )

    def stop( self ):
        "Shut down ONOS cluster"
        self.configPortForwarding( ports=self.forward, action='D' )
        for node in self.nodes():
            node.stop()
        self.net.stop()

    def nodes( self ):
        "Return list of ONOS nodes"
        return [ h for h in self.net.hosts if isinstance( h, ONOSNode ) ]

    def configPortForwarding( self, ports=[], action='A' ):
        """Start or stop port forwarding (any intf) for all nodes
           ports: list of ports to forward
           action: A=add/start, D=delete/stop (default: A)"""
        self.cmd( 'iptables -' + action, 'FORWARD -d', self.ipBase,
                  '-j ACCEPT' )
        for port in ports:
            for index, node in enumerate( self.nodes() ):
                ip, inport = node.IP(), port + index
                # Configure a destination NAT rule
                self.cmd( 'iptables -t nat -' + action,
                          'PREROUTING -t nat -p tcp --dport', inport,
                          '-j DNAT --to-destination %s:%s' % ( ip, port ) )