File: test_multilink.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 (55 lines) | stat: -rwxr-xr-x 1,589 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
51
52
53
54
55
#!/usr/bin/env python

'''
Test for multiple links between nodes
validates mininet interfaces against systems interfaces
'''

import unittest
from mininet.util import pexpect

class testMultiLink( unittest.TestCase ):

    prompt = 'mininet>'

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

        # get interfaces from system by running ifconfig on every host
        sysIntfList = []
        opts = [ 'h(\d)-eth(\d)', self.prompt ]
        p.expect( self.prompt )

        p.sendline( 'h1 ifconfig' )
        while True:
            p.expect( opts )
            if p.after == self.prompt:
                break
            sysIntfList.append( p.after )

        p.sendline( 'h2 ifconfig' )
        while True:
            p.expect( opts )
            if p.after == self.prompt:
                break
            sysIntfList.append( p.after )

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

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

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