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