Statistics
| Branch: | Tag: | Revision:

mininet / mininet / test / test_nets.py @ ea97dea9

History | View | Annotate | Download (3.39 KB)

1
#!/usr/bin/env python
2

    
3
"""Package: mininet
4
   Test creation and all-pairs ping for each included mininet topo type."""
5

    
6
import unittest
7
from functools import partial
8

    
9
from mininet.net import Mininet
10
from mininet.node import Host, Controller
11
from mininet.node import UserSwitch, OVSSwitch, IVSSwitch
12
from mininet.topo import SingleSwitchTopo, LinearTopo
13
from mininet.log import setLogLevel
14
from mininet.util import quietRun
15

    
16
# Tell pylint not to complain about calls to other class
17
# pylint: disable=E1101
18

    
19
class testSingleSwitchCommon( object ):
20
    "Test ping with single switch topology (common code)."
21

    
22
    switchClass = None # overridden in subclasses
23

    
24
    def testMinimal( self ):
25
        "Ping test on minimal topology"
26
        mn = Mininet( SingleSwitchTopo(), self.switchClass, Host, Controller )
27
        dropped = mn.run( mn.ping )
28
        self.assertEqual( dropped, 0 )
29

    
30
    def testSingle5( self ):
31
        "Ping test on 5-host single-switch topology"
32
        mn = Mininet( SingleSwitchTopo( k=5 ), self.switchClass, Host,
33
                      Controller )
34
        dropped = mn.run( mn.ping )
35
        self.assertEqual( dropped, 0 )
36

    
37
# pylint: enable=E1101
38

    
39
class testSingleSwitchOVSKernel( testSingleSwitchCommon, unittest.TestCase ):
40
    "Test ping with single switch topology (OVS kernel switch)."
41
    switchClass = OVSSwitch
42

    
43
class testSingleSwitchOVSUser( testSingleSwitchCommon, unittest.TestCase ):
44
    "Test ping with single switch topology (OVS user switch)."
45
    switchClass = partial( OVSSwitch, datapath='user' )
46

    
47
@unittest.skipUnless( quietRun( 'which ivs-ctl' ), 'IVS is not installed' )
48
class testSingleSwitchIVS( testSingleSwitchCommon, unittest.TestCase ):
49
    "Test ping with single switch topology (IVS switch)."
50
    switchClass = IVSSwitch
51

    
52
@unittest.skipUnless( quietRun( 'which ofprotocol' ),
53
                     'Reference user switch is not installed' )
54
class testSingleSwitchUserspace( testSingleSwitchCommon, unittest.TestCase ):
55
    "Test ping with single switch topology (Userspace switch)."
56
    switchClass = UserSwitch
57

    
58

    
59
# Tell pylint not to complain about calls to other class
60
# pylint: disable=E1101
61

    
62
class testLinearCommon( object ):
63
    "Test all-pairs ping with LinearNet (common code)."
64

    
65
    switchClass = None # overridden in subclasses
66

    
67
    def testLinear5( self ):
68
        "Ping test on a 5-switch topology"
69
        mn = Mininet( LinearTopo( k=5 ), self.switchClass, Host, Controller, waitConnected=True )
70
        dropped = mn.run( mn.ping )
71
        self.assertEqual( dropped, 0 )
72

    
73
# pylint: enable=E1101
74

    
75

    
76
class testLinearOVSKernel( testLinearCommon, unittest.TestCase ):
77
    "Test all-pairs ping with LinearNet (OVS kernel switch)."
78
    switchClass = OVSSwitch
79

    
80
class testLinearOVSUser( testLinearCommon, unittest.TestCase ):
81
    "Test all-pairs ping with LinearNet (OVS user switch)."
82
    switchClass = partial( OVSSwitch, datapath='user' )
83

    
84
@unittest.skipUnless( quietRun( 'which ivs-ctl' ), 'IVS is not installed' )
85
class testLinearIVS( testLinearCommon, unittest.TestCase ):
86
    "Test all-pairs ping with LinearNet (IVS switch)."
87
    switchClass = IVSSwitch
88

    
89
@unittest.skipUnless( quietRun( 'which ofprotocol' ),
90
                      'Reference user switch is not installed' )
91
class testLinearUserspace( testLinearCommon, unittest.TestCase ):
92
    "Test all-pairs ping with LinearNet (Userspace switch)."
93
    switchClass = UserSwitch
94

    
95

    
96
if __name__ == '__main__':
97
    setLogLevel( 'warning' )
98
    unittest.main()