Revision e1205a8a

View differences:

Makefile
32 32
test: $(MININET) $(TEST)
33 33
	-echo "Running tests"
34 34
	mininet/test/test_nets.py
35
	mininet/test/test_hifi.py
35 36

  
36 37
mnexec: mnexec.c $(MN) mininet/net.py
37 38
	cc $(CFLAGS) $(LDFLAGS) -DVERSION=\"`PYTHONPATH=. $(MN) --version`\" $< -o $@
mininet/test/test_hifi.py
1
#!/usr/bin/env python
2

  
3
"""Package: mininet
4
   Test creation and pings for topologies with link and/or CPU options."""
5

  
6
import unittest
7

  
8
from mininet.net import Mininet
9
from mininet.node import OVSKernelSwitch
10
from mininet.topo import Topo
11
from mininet.log import setLogLevel
12

  
13

  
14
SWITCH = OVSKernelSwitch
15
# Number of hosts for each test
16
N = 2
17

  
18

  
19
class SingleSwitchOptionsTopo(Topo):
20
    "Single switch connected to n hosts."
21
    def __init__(self, n=2, hopts={}, lopts={}):
22
        Topo.__init__(self, hopts=hopts, lopts=lopts)
23
        switch = self.addSwitch('s1')
24
        for h in range(n):
25
            host = self.addHost('h%s' % (h + 1))
26
            self.addLink(host, switch)
27

  
28

  
29
class testOptionsTopo( unittest.TestCase ):
30
    "Verify ability to create networks with host and link options."
31

  
32
    def runOptionsTopoTest( self, n, hopts=None, lopts=None ):
33
        "Generic topology-with-options test runner."
34
        mn = Mininet( SingleSwitchOptionsTopo( n=n, hopts=hopts ) )
35
        dropped = mn.run( mn.ping )
36
        self.assertEqual( dropped, 0 )
37

  
38
    def testCPULimits( self ):
39
        hopts = { 'cpu': 0.5 / N }
40
        self.runOptionsTopoTest(N, hopts=hopts)
41

  
42
    def testLinkBandwidth( self ):
43
        lopts = { 'bw': 10, 'use_htb': True }
44
        self.runOptionsTopoTest(N, lopts=lopts)
45

  
46
    def testLinkDelay( self ):
47
        lopts = { 'delay': '5ms', 'use_htb': True }
48
        self.runOptionsTopoTest(N, lopts=lopts)
49

  
50
    def testLinkLoss( self ):
51
        lopts = { 'loss': 10, 'use_htb': True }
52
        self.runOptionsTopoTest(N, lopts=lopts)
53

  
54
    def testAllOptions( self ):
55
        lopts = { 'bw': 10, 'delay': '5ms', 'loss': 10, 'use_htb': True }
56
        hopts = { 'cpu': 0.5 / N }
57
        self.runOptionsTopoTest(N, hopts=hopts, lopts=lopts)
58

  
59

  
60

  
61
if __name__ == '__main__':
62
    setLogLevel( 'warning' )
63
    unittest.main()

Also available in: Unified diff