blob: 39897d51a358940769d910a10bc0bff9e746dd3d [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
You Wang68568b12019-03-04 11:49:57 -080026 import tests.USECASE.SegmentRouting.dependencies.cfgtranslator as translator
27
You Wangc02d8352018-04-17 16:42:10 -070028 skipPackage = False
29 init = False
30 if not hasattr( main, "apps" ):
31 init = True
32 lib.initTest( main )
33 # Skip onos packaging if the cluster size stays the same
34 if not init and onosNodes == main.Cluster.numCtrls:
35 skipPackage = True
Pier6a0c4de2018-03-18 16:01:30 -070036
You Wangc02d8352018-04-17 16:42:10 -070037 main.resultFileName = "CASE%03d" % test_idx
38 main.Cluster.setRunningNode( onosNodes )
39 lib.installOnos( main, skipPackage=skipPackage, cliSleep=5 )
40 # Load configuration files
41 main.step( "Load configurations" )
You Wang583705d2018-10-26 16:46:21 -070042 main.cfgName = "TEST_CONFIG_ipv4=1_ipv6=1" if hasattr( main, "Mininet1" ) else main.params[ "DEPENDENCY" ][ "confName" ]
You Wang68568b12019-03-04 11:49:57 -080043 if main.useBmv2:
44 # Translate configuration file from OVS-OFDPA to BMv2 driver
45 translator.ofdpaToBmv2( main )
46 else:
47 translator.bmv2ToOfdpa( main )
You Wangc02d8352018-04-17 16:42:10 -070048 lib.loadJson( main )
49 time.sleep( float( main.params[ "timers" ][ "loadNetcfgSleep" ] ) )
You Wang583705d2018-10-26 16:46:21 -070050 main.cfgName = "common" if hasattr( main, "Mininet1" ) else main.params[ "DEPENDENCY" ][ "confName" ]
You Wangc02d8352018-04-17 16:42:10 -070051 lib.loadMulticastConfig( main )
You Wang88b3cbe2018-05-10 15:21:39 -070052 lib.loadHost( main )
Pier6a0c4de2018-03-18 16:01:30 -070053
You Wangc02d8352018-04-17 16:42:10 -070054 if hasattr( main, "Mininet1" ):
55 # Run the test with Mininet
56 mininet_args = " --dhcp=1 --routers=1 --ipv6=1 --ipv4=1"
You Wang68568b12019-03-04 11:49:57 -080057 if main.useBmv2:
58 mininet_args += ' --switch bmv2'
59 main.log.info( "Using BMv2 switch" )
You Wangc02d8352018-04-17 16:42:10 -070060 lib.startMininet( main, main.params[ "DEPENDENCY" ][ "topology" ], args=mininet_args )
61 time.sleep( float( main.params[ "timers" ][ "startMininetSleep" ] ) )
62 else:
63 # Run the test with physical devices
You Wang4cc61912018-08-28 10:10:58 -070064 lib.connectToPhysicalNetwork( main )
Pier6a0c4de2018-03-18 16:01:30 -070065
You Wangc02d8352018-04-17 16:42:10 -070066 # Create scapy components
67 lib.startScapyHosts( main )
You Wang88b3cbe2018-05-10 15:21:39 -070068 # Verify host IP assignment
69 lib.verifyOnosHostIp( main )
70 lib.verifyNetworkHostIp( main )
You Wangece951a2018-04-16 13:34:43 -070071
You Wangc02d8352018-04-17 16:42:10 -070072def verifyMcastRoutes( main ):
73 """
74 Install multicast routes and check traffic
75 """
76 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
77 for routeName in main.mcastRoutes.keys():
You Wangc02d8352018-04-17 16:42:10 -070078 installMcastRoute( main, routeName )
79 lib.verifyMulticastTraffic( main, routeName, True )
You Wange24d6272018-03-27 21:18:50 -070080
You Wangc02d8352018-04-17 16:42:10 -070081def installMcastRoute( main, routeName ):
82 """
83 Install a multicast route
84 """
You Wang85747762018-05-11 15:51:50 -070085 main.step( "Install {} multicast route".format( routeName ) )
You Wangc02d8352018-04-17 16:42:10 -070086 routeData = main.multicastConfig[ routeName ]
87 src = main.mcastRoutes[ routeName ][ "src" ]
88 dst = main.mcastRoutes[ routeName ][ "dst" ]
89 main.Cluster.active( 0 ).CLI.mcastHostJoin( routeData[ "src" ][ src[ 0 ] ][ "ip" ], routeData[ "group" ],
You Wang547893e2018-05-08 13:34:59 -070090 [ routeData[ "src" ][ i ][ "id" ] for i in src ],
You Wangc02d8352018-04-17 16:42:10 -070091 [ routeData[ "dst" ][ i ][ "id" ] for i in dst ] )
92 time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) )
You Wange24d6272018-03-27 21:18:50 -070093
You Wangc02d8352018-04-17 16:42:10 -070094def verifyMcastRouteRemoval( main, routeName ):
95 """
96 Verify removal of a multicast route
97 """
98 routeData = main.multicastConfig[ routeName ]
You Wang85747762018-05-11 15:51:50 -070099 main.step( "Remove {} route".format( routeName ) )
You Wang547893e2018-05-08 13:34:59 -0700100 main.Cluster.active( 0 ).CLI.mcastSinkDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ] )
You Wangc02d8352018-04-17 16:42:10 -0700101 # TODO: verify the deletion
You Wange24d6272018-03-27 21:18:50 -0700102
You Wangc02d8352018-04-17 16:42:10 -0700103def verifyMcastSinkRemoval( main, routeName, sinkIndex, expect ):
104 """
105 Verify removal of a multicast sink
106 """
107 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
108 routeData = main.multicastConfig[ routeName ]
109 sinkId = routeData[ "dst" ][ sinkIndex ][ "id" ]
You Wang85747762018-05-11 15:51:50 -0700110 main.step( "Remove sink {} of route {}".format( sinkId, routeName ) )
You Wang547893e2018-05-08 13:34:59 -0700111 main.Cluster.active( 0 ).CLI.mcastSinkDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ], sinkId )
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 verifyMcastSourceRemoval( main, routeName, sourceIndex, expect ):
116 """
117 Verify removal of a multicast source
118 """
119 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
120 routeData = main.multicastConfig[ routeName ]
You Wang547893e2018-05-08 13:34:59 -0700121 sourceId = [ routeData[ "src" ][ sourceIndex ][ "id" ] ]
You Wang85747762018-05-11 15:51:50 -0700122 main.step( "Remove source {} of route {}".format( sourceId, routeName ) )
You Wang547893e2018-05-08 13:34:59 -0700123 main.Cluster.active( 0 ).CLI.mcastSourceDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ], sourceId )
You Wangc02d8352018-04-17 16:42:10 -0700124 time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) )
125 lib.verifyMulticastTraffic( main, routeName, expect )
You Wange24d6272018-03-27 21:18:50 -0700126
You Wangc02d8352018-04-17 16:42:10 -0700127def verifyMcastRemoval( main, removeDHT1=True ):
128 """
129 Verify removal of IPv6 route, IPv4 sinks and IPv4 source
130 """
131 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
132 verifyMcastRouteRemoval( main, "ipv6" )
133 if removeDHT1:
134 verifyMcastSinkRemoval( main, "ipv4", 0, [ False, True, True ] )
135 verifyMcastSinkRemoval( main, "ipv4", 1, [ False, False, True ] )
136 else:
137 verifyMcastSinkRemoval( main, "ipv4", 2, [ True, True, False ] )
138 verifyMcastSinkRemoval( main, "ipv4", 1, [ True, False, False ] )
139 verifyMcastSourceRemoval( main, "ipv4", 0, False )
You Wange24d6272018-03-27 21:18:50 -0700140
You Wang547893e2018-05-08 13:34:59 -0700141def verifyLinkDown( main, link, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ):
You Wangc02d8352018-04-17 16:42:10 -0700142 """
143 Kill a batch of links and verify traffic
144 Restore the links and verify traffic
145 """
146 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
147 link = link if ( isinstance( link, list ) and isinstance( link[ 0 ], list ) ) else [ link ]
148 # Kill the link(s)
149 lib.killLinkBatch( main, link, int( main.params[ "TOPO" ][ "linkNum" ] ) - affectedLinkNum, int( main.params[ "TOPO" ][ "switchNum" ] ) )
150 for routeName in expectList.keys():
151 lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] )
152 # Restore the link(s)
153 lib.restoreLinkBatch( main, link, int( main.params[ "TOPO" ][ "linkNum" ] ), int( main.params[ "TOPO" ][ "switchNum" ] ) )
You Wang547893e2018-05-08 13:34:59 -0700154 if hostsToDiscover:
155 main.Network.discoverHosts( hostList=hostsToDiscover )
You Wang85747762018-05-11 15:51:50 -0700156 if hostLocations:
You Wang5c4a6382018-05-16 15:36:41 -0700157 lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) )
You Wangc02d8352018-04-17 16:42:10 -0700158 for routeName in expectList.keys():
159 lib.verifyMulticastTraffic( main, routeName, True )
You Wange24d6272018-03-27 21:18:50 -0700160
You Wang547893e2018-05-08 13:34:59 -0700161def verifyPortDown( main, dpid, port, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ):
162 """
163 Disable a port and verify traffic
164 Reenable the port and verify traffic
165 """
166 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
You Wang5c4a6382018-05-16 15:36:41 -0700167 # Disable the port(s)
You Wang547893e2018-05-08 13:34:59 -0700168 main.step( "Disable port {}/{}".format( dpid, port ) )
169 main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="disable" )
170 time.sleep( 10 )
171 for routeName in expectList.keys():
172 lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] )
You Wang5c4a6382018-05-16 15:36:41 -0700173 # Reenable the port(s)
174 main.step( "Enable port {}/{}".format( dpid, port ) )
You Wang547893e2018-05-08 13:34:59 -0700175 main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="enable" )
176 if hostsToDiscover:
177 main.Network.discoverHosts( hostList=hostsToDiscover )
You Wang85747762018-05-11 15:51:50 -0700178 if hostLocations:
You Wang5c4a6382018-05-16 15:36:41 -0700179 lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) )
You Wang547893e2018-05-08 13:34:59 -0700180 for routeName in expectList.keys():
181 lib.verifyMulticastTraffic( main, routeName, True )
182
183def verifySwitchDown( main, switchName, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ):
You Wangc02d8352018-04-17 16:42:10 -0700184 """
185 Kill a batch of switches and verify traffic
186 Recover the swithces and verify traffic
187 """
188 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
189 switchName = switchName if isinstance( switchName, list ) else [ switchName ]
190 # Kill the switch(es)
191 lib.killSwitch( main, switchName, int( main.params[ "TOPO" ][ "switchNum" ] ) - len( switchName ), int( main.params[ "TOPO" ][ "linkNum" ] ) - affectedLinkNum )
192 for routeName in expectList.keys():
193 lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] )
194 # Recover the switch(es)
You Wang547893e2018-05-08 13:34:59 -0700195 lib.recoverSwitch( main, switchName, int( main.params[ "TOPO" ][ "switchNum" ] ), int( main.params[ "TOPO" ][ "linkNum" ] ), True if hostsToDiscover else False, hostsToDiscover )
You Wang85747762018-05-11 15:51:50 -0700196 if hostLocations:
You Wang5c4a6382018-05-16 15:36:41 -0700197 lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) )
You Wangc02d8352018-04-17 16:42:10 -0700198 for routeName in expectList.keys():
199 lib.verifyMulticastTraffic( main, routeName, True )
You Wange24d6272018-03-27 21:18:50 -0700200
You Wangc02d8352018-04-17 16:42:10 -0700201def verifyOnosDown( main, expectList={ "ipv4": True, "ipv6": True } ):
202 """
203 Kill and recover ONOS instances Sequencially and check traffic
204 """
205 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
206 import json
207 numCtrls = len( main.Cluster.runningNodes )
208 links = len( json.loads( main.Cluster.next().links() ) )
209 switches = len( json.loads( main.Cluster.next().devices() ) )
210 for ctrl in xrange( numCtrls ):
211 # Kill node
212 lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) )
213 main.Cluster.active(0).CLI.balanceMasters()
214 time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
215 for routeName in expectList.keys():
216 lib.verifyMulticastTraffic( main, routeName, True )
217 # Recover node
218 lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls )
219 main.Cluster.active(0).CLI.balanceMasters()
220 time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
221 for routeName in expectList.keys():
222 lib.verifyMulticastTraffic( main, routeName, True )