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 |
| 45 | translator.ofdpaToBmv2( main ) |
| 46 | else: |
| 47 | translator.bmv2ToOfdpa( main ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 48 | lib.loadJson( main ) |
| 49 | time.sleep( float( main.params[ "timers" ][ "loadNetcfgSleep" ] ) ) |
You Wang | 583705d | 2018-10-26 16:46:21 -0700 | [diff] [blame] | 50 | main.cfgName = "common" if hasattr( main, "Mininet1" ) else main.params[ "DEPENDENCY" ][ "confName" ] |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 51 | lib.loadMulticastConfig( main ) |
You Wang | 88b3cbe | 2018-05-10 15:21:39 -0700 | [diff] [blame] | 52 | lib.loadHost( main ) |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 53 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 54 | if hasattr( main, "Mininet1" ): |
| 55 | # Run the test with Mininet |
| 56 | mininet_args = " --dhcp=1 --routers=1 --ipv6=1 --ipv4=1" |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 57 | if main.useBmv2: |
| 58 | mininet_args += ' --switch bmv2' |
| 59 | main.log.info( "Using BMv2 switch" ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 60 | lib.startMininet( main, main.params[ "DEPENDENCY" ][ "topology" ], args=mininet_args ) |
| 61 | time.sleep( float( main.params[ "timers" ][ "startMininetSleep" ] ) ) |
| 62 | else: |
| 63 | # Run the test with physical devices |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 64 | lib.connectToPhysicalNetwork( main ) |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 65 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 66 | # Create scapy components |
| 67 | lib.startScapyHosts( main ) |
You Wang | 88b3cbe | 2018-05-10 15:21:39 -0700 | [diff] [blame] | 68 | # Verify host IP assignment |
| 69 | lib.verifyOnosHostIp( main ) |
| 70 | lib.verifyNetworkHostIp( main ) |
You Wang | ece951a | 2018-04-16 13:34:43 -0700 | [diff] [blame] | 71 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 72 | def verifyMcastRoutes( main ): |
| 73 | """ |
| 74 | Install multicast routes and check traffic |
| 75 | """ |
| 76 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 77 | for routeName in main.mcastRoutes.keys(): |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 78 | installMcastRoute( main, routeName ) |
| 79 | lib.verifyMulticastTraffic( main, routeName, True ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 80 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 81 | def installMcastRoute( main, routeName ): |
| 82 | """ |
| 83 | Install a multicast route |
| 84 | """ |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 85 | main.step( "Install {} multicast route".format( routeName ) ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 86 | routeData = main.multicastConfig[ routeName ] |
| 87 | src = main.mcastRoutes[ routeName ][ "src" ] |
| 88 | dst = main.mcastRoutes[ routeName ][ "dst" ] |
| 89 | 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] | 90 | [ routeData[ "src" ][ i ][ "id" ] for i in src ], |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 91 | [ routeData[ "dst" ][ i ][ "id" ] for i in dst ] ) |
| 92 | time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 93 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 94 | def verifyMcastRouteRemoval( main, routeName ): |
| 95 | """ |
| 96 | Verify removal of a multicast route |
| 97 | """ |
| 98 | routeData = main.multicastConfig[ routeName ] |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 99 | main.step( "Remove {} route".format( routeName ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 100 | main.Cluster.active( 0 ).CLI.mcastSinkDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ] ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 101 | # TODO: verify the deletion |
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 verifyMcastSinkRemoval( main, routeName, sinkIndex, expect ): |
| 104 | """ |
| 105 | Verify removal of a multicast sink |
| 106 | """ |
| 107 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 108 | routeData = main.multicastConfig[ routeName ] |
| 109 | sinkId = routeData[ "dst" ][ sinkIndex ][ "id" ] |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 110 | main.step( "Remove sink {} of route {}".format( sinkId, routeName ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 111 | 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] | 112 | time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) ) |
| 113 | lib.verifyMulticastTraffic( main, routeName, expect ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 114 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 115 | def verifyMcastSourceRemoval( main, routeName, sourceIndex, expect ): |
| 116 | """ |
| 117 | Verify removal of a multicast source |
| 118 | """ |
| 119 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 120 | routeData = main.multicastConfig[ routeName ] |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 121 | sourceId = [ routeData[ "src" ][ sourceIndex ][ "id" ] ] |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 122 | main.step( "Remove source {} of route {}".format( sourceId, routeName ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 123 | 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] | 124 | time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) ) |
| 125 | lib.verifyMulticastTraffic( main, routeName, expect ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 126 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 127 | def verifyMcastRemoval( main, removeDHT1=True ): |
| 128 | """ |
| 129 | Verify removal of IPv6 route, IPv4 sinks and IPv4 source |
| 130 | """ |
| 131 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 132 | verifyMcastRouteRemoval( main, "ipv6" ) |
| 133 | if removeDHT1: |
| 134 | verifyMcastSinkRemoval( main, "ipv4", 0, [ False, True, True ] ) |
| 135 | verifyMcastSinkRemoval( main, "ipv4", 1, [ False, False, True ] ) |
| 136 | else: |
| 137 | verifyMcastSinkRemoval( main, "ipv4", 2, [ True, True, False ] ) |
| 138 | verifyMcastSinkRemoval( main, "ipv4", 1, [ True, False, False ] ) |
| 139 | verifyMcastSourceRemoval( main, "ipv4", 0, False ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 140 | |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 141 | def verifyLinkDown( main, link, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ): |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 142 | """ |
| 143 | Kill a batch of links and verify traffic |
| 144 | Restore the links and verify traffic |
| 145 | """ |
| 146 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 147 | link = link if ( isinstance( link, list ) and isinstance( link[ 0 ], list ) ) else [ link ] |
| 148 | # Kill the link(s) |
| 149 | lib.killLinkBatch( main, link, int( main.params[ "TOPO" ][ "linkNum" ] ) - affectedLinkNum, int( main.params[ "TOPO" ][ "switchNum" ] ) ) |
| 150 | for routeName in expectList.keys(): |
| 151 | lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] ) |
| 152 | # Restore the link(s) |
| 153 | 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] | 154 | if hostsToDiscover: |
| 155 | main.Network.discoverHosts( hostList=hostsToDiscover ) |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 156 | if hostLocations: |
You Wang | 5c4a638 | 2018-05-16 15:36:41 -0700 | [diff] [blame] | 157 | lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 158 | for routeName in expectList.keys(): |
| 159 | lib.verifyMulticastTraffic( main, routeName, True ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 160 | |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 161 | def verifyPortDown( main, dpid, port, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ): |
| 162 | """ |
| 163 | Disable a port and verify traffic |
| 164 | Reenable the port and verify traffic |
| 165 | """ |
| 166 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
You Wang | 5c4a638 | 2018-05-16 15:36:41 -0700 | [diff] [blame] | 167 | # Disable the port(s) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 168 | main.step( "Disable port {}/{}".format( dpid, port ) ) |
| 169 | main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="disable" ) |
| 170 | time.sleep( 10 ) |
| 171 | for routeName in expectList.keys(): |
| 172 | lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] ) |
You Wang | 5c4a638 | 2018-05-16 15:36:41 -0700 | [diff] [blame] | 173 | # Reenable the port(s) |
| 174 | main.step( "Enable port {}/{}".format( dpid, port ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 175 | main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="enable" ) |
| 176 | if hostsToDiscover: |
| 177 | main.Network.discoverHosts( hostList=hostsToDiscover ) |
You Wang | 8574776 | 2018-05-11 15:51:50 -0700 | [diff] [blame] | 178 | if hostLocations: |
You Wang | 5c4a638 | 2018-05-16 15:36:41 -0700 | [diff] [blame] | 179 | lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 180 | for routeName in expectList.keys(): |
| 181 | lib.verifyMulticastTraffic( main, routeName, True ) |
| 182 | |
| 183 | def verifySwitchDown( main, switchName, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ): |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 184 | """ |
| 185 | Kill a batch of switches and verify traffic |
| 186 | Recover the swithces and verify traffic |
| 187 | """ |
| 188 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 189 | switchName = switchName if isinstance( switchName, list ) else [ switchName ] |
| 190 | # Kill the switch(es) |
| 191 | lib.killSwitch( main, switchName, int( main.params[ "TOPO" ][ "switchNum" ] ) - len( switchName ), int( main.params[ "TOPO" ][ "linkNum" ] ) - affectedLinkNum ) |
| 192 | for routeName in expectList.keys(): |
| 193 | lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] ) |
| 194 | # Recover the switch(es) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 195 | 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] | 196 | if hostLocations: |
You Wang | 5c4a638 | 2018-05-16 15:36:41 -0700 | [diff] [blame] | 197 | lib.verifyHostLocations( main, hostLocations, retry=int( main.params[ "RETRY" ][ "hostDiscovery" ] ) ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 198 | for routeName in expectList.keys(): |
| 199 | lib.verifyMulticastTraffic( main, routeName, True ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 200 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 201 | def verifyOnosDown( main, expectList={ "ipv4": True, "ipv6": True } ): |
| 202 | """ |
| 203 | Kill and recover ONOS instances Sequencially and check traffic |
| 204 | """ |
| 205 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 206 | import json |
| 207 | numCtrls = len( main.Cluster.runningNodes ) |
| 208 | links = len( json.loads( main.Cluster.next().links() ) ) |
| 209 | switches = len( json.loads( main.Cluster.next().devices() ) ) |
| 210 | for ctrl in xrange( numCtrls ): |
| 211 | # Kill node |
| 212 | lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) ) |
| 213 | main.Cluster.active(0).CLI.balanceMasters() |
| 214 | time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) ) |
| 215 | for routeName in expectList.keys(): |
| 216 | lib.verifyMulticastTraffic( main, routeName, True ) |
| 217 | # Recover node |
| 218 | lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls ) |
| 219 | main.Cluster.active(0).CLI.balanceMasters() |
| 220 | time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) ) |
| 221 | for routeName in expectList.keys(): |
| 222 | lib.verifyMulticastTraffic( main, routeName, True ) |