Пример #1
0
def find_node(start: Node, node_name: str) -> Optional[Intf]:
    """
    :param start: The starting node of the search
    :param node_name: The name of the node to find
    :return: The interface of the node connected to start with node_name as name
    """

    if start.name == node_name:
        return start.intf()

    visited = set()  # type: Set[IPIntf]
    to_visit = realIntfList(start)
    # Explore all interfaces recursively, until we find one
    # connected to the node
    while to_visit:
        i = to_visit.pop()
        if i in visited:
            continue
        visited.add(i)
        for n in i.broadcast_domain.interfaces:
            if n.node.name == node_name:
                return n
            if L3Router.is_l3router_intf(n):
                to_visit.extend(realIntfList(n.node))
    return None
Пример #2
0
class testHwintf(unittest.TestCase):

    prompt = 'mininet>'

    def setUp(self):
        self.h3 = Node('t0', ip='10.0.0.3/8')
        self.n0 = Node('t1', inNamespace=False)
        Link(self.h3, self.n0)
        self.h3.configDefault()

    def testLocalPing(self):
        "Verify connectivity between virtual hosts using pingall"
        p = pexpect.spawn('python -m mininet.examples.hwintf %s' %
                          self.n0.intf())
        p.expect(self.prompt)
        p.sendline('pingall')
        p.expect('(\d+)% dropped')
        percent = int(p.match.group(1)) if p.match else -1
        self.assertEqual(percent, 0)
        p.expect(self.prompt)
        p.sendline('exit')
        p.wait()

    def testExternalPing(self):
        "Verify connnectivity between virtual host and virtual-physical 'external' host "
        p = pexpect.spawn('python -m mininet.examples.hwintf %s' %
                          self.n0.intf())
        p.expect(self.prompt)
        # test ping external to internal
        expectStr = '(\d+) packets transmitted, (\d+) received'
        m = re.search(expectStr, self.h3.cmd('ping -v -c 1 10.0.0.1'))
        tx = m.group(1)
        rx = m.group(2)
        self.assertEqual(tx, rx)
        # test ping internal to external
        p.sendline('h1 ping -c 1 10.0.0.3')
        p.expect(expectStr)
        tx = p.match.group(1)
        rx = p.match.group(2)
        self.assertEqual(tx, rx)
        p.expect(self.prompt)
        p.sendline('exit')
        p.wait()

    def tearDown(self):
        self.h3.stop(deleteIntfs=True)
        self.n0.stop(deleteIntfs=True)
Пример #3
0
class testHwintf( unittest.TestCase ):

    prompt = 'mininet>'

    def setUp( self ):
        self.h3 = Node( 't0', ip='10.0.0.3/8' )
        self.n0 = Node( 't1', inNamespace=False )
        Link( self.h3, self.n0 )
        self.h3.configDefault()

    def testLocalPing( self ):
        "Verify connectivity between virtual hosts using pingall"
        p = pexpect.spawn( 'python -m mininet.examples.hwintf %s' % self.n0.intf() )
        p.expect( self.prompt )
        p.sendline( 'pingall' )
        p.expect ( '(\d+)% dropped' )
        percent = int( p.match.group( 1 ) ) if p.match else -1
        self.assertEqual( percent, 0 )
        p.expect( self.prompt )
        p.sendline( 'exit' )
        p.wait()

    def testExternalPing( self ):
        "Verify connnectivity between virtual host and virtual-physical 'external' host "
        p = pexpect.spawn( 'python -m mininet.examples.hwintf %s' % self.n0.intf() )
        p.expect( self.prompt )
        # test ping external to internal
        expectStr = '(\d+) packets transmitted, (\d+) received'
        m = re.search( expectStr, self.h3.cmd( 'ping -v -c 1 10.0.0.1' ) )
        tx = m.group( 1 )
        rx = m.group( 2 )
        self.assertEqual( tx, rx )
        # test ping internal to external
        p.sendline( 'h1 ping -c 1 10.0.0.3')
        p.expect( expectStr )
        tx = p.match.group( 1 )
        rx = p.match.group( 2 )
        self.assertEqual( tx, rx )
        p.expect( self.prompt )
        p.sendline( 'exit' )
        p.wait()

    def tearDown( self ):
        self.h3.stop( deleteIntfs=True )
        self.n0.stop( deleteIntfs=True )