Statistics
| Branch: | Tag: | Revision:

mininet / examples / test / test_multilink.py @ 37bdf14b

History | View | Annotate | Download (1.54 KB)

1
#!/usr/bin/env python
2

    
3
'''
4
Test for multiple links between nodes
5
validates mininet interfaces against systems interfaces
6
'''
7

    
8
import unittest
9
import pexpect
10

    
11
class testMultiLink( unittest.TestCase ):
12

    
13
    prompt = 'mininet>'
14

    
15
    def testMultiLink(self):
16
        p = pexpect.spawn( 'python -m mininet.examples.multilink' )
17
        p.expect( self.prompt )
18
        p.sendline( 'intfs' )
19
        p.expect( 's(\d): lo' )
20
        intfsOutput = p.before
21
        # parse interfaces from mininet intfs, and store them in a list
22
        hostToIntfs = intfsOutput.split( '\r\n' )[ 1:3 ]
23
        intfList = []
24
        for hostToIntf in hostToIntfs:
25
            intfList += [ intf for intf in 
26
                          hostToIntf.split()[1].split(',') ]
27

    
28
        # get interfaces from system by running ifconfig on every host
29
        sysIntfList = []
30
        opts = [ 'h(\d)-eth(\d)', self.prompt ]
31
        p.expect( self.prompt )
32
        
33
        p.sendline( 'h1 ifconfig' )
34
        while True:
35
            p.expect( opts )
36
            if p.after == self.prompt:
37
                break
38
            sysIntfList.append( p.after )
39

    
40
        p.sendline( 'h2 ifconfig' )
41
        while True:
42
            p.expect( opts )
43
            if p.after == self.prompt:
44
                break
45
            sysIntfList.append( p.after )
46

    
47
        failMsg = ( 'The systems interfaces and mininet interfaces\n'
48
                    'are not the same' )
49

    
50
        self.assertEqual( sysIntfList, intfList, msg=failMsg )
51
        p.sendline( 'exit' )
52
        p.wait()
53

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