8 from mininet.util import pexpect
10 from mininet.util import quietRun
12 class testVLANHost( unittest.TestCase ):
16 @unittest.skipIf( '-quick' in sys.argv, 'long test' )
17 def testVLANTopo( self ):
18 "Test connectivity (or lack thereof) between hosts in VLANTopo"
19 p = pexpect.spawn( 'python -m mininet.examples.vlanhost' )
20 p.expect( self.prompt )
21 p.sendline( 'pingall 1' ) #ping timeout=1
22 p.expect( '(\d+)% dropped', timeout=30 ) # there should be 24 failed pings
23 percent = int( p.match.group( 1 ) ) if p.match else -1
24 p.expect( self.prompt )
27 self.assertEqual( percent, 80 )
29 def testSpecificVLAN( self ):
30 "Test connectivity between hosts on a specific VLAN"
32 p = pexpect.spawn( 'python -m mininet.examples.vlanhost %d' % vlan )
33 p.expect( self.prompt )
35 p.sendline( 'h1 ping -c 1 h2' )
36 p.expect ( '(\d+)% packet loss' )
37 percent = int( p.match.group( 1 ) ) if p.match else -1
38 p.expect( self.prompt )
40 p.sendline( 'h1 ifconfig' )
41 i = p.expect( ['h1-eth0.%d' % vlan, pexpect.TIMEOUT ], timeout=2 )
42 p.expect( self.prompt )
46 self.assertEqual( percent, 0 ) # no packet loss on ping
47 self.assertEqual( i, 0 ) # check vlan intf is present
49 if __name__ == '__main__':