blob: 18022218ad6535f9a6f039abb1291038ae72f9f0 [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
Jon Hall43060f62020-06-23 13:13:33 -070045 translator.bmv2ToOfdpa( main ) # Try to cleanup if switching between switch types
46 switchPrefix = main.params[ 'DEPENDENCY' ].get( 'switchPrefix', "bmv2" )
47 translator.ofdpaToBmv2( main, switchPrefix=switchPrefix )
You Wang68568b12019-03-04 11:49:57 -080048 else:
49 translator.bmv2ToOfdpa( main )
You Wangc02d8352018-04-17 16:42:10 -070050 lib.loadJson( main )
51 time.sleep( float( main.params[ "timers" ][ "loadNetcfgSleep" ] ) )
You Wang583705d2018-10-26 16:46:21 -070052 main.cfgName = "common" if hasattr( main, "Mininet1" ) else main.params[ "DEPENDENCY" ][ "confName" ]
You Wangc02d8352018-04-17 16:42:10 -070053 lib.loadMulticastConfig( main )
You Wang88b3cbe2018-05-10 15:21:39 -070054 lib.loadHost( main )
Pier6a0c4de2018-03-18 16:01:30 -070055
You Wangc02d8352018-04-17 16:42:10 -070056 if hasattr( main, "Mininet1" ):
57 # Run the test with Mininet
58 mininet_args = " --dhcp=1 --routers=1 --ipv6=1 --ipv4=1"
You Wang68568b12019-03-04 11:49:57 -080059 if main.useBmv2:
60 mininet_args += ' --switch bmv2'
61 main.log.info( "Using BMv2 switch" )
You Wangc02d8352018-04-17 16:42:10 -070062 lib.startMininet( main, main.params[ "DEPENDENCY" ][ "topology" ], args=mininet_args )
63 time.sleep( float( main.params[ "timers" ][ "startMininetSleep" ] ) )
64 else:
65 # Run the test with physical devices
You Wang4cc61912018-08-28 10:10:58 -070066 lib.connectToPhysicalNetwork( main )
Pier6a0c4de2018-03-18 16:01:30 -070067
You Wangc02d8352018-04-17 16:42:10 -070068 # Create scapy components
69 lib.startScapyHosts( main )
You Wang88b3cbe2018-05-10 15:21:39 -070070 # Verify host IP assignment
71 lib.verifyOnosHostIp( main )
72 lib.verifyNetworkHostIp( main )
You Wangece951a2018-04-16 13:34:43 -070073
You Wangc02d8352018-04-17 16:42:10 -070074def verifyMcastRoutes( main ):
75 """
76 Install multicast routes and check traffic
77 """
78 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
79 for routeName in main.mcastRoutes.keys():
You Wangc02d8352018-04-17 16:42:10 -070080 installMcastRoute( main, routeName )
81 lib.verifyMulticastTraffic( main, routeName, True )
You Wange24d6272018-03-27 21:18:50 -070082
You Wangc02d8352018-04-17 16:42:10 -070083def installMcastRoute( main, routeName ):
84 """
85 Install a multicast route
86 """
You Wang85747762018-05-11 15:51:50 -070087 main.step( "Install {} multicast route".format( routeName ) )
You Wangc02d8352018-04-17 16:42:10 -070088 routeData = main.multicastConfig[ routeName ]
89 src = main.mcastRoutes[ routeName ][ "src" ]
90 dst = main.mcastRoutes[ routeName ][ "dst" ]
91 main.Cluster.active( 0 ).CLI.mcastHostJoin( routeData[ "src" ][ src[ 0 ] ][ "ip" ], routeData[ "group" ],
You Wang547893e2018-05-08 13:34:59 -070092 [ routeData[ "src" ][ i ][ "id" ] for i in src ],
You Wangc02d8352018-04-17 16:42:10 -070093 [ routeData[ "dst" ][ i ][ "id" ] for i in dst ] )
94 time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) )
You Wange24d6272018-03-27 21:18:50 -070095
You Wangc02d8352018-04-17 16:42:10 -070096def verifyMcastRouteRemoval( main, routeName ):
97 """
98 Verify removal of a multicast route
99 """
100 routeData = main.multicastConfig[ routeName ]
You Wang85747762018-05-11 15:51:50 -0700101 main.step( "Remove {} route".format( routeName ) )
You Wang547893e2018-05-08 13:34:59 -0700102 main.Cluster.active( 0 ).CLI.mcastSinkDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ] )
You Wangc02d8352018-04-17 16:42:10 -0700103 # TODO: verify the deletion
You Wange24d6272018-03-27 21:18:50 -0700104
You Wangc02d8352018-04-17 16:42:10 -0700105def verifyMcastSinkRemoval( main, routeName, sinkIndex, expect ):
106 """
107 Verify removal of a multicast sink
108 """
109 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
110 routeData = main.multicastConfig[ routeName ]
111 sinkId = routeData[ "dst" ][ sinkIndex ][ "id" ]
You Wang85747762018-05-11 15:51:50 -0700112 main.step( "Remove sink {} of route {}".format( sinkId, routeName ) )
You Wang547893e2018-05-08 13:34:59 -0700113 main.Cluster.active( 0 ).CLI.mcastSinkDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ], sinkId )
You Wangc02d8352018-04-17 16:42:10 -0700114 time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) )
115 lib.verifyMulticastTraffic( main, routeName, expect )
You Wange24d6272018-03-27 21:18:50 -0700116
You Wangc02d8352018-04-17 16:42:10 -0700117def verifyMcastSourceRemoval( main, routeName, sourceIndex, expect ):
118 """
119 Verify removal of a multicast source
120 """
121 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
122 routeData = main.multicastConfig[ routeName ]
You Wang547893e2018-05-08 13:34:59 -0700123 sourceId = [ routeData[ "src" ][ sourceIndex ][ "id" ] ]
You Wang85747762018-05-11 15:51:50 -0700124 main.step( "Remove source {} of route {}".format( sourceId, routeName ) )
You Wang547893e2018-05-08 13:34:59 -0700125 main.Cluster.active( 0 ).CLI.mcastSourceDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ], sourceId )
You Wangc02d8352018-04-17 16:42:10 -0700126 time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) )
127 lib.verifyMulticastTraffic( main, routeName, expect )
You Wange24d6272018-03-27 21:18:50 -0700128
You Wangc02d8352018-04-17 16:42:10 -0700129def verifyMcastRemoval( main, removeDHT1=True ):
130 """
131 Verify removal of IPv6 route, IPv4 sinks and IPv4 source
132 """
133 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
134 verifyMcastRouteRemoval( main, "ipv6" )
135 if removeDHT1:
136 verifyMcastSinkRemoval( main, "ipv4", 0, [ False, True, True ] )
137 verifyMcastSinkRemoval( main, "ipv4", 1, [ False, False, True ] )
138 else:
139 verifyMcastSinkRemoval( main, "ipv4", 2, [ True, True, False ] )
140 verifyMcastSinkRemoval( main, "ipv4", 1, [ True, False, False ] )
141 verifyMcastSourceRemoval( main, "ipv4", 0, False )
You Wange24d6272018-03-27 21:18:50 -0700142
You Wang547893e2018-05-08 13:34:59 -0700143def verifyLinkDown( main, link, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ):
You Wangc02d8352018-04-17 16:42:10 -0700144 """
145 Kill a batch of links and verify traffic
146 Restore the links and verify traffic
147 """
148 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
149 link = link if ( isinstance( link, list ) and isinstance( link[ 0 ], list ) ) else [ link ]
150 # Kill the link(s)
151 lib.killLinkBatch( main, link, int( main.params[ "TOPO" ][ "linkNum" ] ) - affectedLinkNum, int( main.params[ "TOPO" ][ "switchNum" ] ) )
152 for routeName in expectList.keys():
153 lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] )
154 # Restore the link(s)
155 lib.restoreLinkBatch( main, link, int( main.params[ "TOPO" ][ "linkNum" ] ), int( main.params[ "TOPO" ][ "switchNum" ] ) )
You Wang547893e2018-05-08 13:34:59 -0700156 if hostsToDiscover:
157 main.Network.discoverHosts( hostList=hostsToDiscover )
You Wang85747762018-05-11 15:51:50 -0700158 if hostLocations:
You Wang5c4a6382018-05-16 15:36:41 -0700159 lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) )
You Wangc02d8352018-04-17 16:42:10 -0700160 for routeName in expectList.keys():
161 lib.verifyMulticastTraffic( main, routeName, True )
You Wange24d6272018-03-27 21:18:50 -0700162
You Wang547893e2018-05-08 13:34:59 -0700163def verifyPortDown( main, dpid, port, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ):
164 """
165 Disable a port and verify traffic
166 Reenable the port and verify traffic
167 """
168 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
You Wang5c4a6382018-05-16 15:36:41 -0700169 # Disable the port(s)
You Wang547893e2018-05-08 13:34:59 -0700170 main.step( "Disable port {}/{}".format( dpid, port ) )
171 main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="disable" )
172 time.sleep( 10 )
173 for routeName in expectList.keys():
174 lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] )
You Wang5c4a6382018-05-16 15:36:41 -0700175 # Reenable the port(s)
176 main.step( "Enable port {}/{}".format( dpid, port ) )
You Wang547893e2018-05-08 13:34:59 -0700177 main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="enable" )
178 if hostsToDiscover:
179 main.Network.discoverHosts( hostList=hostsToDiscover )
You Wang85747762018-05-11 15:51:50 -0700180 if hostLocations:
You Wang5c4a6382018-05-16 15:36:41 -0700181 lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) )
You Wang547893e2018-05-08 13:34:59 -0700182 for routeName in expectList.keys():
183 lib.verifyMulticastTraffic( main, routeName, True )
184
185def verifySwitchDown( main, switchName, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ):
You Wangc02d8352018-04-17 16:42:10 -0700186 """
187 Kill a batch of switches and verify traffic
188 Recover the swithces and verify traffic
189 """
190 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
191 switchName = switchName if isinstance( switchName, list ) else [ switchName ]
192 # Kill the switch(es)
193 lib.killSwitch( main, switchName, int( main.params[ "TOPO" ][ "switchNum" ] ) - len( switchName ), int( main.params[ "TOPO" ][ "linkNum" ] ) - affectedLinkNum )
194 for routeName in expectList.keys():
195 lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] )
196 # Recover the switch(es)
You Wang547893e2018-05-08 13:34:59 -0700197 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 -0700198 if hostLocations:
You Wang5c4a6382018-05-16 15:36:41 -0700199 lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) )
You Wangc02d8352018-04-17 16:42:10 -0700200 for routeName in expectList.keys():
201 lib.verifyMulticastTraffic( main, routeName, True )
You Wange24d6272018-03-27 21:18:50 -0700202
You Wangc02d8352018-04-17 16:42:10 -0700203def verifyOnosDown( main, expectList={ "ipv4": True, "ipv6": True } ):
204 """
205 Kill and recover ONOS instances Sequencially and check traffic
206 """
207 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
208 import json
209 numCtrls = len( main.Cluster.runningNodes )
210 links = len( json.loads( main.Cluster.next().links() ) )
211 switches = len( json.loads( main.Cluster.next().devices() ) )
212 for ctrl in xrange( numCtrls ):
213 # Kill node
214 lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) )
215 main.Cluster.active(0).CLI.balanceMasters()
216 time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
217 for routeName in expectList.keys():
218 lib.verifyMulticastTraffic( main, routeName, True )
219 # Recover node
220 lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls )
221 main.Cluster.active(0).CLI.balanceMasters()
222 time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
223 for routeName in expectList.keys():
224 lib.verifyMulticastTraffic( main, routeName, True )