blob: f598f9677545eaffe2aa20db84d6330262e1d0fd [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" ],
You Wang547893e2018-05-08 13:34:59 -070078 [ routeData[ "src" ][ i ][ "id" ] for i in src ],
You Wangc02d8352018-04-17 16:42:10 -070079 [ 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 ) )
You Wang547893e2018-05-08 13:34:59 -070088 main.Cluster.active( 0 ).CLI.mcastSinkDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ] )
You Wangc02d8352018-04-17 16:42:10 -070089 # 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 ) )
You Wang547893e2018-05-08 13:34:59 -070099 main.Cluster.active( 0 ).CLI.mcastSinkDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ], sinkId )
You Wangc02d8352018-04-17 16:42:10 -0700100 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 ]
You Wang547893e2018-05-08 13:34:59 -0700109 sourceId = [ routeData[ "src" ][ sourceIndex ][ "id" ] ]
110 main.step( "Verify removal of {} source {}".format( routeName, sourceId ) )
111 main.Cluster.active( 0 ).CLI.mcastSourceDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ], sourceId )
You Wangc02d8352018-04-17 16:42:10 -0700112 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 Wang547893e2018-05-08 13:34:59 -0700129def verifyLinkDown( main, link, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ):
You Wangc02d8352018-04-17 16:42:10 -0700130 """
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" ] ) )
You Wang547893e2018-05-08 13:34:59 -0700142 if hostsToDiscover:
143 main.Network.discoverHosts( hostList=hostsToDiscover )
144 for host, loc in hostLocations.items():
145 lib.verifyHostLocation( main, host, loc, retry=5 )
You Wangc02d8352018-04-17 16:42:10 -0700146 for routeName in expectList.keys():
147 lib.verifyMulticastTraffic( main, routeName, True )
You Wange24d6272018-03-27 21:18:50 -0700148
You Wang547893e2018-05-08 13:34:59 -0700149def verifyPortDown( main, dpid, port, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ):
150 """
151 Disable a port and verify traffic
152 Reenable the port and verify traffic
153 """
154 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
155 main.step( "Disable port {}/{}".format( dpid, port ) )
156 main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="disable" )
157 time.sleep( 10 )
158 for routeName in expectList.keys():
159 lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] )
160 # Restore the link(s)
161 main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="enable" )
162 if hostsToDiscover:
163 main.Network.discoverHosts( hostList=hostsToDiscover )
164 for host, loc in hostLocations.items():
165 lib.verifyHostLocation( main, host, loc, retry=5 )
166 for routeName in expectList.keys():
167 lib.verifyMulticastTraffic( main, routeName, True )
168
169def verifySwitchDown( main, switchName, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ):
You Wangc02d8352018-04-17 16:42:10 -0700170 """
171 Kill a batch of switches and verify traffic
172 Recover the swithces and verify traffic
173 """
174 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
175 switchName = switchName if isinstance( switchName, list ) else [ switchName ]
176 # Kill the switch(es)
177 lib.killSwitch( main, switchName, int( main.params[ "TOPO" ][ "switchNum" ] ) - len( switchName ), int( main.params[ "TOPO" ][ "linkNum" ] ) - affectedLinkNum )
178 for routeName in expectList.keys():
179 lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] )
180 # Recover the switch(es)
You Wang547893e2018-05-08 13:34:59 -0700181 lib.recoverSwitch( main, switchName, int( main.params[ "TOPO" ][ "switchNum" ] ), int( main.params[ "TOPO" ][ "linkNum" ] ), True if hostsToDiscover else False, hostsToDiscover )
182 for host, loc in hostLocations.items():
183 lib.verifyHostLocation( host, loc, retry=5 )
You Wangc02d8352018-04-17 16:42:10 -0700184 for routeName in expectList.keys():
185 lib.verifyMulticastTraffic( main, routeName, True )
You Wange24d6272018-03-27 21:18:50 -0700186
You Wangc02d8352018-04-17 16:42:10 -0700187def verifyOnosDown( main, expectList={ "ipv4": True, "ipv6": True } ):
188 """
189 Kill and recover ONOS instances Sequencially and check traffic
190 """
191 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
192 import json
193 numCtrls = len( main.Cluster.runningNodes )
194 links = len( json.loads( main.Cluster.next().links() ) )
195 switches = len( json.loads( main.Cluster.next().devices() ) )
196 for ctrl in xrange( numCtrls ):
197 # Kill node
198 lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) )
199 main.Cluster.active(0).CLI.balanceMasters()
200 time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
201 for routeName in expectList.keys():
202 lib.verifyMulticastTraffic( main, routeName, True )
203 # Recover node
204 lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls )
205 main.Cluster.active(0).CLI.balanceMasters()
206 time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
207 for routeName in expectList.keys():
208 lib.verifyMulticastTraffic( main, routeName, True )