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 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 28 | 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 |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 36 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 37 | 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 Wang | 583705d | 2018-10-26 16:46:21 -0700 | [diff] [blame] | 42 | 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] | 43 | if main.useBmv2: |
| 44 | # Translate configuration file from OVS-OFDPA to BMv2 driver |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 45 | 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 Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 48 | else: |
| 49 | translator.bmv2ToOfdpa( main ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 50 | lib.loadJson( main ) |
| 51 | time.sleep( float( main.params[ "timers" ][ "loadNetcfgSleep" ] ) ) |
You Wang | 583705d | 2018-10-26 16:46:21 -0700 | [diff] [blame] | 52 | main.cfgName = "common" if hasattr( main, "Mininet1" ) else main.params[ "DEPENDENCY" ][ "confName" ] |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 53 | lib.loadMulticastConfig( main ) |
You Wang | 88b3cbe | 2018-05-10 15:21:39 -0700 | [diff] [blame] | 54 | lib.loadHost( main ) |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 55 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 56 | if hasattr( main, "Mininet1" ): |
| 57 | # Run the test with Mininet |
| 58 | mininet_args = " --dhcp=1 --routers=1 --ipv6=1 --ipv4=1" |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 59 | if main.useBmv2: |
| 60 | mininet_args += ' --switch bmv2' |
| 61 | main.log.info( "Using BMv2 switch" ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 62 | 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 Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 66 | lib.connectToPhysicalNetwork( main ) |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 67 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 68 | # Create scapy components |
| 69 | lib.startScapyHosts( main ) |
You Wang | 88b3cbe | 2018-05-10 15:21:39 -0700 | [diff] [blame] | 70 | # Verify host IP assignment |
| 71 | lib.verifyOnosHostIp( main ) |
| 72 | lib.verifyNetworkHostIp( main ) |
You Wang | ece951a | 2018-04-16 13:34:43 -0700 | [diff] [blame] | 73 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 74 | def 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 Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 80 | installMcastRoute( main, routeName ) |
| 81 | lib.verifyMulticastTraffic( main, routeName, True ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 82 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 83 | def installMcastRoute( main, routeName ): |
| 84 | """ |
| 85 | Install a multicast route |
| 86 | """ |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 87 | main.step( "Install {} multicast route".format( routeName ) ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 88 | 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 Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 92 | [ routeData[ "src" ][ i ][ "id" ] for i in src ], |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 93 | [ routeData[ "dst" ][ i ][ "id" ] for i in dst ] ) |
| 94 | time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 95 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 96 | def verifyMcastRouteRemoval( main, routeName ): |
| 97 | """ |
| 98 | Verify removal of a multicast route |
| 99 | """ |
| 100 | routeData = main.multicastConfig[ routeName ] |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 101 | main.step( "Remove {} route".format( routeName ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 102 | main.Cluster.active( 0 ).CLI.mcastSinkDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ] ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 103 | # TODO: verify the deletion |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 104 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 105 | def 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 Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 112 | main.step( "Remove sink {} of route {}".format( sinkId, routeName ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 113 | 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] | 114 | time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) ) |
| 115 | lib.verifyMulticastTraffic( main, routeName, expect ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 116 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 117 | def 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 Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 123 | sourceId = [ routeData[ "src" ][ sourceIndex ][ "id" ] ] |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 124 | main.step( "Remove source {} of route {}".format( sourceId, routeName ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 125 | 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] | 126 | time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) ) |
| 127 | lib.verifyMulticastTraffic( main, routeName, expect ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 128 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 129 | def 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 Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 142 | |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 143 | def verifyLinkDown( main, link, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ): |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 144 | """ |
| 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 Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 156 | if hostsToDiscover: |
| 157 | main.Network.discoverHosts( hostList=hostsToDiscover ) |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 158 | if hostLocations: |
You Wang | 5c4a638 | 2018-05-16 15:36:41 -0700 | [diff] [blame] | 159 | lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 160 | for routeName in expectList.keys(): |
| 161 | lib.verifyMulticastTraffic( main, routeName, True ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 162 | |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 163 | def 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 Wang | 5c4a638 | 2018-05-16 15:36:41 -0700 | [diff] [blame] | 169 | # Disable the port(s) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 170 | 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 Wang | 5c4a638 | 2018-05-16 15:36:41 -0700 | [diff] [blame] | 175 | # Reenable the port(s) |
| 176 | main.step( "Enable port {}/{}".format( dpid, port ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 177 | main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="enable" ) |
| 178 | if hostsToDiscover: |
| 179 | main.Network.discoverHosts( hostList=hostsToDiscover ) |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 180 | if hostLocations: |
You Wang | 5c4a638 | 2018-05-16 15:36:41 -0700 | [diff] [blame] | 181 | lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 182 | for routeName in expectList.keys(): |
| 183 | lib.verifyMulticastTraffic( main, routeName, True ) |
| 184 | |
| 185 | def verifySwitchDown( main, switchName, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ): |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 186 | """ |
| 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 Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 197 | 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] | 198 | if hostLocations: |
You Wang | 5c4a638 | 2018-05-16 15:36:41 -0700 | [diff] [blame] | 199 | lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 200 | for routeName in expectList.keys(): |
| 201 | lib.verifyMulticastTraffic( main, routeName, True ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 202 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 203 | def 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 ) |