Revision 37bdf14b

View differences:

examples/intfoptions.py
19 19
    h2 = net.addHost( 'h2' )
20 20
    s1 = net.addSwitch( 's1' )
21 21
    link1 = net.addLink( h1, s1, cls=TCLink )
22
    link2 = net.addLink( h2, s1 )
22
    net.addLink( h2, s1 )
23 23
    net.start()
24 24
    
25 25
    # flush out latency from reactive forwarding delay
examples/multilink.py
1
#!/usr/bin/python
2

  
3
"""
4
This is a simple example that demonstrates multiple links
5
between nodes.
6
"""
7

  
8
from mininet.cli import CLI
9
from mininet.log import lg, info
10
from mininet.net import Mininet
11
from mininet.topo import Topo
12
    
13
def runMultiLink():
14
    
15
    topo = simpleMultiLinkTopo( n=2 )
16
    net = Mininet( topo=topo )
17
    net.start()
18
    CLI( net )
19
    net.stop()
20

  
21
class simpleMultiLinkTopo( Topo ):
22

  
23
    def __init__( self, n, **kwargs ):
24
        Topo.__init__( self, **kwargs )
25

  
26
        h1, h2 = self.addHost( 'h1' ), self.addHost( 'h2' )
27
        s1 = self.addSwitch( 's1' )
28
        
29
        for _ in range( n ):
30
            self.addLink( s1, h1 )
31
            self.addLink( s1, h2 )
32

  
33
if __name__ == '__main__':
34
    lg.setLogLevel( 'info' )
35
    runMultiLink()
examples/test/test_intfoptions.py
1
#!/usr/bin/env python
2

  
3
"""
4
Test for intfOptions.py
5
"""
6

  
7
import unittest
8
import pexpect
9
import sys
10

  
11
class testIntfOptions( unittest.TestCase ):
12

  
13
    def testIntfOptions( self ):
14
        "verify that intf.config is correctly limiting traffic"
15
        p = pexpect.spawn( 'python -m mininet.examples.intfoptions ' )
16
        tolerance = .8
17
        opts = [ "Results: \['([\d\.]+) .bits/sec",
18
                 "Results: \['10M', '([\d\.]+) .bits/sec",
19
                 "h(\d+)->h(\d+): (\d)/(\d), rtt min/avg/max/mdev ([\d\.]+)/([\d\.]+)/([\d\.]+)/([\d\.]+) ms",
20
                 pexpect.EOF ]
21
        while True:
22
            index = p.expect( opts, timeout=600 )
23
            if index == 0:
24
                bw = float( p.match.group( 1 ) )
25
                self.assertGreaterEqual( bw, float( 5 * tolerance ) )
26
                self.assertLessEqual( bw, float( 5 + 5 * ( 1 - tolerance ) ) )
27
            elif index == 1:
28
                BW = 10
29
                measuredBw = float( p.match.group( 1 ) )
30
                loss = ( measuredBw / BW ) * 100
31
                self.assertGreaterEqual( loss, 50 * tolerance )
32
                self.assertLessEqual( loss,  50 + 50 * ( 1 - tolerance ) )
33
            elif index == 2:
34
                delay = float( p.match.group( 6 ) )
35
                self.assertGreaterEqual( delay, 15 * tolerance )
36
                self.assertLessEqual( delay,  15 + 15 * ( 1 - tolerance ) )
37
            else:
38
                break
39

  
40

  
41
if __name__ == '__main__':
42
    unittest.main()
examples/test/test_multilink.py
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()

Also available in: Unified diff