blob: 30b7e92cedf930231bef9ed7247171b2752ff10d [file] [log] [blame]
Pier6a0c4de2018-03-18 16:01:30 -07001"""
2Copyright 2018 Open Networking Foundation ( ONF )
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 ( at your option ) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
21
You Wange24d6272018-03-27 21:18:50 -070022import time
Pier6a0c4de2018-03-18 16:01:30 -070023
You Wangc02d8352018-04-17 16:42:10 -070024def setupTest( main, test_idx, onosNodes ):
25 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
26 skipPackage = False
27 init = False
28 if not hasattr( main, "apps" ):
29 init = True
30 lib.initTest( main )
31 # Skip onos packaging if the cluster size stays the same
32 if not init and onosNodes == main.Cluster.numCtrls:
33 skipPackage = True
Pier6a0c4de2018-03-18 16:01:30 -070034
You Wangc02d8352018-04-17 16:42:10 -070035 main.resultFileName = "CASE%03d" % test_idx
36 main.Cluster.setRunningNode( onosNodes )
37 lib.installOnos( main, skipPackage=skipPackage, cliSleep=5 )
38 # Load configuration files
39 main.step( "Load configurations" )
40 main.cfgName = "TEST_CONFIG_ipv4=1_ipv6=1_dhcp=1_routers=1"
41 lib.loadJson( main )
42 time.sleep( float( main.params[ "timers" ][ "loadNetcfgSleep" ] ) )
43 main.cfgName = "common"
44 lib.loadMulticastConfig( main )
Pier6a0c4de2018-03-18 16:01:30 -070045
You Wangc02d8352018-04-17 16:42:10 -070046 if hasattr( main, "Mininet1" ):
47 # Run the test with Mininet
48 mininet_args = " --dhcp=1 --routers=1 --ipv6=1 --ipv4=1"
49 lib.startMininet( main, main.params[ "DEPENDENCY" ][ "topology" ], args=mininet_args )
50 time.sleep( float( main.params[ "timers" ][ "startMininetSleep" ] ) )
51 else:
52 # Run the test with physical devices
53 lib.connectToPhysicalNetwork( main, self.switchNames )
54 # Check if the devices are up
55 lib.checkDevices( main, switches=len( self.switchNames ) )
Pier6a0c4de2018-03-18 16:01:30 -070056
You Wangc02d8352018-04-17 16:42:10 -070057 # Create scapy components
58 lib.startScapyHosts( main )
You Wangece951a2018-04-16 13:34:43 -070059
You Wangc02d8352018-04-17 16:42:10 -070060def verifyMcastRoutes( main ):
61 """
62 Install multicast routes and check traffic
63 """
64 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
65 for routeName in main.mcastRoutes.keys():
66 main.step( "Verify {} multicast route".format( routeName ) )
67 installMcastRoute( main, routeName )
68 lib.verifyMulticastTraffic( main, routeName, True )
You Wange24d6272018-03-27 21:18:50 -070069
You Wangc02d8352018-04-17 16:42:10 -070070def installMcastRoute( main, routeName ):
71 """
72 Install a multicast route
73 """
74 routeData = main.multicastConfig[ routeName ]
75 src = main.mcastRoutes[ routeName ][ "src" ]
76 dst = main.mcastRoutes[ routeName ][ "dst" ]
77 main.Cluster.active( 0 ).CLI.mcastHostJoin( routeData[ "src" ][ src[ 0 ] ][ "ip" ], routeData[ "group" ],
78 [ routeData[ "src" ][ i ][ "port" ] for i in src ],
79 [ routeData[ "dst" ][ i ][ "id" ] for i in dst ] )
80 time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) )
You Wange24d6272018-03-27 21:18:50 -070081
You Wangc02d8352018-04-17 16:42:10 -070082def verifyMcastRouteRemoval( main, routeName ):
83 """
84 Verify removal of a multicast route
85 """
86 routeData = main.multicastConfig[ routeName ]
87 main.step( "Verify removal of {} route".format( routeName ) )
88 main.Cluster.active( 0 ).CLI.mcastHostDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ] )
89 # TODO: verify the deletion
You Wange24d6272018-03-27 21:18:50 -070090
You Wangc02d8352018-04-17 16:42:10 -070091def verifyMcastSinkRemoval( main, routeName, sinkIndex, expect ):
92 """
93 Verify removal of a multicast sink
94 """
95 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
96 routeData = main.multicastConfig[ routeName ]
97 sinkId = routeData[ "dst" ][ sinkIndex ][ "id" ]
98 main.step( "Verify removal of {} sink {}".format( routeName, sinkId ) )
99 main.Cluster.active( 0 ).CLI.mcastHostDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ], sinkId )
100 time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) )
101 lib.verifyMulticastTraffic( main, routeName, expect )
You Wange24d6272018-03-27 21:18:50 -0700102
You Wangc02d8352018-04-17 16:42:10 -0700103def verifyMcastSourceRemoval( main, routeName, sourceIndex, expect ):
104 """
105 Verify removal of a multicast source
106 """
107 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
108 routeData = main.multicastConfig[ routeName ]
109 sourcePort = [ routeData[ "src" ][ sourceIndex ][ "port" ] ]
110 main.step( "Verify removal of {} source {}".format( routeName, sourcePort ) )
111 main.Cluster.active( 0 ).CLI.mcastSourceDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ], sourcePort )
112 time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) )
113 lib.verifyMulticastTraffic( main, routeName, expect )
You Wange24d6272018-03-27 21:18:50 -0700114
You Wangc02d8352018-04-17 16:42:10 -0700115def verifyMcastRemoval( main, removeDHT1=True ):
116 """
117 Verify removal of IPv6 route, IPv4 sinks and IPv4 source
118 """
119 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
120 verifyMcastRouteRemoval( main, "ipv6" )
121 if removeDHT1:
122 verifyMcastSinkRemoval( main, "ipv4", 0, [ False, True, True ] )
123 verifyMcastSinkRemoval( main, "ipv4", 1, [ False, False, True ] )
124 else:
125 verifyMcastSinkRemoval( main, "ipv4", 2, [ True, True, False ] )
126 verifyMcastSinkRemoval( main, "ipv4", 1, [ True, False, False ] )
127 verifyMcastSourceRemoval( main, "ipv4", 0, False )
You Wange24d6272018-03-27 21:18:50 -0700128
You Wangc02d8352018-04-17 16:42:10 -0700129def verifyLinkDown( main, link, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True } ):
130 """
131 Kill a batch of links and verify traffic
132 Restore the links and verify traffic
133 """
134 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
135 link = link if ( isinstance( link, list ) and isinstance( link[ 0 ], list ) ) else [ link ]
136 # Kill the link(s)
137 lib.killLinkBatch( main, link, int( main.params[ "TOPO" ][ "linkNum" ] ) - affectedLinkNum, int( main.params[ "TOPO" ][ "switchNum" ] ) )
138 for routeName in expectList.keys():
139 lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] )
140 # Restore the link(s)
141 lib.restoreLinkBatch( main, link, int( main.params[ "TOPO" ][ "linkNum" ] ), int( main.params[ "TOPO" ][ "switchNum" ] ) )
142 for routeName in expectList.keys():
143 lib.verifyMulticastTraffic( main, routeName, True )
You Wange24d6272018-03-27 21:18:50 -0700144
You Wangc02d8352018-04-17 16:42:10 -0700145def verifySwitchDown( main, switchName, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True } ):
146 """
147 Kill a batch of switches and verify traffic
148 Recover the swithces and verify traffic
149 """
150 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
151 switchName = switchName if isinstance( switchName, list ) else [ switchName ]
152 # Kill the switch(es)
153 lib.killSwitch( main, switchName, int( main.params[ "TOPO" ][ "switchNum" ] ) - len( switchName ), int( main.params[ "TOPO" ][ "linkNum" ] ) - affectedLinkNum )
154 for routeName in expectList.keys():
155 lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] )
156 # Recover the switch(es)
157 lib.recoverSwitch( main, switchName, int( main.params[ "TOPO" ][ "switchNum" ] ), int( main.params[ "TOPO" ][ "linkNum" ] ) )
158 for routeName in expectList.keys():
159 lib.verifyMulticastTraffic( main, routeName, True )
You Wange24d6272018-03-27 21:18:50 -0700160
You Wangc02d8352018-04-17 16:42:10 -0700161def verifyOnosDown( main, expectList={ "ipv4": True, "ipv6": True } ):
162 """
163 Kill and recover ONOS instances Sequencially and check traffic
164 """
165 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
166 import json
167 numCtrls = len( main.Cluster.runningNodes )
168 links = len( json.loads( main.Cluster.next().links() ) )
169 switches = len( json.loads( main.Cluster.next().devices() ) )
170 for ctrl in xrange( numCtrls ):
171 # Kill node
172 lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) )
173 main.Cluster.active(0).CLI.balanceMasters()
174 time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
175 for routeName in expectList.keys():
176 lib.verifyMulticastTraffic( main, routeName, True )
177 # Recover node
178 lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls )
179 main.Cluster.active(0).CLI.balanceMasters()
180 time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
181 for routeName in expectList.keys():
182 lib.verifyMulticastTraffic( main, routeName, True )