blob: 27b6dd09ef8415ad13c8ce5ac924a0d5ce28a5e1 [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" )
Andreas Pantelopoulos1e0665a2018-06-05 13:34:59 -070040 main.cfgName = "TEST_CONFIG_ipv4=1_ipv6=1"
You Wangc02d8352018-04-17 16:42:10 -070041 lib.loadJson( main )
42 time.sleep( float( main.params[ "timers" ][ "loadNetcfgSleep" ] ) )
43 main.cfgName = "common"
44 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
54 lib.connectToPhysicalNetwork( main, self.switchNames )
55 # Check if the devices are up
56 lib.checkDevices( main, switches=len( self.switchNames ) )
Pier6a0c4de2018-03-18 16:01:30 -070057
You Wangc02d8352018-04-17 16:42:10 -070058 # Create scapy components
59 lib.startScapyHosts( main )
You Wang88b3cbe2018-05-10 15:21:39 -070060 # Verify host IP assignment
61 lib.verifyOnosHostIp( main )
62 lib.verifyNetworkHostIp( main )
You Wangece951a2018-04-16 13:34:43 -070063
You Wangc02d8352018-04-17 16:42:10 -070064def verifyMcastRoutes( main ):
65 """
66 Install multicast routes and check traffic
67 """
68 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
69 for routeName in main.mcastRoutes.keys():
You Wangc02d8352018-04-17 16:42:10 -070070 installMcastRoute( main, routeName )
71 lib.verifyMulticastTraffic( main, routeName, True )
You Wange24d6272018-03-27 21:18:50 -070072
You Wangc02d8352018-04-17 16:42:10 -070073def installMcastRoute( main, routeName ):
74 """
75 Install a multicast route
76 """
You Wang85747762018-05-11 15:51:50 -070077 main.step( "Install {} multicast route".format( routeName ) )
You Wangc02d8352018-04-17 16:42:10 -070078 routeData = main.multicastConfig[ routeName ]
79 src = main.mcastRoutes[ routeName ][ "src" ]
80 dst = main.mcastRoutes[ routeName ][ "dst" ]
81 main.Cluster.active( 0 ).CLI.mcastHostJoin( routeData[ "src" ][ src[ 0 ] ][ "ip" ], routeData[ "group" ],
You Wang547893e2018-05-08 13:34:59 -070082 [ routeData[ "src" ][ i ][ "id" ] for i in src ],
You Wangc02d8352018-04-17 16:42:10 -070083 [ routeData[ "dst" ][ i ][ "id" ] for i in dst ] )
84 time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) )
You Wange24d6272018-03-27 21:18:50 -070085
You Wangc02d8352018-04-17 16:42:10 -070086def verifyMcastRouteRemoval( main, routeName ):
87 """
88 Verify removal of a multicast route
89 """
90 routeData = main.multicastConfig[ routeName ]
You Wang85747762018-05-11 15:51:50 -070091 main.step( "Remove {} route".format( routeName ) )
You Wang547893e2018-05-08 13:34:59 -070092 main.Cluster.active( 0 ).CLI.mcastSinkDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ] )
You Wangc02d8352018-04-17 16:42:10 -070093 # TODO: verify the deletion
You Wange24d6272018-03-27 21:18:50 -070094
You Wangc02d8352018-04-17 16:42:10 -070095def verifyMcastSinkRemoval( main, routeName, sinkIndex, expect ):
96 """
97 Verify removal of a multicast sink
98 """
99 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
100 routeData = main.multicastConfig[ routeName ]
101 sinkId = routeData[ "dst" ][ sinkIndex ][ "id" ]
You Wang85747762018-05-11 15:51:50 -0700102 main.step( "Remove sink {} of route {}".format( sinkId, routeName ) )
You Wang547893e2018-05-08 13:34:59 -0700103 main.Cluster.active( 0 ).CLI.mcastSinkDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ], sinkId )
You Wangc02d8352018-04-17 16:42:10 -0700104 time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) )
105 lib.verifyMulticastTraffic( main, routeName, expect )
You Wange24d6272018-03-27 21:18:50 -0700106
You Wangc02d8352018-04-17 16:42:10 -0700107def verifyMcastSourceRemoval( main, routeName, sourceIndex, expect ):
108 """
109 Verify removal of a multicast source
110 """
111 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
112 routeData = main.multicastConfig[ routeName ]
You Wang547893e2018-05-08 13:34:59 -0700113 sourceId = [ routeData[ "src" ][ sourceIndex ][ "id" ] ]
You Wang85747762018-05-11 15:51:50 -0700114 main.step( "Remove source {} of route {}".format( sourceId, routeName ) )
You Wang547893e2018-05-08 13:34:59 -0700115 main.Cluster.active( 0 ).CLI.mcastSourceDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ], sourceId )
You Wangc02d8352018-04-17 16:42:10 -0700116 time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) )
117 lib.verifyMulticastTraffic( main, routeName, expect )
You Wange24d6272018-03-27 21:18:50 -0700118
You Wangc02d8352018-04-17 16:42:10 -0700119def verifyMcastRemoval( main, removeDHT1=True ):
120 """
121 Verify removal of IPv6 route, IPv4 sinks and IPv4 source
122 """
123 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
124 verifyMcastRouteRemoval( main, "ipv6" )
125 if removeDHT1:
126 verifyMcastSinkRemoval( main, "ipv4", 0, [ False, True, True ] )
127 verifyMcastSinkRemoval( main, "ipv4", 1, [ False, False, True ] )
128 else:
129 verifyMcastSinkRemoval( main, "ipv4", 2, [ True, True, False ] )
130 verifyMcastSinkRemoval( main, "ipv4", 1, [ True, False, False ] )
131 verifyMcastSourceRemoval( main, "ipv4", 0, False )
You Wange24d6272018-03-27 21:18:50 -0700132
You Wang547893e2018-05-08 13:34:59 -0700133def verifyLinkDown( main, link, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ):
You Wangc02d8352018-04-17 16:42:10 -0700134 """
135 Kill a batch of links and verify traffic
136 Restore the links and verify traffic
137 """
138 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
139 link = link if ( isinstance( link, list ) and isinstance( link[ 0 ], list ) ) else [ link ]
140 # Kill the link(s)
141 lib.killLinkBatch( main, link, int( main.params[ "TOPO" ][ "linkNum" ] ) - affectedLinkNum, int( main.params[ "TOPO" ][ "switchNum" ] ) )
142 for routeName in expectList.keys():
143 lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] )
144 # Restore the link(s)
145 lib.restoreLinkBatch( main, link, int( main.params[ "TOPO" ][ "linkNum" ] ), int( main.params[ "TOPO" ][ "switchNum" ] ) )
You Wang547893e2018-05-08 13:34:59 -0700146 if hostsToDiscover:
147 main.Network.discoverHosts( hostList=hostsToDiscover )
You Wang85747762018-05-11 15:51:50 -0700148 if hostLocations:
You Wang5c4a6382018-05-16 15:36:41 -0700149 lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) )
You Wangc02d8352018-04-17 16:42:10 -0700150 for routeName in expectList.keys():
151 lib.verifyMulticastTraffic( main, routeName, True )
You Wange24d6272018-03-27 21:18:50 -0700152
You Wang547893e2018-05-08 13:34:59 -0700153def verifyPortDown( main, dpid, port, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ):
154 """
155 Disable a port and verify traffic
156 Reenable the port and verify traffic
157 """
158 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
You Wang5c4a6382018-05-16 15:36:41 -0700159 # Disable the port(s)
You Wang547893e2018-05-08 13:34:59 -0700160 main.step( "Disable port {}/{}".format( dpid, port ) )
161 main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="disable" )
162 time.sleep( 10 )
163 for routeName in expectList.keys():
164 lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] )
You Wang5c4a6382018-05-16 15:36:41 -0700165 # Reenable the port(s)
166 main.step( "Enable port {}/{}".format( dpid, port ) )
You Wang547893e2018-05-08 13:34:59 -0700167 main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="enable" )
168 if hostsToDiscover:
169 main.Network.discoverHosts( hostList=hostsToDiscover )
You Wang85747762018-05-11 15:51:50 -0700170 if hostLocations:
You Wang5c4a6382018-05-16 15:36:41 -0700171 lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) )
You Wang547893e2018-05-08 13:34:59 -0700172 for routeName in expectList.keys():
173 lib.verifyMulticastTraffic( main, routeName, True )
174
175def verifySwitchDown( main, switchName, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ):
You Wangc02d8352018-04-17 16:42:10 -0700176 """
177 Kill a batch of switches and verify traffic
178 Recover the swithces and verify traffic
179 """
180 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
181 switchName = switchName if isinstance( switchName, list ) else [ switchName ]
182 # Kill the switch(es)
183 lib.killSwitch( main, switchName, int( main.params[ "TOPO" ][ "switchNum" ] ) - len( switchName ), int( main.params[ "TOPO" ][ "linkNum" ] ) - affectedLinkNum )
184 for routeName in expectList.keys():
185 lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] )
186 # Recover the switch(es)
You Wang547893e2018-05-08 13:34:59 -0700187 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 -0700188 if hostLocations:
You Wang5c4a6382018-05-16 15:36:41 -0700189 lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) )
You Wangc02d8352018-04-17 16:42:10 -0700190 for routeName in expectList.keys():
191 lib.verifyMulticastTraffic( main, routeName, True )
You Wange24d6272018-03-27 21:18:50 -0700192
You Wangc02d8352018-04-17 16:42:10 -0700193def verifyOnosDown( main, expectList={ "ipv4": True, "ipv6": True } ):
194 """
195 Kill and recover ONOS instances Sequencially and check traffic
196 """
197 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
198 import json
199 numCtrls = len( main.Cluster.runningNodes )
200 links = len( json.loads( main.Cluster.next().links() ) )
201 switches = len( json.loads( main.Cluster.next().devices() ) )
202 for ctrl in xrange( numCtrls ):
203 # Kill node
204 lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) )
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 )
209 # Recover node
210 lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls )
211 main.Cluster.active(0).CLI.balanceMasters()
212 time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
213 for routeName in expectList.keys():
214 lib.verifyMulticastTraffic( main, routeName, True )