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 |
| 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 |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 34 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 35 | 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" ) |
| 40 | main.cfgName = "TEST_CONFIG_ipv4=1_ipv6=1_dhcp=1_routers=1" |
| 41 | lib.loadJson( main ) |
| 42 | time.sleep( float( main.params[ "timers" ][ "loadNetcfgSleep" ] ) ) |
| 43 | main.cfgName = "common" |
| 44 | lib.loadMulticastConfig( main ) |
You Wang | 88b3cbe | 2018-05-10 15:21:39 -0700 | [diff] [blame] | 45 | lib.loadHost( main ) |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 46 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 47 | 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 ) ) |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 57 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 58 | # Create scapy components |
| 59 | lib.startScapyHosts( main ) |
You Wang | 88b3cbe | 2018-05-10 15:21:39 -0700 | [diff] [blame] | 60 | # Verify host IP assignment |
| 61 | lib.verifyOnosHostIp( main ) |
| 62 | lib.verifyNetworkHostIp( main ) |
You Wang | ece951a | 2018-04-16 13:34:43 -0700 | [diff] [blame] | 63 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 64 | def 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(): |
| 70 | main.step( "Verify {} multicast route".format( routeName ) ) |
| 71 | installMcastRoute( main, routeName ) |
| 72 | lib.verifyMulticastTraffic( main, routeName, True ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 73 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 74 | def installMcastRoute( main, routeName ): |
| 75 | """ |
| 76 | Install a multicast route |
| 77 | """ |
| 78 | 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 Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 82 | [ routeData[ "src" ][ i ][ "id" ] for i in src ], |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 83 | [ routeData[ "dst" ][ i ][ "id" ] for i in dst ] ) |
| 84 | time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 85 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 86 | def verifyMcastRouteRemoval( main, routeName ): |
| 87 | """ |
| 88 | Verify removal of a multicast route |
| 89 | """ |
| 90 | routeData = main.multicastConfig[ routeName ] |
| 91 | main.step( "Verify removal of {} route".format( routeName ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 92 | main.Cluster.active( 0 ).CLI.mcastSinkDelete( routeData[ "src" ][ 0 ][ "ip" ], routeData[ "group" ] ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 93 | # TODO: verify the deletion |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 94 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 95 | def 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" ] |
| 102 | main.step( "Verify removal of {} sink {}".format( routeName, sinkId ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 103 | 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] | 104 | time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) ) |
| 105 | lib.verifyMulticastTraffic( main, routeName, expect ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 106 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 107 | def 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 Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 113 | sourceId = [ routeData[ "src" ][ sourceIndex ][ "id" ] ] |
| 114 | main.step( "Verify removal of {} source {}".format( routeName, sourceId ) ) |
| 115 | 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] | 116 | time.sleep( float( main.params[ "timers" ][ "mcastSleep" ] ) ) |
| 117 | lib.verifyMulticastTraffic( main, routeName, expect ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 118 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 119 | def 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 Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 132 | |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 133 | def verifyLinkDown( main, link, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ): |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 134 | """ |
| 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 Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 146 | if hostsToDiscover: |
| 147 | main.Network.discoverHosts( hostList=hostsToDiscover ) |
| 148 | for host, loc in hostLocations.items(): |
| 149 | lib.verifyHostLocation( main, host, loc, retry=5 ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 150 | for routeName in expectList.keys(): |
| 151 | lib.verifyMulticastTraffic( main, routeName, True ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 152 | |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 153 | def 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 |
| 159 | main.step( "Disable port {}/{}".format( dpid, port ) ) |
| 160 | main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="disable" ) |
| 161 | time.sleep( 10 ) |
| 162 | for routeName in expectList.keys(): |
| 163 | lib.verifyMulticastTraffic( main, routeName, expectList[ routeName ] ) |
| 164 | # Restore the link(s) |
| 165 | main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state="enable" ) |
| 166 | if hostsToDiscover: |
| 167 | main.Network.discoverHosts( hostList=hostsToDiscover ) |
| 168 | for host, loc in hostLocations.items(): |
| 169 | lib.verifyHostLocation( main, host, loc, retry=5 ) |
| 170 | for routeName in expectList.keys(): |
| 171 | lib.verifyMulticastTraffic( main, routeName, True ) |
| 172 | |
| 173 | def verifySwitchDown( main, switchName, affectedLinkNum, expectList={ "ipv4": True, "ipv6": True }, hostsToDiscover=[], hostLocations={} ): |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 174 | """ |
| 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 Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 185 | lib.recoverSwitch( main, switchName, int( main.params[ "TOPO" ][ "switchNum" ] ), int( main.params[ "TOPO" ][ "linkNum" ] ), True if hostsToDiscover else False, hostsToDiscover ) |
| 186 | for host, loc in hostLocations.items(): |
You Wang | 88b3cbe | 2018-05-10 15:21:39 -0700 | [diff] [blame] | 187 | lib.verifyHostLocation( main, host, loc, retry=5 ) |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 188 | for routeName in expectList.keys(): |
| 189 | lib.verifyMulticastTraffic( main, routeName, True ) |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 190 | |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 191 | def 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 ) |