4 Test creation and all-pairs ping for each included mininet topo type."""
8 from functools import partial
10 from mininet.net import Mininet
11 from mininet.node import Host, Controller
12 from mininet.node import UserSwitch, OVSSwitch, IVSSwitch
13 from mininet.topo import SingleSwitchTopo, LinearTopo
14 from mininet.log import setLogLevel
15 from mininet.util import quietRun
16 from mininet.clean import cleanup
18 # Tell pylint not to complain about calls to other class
19 # pylint: disable=E1101
21 class testSingleSwitchCommon( object ):
22 "Test ping with single switch topology (common code)."
24 switchClass = None # overridden in subclasses
28 "Clean up if necessary"
29 if sys.exc_info != ( None, None, None ):
32 def testMinimal( self ):
33 "Ping test on minimal topology"
34 mn = Mininet( SingleSwitchTopo(), self.switchClass, Host, Controller,
36 dropped = mn.run( mn.ping )
37 self.assertEqual( dropped, 0 )
39 def testSingle5( self ):
40 "Ping test on 5-host single-switch topology"
41 mn = Mininet( SingleSwitchTopo( k=5 ), self.switchClass, Host,
42 Controller, waitConnected=True )
43 dropped = mn.run( mn.ping )
44 self.assertEqual( dropped, 0 )
46 # pylint: enable=E1101
48 class testSingleSwitchOVSKernel( testSingleSwitchCommon, unittest.TestCase ):
49 "Test ping with single switch topology (OVS kernel switch)."
50 switchClass = OVSSwitch
52 class testSingleSwitchOVSUser( testSingleSwitchCommon, unittest.TestCase ):
53 "Test ping with single switch topology (OVS user switch)."
54 switchClass = partial( OVSSwitch, datapath='user' )
56 @unittest.skipUnless( quietRun( 'which ivs-ctl' ), 'IVS is not installed' )
57 class testSingleSwitchIVS( testSingleSwitchCommon, unittest.TestCase ):
58 "Test ping with single switch topology (IVS switch)."
59 switchClass = IVSSwitch
61 @unittest.skipUnless( quietRun( 'which ofprotocol' ),
62 'Reference user switch is not installed' )
63 class testSingleSwitchUserspace( testSingleSwitchCommon, unittest.TestCase ):
64 "Test ping with single switch topology (Userspace switch)."
65 switchClass = UserSwitch
68 # Tell pylint not to complain about calls to other class
69 # pylint: disable=E1101
71 class testLinearCommon( object ):
72 "Test all-pairs ping with LinearNet (common code)."
74 switchClass = None # overridden in subclasses
76 def testLinear5( self ):
77 "Ping test on a 5-switch topology"
78 mn = Mininet( LinearTopo( k=5 ), self.switchClass, Host,
79 Controller, waitConnected=True )
80 dropped = mn.run( mn.ping )
81 self.assertEqual( dropped, 0 )
83 # pylint: enable=E1101
86 class testLinearOVSKernel( testLinearCommon, unittest.TestCase ):
87 "Test all-pairs ping with LinearNet (OVS kernel switch)."
88 switchClass = OVSSwitch
90 class testLinearOVSUser( testLinearCommon, unittest.TestCase ):
91 "Test all-pairs ping with LinearNet (OVS user switch)."
92 switchClass = partial( OVSSwitch, datapath='user' )
94 @unittest.skipUnless( quietRun( 'which ivs-ctl' ), 'IVS is not installed' )
95 class testLinearIVS( testLinearCommon, unittest.TestCase ):
96 "Test all-pairs ping with LinearNet (IVS switch)."
97 switchClass = IVSSwitch
99 @unittest.skipUnless( quietRun( 'which ofprotocol' ),
100 'Reference user switch is not installed' )
101 class testLinearUserspace( testLinearCommon, unittest.TestCase ):
102 "Test all-pairs ping with LinearNet (Userspace switch)."
103 switchClass = UserSwitch
106 if __name__ == '__main__':
107 setLogLevel( 'warning' )