Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2018 Open Networking Foundation ( ONF ) |
| 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or 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 Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 22 | import time |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 23 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 24 | def setupTest( main, test_idx, onosNodes ): |
| 25 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 26 | import tests.USECASE.SegmentRouting.dependencies.cfgtranslator as translator |
| 27 | |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 28 | try: |
| 29 | skipPackage = False |
| 30 | init = False |
| 31 | if not hasattr( main, "apps" ): |
| 32 | init = True |
| 33 | lib.initTest( main ) |
| 34 | # Skip onos packaging if the cluster size stays the same |
| 35 | if not init and onosNodes == main.Cluster.numCtrls: |
| 36 | skipPackage = True |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 37 | |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 38 | main.resultFileName = "CASE%03d" % test_idx |
| 39 | main.Cluster.setRunningNode( onosNodes ) |
| 40 | lib.installOnos( main, skipPackage=skipPackage, cliSleep=5 ) |
| 41 | # Load configuration files |
| 42 | main.step( "Load configurations" ) |
| 43 | main.cfgName = "TEST_CONFIG_ipv4=1_ipv6=1" if hasattr( main, "Mininet1" ) else main.params[ "DEPENDENCY" ][ "confName" ] |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 44 | if main.useBmv2: |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 45 | # Translate configuration file from OVS-OFDPA to BMv2 driver |
| 46 | translator.bmv2ToOfdpa( main ) # Try to cleanup if switching between switch types |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame^] | 47 | switchPrefix = main.params[ 'DEPENDENCY' ].get( 'switchPrefix', '' ) |
| 48 | if switchPrefix is None: |
| 49 | switchPrefix = '' |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 50 | translator.ofdpaToBmv2( main, switchPrefix=switchPrefix ) |
| 51 | else: |
| 52 | translator.bmv2ToOfdpa( main ) |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame^] | 53 | if not main.persistentSetup: |
| 54 | lib.loadJson( main ) |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 55 | time.sleep( float( main.params[ "timers" ][ "loadNetcfgSleep" ] ) ) |
| 56 | main.cfgName = "common" if hasattr( main, "Mininet1" ) else main.params[ "DEPENDENCY" ][ "confName" ] |
| 57 | lib.loadMulticastConfig( main ) |
| 58 | lib.loadHost( main ) |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 59 | |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 60 | if hasattr( main, "Mininet1" ): |
| 61 | # Run the test with Mininet |
| 62 | mininet_args = " --dhcp=1 --routers=1 --ipv6=1 --ipv4=1" |
| 63 | if main.useBmv2: |
Jon Hall | f69e316 | 2020-09-01 09:08:44 -0700 | [diff] [blame] | 64 | mininet_args += ' --switch %s' % main.switchType |
| 65 | main.log.info( "Using %s switch" % main.switchType ) |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 66 | lib.startMininet( main, main.params[ "DEPENDENCY" ][ "topology" ], args=mininet_args ) |
| 67 | time.sleep( float( main.params[ "timers" ][ "startMininetSleep" ] ) ) |
| 68 | else: |
| 69 | # Run the test with physical devices |
| 70 | lib.connectToPhysicalNetwork( main ) |
| 71 | |
| 72 | # Create scapy components |
| 73 | lib.startScapyHosts( main ) |
| 74 | # Verify host IP assignment |
| 75 | lib.verifyOnosHostIp( main ) |
| 76 | lib.verifyNetworkHostIp( main ) |
| 77 | except Exception as e: |
| 78 | main.log.exception( "Error in setupTest" ) |
| 79 | main.skipCase( result="FAIL", msg=e ) |
You Wang | ece951a | 2018-04-16 13:34:43 -0700 | [diff] [blame] | 80 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 81 | def verifyMcastRoutes( main ): |
| 82 | """ |
| 83 | Install multicast routes and check traffic |
| 84 | """ |
| 85 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 86 | for routeName in main.mcastRoutes.keys(): |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 87 | installMcastRoute( main, routeName ) |
| 88 | lib.verifyMulticastTraffic( main, routeName, True ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 89 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 90 | def installMcastRoute( main, routeName ): |
| 91 | """ |
| 92 | Install a multicast route |
| 93 | """ |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 94 | main.step( "Install {} multicast route".format( routeName ) ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 95 | routeData = main.multicastConfig[ routeName ] |
| 96 | src = main.mcastRoutes[ routeName ][ "src" ] |
| 97 | dst = main.mcastRoutes[ routeName ][ "dst" ] |
| 98 | main.Cluster.active( 0 ).CLI.mcastHostJoin( routeData[ "src" ][ src[ 0 ] ][ "ip" ], routeData[ "group" ], |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 99 | [ routeData[ "src" ][ i ][ "id" ] for i in src ], |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 100 | [ routeData[ "dst" ][ i ][ "id" ] for i in dst ] ) |
| 101 | time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 102 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 103 | def verifyMcastRouteRemoval( main, routeName ): |
| 104 | """ |
| 105 | Verify removal of a multicast route |
| 106 | """ |
| 107 | routeData = main.multicastConfig[ routeName ] |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 108 | main.step( "Remove {} route".format( routeName ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 109 | main.Cluster.active( 0 ).CLI.mcastSinkDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ] ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 110 | # TODO: verify the deletion |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 111 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 112 | def verifyMcastSinkRemoval( main, routeName, sinkIndex, expect ): |
| 113 | """ |
| 114 | Verify removal of a multicast sink |
| 115 | """ |
| 116 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 117 | routeData = main.multicastConfig[ routeName ] |
| 118 | sinkId = routeData[ "dst" ][ sinkIndex ][ "id" ] |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 119 | main.step( "Remove sink {} of route {}".format( sinkId, routeName ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 120 | main.Cluster.active( 0 ).CLI.mcastSinkDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ], sinkId ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 121 | time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) ) |
| 122 | lib.verifyMulticastTraffic( main, routeName, expect ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 123 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 124 | def verifyMcastSourceRemoval( main, routeName, sourceIndex, expect ): |
| 125 | """ |
| 126 | Verify removal of a multicast source |
| 127 | """ |
| 128 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 129 | routeData = main.multicastConfig[ routeName ] |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 130 | sourceId = [ routeData[ "src" ][ sourceIndex ][ "id" ] ] |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 131 | main.step( "Remove source {} of route {}".format( sourceId, routeName ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 132 | main.Cluster.active( 0 ).CLI.mcastSourceDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ], sourceId ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 133 | time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) ) |
| 134 | lib.verifyMulticastTraffic( main, routeName, expect ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 135 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 136 | def verifyMcastRemoval( main, removeDHT1=True ): |
| 137 | """ |
| 138 | Verify removal of IPv6 route, IPv4 sinks and IPv4 source |
| 139 | """ |
| 140 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 141 | verifyMcastRouteRemoval( main, "ipv6" ) |
| 142 | if removeDHT1: |
| 143 | verifyMcastSinkRemoval( main, "ipv4", 0, [ False, True, True ] ) |
| 144 | verifyMcastSinkRemoval( main, "ipv4", 1, [ False, False, True ] ) |
| 145 | else: |
| 146 | verifyMcastSinkRemoval( main, "ipv4", 2, [ True, True, False ] ) |
| 147 | verifyMcastSinkRemoval( main, "ipv4", 1, [ True, False, False ] ) |
| 148 | verifyMcastSourceRemoval( main, "ipv4", 0, False ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 149 | |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 150 | def verifyLinkDown( main, link, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ): |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 151 | """ |
| 152 | Kill a batch of links and verify traffic |
| 153 | Restore the links and verify traffic |
| 154 | """ |
| 155 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 156 | link = link if ( isinstance( link, list ) and isinstance( link[ 0 ], list ) ) else [ link ] |
| 157 | # Kill the link(s) |
| 158 | lib.killLinkBatch( main, link, int( main.params[ "TOPO" ][ "linkNum" ] ) - affectedLinkNum, int( main.params[ "TOPO" ][ "switchNum" ] ) ) |
| 159 | for routeName in expectList.keys(): |
| 160 | lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] ) |
| 161 | # Restore the link(s) |
| 162 | lib.restoreLinkBatch( main, link, int( main.params[ "TOPO" ][ "linkNum" ] ), int( main.params[ "TOPO" ][ "switchNum" ] ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 163 | if hostsToDiscover: |
| 164 | main.Network.discoverHosts( hostList=hostsToDiscover ) |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 165 | if hostLocations: |
You Wang | 5c4a638 | 2018-05-16 15:36:41 -0700 | [diff] [blame] | 166 | lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 167 | for routeName in expectList.keys(): |
| 168 | lib.verifyMulticastTraffic( main, routeName, True ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 169 | |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 170 | def verifyPortDown( main, dpid, port, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ): |
| 171 | """ |
| 172 | Disable a port and verify traffic |
| 173 | Reenable the port and verify traffic |
| 174 | """ |
| 175 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
You Wang | 5c4a638 | 2018-05-16 15:36:41 -0700 | [diff] [blame] | 176 | # Disable the port(s) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 177 | main.step( "Disable port {}/{}".format( dpid, port ) ) |
| 178 | main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="disable" ) |
| 179 | time.sleep( 10 ) |
| 180 | for routeName in expectList.keys(): |
| 181 | lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] ) |
You Wang | 5c4a638 | 2018-05-16 15:36:41 -0700 | [diff] [blame] | 182 | # Reenable the port(s) |
| 183 | main.step( "Enable port {}/{}".format( dpid, port ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 184 | main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="enable" ) |
| 185 | if hostsToDiscover: |
| 186 | main.Network.discoverHosts( hostList=hostsToDiscover ) |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 187 | if hostLocations: |
You Wang | 5c4a638 | 2018-05-16 15:36:41 -0700 | [diff] [blame] | 188 | lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 189 | for routeName in expectList.keys(): |
| 190 | lib.verifyMulticastTraffic( main, routeName, True ) |
| 191 | |
| 192 | def verifySwitchDown( main, switchName, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ): |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 193 | """ |
| 194 | Kill a batch of switches and verify traffic |
| 195 | Recover the swithces and verify traffic |
| 196 | """ |
| 197 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 198 | switchName = switchName if isinstance( switchName, list ) else [ switchName ] |
| 199 | # Kill the switch(es) |
| 200 | lib.killSwitch( main, switchName, int( main.params[ "TOPO" ][ "switchNum" ] ) - len( switchName ), int( main.params[ "TOPO" ][ "linkNum" ] ) - affectedLinkNum ) |
| 201 | for routeName in expectList.keys(): |
| 202 | lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] ) |
| 203 | # Recover the switch(es) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 204 | lib.recoverSwitch( main, switchName, int( main.params[ "TOPO" ][ "switchNum" ] ), int( main.params[ "TOPO" ][ "linkNum" ] ), True if hostsToDiscover else False, hostsToDiscover ) |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 205 | if hostLocations: |
You Wang | 5c4a638 | 2018-05-16 15:36:41 -0700 | [diff] [blame] | 206 | lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 207 | for routeName in expectList.keys(): |
| 208 | lib.verifyMulticastTraffic( main, routeName, True ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 209 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 210 | def verifyOnosDown( main, expectList={ "ipv4": True, "ipv6": True } ): |
| 211 | """ |
| 212 | Kill and recover ONOS instances Sequencially and check traffic |
| 213 | """ |
| 214 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 215 | import json |
| 216 | numCtrls = len( main.Cluster.runningNodes ) |
| 217 | links = len( json.loads( main.Cluster.next().links() ) ) |
| 218 | switches = len( json.loads( main.Cluster.next().devices() ) ) |
| 219 | for ctrl in xrange( numCtrls ): |
| 220 | # Kill node |
| 221 | lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) ) |
| 222 | main.Cluster.active(0).CLI.balanceMasters() |
| 223 | time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) ) |
| 224 | for routeName in expectList.keys(): |
| 225 | lib.verifyMulticastTraffic( main, routeName, True ) |
| 226 | # Recover node |
| 227 | lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls ) |
| 228 | main.Cluster.active(0).CLI.balanceMasters() |
| 229 | time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) ) |
| 230 | for routeName in expectList.keys(): |
| 231 | lib.verifyMulticastTraffic( main, routeName, True ) |