Exemple #1
0
def topology():
    "Create a network."
    net = Mininet(controller=RemoteController,
                  link=TCLink,
                  switch=OVSKernelSwitch)
    print "*** Creating nodes"
    h1 = net.addHost('h1', mac='00:00:00:00:00:01', ip='10.0.0.1/24')
    h2 = net.addHost('h2', mac='00:00:00:00:00:02', ip='10.0.10.2/24')
    h3 = net.addHost('h3', mac='00:00:00:00:00:03', ip='10.0.0.2/24')
    s4 = net.addSwitch('s4', listenPort=6673, mac='00:00:00:00:00:04')
    s5 = net.addSwitch('s5', listenPort=6674, mac='00:00:00:00:00:05')
    c7 = net.addController('c7',
                           controller=RemoteController,
                           ip='127.0.0.1',
                           port=6633)

    print "*** Creating links"
    net.addLink(s4, h3, 2, 0)
    #net.addLink(h1, s4, 0, 1)
    Link(h1, s4, intfName1='h1-eth0')
    net.addLink(s5, h2, 2, 0)
    #net.addLink(h1, s5, 0, 1)
    Link(h1, s5, intfName1='h1-eth1')
    h1.cmd('ifconfig h1-eth1 10.0.10.1 netmask 255.255.255.0')

    print "*** Starting network"
    net.build()
    c7.start()
    s4.start([c7])
    s5.start([c7])

    print "*** Running CLI"
    CLI(net)
    print "*** Stopping network"
    net.stop()
Exemple #2
0
    def __init__(self,
                 node1,
                 node2,
                 port1=None,
                 port2=None,
                 intfName1=None,
                 intfName2=None,
                 addr1=None,
                 addr2=None,
                 ip1=None,
                 ip2=None,
                 **params):
        Link.__init__(self,
                      node1,
                      node2,
                      port1=port1,
                      port2=port2,
                      intfName1=intfName1,
                      intfName2=intfName2,
                      cls1=TCIntf,
                      cls2=TCIntf,
                      addr1=addr1,
                      addr2=addr2,
                      params1=params,
                      params2=params)
        if ip1 is not None:
            self.intf1.setIP(ip1)

        if ip2 is not None:
            self.intf2.setIP(ip2)
    def __init__(
        self,
        node1,
        node2,
        port1=None,
        port2=None,
        intfName1=None,
        intfName2=None,
        addr1=None,
        addr2=None,
        ip1=None,
        ip2=None,
        **params
    ):
        Link.__init__(
            self,
            node1,
            node2,
            port1=port1,
            port2=port2,
            intfName1=intfName1,
            intfName2=intfName2,
            cls1=TCIntf,
            cls2=TCIntf,
            addr1=addr1,
            addr2=addr2,
            params1=params,
            params2=params,
        )
        if ip1 is not None:
            self.intf1.setIP(ip1)

        if ip2 is not None:
            self.intf2.setIP(ip2)
Exemple #4
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()
Exemple #5
0
    def __init__(self,
                 node1,
                 node2,
                 port1=None,
                 port2=None,
                 intfName1=None,
                 intfName2=None,
                 addr1=None,
                 addr2=None,
                 **params):
        params1 = params
        params2 = params
        if 'params1' in params:
            params1 = params['params1']
            params1.update(params)

        if 'params2' in params:
            params2 = params['params2']
            params2.update(params)

        Link.__init__(self,
                      node1,
                      node2,
                      port1=port1,
                      port2=port2,
                      intfName1=intfName1,
                      intfName2=intfName2,
                      cls1=TCIntf,
                      cls2=TCIntf,
                      addr1=addr1,
                      addr2=addr2,
                      params1=params1,
                      params2=params2)
Exemple #6
0
    def __init__(self,
                 node1,
                 node2,
                 port1=None,
                 port2=None,
                 intfName1=None,
                 intfName2=None,
                 addr1=None,
                 addr2=None,
                 **params):

        _params1 = params.pop("params1", None)
        _params2 = params.pop("params2", None)

        params1 = params.copy()
        if _params1:
            params1.update(_params1)
        params2 = params.copy()
        if _params2:
            params2.update(_params2)

        Link.__init__(self,
                      node1,
                      node2,
                      port1=port1,
                      port2=port2,
                      intfName1=intfName1,
                      intfName2=intfName2,
                      cls1=TCIntf,
                      cls2=TCIntf,
                      addr1=addr1,
                      addr2=addr2,
                      params1=params1,
                      params2=params2)
Exemple #7
0
    def __init__(self,
                 node1,
                 node2,
                 port1=None,
                 port2=None,
                 intfName1=None,
                 intfName2=None,
                 addr1=None,
                 addr2=None,
                 params1=None,
                 params2=None,
                 **params):

        params1 = params1 if params1 is not None else {}
        params2 = params2 if params2 is not None else {}
        params1.update(params)
        params2.update(params)
        Link.__init__(self,
                      node1,
                      node2,
                      port1=port1,
                      port2=port2,
                      intfName1=intfName1,
                      intfName2=intfName2,
                      cls1=TCIntf,
                      cls2=TCIntf,
                      addr1=addr1,
                      addr2=addr2,
                      params1=params1,
                      params2=params2)
Exemple #8
0
    def do_add_node(self, line):
        """Spawn a new node."""

        host_num = len(NET.hosts) + 1

        end_switch = NET.switches[-1]

        new_switch = NET.addSwitch('s%d' % host_num)
        new_host = NET.addHost("h%ds%d" % (host_num, host_num))

        # TODO: Fix bug that doesn't allow adding nodes starting from 1
        Link(new_host, new_switch)
        slink = Link(end_switch, new_switch)

        end_switch.attach(slink.intf1)

        new_switch.start(NET.controllers)
        new_host.configDefault(defaultRoute=new_host.defaultIntf())

        c = xterm_cmd(ip=new_host.IP(),
                      port=config.PORT,
                      b_ip=NET.hosts[0].IP(),
                      b_port=config.PORT)

        new_host.cmd(c % host_num)

        print("Started new node: %s" % new_host)
 def __init__(self, node1, node2, port1=None, port2=None, allowed=True,
               intfName1=None, intfName2=None, linkType='OPTICAL',
               annotations={}, speed1=0, speed2=0, **params):
     "Creates a dummy link without a virtual ethernet pair."
     self.allowed = allowed
     self.annotations = annotations
     self.linkType = linkType
     self.port1 = port1
     self.port2 = port2
     params1 = { 'speed': speed1 }
     params2 = { 'speed': speed2 }
     if isinstance(node1, LINCSwitch) and isinstance(node2, LINCSwitch):
         self.isXC = False
     else:
         self.isXC = True
     if isinstance(node1, LINCSwitch):
         cls1 = LINCIntf
         if self.isXC:
             node1.crossConnects.append(self)
     else:
         cls1 = Intf
         # bad hack to stop error message from appearing when we try to set up intf in a packet switch,
         # and there is no interface there( because we do not run makeIntfPair ). This way, we just set lo up
         intfName1 = 'lo'
     if isinstance(node2, LINCSwitch):
         cls2 = LINCIntf
         if self.isXC:
             node2.crossConnects.append(self)
     else:
         cls2 = Intf
         intfName2 = 'lo'
     Link.__init__(self, node1, node2, port1=port1, port2=port2,
                    intfName1=intfName1, intfName2=intfName2, cls1=cls1,
                    cls2=cls2, params1=params1, params2=params2)
Exemple #10
0
 def makeIntfPair(self,
                  intfname1,
                  intfname2,
                  addr1=None,
                  addr2=None,
                  node1=None,
                  node2=None,
                  deleteIntfs=True):
     """Create pair of interfaces
         intfname1: name of interface 1
         intfname2: name of interface 2
         (override this method [and possibly delete()]
         to change link type)"""
     node1 = self.node1 if node1 is None else node1
     node2 = self.node2 if node2 is None else node2
     server1 = getattr(node1, 'server', 'localhost')
     server2 = getattr(node2, 'server', 'localhost')
     if server1 == server2:
         # Link within same server
         Link.makeIntfPair(intfname1,
                           intfname2,
                           addr1,
                           addr2,
                           node1,
                           node2,
                           deleteIntfs=deleteIntfs)
         # Need to reduce the MTU of all emulated hosts to 1450 for GRE
         # tunneling, otherwise packets larger than 1400 bytes cannot be
         # successfully transmitted through the tunnel.
         node1.cmd('ip link set dev %s mtu 1450' % intfname1)
         node2.cmd('ip link set dev %s mtu 1450' % intfname2)
     else:
         # Otherwise, make a tunnel
         self.makeTunnel(node1, node2, intfname1, intfname2, addr1, addr2)
         self.tunnel = 1
Exemple #11
0
 def __init__(self,
              node1,
              node2,
              port1=None,
              port2=None,
              intfName1=None,
              intfName2=None,
              addr1=None,
              addr2=None,
              params1=None,
              params2=None,
              **kvargs):
     Link.__init__(self,
                   node1,
                   node2,
                   port1=port1,
                   port2=port2,
                   intfName1=intfName1,
                   intfName2=intfName2,
                   cls1=TCIntf,
                   cls2=TCIntf,
                   addr1=addr1,
                   addr2=addr2,
                   params1=params1,
                   params2=params2)
 def __init__( self, node1, node2, port1=None, port2=None, allowed=True,
               intfName1=None, intfName2=None, linkType='OPTICAL',
               annotations={}, speed1=0, speed2=0, **params ):
     "Creates a dummy link without a virtual ethernet pair."
     self.allowed = allowed
     self.annotations = annotations
     self.linkType = linkType
     params1 = { 'speed': speed1 }
     params2 = { 'speed': speed2 }
     
     if isinstance( node1, OpticalSwitch ):
         cls1 = OpticalIntf
     else:
         cls1 = Intf
         # bad hack to stop error message from appearing when we try to set up intf in a packet switch, 
         # and there is no interface there( because we do not run makeIntfPair ). This way, we just set lo up
         intfName1 = 'lo'
     if isinstance( node2, OpticalSwitch ):
         cls2 = OpticalIntf
     else:
         cls2 = Intf
         intfName2 = 'lo'
     Link.__init__( self, node1, node2, port1=port1, port2=port2,
                    intfName1=intfName1, intfName2=intfName2, cls1=cls1,
                    cls2=cls2, params1=params1, params2=params2 )
Exemple #13
0
 def __init__(self, node1, node2, port1=None, port2=None, allowed=True,
               intfName1=None, intfName2=None, linkType='OPTICAL',
               annotations={}, speed1=0, speed2=0, **params):
     "Creates a dummy link without a virtual ethernet pair."
     self.allowed = allowed
     self.annotations = annotations
     self.linkType = linkType
     self.port1 = port1
     self.port2 = port2
     params1 = { 'speed': speed1 }
     params2 = { 'speed': speed2 }
     # self.isCrossConnect = True if self.annotations.get('optical.type') == 'cross-connect' else False
     if isinstance(node1, LINCSwitch) and isinstance(node2, LINCSwitch):
         self.isCrossConnect = False
     else:
         self.isCrossConnect = True
     if isinstance(node1, LINCSwitch):
         cls1 = LINCIntf
         if self.isCrossConnect:
             node1.crossConnects.append(self)
     else:
         cls1 = Intf
         # bad hack to stop error message from appearing when we try to set up intf in a packet switch, 
         # and there is no interface there( because we do not run makeIntfPair ). This way, we just set lo up
         intfName1 = 'lo'
     if isinstance(node2, LINCSwitch):
         cls2 = LINCIntf
         if self.isCrossConnect:
             node2.crossConnects.append(self)
     else:
         cls2 = Intf
         intfName2 = 'lo'
     Link.__init__(self, node1, node2, port1=port1, port2=port2,
                    intfName1=intfName1, intfName2=intfName2, cls1=cls1,
                    cls2=cls2, params1=params1, params2=params2)
Exemple #14
0
def connectToRootNS(net,
                    ip='10.123.123.1',
                    mac='00123456789A',
                    prefixLen=8,
                    routes=['10.0.0.0/8']):
    print "*** Creating controller"
    c0 = net.addController('c0', ip='127.0.0.1', port=6633)
    rootswitch = net.addSwitch('roots1', )
    rootswitch.dpid = 'FFFFFFFFFFFFFFFF'
    # Connect hosts to root namespace via switch. Starts network.
    # network: Mininet() network object
    # ip: IP address for root namespace node
    # prefixLen: IP address prefix length (e.g. 8, 16, 24)
    # routes: host networks to route to"
    # Create a node in root namespace and link to switch 0
    root = Node('root', inNamespace=False)
    intf = Link(root, rootswitch).intf1
    intf.setMAC(mac)
    root.setIP(ip, prefixLen, intf)
    print "*** Added Interface", str(intf), "Connected To Root-NameSpace"
    fixNetworkManager(str(intf))
    for host in net.hosts:
        net.addLink(host, rootswitch)
    # Add routes from root ns to hosts
    for route in routes:
        root.cmd('route add -net ' + route + ' dev ' + str(intf))
    root.cmd('service network-manager restart')
    return rootswitch
Exemple #15
0
def emptyNet():

    "Create an empty network and add nodes to it."
    "[h1]<---network-a--->[s3]<--wifi-bridge-->[s4]<---network-b--->[h2]"

    net = Mininet( controller=OVSController )

    info( '*** Adding controllers\n' )
    net.addController( 'c0' )
    net.addController( 'c1' )

    info( '*** Adding hosts\n' )
    h1 = net.addHost( 'h1', ip='10.0.0.1' )
    h2 = net.addHost( 'h2', ip='10.0.0.2' )

    info( '*** Adding switches\n' )
    s3 = net.addSwitch( 's3' )
    s4 = net.addSwitch( 's4' )

    info( '*** Creating links\n' )
    Link( s3, h1 )
    WIFIBridgeLink( s3, s4 )
    Link( s4, h2 )

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

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

    info( '*** Stopping network' )
    mininet.ns3.stop()
    mininet.ns3.clear()
    net.stop()
Exemple #16
0
def myNet():
    "Create network from scratch using Open vSwitch."
 
    info( "*** Creating nodes\n" )
    switch0 = Node( 's0', inNamespace=False )
 
    h0 = Node( 'h0' )
    h1 = Node( 'h1' )
    h2 = Node( 'h2' )
 
    info( "*** Creating links\n" )
    Link( h0, switch0)
    Link( h1, switch0)
    Link( h2, switch0)
 
    info( "*** Configuring hosts\n" )
    h0.setIP( '192.168.123.1/24' )
    h1.setIP( '192.168.123.2/24' )
    h2.setIP( '192.168.123.3/24' )
       
    info( "*** Starting network using Open vSwitch\n" )
    switch0.cmd( 'ovs-vsctl del-br dp0' )
    switch0.cmd( 'ovs-vsctl add-br dp0' )
 
    for intf in switch0.intfs.values():
        print intf
        print switch0.cmd( 'ovs-vsctl add-port dp0 %s' % intf )
 
    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    #switch0.cmd( 'ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633' )
  
    print switch0.cmd(r'ovs-vsctl show')
 
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=1,actions=flood' ) 
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=2,actions=flood' )
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=3,actions=flood' )
  
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.1,actions=output:1' ) 
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,actions=output:2' ) 
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.3,actions=output:3')
 
    #switch0.cmd('tcpdump -i s0-eth0 -U -w aaa &')
    #h0.cmd('tcpdump -i h0-eth0 -U -w aaa &')
    info( "*** Running test\n" )
    h0.cmdPrint( 'ping -c 3 ' + h1.IP() )
    h0.cmdPrint( 'ping -c 3 ' + h2.IP() )
 
    #print switch0.cmd( 'ovs-ofctl show dp0' )    
    #print switch0.cmd( 'ovs-ofctl dump-tables  dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-ports   dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-flows  dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-aggregate  dp0' )
    #print switch0.cmd( 'ovs-ofctl queue-stats dp0' )
 
    info( "*** Stopping network\n" )
    switch0.cmd( 'ovs-vsctl del-br dp0' )
    switch0.deleteIntfs()
    info( '\n' )
Exemple #17
0
 def stop( self ):
     "Stop this link"
     if self.tunnel:
         self.intf1.delete()
         self.intf2.delete()
     else:
         Link.stop( self )
     self.tunnel = None
Exemple #18
0
 def stop(self):
     "Stop this link"
     if self.tunnel:
         self.intf1.delete()
         self.intf2.delete()
     else:
         Link.stop(self)
     self.tunnel = None
Exemple #19
0
 def __init__(self, node1, node2, port1=None, port2=None,
              intf_name1=None, intf_name2=None,
              addr1=None, addr2=None, **params):
     Link.__init__(self, node1, node2, port1=port1, port2=port2,
                   intfName1=intf_name1, intfName2=intf_name2,
                   cls1=FaucetIntf, cls2=FaucetIntf,
                   addr1=addr1, addr2=addr2,
                   params1=params, params2=params)
Exemple #20
0
 def __init__(self, node1, node2, **kwargs):
     "See Link.__init__() for options"
     self.isPatchLink = False
     if (isinstance(node1, OVSSwitch) and isinstance(node2, OVSSwitch)
             and getattr(node1, 'ovsdb', None) == getattr(
                 node2, 'ovsdb', None)):
         self.isPatchLink = True
         kwargs.update(cls1=OVSIntf, cls2=OVSIntf)
     Link.__init__(self, node1, node2, **kwargs)
Exemple #21
0
 def __init__(self, node1, node2, port1=None, port2=None,
              intfName1=None, intfName2=None, **params):
     Link.__init__(self, node1, node2, port1=port1, port2=port2,
                   intfName1=intfName1, intfName2=intfName2,
                   cls1=SdnIntf,
                   cls2=SdnIntf,
                   params1=params,
                   params2=params)
     self._connected = True
Exemple #22
0
 def __init__(self, node1, node2, **kwargs):
     """Initialize a RemoteLink
        see Link() for parameters"""
     # Create links on remote node
     self.node1 = node1
     self.node2 = node2
     self.tunnel = None
     kwargs.setdefault('params1', {})
     kwargs.setdefault('params2', {})
     Link.__init__(self, node1, node2, **kwargs)
 def __init__(self, node1, node2, port1=None, port2=None,
              intf_name1=None, intf_name2=None,
              addr1=None, addr2=None, **params):
     Link.__init__(self, node1, node2, port1=port1, port2=port2,
                   intfName1=intf_name1, intfName2=intf_name2,
                   cls1=ECNIntf,
                   cls2=ECNIntf,
                   addr1=addr1, addr2=addr2,
                   params1=params,
                   params2=params)
 def __init__( self, node1, node2, **kwargs ):
     "See Link.__init__() for options"
     self.isPatchLink = False
     if ( isinstance( node1, OVSSwitch ) and
          isinstance( node2, OVSSwitch ) and
          getattr( node1, 'ovsdb', None ) ==
          getattr( node2, 'ovsdb', None ) ):
         self.isPatchLink = True
         kwargs.update( cls1=OVSIntf, cls2=OVSIntf )
     Link.__init__( self, node1, node2, **kwargs )
Exemple #25
0
 def __init__( self, node1, node2, **kwargs ):
     """Initialize a RemoteLink
        see Link() for parameters"""
     # Create links on remote node
     self.node1 = node1
     self.node2 = node2
     self.tunnel = None
     kwargs.setdefault( 'params1', {} )
     kwargs.setdefault( 'params2', {} )
     Link.__init__( self, node1, node2, **kwargs )
Exemple #26
0
 def __init__(self,
              node1,
              node2,
              port1=None,
              port2=None,
              intfName1=None,
              intfName2=None):
     WIFISegment.__init__(self,
                          standard=ns.wifi.WIFI_PHY_STANDARD_80211n_5GHZ)
     #
     if hasattr(node1, 'nsNode') and node1.nsNode is not None:
         pass
     else:
         node1.nsNode = ns.network.Node()
         allNodes.append(node1)
     mobilityhelper1 = ns.mobility.MobilityHelper()
     mobilityhelper1.Install(node1.nsNode)
     if port1 is None:
         port1 = node1.newPort()
     if intfName1 is None:
         intfName1 = Link.intfName(node1, port1)  # classmethod
     tb1 = TBIntf(intfName1, node1, port1, node1.nsNode)
     #
     if hasattr(node2, 'nsNode') and node2.nsNode is not None:
         pass
     else:
         node2.nsNode = ns.network.Node()
         allNodes.append(node2)
     mobilityhelper2 = ns.mobility.MobilityHelper()
     mobilityhelper2.Install(node2.nsNode)
     if port2 is None:
         port2 = node2.newPort()
     if intfName2 is None:
         intfName2 = Link.intfName(node2, port2)  # classmethod
     tb2 = TBIntf(intfName2, node2, port2, node2.nsNode)
     #
     self.machelper.SetType(
         "ns3::WDSWifiMac", "ReceiverAddress",
         ns.network.Mac48AddressValue(ns.network.Mac48Address(tb2.MAC())))
     device1 = self.wifihelper.Install(self.phyhelper, self.machelper,
                                       node1.nsNode).Get(0)
     tb1.nsDevice = device1
     tb1.nsInstall()
     #
     self.machelper.SetType(
         "ns3::WDSWifiMac", "ReceiverAddress",
         ns.network.Mac48AddressValue(ns.network.Mac48Address(tb1.MAC())))
     device2 = self.wifihelper.Install(self.phyhelper, self.machelper,
                                       node2.nsNode).Get(0)
     tb2.nsDevice = device2
     tb2.nsInstall()
     #
     tb1.link = self
     tb2.link = self
     self.intf1, self.intf2 = tb1, tb2
Exemple #27
0
 def stop(self):
     """
     Stop this link
     :return:
     """
     if self.tunnel:
         self.tunnel.terminate()
         self.intf1.delete()
         self.intf2.delete()
     else:
         Link.stop(self)
     self.tunnel = None
def scratchNet(cname='controller', cargs='-v ptcp:'):
    "Create network from scratch using Open vSwitch."

    info("*** Creating nodes\n")
    controller = Node('c0', inNamespace=False)
    switch = Node('s0', inNamespace=False)
    h0 = Node('h0')
    h1 = Node('h1')

    info("*** Creating links\n")
    Link(h0, switch)
    Link(h1, switch)

    info("*** Configuring hosts\n")
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')
    info(str(h0) + '\n')
    info(str(h1) + '\n')

    info("*** Starting network using Open vSwitch\n")
    controller.cmd(cname + ' ' + cargs + '&')
    switch.cmd('ovs-vsctl del-br dp0')
    switch.cmd(
        'ovs-vsctl add-br dp0 other-config:datapath-id={}'.format(datapath_id))
    for intf in switch.intfs.values():
        print switch.cmd('ovs-vsctl add-port dp0 %s' % intf)

    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    s_cmd = 'ovs-vsctl set-controller dp0 tcp:[{}]:{}'.format(
        CTLR_IP, CTLR_PRT)
    print s_cmd
    switch.cmd(s_cmd)
    ping_results = [
        'received,host,jitter,packet_loss,avgping,minping,time,sent,maxping\n'
    ]
    try:
        h0.cmd('echo "" > pings.txt')
        if mode == 0:
            step_wise_testing(h0, h1, ping_results)
        else:
            continuous_testing(h0, h1, ping_results)
    except KeyboardInterrupt:
        print "Warning: Caught KeyboardInterrupt, stopping network"
        tm_local = time.localtime()
        dt = time.gmtime()
        file_name = 'pings_{}_{}_{}-{}_{}_{}.csv'.format(
            dt.tm_year, dt.tm_mon, dt.tm_mday, tm_local.tm_hour,
            tm_local.tm_min, tm_local.tm_sec)
        f = open(file_name, 'w+')
        for item in ping_results:
            f.write(item)
        stop_net(controller, cname, switch)
Exemple #29
0
def scratchNet(cname='controller', cargs='-v ptcp:'):
    "Create network from scratch using Open vSwitch."

    info("*** Creating nodes\n")
    controller = Node('c0', inNamespace=False)
    switch0 = Node('s0', inNamespace=False)
    h0 = Node('h0')
    h1 = Node('h1')

    info("*** Creating links\n")
    Link(h0, switch0)
    Link(h1, switch0)

    info("*** Configuring hosts\n")
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')
    info(str(h0) + '\n')
    info(str(h1) + '\n')

    info("*** Starting network using Open vSwitch\n")
    controller.cmd(cname + ' ' + cargs + '&')
    switch0.cmd('ovs-vsctl del-br dp0')
    switch0.cmd('ovs-vsctl add-br dp0')

    for intf in switch0.intfs.values():
        print intf
        print switch0.cmd('ovs-vsctl add-port dp0 %s' % intf)

    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    switch0.cmd('ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633')
    switch0.cmd('ovs-ofctl add-flow dp0 \"in_port=1 actions=output:2\"')
    switch0.cmd('ovs-ofctl add-flow dp0 \"in_port=2 actions=output:1\"')

    info('*** Waiting for switch to connect to controller')
    while 'is_connected' not in quietRun('ovs-vsctl show'):
        sleep(1)
        info('.')
    info('\n')

    info("*** Running test\n")
    h0.cmdPrint('ping -c3 ' + h1.IP())
    h1.cmdPrint('ping -c3 ' + h0.IP())

    info("*** Stopping network\n")
    controller.cmd('kill %' + cname)
    switch0.cmd('ovs-vsctl del-br dp0')
    switch0.deleteIntfs()
    info('\n')
Exemple #30
0
def scratchNet(cname='controller', cargs='-v ptcp:'):
    "Create network from scratch using Open vSwitch."

    info("*** Creating nodes\n")
    controller = Node('c0', inNamespace=False)
    switch = Node('s0', inNamespace=False)
    h0 = Node('h0')
    h1 = Node('h1')

    info("*** Creating links\n")
    Link(h0, switch)
    Link(h1, switch)

    info("*** Configuring hosts\n")
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')
    info(str(h0) + '\n')
    info(str(h1) + '\n')

    info("*** Starting network using Open vSwitch\n")
    controller.cmd(cname + ' ' + cargs + '&')
    switch.cmd('ovs-vsctl del-br dp0')
    switch.cmd('ovs-vsctl add-br dp0')
    for intf in switch.intfs.values():
        print switch.cmd('ovs-vsctl add-port dp0 %s' % intf)

    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    s_cmd = 'ovs-vsctl set-controller dp0 tcp:[{}]:{}'.format(
        CTLR_IP, CTLR_PRT)
    print s_cmd
    switch.cmd(s_cmd)

    info('*** Waiting for switch to connect to controller')
    try:
        while 'is_connected' not in quietRun('ovs-vsctl show'):
            sleep(1)
            info('.')

        info('\n')

        while True:
            info("*** Running test\n")
            h0.cmdPrint('ping -c1 ' + h1.IP())
            info("*** Sleep\n")
            sleep(2)
    except KeyboardInterrupt:
        print "Warning: Caught KeyboardInterrupt, stopping network"
        stop_net(controller, cname, switch)
Exemple #31
0
def add_link():
    Link(hosts[0], switches[0])
    Link(hosts[1], switches[0])
    tmp1 = int(hosts.index('h0')) + 1
    tmp2 = int(hosts.index('h1')) + 1
    ip1 = '10.' + str(tmp1) + '/8'
    ip2 = '10.' + str(tmp2) + '/8'
    hosts[0].setIP(ip1)
    hosts[1].setIP(ip2)
    controllers[0].start()
    switches[0].start(controllers[0])
    ping = hosts[0].cmd('ping -c1', hosts[1].IP())
    switches[0].stop()
    controllers[0].stop()
    return redirect(url_for('create'))
Exemple #32
0
    def configNameSpace(self):
        global CONTROLLER
        if self.controllers:
            controller = self.controllers[0]
            self.sip = controller.IP()
        else:
            if not CONTROLLER:
                controller = P4Host('c0', inNamespace=False)
                CONTROLLER = controller
            else:
                controller = CONTROLLER

        self.cmd('ip link set lo up')
        if not self.inband:
            link = Link(self, controller, port1=0)
            sintf, cintf = link.intf1, link.intf2
            if controller.IP() == '127.0.0.1' or not controller.IP():
                cip = self.getIP()
            else:
                cip = controller.IP()
            controller.setIP(cip, intf='c0-eth%s' % (len(controller.intfs) - 1))
            self.setIP(intf='%s-eth0' % self.name, ip=self.sip)

            controller.setHostRoute('%s' % self.sip, cintf)
            self.setHostRoute(cip, sintf)

        return controller
Exemple #33
0
 def add(self, node, port=None, intfName=None, mode=None):
     """Connect Mininet node to the segment.
        Will create WifiNetDevice with Mac type specified in
        the MacHelper (default: AdhocWifiMac).
        node: Mininet node
        port: node port number (optional)
        intfName: node tap interface name (optional)
        mode: TapBridge mode (UseLocal or UseBridge) (optional)"""
     # Check if this Mininet node has assigned an underlying ns-3 node.
     if hasattr(node, 'nsNode') and node.nsNode is not None:
         # If it is assigned, go ahead.
         pass
     else:
         # If not, create new ns-3 node and assign it to this Mininet node.
         node.nsNode = ns.network.Node()
         allNodes.append(node)
     # Install new device to the ns-3 node, using provided helpers.
     device = self.wifihelper.Install(self.phyhelper, self.machelper,
                                      node.nsNode).Get(0)
     mobilityhelper = ns.mobility.MobilityHelper()
     # Install mobility object to the ns-3 node.
     mobilityhelper.Install(node.nsNode)
     # If port number is not specified...
     if port is None:
         # ...obtain it automatically.
         port = node.newPort()
     # If interface name is not specified...
     if intfName is None:
         # ...obtain it automatically.
         intfName = Link.intfName(node, port)  # classmethod
     # In the specified Mininet node, create TBIntf bridged with the 'device'.
     tb = TBIntf(intfName, node, port, node.nsNode, device, mode)
     return tb
Exemple #34
0
 def _auto_config_intf(self, node_name, intf_name, **param):
     node = self.nodemap[node_name]
     if 'port' not in param:
         param['port'] = node.newPort()
     if intf_name == 'auto':
         intf_name = Link.intfName(node, param['port'])
     if intf_name in node.nameToIntf:
         error("Node %s already has interface %s." % (node, name))
         return False
     net = self.mn
     if 'ip' not in param:
         ip = net.nextIP
         net.nextIP += 1
         sufix = ipAdd(ip, ipBaseNum=net.ipBaseNum, prefixLen=net.prefixLen)
         prefix = '/%s' % net.prefixLen
         param['ip'] =  sufix + prefix 
         if 'mac' not in param:
             param['mac'] = macColonHex(ip)
     elif 'mac' not in param:
         ip, prefix = netParse(param['ip'])
         param['mac'] = macColonHex(ip)
     if 'cores' not in param and net.autoPinCpus:
         param['cores'] = self.nextCore
         net.nextCore = (net.nextCore + 1) % net.numCores
     return True
Exemple #35
0
 def makeIntfPair(self,
                  intfname1,
                  intfname2,
                  addr1=None,
                  addr2=None,
                  node1=None,
                  node2=None,
                  deleteIntfs=True):
     """Create pair of interfaces
         intfname1: name of interface 1
         intfname2: name of interface 2
         (override this method [and possibly delete()]
         to change link type)"""
     node1 = self.node1 if node1 is None else node1
     node2 = self.node2 if node2 is None else node2
     server1 = getattr(node1, 'server', 'localhost')
     server2 = getattr(node2, 'server', 'localhost')
     if server1 == server2:
         # Link within same server
         return Link.makeIntfPair(intfname1,
                                  intfname2,
                                  addr1,
                                  addr2,
                                  node1,
                                  node2,
                                  deleteIntfs=deleteIntfs)
     # Otherwise, make a tunnel
     self.tunnel = self.makeTunnel(node1, node2, intfname1, intfname2,
                                   addr1, addr2)
     return self.tunnel
    def _create_links(self, links):
        def is_remote(node):
            return isinstance(node, RemoteSwitch)

        def is_local(node):
            return not is_remote(node)

        self._info('**** Create %d link(s)' % len(links))
        for id, link in links.iteritems():
            self._debug('\tCreate link %s with params: %s' % (id, link))
            node1 = self.net.get(link['node1'])
            node2 = self.net.get(link['node2'])
            name_to_node = {'node1': node1, 'node2': node2}
            link.update(name_to_node)

            remote = filter(is_remote, [node1, node2])
            local = filter(is_local, [node1, node2])
            if not remote:
                self.net.addLink(**link)
            else:
                sw = local[0]
                r = remote[0]
                intfName = r.params['local_intf_name']
                r_mac = None  # unknown, r.params['remote_mac']
                r_port = r.params['remote_port']
                self._debug('\tadd hw interface (%s) to node (%s)' %
                            (intfName, sw.name))

                # This hack avoids calling __init__ which always makeIntfPair()
                link = Link.__new__(Link)
                i1 = Intf(intfName, node=sw, link=link)
                i2 = Intf(intfName, node=r, mac=r_mac, port=r_port, link=link)
                i2.mac = r_mac  # mn runs 'ifconfig', which resets mac to None
                #
                link.intf1, link.intf2 = i1, i2
Exemple #37
0
 def add(self, node, port=None, intfName=None, mode=None):
     """Connect Mininet node to the segment.
        node: Mininet node
        port: node port number (optional)
        intfName: node tap interface name (optional)
        mode: TapBridge mode (UseLocal or UseBridge) (optional)"""
     # Check if this Mininet node has assigned an underlying ns-3 node.
     if hasattr(node, 'nsNode') and node.nsNode is not None:
         # If it is assigned, go ahead.
         pass
     else:
         # If not, create new ns-3 node and assign it to this Mininet node.
         node.nsNode = ns.network.Node()
         allNodes.append(node)
     # Create ns-3 device.
     device = ns.csma.CsmaNetDevice()
     # Create queue used in the device.
     queue = ns.network.DropTailQueue()
     # Connect this device to the segment's channel.
     device.Attach(self.channel)
     # Set ns-3 device to use created queue.
     device.SetQueue(queue)
     # Add this device to the ns-3 node.
     node.nsNode.AddDevice(device)
     # If port number is not specified...
     if port is None:
         # ...obtain it automatically.
         port = node.newPort()
     # If interface name is not specified...
     if intfName is None:
         # ...obtain it automatically.
         intfName = Link.intfName(node, port)  # classmethod
     # In the specified Mininet node, create TBIntf bridged with the 'device'.
     tb = TBIntf(intfName, node, port, node.nsNode, device, mode)
     return tb
    def _create_links(self, links):

        def is_remote(node):
            return isinstance(node, RemoteSwitch)

        def is_local(node):
            return not is_remote(node)

        self._info('**** Create %d link(s)' % len(links))
        for id, link in links.iteritems():
            self._debug('\tCreate link %s with params: %s' % (id, link))
            node1 = self.net.get(link['node1'])
            node2 = self.net.get(link['node2'])
            name_to_node = {'node1': node1, 'node2': node2}
            link.update(name_to_node)

            remote = filter(is_remote, [node1, node2])
            local = filter(is_local, [node1, node2])
            if not remote:
                self.net.addLink(**link)
            else:
                sw = local[0]
                r = remote[0]
                intfName = r.params['local_intf_name']
                r_mac = None # unknown, r.params['remote_mac']
                r_port = r.params['remote_port']
                self._debug('\tadd hw interface (%s) to node (%s)' % (intfName, sw.name))

                # This hack avoids calling __init__ which always makeIntfPair()
                link = Link.__new__(Link)
                i1 = Intf(intfName, node=sw, link=link)
                i2 = Intf(intfName, node=r, mac=r_mac, port=r_port, link=link)
                i2.mac = r_mac # mn runs 'ifconfig', which resets mac to None
                #
                link.intf1, link.intf2 = i1, i2
Exemple #39
0
    def do_AddNode(self, line):

        id = len(P2PNet.hosts)

        newHost = P2PNet.addHost("h%ds%d" % (id, id))

        switch = P2PNet.switches[0]

        P2PNet.addLink(switch, newHost)

        slink = Link(switch, newHost)
        switch.attach(slink)
        switch.start(P2PNet.controllers)

        newHost.configDefault(defaultRoute=newHost.defaultIntf())

        print(P2PNet.hosts[0].cmd("ping -c1 %s" % newHost.IP()))  #important!!!

        print(newHost.cmd("ping -c1 10.0.0.1"))

        cmd = xtermCMD(newHost.IP(), PORT, P2PNet.hosts[0].IP(), PORT, MODE)

        print(cmd)

        newHost.cmd(cmd % (id))

        print("Started new node: %s" % newHost)
Exemple #40
0
 def status( self ):
     "Detailed representation of link"
     if self.tunnel:
         if self.tunnel.poll() is not None:
             status = "Tunnel EXITED %s" % self.tunnel.returncode
         else:
             status = "Tunnel Running (%s: %s)" % (
                 self.tunnel.pid, self.cmd )
     else:
         status = "OK"
     result = "%s %s" % ( Link.status( self ), status )
     return result
def connectToRootNS( net, ip='10.123.123.1', mac='00123456789A', prefixLen=8, routes=['10.0.0.0/8']):
	print "*** Creating controller"
	c0 = net.addController( 'c0', ip='127.0.0.1', port=6633 )
	rootswitch = net.addSwitch('roots1',)
	rootswitch.dpid = 'FFFFFFFFFFFFFFFF'
	# Connect hosts to root namespace via switch. Starts network.
	# network: Mininet() network object
	# ip: IP address for root namespace node
	# prefixLen: IP address prefix length (e.g. 8, 16, 24)
	# routes: host networks to route to"
	# Create a node in root namespace and link to switch 0
	root = Node( 'root', inNamespace=False )
	intf = Link( root, rootswitch ).intf1
	intf.setMAC(mac)
	root.setIP( ip, prefixLen, intf )
	print "*** Added Interface", str(intf), "Connected To Root-NameSpace"
	fixNetworkManager(str(intf))
	for host in net.hosts:
	    net.addLink(host,rootswitch)
	# Add routes from root ns to hosts
	for route in routes:
         root.cmd( 'route add -net ' + route + ' dev ' + str( intf ) )
	root.cmd('service network-manager restart')
	return rootswitch
Exemple #42
0
 def makeIntfPair( self, intfname1, intfname2, addr1=None, addr2=None,
                   node1=None, node2=None, deleteIntfs=True   ):
     """Create pair of interfaces
         intfname1: name of interface 1
         intfname2: name of interface 2
         (override this method [and possibly delete()]
         to change link type)"""
     node1 = self.node1 if node1 is None else node1
     node2 = self.node2 if node2 is None else node2
     server1 = getattr( node1, 'server', 'localhost' )
     server2 = getattr( node2, 'server', 'localhost' )
     if server1 == server2:
         # Link within same server
         Link.makeIntfPair( intfname1, intfname2, addr1, addr2,
                            node1, node2, deleteIntfs=deleteIntfs )
         # Need to reduce the MTU of all emulated hosts to 1450 for GRE
         # tunneling, otherwise packets larger than 1400 bytes cannot be
         # successfully transmitted through the tunnel.
         node1.cmd('ip link set dev %s mtu 1450' % intfname1)
         node2.cmd('ip link set dev %s mtu 1450' % intfname2)
     else:
         # Otherwise, make a tunnel
         self.makeTunnel( node1, node2, intfname1, intfname2, addr1, addr2 )
         self.tunnel = 1
Exemple #43
0
 def add( self, node, port=None, intfName=None ):
     if hasattr( node, 'nsNode' ) and node.nsNode is not None:
         pass
     else:
         node.nsNode = ns.network.Node()
         allNodes.append( node )
     device = ns.network.SimpleNetDevice()
     device.SetChannel(self.channel)
     device.SetAddress (ns.network.Mac48Address.Allocate ())
     node.nsNode.AddDevice(device)
     if port is None:
         port = node.newPort()
     if intfName is None:
         intfName = Link.intfName( node, port ) # classmethod
     tb = TBIntf( intfName, node, port, node.nsNode, device )
     return tb
Exemple #44
0
 def makeIntfPair( self, intfname1, intfname2, addr1=None, addr2=None,
                   node1=None, node2=None, deleteIntfs=True   ):
     """Create pair of interfaces
         intfname1: name of interface 1
         intfname2: name of interface 2
         (override this method [and possibly delete()]
         to change link type)"""
     node1 = self.node1 if node1 is None else node1
     node2 = self.node2 if node2 is None else node2
     server1 = getattr( node1, 'server', 'localhost' )
     server2 = getattr( node2, 'server', 'localhost' )
     if server1 == server2:
         # Link within same server
         return Link.makeIntfPair( intfname1, intfname2, addr1, addr2,
                                   node1, node2, deleteIntfs=deleteIntfs )
     # Otherwise, make a tunnel
     self.tunnel = self.makeTunnel( node1, node2, intfname1, intfname2,
                                    addr1, addr2 )
     return self.tunnel
Exemple #45
0
 def add( self, node, phyHelper, macHelper, port=None, intfName=None ):
     if phyHelper is None or macHelper is None:
         warn( "phyHelper and macHelper must not be none.\n" )
         return None
     if hasattr( node, 'nsNode' ) and node.nsNode is not None:
         pass
     else:
         node.nsNode = ns.network.Node()
         allNodes.append( node )
     phyHelper.SetChannel (channel = self.channel)
     device = self.wifiHelper.Install (phyHelper, macHelper, node.nsNode).Get(0)
     node.nsNode.AddDevice (device)
     device.SetAddress (ns.network.Mac48Address.Allocate ())
     node.nsNode.AddDevice (device)
     if port is None:
         port = node.newPort()
     if intfName is None:
         intfName = Link.intfName( node, port ) # classmethod
     tb = TBIntf( intfName, node, port, node.nsNode, device)
     return tb
h0 = Host( 'h0' )
h1 = Host( 'h1' )
h2 = Host( 'h2' )
h3 = Host( 'h3' )

s0 = OVSKernelSwitch( 's0' ,inNamespace=False )
s1 = OVSKernelSwitch( 's1' ,inNamespace=False )
s2 = OVSKernelSwitch( 's2', inNamespace=False  )
s3 = OVSKernelSwitch( 's3' ,inNamespace=False ) 

c0 = RemoteController( 'c0', ip = '10.108.100.195' ) 
c1 = RemoteController( 'c1', ip = '10.108.100.248' ) 
c2 = RemoteController( 'c2', ip = '10.108.102.176' ) 
c3 = RemoteController( 'c3', ip = '10.108.101.48' )

l1 = Link( h0, s1 )
Link( h1, s1 ) 
Link( h2, s2 )
Link( h3, s3 )
Link( s0, s1 )
Link( s0, s2 )
Link( s0, s3 )

h0.setIP( '10.1.0.1/16' )
h1.setIP( '10.1.0.2/16' )
h2.setIP( '10.2.0.1/16' )
h3.setIP( '10.3.0.1/16' )

print h0.cmd('ifconfig')
c0.start()
c1.start()