Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2017 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 | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 22 | def setupTest( main, test_idx, onosNodes, ipv4=True, ipv6=True, external=True, static=False, countFlowsGroups=False ): |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 23 | """ |
| 24 | SRRouting test setup |
| 25 | """ |
| 26 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 27 | import time |
| 28 | |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 29 | skipPackage = False |
| 30 | init = False |
| 31 | if not hasattr( main, 'apps' ): |
| 32 | init = True |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 33 | lib.initTest( main ) |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 34 | # Skip onos packaging if the cluster size stays the same |
| 35 | if not init and onosNodes == main.Cluster.numCtrls: |
| 36 | skipPackage = True |
| 37 | |
| 38 | main.internalIpv4Hosts = main.params[ 'TOPO' ][ 'internalIpv4Hosts' ].split( ',' ) |
| 39 | main.internalIpv6Hosts = main.params[ 'TOPO' ][ 'internalIpv6Hosts' ].split( ',' ) |
| 40 | main.externalIpv4Hosts = main.params[ 'TOPO' ][ 'externalIpv4Hosts' ].split( ',' ) |
| 41 | main.externalIpv6Hosts = main.params[ 'TOPO' ][ 'externalIpv6Hosts' ].split( ',' ) |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 42 | main.disconnectedIpv4Hosts = [] |
| 43 | main.disconnectedIpv6Hosts = [] |
| 44 | main.resultFileName = 'CASE%03d' % test_idx |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 45 | main.Cluster.setRunningNode( onosNodes ) |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 46 | |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 47 | lib.installOnos( main, skipPackage=skipPackage, cliSleep=5, parallel=False ) |
| 48 | |
| 49 | # Load configuration files |
| 50 | main.cfgName = 'TEST_CONFIG_ipv4={}_ipv6={}_dhcp=1_routers=1{}{}'.format( 1 if ipv4 else 0, |
| 51 | 1 if ipv6 else 0, |
| 52 | "_external=1" if external else "", |
| 53 | "_static=1" if static else "" ) |
| 54 | lib.loadJson( main ) |
| 55 | time.sleep( float( main.params[ 'timers' ][ 'loadNetcfgSleep' ] ) ) |
| 56 | lib.loadHost( main ) |
| 57 | |
| 58 | # if static route flag add routes |
| 59 | # these routes are topology specific |
| 60 | if static: |
| 61 | if ipv4: |
| 62 | lib.addStaticOnosRoute( main, "10.0.88.0/24", "10.0.1.1") |
| 63 | if ipv6: |
| 64 | lib.addStaticOnosRoute( main, "2000::8700/120", "2000::101") |
| 65 | if countFlowsGroups: |
| 66 | lib.loadCount( main ) |
| 67 | |
| 68 | if hasattr( main, 'Mininet1' ): |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 69 | # Run the test with Mininet |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 70 | mininet_args = ' --dhcp=1 --routers=1 --ipv6={} --ipv4={}'.format( 1 if ipv6 else 0, |
| 71 | 1 if ipv4 else 0 ) |
| 72 | lib.startMininet( main, main.params[ 'DEPENDENCY' ][ 'topology' ], args=mininet_args ) |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 73 | time.sleep( float( main.params[ "timers" ][ "startMininetSleep" ] ) ) |
| 74 | else: |
| 75 | # Run the test with physical devices |
| 76 | lib.connectToPhysicalNetwork( main, self.switchNames ) |
| 77 | # Check if the devices are up |
| 78 | lib.checkDevices( main, switches=len( self.switchNames ) ) |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 79 | # wait some time for onos to install the rules! |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 80 | time.sleep( float( main.params[ 'timers' ][ 'dhcpSleep' ] ) ) |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 81 | |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 82 | def verifyPingInternal( main, ipv4=True, ipv6=True, disconnected=True ): |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 83 | """ |
| 84 | Verify all connected internal hosts are able to reach each other, |
| 85 | and disconnected internal hosts cannot reach any other internal host |
| 86 | """ |
| 87 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 88 | # Verify connected hosts |
| 89 | main.step("Verify reachability of connected internal hosts") |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 90 | if ipv4: |
| 91 | lib.verifyPing( main, |
| 92 | [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ], |
| 93 | [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ] ) |
| 94 | if ipv6: |
| 95 | lib.verifyPing( main, |
| 96 | [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ], |
| 97 | [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ], |
| 98 | ipv6=True, acceptableFailed=7 ) |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 99 | # Verify disconnected hosts |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 100 | if disconnected: |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 101 | main.step("Verify unreachability of disconnected internal hosts") |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 102 | if main.disconnectedIpv4Hosts: |
| 103 | lib.verifyPing( main, main.internalIpv4Hosts, main.disconnectedIpv4Hosts, expect=False ) |
| 104 | if main.disconnectedIpv6Hosts: |
| 105 | lib.verifyPing( main, main.internalIpv6Hosts, main.disconnectedIpv6Hosts, ipv6=True, expect=False ) |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 106 | |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 107 | def verifyPingExternal( main, ipv4=True, ipv6=True, disconnected=True ): |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 108 | """ |
| 109 | Verify all connected internal hosts are able to reach external hosts, |
| 110 | and disconnected internal hosts cannot reach any external host |
| 111 | """ |
| 112 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 113 | # Verify connected hosts |
| 114 | main.step("Verify reachability of from connected internal hosts to external hosts") |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 115 | if ipv4: |
| 116 | lib.verifyPing( main, |
| 117 | [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ], |
| 118 | main.externalIpv4Hosts ) |
| 119 | if ipv6: |
| 120 | lib.verifyPing( main, |
| 121 | [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ], |
| 122 | main.externalIpv6Hosts, |
| 123 | ipv6=True, acceptableFailed=7 ) |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 124 | # Verify disconnected hosts |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 125 | if disconnected: |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 126 | main.step("Verify unreachability of disconnected internal hosts to external hosts") |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 127 | if main.disconnectedIpv4Hosts: |
| 128 | lib.verifyPing( main, main.disconnectedIpv4Hosts, main.externalIpv4Hosts, expect=False ) |
| 129 | if main.disconnectedIpv6Hosts: |
| 130 | lib.verifyPing( main, main.disconnectedIpv6Hosts, main.externalIpv6Hosts, ipv6=True, expect=False ) |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 131 | |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 132 | def verifyPing( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True ): |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 133 | """ |
| 134 | Verify reachability and unreachability of connected/disconnected hosts |
| 135 | """ |
You Wang | d66de19 | 2018-04-30 17:30:12 -0700 | [diff] [blame] | 136 | if internal: |
| 137 | verifyPingInternal( main, ipv4, ipv6, disconnected ) |
| 138 | if external: |
| 139 | verifyPingExternal( main, ipv4, ipv6, disconnected ) |
| 140 | |
| 141 | def verifyLinkFailure( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True, countFlowsGroups=False ): |
| 142 | """ |
| 143 | Kill and recover all links to spine101 and 102 sequencially and run verifications |
| 144 | """ |
| 145 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 146 | linksToRemove = [ ["spine103", "spine101"], |
| 147 | ["leaf2", "spine101"], |
| 148 | ["leaf3", "spine101"], |
| 149 | ["leaf4", "spine101"], |
| 150 | ["leaf5", "spine101"] ] |
| 151 | lib.killLinkBatch( main, linksToRemove, 30, 10 ) |
| 152 | verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups ) |
| 153 | lib.restoreLinkBatch( main, linksToRemove, 48, 10 ) |
| 154 | verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups ) |
| 155 | linksToRemove = [ ["spine104", "spine102"], |
| 156 | ["leaf2", "spine102"], |
| 157 | ["leaf3", "spine102"], |
| 158 | ["leaf4", "spine102"], |
| 159 | ["leaf5", "spine102"] ] |
| 160 | lib.killLinkBatch( main, linksToRemove, 30, 10 ) |
| 161 | verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups ) |
| 162 | lib.restoreLinkBatch( main, linksToRemove, 48, 10 ) |
| 163 | verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups ) |
| 164 | |
| 165 | def verifySwitchFailure( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True, countFlowsGroups=False ): |
| 166 | """ |
| 167 | Kill and recover spine101 and 102 sequencially and run verifications |
| 168 | """ |
| 169 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 170 | for switchToKill in [ "spine101", "spine102" ]: |
| 171 | lib.killSwitch( main, switchToKill, 9, 30 ) |
| 172 | verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups ) |
| 173 | lib.recoverSwitch( main, switchToKill, 10, 48 ) |
| 174 | verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups ) |
| 175 | |
| 176 | def verifyOnosFailure( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True, countFlowsGroups=False ): |
| 177 | """ |
| 178 | Kill and recover onos nodes sequencially and run verifications |
| 179 | """ |
| 180 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 181 | import json |
| 182 | import time |
| 183 | |
| 184 | numCtrls = len( main.Cluster.runningNodes ) |
| 185 | links = len( json.loads( main.Cluster.next().links() ) ) |
| 186 | switches = len( json.loads( main.Cluster.next().devices() ) ) |
| 187 | for ctrl in xrange( numCtrls ): |
| 188 | # Kill node |
| 189 | lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) ) |
| 190 | main.Cluster.active(0).CLI.balanceMasters() |
| 191 | time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) ) |
| 192 | verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups ) |
| 193 | # Recover node |
| 194 | lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls ) |
| 195 | main.Cluster.active(0).CLI.balanceMasters() |
| 196 | time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) ) |
| 197 | verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups ) |
| 198 | |
| 199 | def verify( main, ipv4=True, ipv6=True, disconnected=True, internal=True, external=True, countFlowsGroups=False ): |
| 200 | """ |
| 201 | Verify host IP assignment, flow/group number and pings |
| 202 | """ |
| 203 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib |
| 204 | # Verify host IP assignment |
| 205 | lib.verifyOnosHostIp( main ) |
| 206 | lib.verifyNetworkHostIp( main ) |
| 207 | # check flows / groups numbers |
| 208 | if countFlowsGroups: |
| 209 | run.checkFlowsGroupsFromFile( main ) |
| 210 | # ping hosts |
| 211 | verifyPing( main, ipv4, ipv6, disconnected, internal, external ) |