blob: 33e9656eba8cfe837f054a6c925ff371a98fbecc [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" )
You Wang583705d2018-10-26 16:46:21 -070040 main.cfgName = "TEST_CONFIG_ipv4=1_ipv6=1" if hasattr( main, "Mininet1" ) else main.params[ "DEPENDENCY" ][ "confName" ]
You Wangc02d8352018-04-17 16:42:10 -070041 lib.loadJson( main )
42 time.sleep( float( main.params[ "timers" ][ "loadNetcfgSleep" ] ) )
You Wang583705d2018-10-26 16:46:21 -070043 main.cfgName = "common" if hasattr( main, "Mininet1" ) else main.params[ "DEPENDENCY" ][ "confName" ]
You Wangc02d8352018-04-17 16:42:10 -070044 lib.loadMulticastConfig( main )
You Wang88b3cbe2018-05-10 15:21:39 -070045 lib.loadHost( main )
Pier6a0c4de2018-03-18 16:01:30 -070046
You Wangc02d8352018-04-17 16:42:10 -070047 if hasattr( main, "Mininet1" ):
48 # Run the test with Mininet
49 mininet_args = " --dhcp=1 --routers=1 --ipv6=1 --ipv4=1"
50 lib.startMininet( main, main.params[ "DEPENDENCY" ][ "topology" ], args=mininet_args )
51 time.sleep( float( main.params[ "timers" ][ "startMininetSleep" ] ) )
52 else:
53 # Run the test with physical devices
You Wang4cc61912018-08-28 10:10:58 -070054 lib.connectToPhysicalNetwork( main )
Pier6a0c4de2018-03-18 16:01:30 -070055
You Wangc02d8352018-04-17 16:42:10 -070056 # Create scapy components
57 lib.startScapyHosts( main )
You Wang88b3cbe2018-05-10 15:21:39 -070058 # Verify host IP assignment
59 lib.verifyOnosHostIp( main )
60 lib.verifyNetworkHostIp( main )
You Wangece951a2018-04-16 13:34:43 -070061
You Wangc02d8352018-04-17 16:42:10 -070062def verifyMcastRoutes( main ):
63 """
64 Install multicast routes and check traffic
65 """
66 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
67 for routeName in main.mcastRoutes.keys():
You Wangc02d8352018-04-17 16:42:10 -070068 installMcastRoute( main, routeName )
69 lib.verifyMulticastTraffic( main, routeName, True )
You Wange24d6272018-03-27 21:18:50 -070070
You Wangc02d8352018-04-17 16:42:10 -070071def installMcastRoute( main, routeName ):
72 """
73 Install a multicast route
74 """
You Wang85747762018-05-11 15:51:50 -070075 main.step( "Install {} multicast route".format( routeName ) )
You Wangc02d8352018-04-17 16:42:10 -070076 routeData = main.multicastConfig[ routeName ]
77 src = main.mcastRoutes[ routeName ][ "src" ]
78 dst = main.mcastRoutes[ routeName ][ "dst" ]
79 main.Cluster.active( 0 ).CLI.mcastHostJoin( routeData[ "src" ][ src[ 0 ] ][ "ip" ], routeData[ "group" ],
You Wang547893e2018-05-08 13:34:59 -070080 [ routeData[ "src" ][ i ][ "id" ] for i in src ],
You Wangc02d8352018-04-17 16:42:10 -070081 [ routeData[ "dst" ][ i ][ "id" ] for i in dst ] )
82 time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) )
You Wange24d6272018-03-27 21:18:50 -070083
You Wangc02d8352018-04-17 16:42:10 -070084def verifyMcastRouteRemoval( main, routeName ):
85 """
86 Verify removal of a multicast route
87 """
88 routeData = main.multicastConfig[ routeName ]
You Wang85747762018-05-11 15:51:50 -070089 main.step( "Remove {} route".format( routeName ) )
You Wang547893e2018-05-08 13:34:59 -070090 main.Cluster.active( 0 ).CLI.mcastSinkDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ] )
You Wangc02d8352018-04-17 16:42:10 -070091 # TODO: verify the deletion
You Wange24d6272018-03-27 21:18:50 -070092
You Wangc02d8352018-04-17 16:42:10 -070093def verifyMcastSinkRemoval( main, routeName, sinkIndex, expect ):
94 """
95 Verify removal of a multicast sink
96 """
97 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
98 routeData = main.multicastConfig[ routeName ]
99 sinkId = routeData[ "dst" ][ sinkIndex ][ "id" ]
You Wang85747762018-05-11 15:51:50 -0700100 main.step( "Remove sink {} of route {}".format( sinkId, routeName ) )
You Wang547893e2018-05-08 13:34:59 -0700101 main.Cluster.active( 0 ).CLI.mcastSinkDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ], sinkId )
You Wangc02d8352018-04-17 16:42:10 -0700102 time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) )
103 lib.verifyMulticastTraffic( main, routeName, expect )
You Wange24d6272018-03-27 21:18:50 -0700104
You Wangc02d8352018-04-17 16:42:10 -0700105def verifyMcastSourceRemoval( main, routeName, sourceIndex, expect ):
106 """
107 Verify removal of a multicast source
108 """
109 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
110 routeData = main.multicastConfig[ routeName ]
You Wang547893e2018-05-08 13:34:59 -0700111 sourceId = [ routeData[ "src" ][ sourceIndex ][ "id" ] ]
You Wang85747762018-05-11 15:51:50 -0700112 main.step( "Remove source {} of route {}".format( sourceId, routeName ) )
You Wang547893e2018-05-08 13:34:59 -0700113 main.Cluster.active( 0 ).CLI.mcastSourceDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ], sourceId )
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 verifyMcastRemoval( main, removeDHT1=True ):
118 """
119 Verify removal of IPv6 route, IPv4 sinks and IPv4 source
120 """
121 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
122 verifyMcastRouteRemoval( main, "ipv6" )
123 if removeDHT1:
124 verifyMcastSinkRemoval( main, "ipv4", 0, [ False, True, True ] )
125 verifyMcastSinkRemoval( main, "ipv4", 1, [ False, False, True ] )
126 else:
127 verifyMcastSinkRemoval( main, "ipv4", 2, [ True, True, False ] )
128 verifyMcastSinkRemoval( main, "ipv4", 1, [ True, False, False ] )
129 verifyMcastSourceRemoval( main, "ipv4", 0, False )
You Wange24d6272018-03-27 21:18:50 -0700130
You Wang547893e2018-05-08 13:34:59 -0700131def verifyLinkDown( main, link, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ):
You Wangc02d8352018-04-17 16:42:10 -0700132 """
133 Kill a batch of links and verify traffic
134 Restore the links and verify traffic
135 """
136 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
137 link = link if ( isinstance( link, list ) and isinstance( link[ 0 ], list ) ) else [ link ]
138 # Kill the link(s)
139 lib.killLinkBatch( main, link, int( main.params[ "TOPO" ][ "linkNum" ] ) - affectedLinkNum, int( main.params[ "TOPO" ][ "switchNum" ] ) )
140 for routeName in expectList.keys():
141 lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] )
142 # Restore the link(s)
143 lib.restoreLinkBatch( main, link, int( main.params[ "TOPO" ][ "linkNum" ] ), int( main.params[ "TOPO" ][ "switchNum" ] ) )
You Wang547893e2018-05-08 13:34:59 -0700144 if hostsToDiscover:
145 main.Network.discoverHosts( hostList=hostsToDiscover )
You Wang85747762018-05-11 15:51:50 -0700146 if hostLocations:
You Wang5c4a6382018-05-16 15:36:41 -0700147 lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) )
You Wangc02d8352018-04-17 16:42:10 -0700148 for routeName in expectList.keys():
149 lib.verifyMulticastTraffic( main, routeName, True )
You Wange24d6272018-03-27 21:18:50 -0700150
You Wang547893e2018-05-08 13:34:59 -0700151def verifyPortDown( main, dpid, port, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ):
152 """
153 Disable a port and verify traffic
154 Reenable the port and verify traffic
155 """
156 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
You Wang5c4a6382018-05-16 15:36:41 -0700157 # Disable the port(s)
You Wang547893e2018-05-08 13:34:59 -0700158 main.step( "Disable port {}/{}".format( dpid, port ) )
159 main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="disable" )
160 time.sleep( 10 )
161 for routeName in expectList.keys():
162 lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] )
You Wang5c4a6382018-05-16 15:36:41 -0700163 # Reenable the port(s)
164 main.step( "Enable port {}/{}".format( dpid, port ) )
You Wang547893e2018-05-08 13:34:59 -0700165 main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="enable" )
166 if hostsToDiscover:
167 main.Network.discoverHosts( hostList=hostsToDiscover )
You Wang85747762018-05-11 15:51:50 -0700168 if hostLocations:
You Wang5c4a6382018-05-16 15:36:41 -0700169 lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) )
You Wang547893e2018-05-08 13:34:59 -0700170 for routeName in expectList.keys():
171 lib.verifyMulticastTraffic( main, routeName, True )
172
173def verifySwitchDown( main, switchName, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ):
You Wangc02d8352018-04-17 16:42:10 -0700174 """
175 Kill a batch of switches and verify traffic
176 Recover the swithces and verify traffic
177 """
178 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
179 switchName = switchName if isinstance( switchName, list ) else [ switchName ]
180 # Kill the switch(es)
181 lib.killSwitch( main, switchName, int( main.params[ "TOPO" ][ "switchNum" ] ) - len( switchName ), int( main.params[ "TOPO" ][ "linkNum" ] ) - affectedLinkNum )
182 for routeName in expectList.keys():
183 lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] )
184 # Recover the switch(es)
You Wang547893e2018-05-08 13:34:59 -0700185 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 -0700186 if hostLocations:
You Wang5c4a6382018-05-16 15:36:41 -0700187 lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) )
You Wangc02d8352018-04-17 16:42:10 -0700188 for routeName in expectList.keys():
189 lib.verifyMulticastTraffic( main, routeName, True )
You Wange24d6272018-03-27 21:18:50 -0700190
You Wangc02d8352018-04-17 16:42:10 -0700191def verifyOnosDown( main, expectList={ "ipv4": True, "ipv6": True } ):
192 """
193 Kill and recover ONOS instances Sequencially and check traffic
194 """
195 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
196 import json
197 numCtrls = len( main.Cluster.runningNodes )
198 links = len( json.loads( main.Cluster.next().links() ) )
199 switches = len( json.loads( main.Cluster.next().devices() ) )
200 for ctrl in xrange( numCtrls ):
201 # Kill node
202 lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) )
203 main.Cluster.active(0).CLI.balanceMasters()
204 time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
205 for routeName in expectList.keys():
206 lib.verifyMulticastTraffic( main, routeName, True )
207 # Recover node
208 lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls )
209 main.Cluster.active(0).CLI.balanceMasters()
210 time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
211 for routeName in expectList.keys():
212 lib.verifyMulticastTraffic( main, routeName, True )