File: test_vlanhost.py

package info (click to toggle)
mininet 2.3.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,588 kB
  • sloc: python: 11,181; ansic: 1,332; sh: 967; makefile: 87
file content (50 lines) | stat: -rwxr-xr-x 1,557 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python

"""
Test for vlanhost.py
"""

import unittest
from mininet.util import pexpect
import sys
from mininet.util import quietRun

class testVLANHost( unittest.TestCase ):

    prompt = 'mininet>'

    @unittest.skipIf( '-quick' in sys.argv, 'long test' )
    def testVLANTopo( self ):
        "Test connectivity (or lack thereof) between hosts in VLANTopo"
        p = pexpect.spawn( 'python -m mininet.examples.vlanhost' )
        p.expect( self.prompt )
        p.sendline( 'pingall 1' ) #ping timeout=1
        p.expect( '(\d+)% dropped', timeout=30  ) # there should be 24 failed pings
        percent = int( p.match.group( 1 ) ) if p.match else -1
        p.expect( self.prompt )
        p.sendline( 'exit' )
        p.wait()
        self.assertEqual( percent, 80 )

    def testSpecificVLAN( self ):
        "Test connectivity between hosts on a specific VLAN"
        vlan = 1001
        p = pexpect.spawn( 'python -m mininet.examples.vlanhost %d' % vlan )
        p.expect( self.prompt )

        p.sendline( 'h1 ping -c 1 h2' )
        p.expect ( '(\d+)% packet loss' )
        percent = int( p.match.group( 1 ) ) if p.match else -1
        p.expect( self.prompt )

        p.sendline( 'h1 ifconfig' )
        i = p.expect( ['h1-eth0.%d' % vlan, pexpect.TIMEOUT ], timeout=2 )
        p.expect( self.prompt )

        p.sendline( 'exit' )
        p.wait()
        self.assertEqual( percent, 0 ) # no packet loss on ping
        self.assertEqual( i, 0 ) # check vlan intf is present

if __name__ == '__main__':
    unittest.main()