Jonghwan Hyun | 812c70f | 2018-02-16 16:33:16 -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 | |
| 22 | class SRDynamicConfTest: |
| 23 | def __init__( self ): |
| 24 | self.default = '' |
| 25 | |
| 26 | @staticmethod |
| 27 | def runTest( main, testIndex, topology, onosNodes, description, vlan=( 0, 0, 0, 0 ) ): |
| 28 | ''' |
| 29 | Tests connectivity for each test case. |
| 30 | Configuration files: |
| 31 | - (0x1, 0x2, 2x2, 2x4).json: device configuration, fed to ONOS before configuration change |
| 32 | - CASE*.json: interface configuration, fed to ONOS before configuration change |
| 33 | - CASE*0.chart: ping chart, used to check connectivity before configuration change. |
| 34 | Shared among same test scenario with different topology. |
| 35 | - CASE*0_after.chart: ping chart, used to check connectivity after configuration change. |
| 36 | Shared among same test scenario with different topology. |
| 37 | Only used when ping chart is updated. |
| 38 | ''' |
| 39 | topo = dict() |
| 40 | # (number of spine switch, number of leaf switch, dual-homed, description, port number of h1) |
| 41 | topo[ '0x1' ] = ( 0, 1, False, 'single ToR', 1 ) |
| 42 | topo[ '0x2' ] = ( 0, 2, True, 'dual-homed ToR', 2 ) |
| 43 | topo[ '2x2' ] = ( 2, 2, False, '2x2 leaf-spine topology', 3 ) |
| 44 | topo[ '2x4' ] = ( 2, 4, True, '2x4 dual-homed leaf-spine topology', 6 ) |
| 45 | fanout = 4 |
| 46 | switchNames = {} |
| 47 | switchNames[ '2x2' ] = [ "leaf1", "leaf2", "spine101", "spine102" ] |
| 48 | |
| 49 | TAG = 'CASE%d' % testIndex |
| 50 | skipPackage = False |
| 51 | init = False |
| 52 | dualHomed = topo[ topology ][ 2 ] |
| 53 | portNum = topo[ topology ][ 4 ] |
| 54 | defaultIntf = 'bond0' if dualHomed else 'eth0' |
| 55 | |
| 56 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as run |
| 57 | if not hasattr( main, 'apps' ): |
| 58 | init = True |
| 59 | run.initTest( main ) |
| 60 | # Skip onos packaging if the clusrer size stays the same |
| 61 | if not init and onosNodes == main.Cluster.numCtrls: |
| 62 | skipPackage = True |
| 63 | |
| 64 | main.case( '%s, with %s and %d ONOS instance%s' % |
| 65 | ( description, topo[ topology ][ 3 ], onosNodes, 's' if onosNodes > 1 else '' ) ) |
| 66 | main.cfgName = topology |
| 67 | main.Cluster.setRunningNode( onosNodes ) |
| 68 | run.installOnos( main, skipPackage=skipPackage, cliSleep=5 ) |
| 69 | |
| 70 | # Provide common configuration |
| 71 | # TODO: Generate json and chart dynamically, according to topologies and scenarios |
| 72 | run.loadJson( main ) |
| 73 | run.loadChart( main ) |
| 74 | |
| 75 | # Provide topology-specific interface configuration |
| 76 | import json |
| 77 | try: |
| 78 | with open( "%s%s%s.json" % (main.configPath, main.forJson, TAG) ) as cfg: |
| 79 | main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) ) |
| 80 | except IOError: |
| 81 | # Load default interface configuration |
| 82 | with open( "%s%s%s_ports.json" % (main.configPath, main.forJson, topology) ) as cfg: |
| 83 | main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) ) |
| 84 | |
| 85 | try: |
| 86 | with open( "%s%sCASE%d.chart" % (main.configPath, main.forChart, testIndex / 10 * 10) ) as chart: |
| 87 | main.pingChart = json.load( chart ) |
| 88 | except IOError: |
| 89 | # Load default chart |
| 90 | with open( "%s%sdefault.chart" % (main.configPath, main.forChart) ) as chart: |
| 91 | main.pingChart = json.load( chart ) |
| 92 | |
| 93 | # Set up topology |
| 94 | if hasattr( main, 'Mininet1' ): |
| 95 | # Run the test with mininet topology |
| 96 | mininet_args = ' --spine=%d --leaf=%d --fanout=%d' \ |
| 97 | % ( topo[ topology ][ 0 ], topo[ topology ][ 1 ], fanout ) |
| 98 | if len( vlan ) > 0 : |
| 99 | mininet_args += ' --vlan=%s' % ( ','.join( [ '%d' % vlanId for vlanId in vlan ] ) ) |
| 100 | if topo[ topology ][ 0 ] > 0: |
| 101 | mininet_args += ',0,0,0,0' |
| 102 | if dualHomed: |
| 103 | mininet_args += ' --dual-homed' |
| 104 | |
| 105 | run.startMininet( main, 'trellis_fabric.py', args=mininet_args ) |
| 106 | else: |
| 107 | # Run the test with physical devices |
| 108 | run.connectToPhysicalNetwork( main, switchNames[ topology ] ) |
| 109 | |
| 110 | # minFlowCountPerLeaf = 13 + [# of ports] * 5 + [# of hosts] * 2 + [# of vlan ids] |
| 111 | minFlowCountPerLeaf = 13 + ( fanout + topo[ topology ][ 0 ]) * 5 + fanout * 2 + len( set( vlan ) ) |
| 112 | run.checkFlows( main, minFlowCount=minFlowCountPerLeaf * topo[ topology ][ 1 ], sleep=5, dumpflows=False ) |
| 113 | # Check connectivity before changing interface configuration |
| 114 | run.pingAll( main, '%s_Before' % TAG, retryAttempts=2 ) |
| 115 | |
| 116 | leaf_dpid = [ "of:%016d" % ( ls + 1 ) for ls in range( topo[ topology ][ 1 ] ) ] |
| 117 | for dpid in leaf_dpid: |
| 118 | run.checkFlowsByDpid( main, dpid, minFlowCountPerLeaf, sleep=5 ) |
| 119 | |
| 120 | # Testcase-specific interface configuration change |
| 121 | if testIndex / 10 == 1: |
| 122 | # CASE11-14 |
| 123 | if hasattr( main, 'Mininet1' ): |
| 124 | # Assign vlan tag 10 to host h1 |
| 125 | main.Mininet1.assignVLAN( 'h1', 'h1-%s' % defaultIntf, '10' ) |
| 126 | # Update port configuration of port 1 |
| 127 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 128 | [ '10.0.2.254/24', ], tagged=[ 10, ] ) |
| 129 | else: |
| 130 | # TODO: update physical device configuration, same for all test cases |
| 131 | pass |
| 132 | elif testIndex / 10 == 2: |
| 133 | # CASE21-24 |
| 134 | if hasattr( main, 'Mininet1' ): |
| 135 | # Update port configuration of port 1 |
| 136 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 137 | [ '10.0.2.254/24', ], untagged=20 ) |
| 138 | elif testIndex / 10 == 3: |
| 139 | # CASE31-34 |
| 140 | if hasattr( main, 'Mininet1' ): |
| 141 | # Update port configuration of port 1 |
| 142 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 143 | [ '10.0.2.254/24', ], untagged=110 ) |
| 144 | # Update port configuration of port 2 |
| 145 | SRDynamicConfTest.updateIntfCfg( main, portNum + 1, dualHomed, |
| 146 | [ '10.0.2.254/24', ], untagged=110 ) |
| 147 | elif testIndex / 10 == 4: |
| 148 | # CASE41-44 |
| 149 | if hasattr( main, 'Mininet1' ): |
| 150 | # Assign vlan tag 20 to host h1 |
| 151 | main.Mininet1.assignVLAN( 'h1', 'h1-%s' % defaultIntf, '20') |
| 152 | # Update port configuration of port 1 |
| 153 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 154 | [ '10.0.2.254/24', ], tagged=[ 20, ] ) |
| 155 | elif testIndex / 10 == 5: |
| 156 | # CASE51-54 |
| 157 | if hasattr( main, 'Mininet1' ): |
| 158 | # Update port configuration of port 1 |
| 159 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 160 | [ '10.0.2.254/24', ], tagged=[ 20, ], native=10 ) |
| 161 | elif testIndex / 10 == 6: |
| 162 | # CASE61-64 |
| 163 | if hasattr( main, 'Mininet1' ): |
| 164 | # Update port configuration of port 1 |
| 165 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 166 | [ '10.0.2.254/24', ], tagged=[ 120, ], native=110 ) |
| 167 | # Update port configuration of port 2 |
| 168 | SRDynamicConfTest.updateIntfCfg( main, portNum + 1, dualHomed, |
| 169 | [ '10.0.2.254/24', ], tagged=[ 120, ], native=110 ) |
| 170 | elif testIndex / 10 == 7: |
| 171 | # CASE71-74 |
| 172 | if hasattr( main, 'Mininet1' ): |
| 173 | # Update host configuration of h1 |
| 174 | main.Mininet1.removeVLAN( 'h1', 'h1-%s.10' % defaultIntf ) |
| 175 | # Update port configuration of port 1 |
| 176 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 177 | [ '10.0.2.254/24', ], untagged=10 ) |
| 178 | elif testIndex / 10 == 8: |
| 179 | # CASE81-84 |
| 180 | if hasattr( main, 'Mininet1' ): |
| 181 | # Update port configuration of port 1 |
| 182 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 183 | [ '10.0.2.254/24', ], tagged=[ 20, ], native=10 ) |
| 184 | elif testIndex / 10 == 9: |
| 185 | # CASE91-94 |
| 186 | if hasattr( main, 'Mininet1' ): |
| 187 | # Update host configuration |
| 188 | main.Mininet1.removeVLAN( 'h1', 'h1-%s.10' % defaultIntf ) |
| 189 | main.Mininet1.removeVLAN( 'h2', 'h2-%s.10' % defaultIntf ) |
| 190 | |
| 191 | # Update port configuration |
| 192 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 193 | [ '10.0.2.254/24', ], tagged=[ 120, ], native=110 ) |
| 194 | SRDynamicConfTest.updateIntfCfg( main, portNum + 1, dualHomed, |
| 195 | [ '10.0.2.254/24', ], tagged=[ 120, ], native=110 ) |
| 196 | elif testIndex / 10 == 10: |
| 197 | # CASE101-104 |
| 198 | if hasattr( main, 'Mininet1' ): |
| 199 | # Update port configuration |
| 200 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 201 | [ '10.0.2.254/24', ], untagged=20 ) |
| 202 | elif testIndex / 10 == 11: |
| 203 | # CASE111-114 |
| 204 | if hasattr( main, 'Mininet1' ): |
| 205 | # Update port configuration |
| 206 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 207 | [ '10.0.2.254/24', ], tagged=[ 20, ] ) |
| 208 | elif testIndex / 10 == 12: |
| 209 | # CASE121-124 |
| 210 | if hasattr( main, 'Mininet1' ): |
| 211 | # Update port configuration |
| 212 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 213 | [ '10.0.2.254/24', ], tagged=[ 20, ], native=110 ) |
| 214 | SRDynamicConfTest.updateIntfCfg( main, portNum + 1, dualHomed, |
| 215 | [ '10.0.2.254/24', ], tagged=[ 20, ], native=110 ) |
| 216 | elif testIndex / 10 == 13: |
| 217 | # CASE131-134 |
| 218 | if hasattr( main, 'Mininet1' ): |
| 219 | # Update port configuration |
| 220 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 221 | [ '10.0.2.254/24', ], tagged=[ 120, ], native=10 ) |
| 222 | elif testIndex / 10 == 14: |
| 223 | # CASE141-144 |
| 224 | if hasattr( main, 'Mininet1' ): |
| 225 | # Update port configuration |
| 226 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 227 | [ '10.0.2.254/24', ], tagged=[ 20, ] ) |
| 228 | elif testIndex / 10 == 15: |
| 229 | # CASE151-154 |
| 230 | if hasattr( main, 'Mininet1' ): |
| 231 | # Update port configuration |
| 232 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 233 | [ '10.0.2.254/24', ], tagged=[ 120, ] ) |
| 234 | elif testIndex / 10 == 16: |
| 235 | # CASE161-164 |
| 236 | if hasattr( main, 'Mininet1' ): |
| 237 | # Update port configuration |
| 238 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 239 | [ '10.0.2.254/24', ], tagged=[ 20, ], native=10 ) |
| 240 | elif testIndex / 10 == 17: |
| 241 | # CASE171-174 |
| 242 | if hasattr( main, 'Mininet1' ): |
| 243 | # Update port configuration |
| 244 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 245 | [ '10.0.2.254/24', ], tagged=[ 120, ] ) |
| 246 | elif testIndex / 10 == 18: |
| 247 | # CASE181-184 |
| 248 | if hasattr( main, 'Mininet1' ): |
| 249 | # Update port configuration |
| 250 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 251 | [ '10.0.2.254/24', ], tagged=[ 20, ], native=10 ) |
| 252 | elif testIndex / 10 == 19: |
| 253 | # CASE191-194 |
| 254 | if hasattr( main, 'Mininet1' ): |
| 255 | # Update port configuration |
| 256 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 257 | [ '10.0.2.254/24', ], untagged=20 ) |
| 258 | elif testIndex / 10 == 20: |
| 259 | # CASE201-204 |
| 260 | if hasattr( main, 'Mininet1' ): |
| 261 | # Update port configuration |
| 262 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 263 | [ '10.0.2.254/24', ], tagged=[ 20 ] ) |
| 264 | elif testIndex / 10 == 21: |
| 265 | # CASE211-214 |
| 266 | if hasattr( main, 'Mininet1' ): |
| 267 | # Update port configuration |
| 268 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 269 | [ '10.0.2.254/24', ], tagged=[ 20 ], native=110 ) |
| 270 | elif testIndex / 10 == 22: |
| 271 | # CASE221-224 |
| 272 | if hasattr( main, 'Mininet1' ): |
| 273 | # Update port configuration |
| 274 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 275 | [ '10.0.2.254/24', ], tagged=[ 120 ], native=10 ) |
| 276 | elif testIndex / 10 == 23: |
| 277 | # CASE231-234 |
| 278 | if hasattr( main, "Mininet1" ): |
| 279 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 280 | [ '10.0.2.254/24', ], tagged=[ 10, ] ) |
| 281 | for dpid in leaf_dpid: |
| 282 | run.checkFlowsByDpid( main, dpid, minFlowCountPerLeaf, sleep=5 ) |
| 283 | main.pingChart[ 'leaf1' ][ 'expect' ] = False |
| 284 | run.pingAll( main, '%s_1' % TAG, retryAttempts=2 ) |
| 285 | |
| 286 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 287 | [ '10.0.2.254/24', ], untagged=50 ) |
| 288 | for dpid in leaf_dpid: |
| 289 | run.checkFlowsByDpid( main, dpid, minFlowCountPerLeaf, sleep=5 ) |
| 290 | run.pingAll( main, '%s_2' % TAG, retryAttempts=2 ) |
| 291 | |
| 292 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 293 | [ '10.0.2.254/24', ], tagged=[ 20, ] ) |
| 294 | for dpid in leaf_dpid: |
| 295 | run.checkFlowsByDpid( main, dpid, minFlowCountPerLeaf, sleep=5 ) |
| 296 | run.pingAll( main, '%s_3' % TAG, retryAttempts=2 ) |
| 297 | |
| 298 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 299 | [ '10.0.2.254/24', ], tagged=[ 40, ], native=10 ) |
| 300 | for dpid in leaf_dpid: |
| 301 | run.checkFlowsByDpid( main, dpid, minFlowCountPerLeaf, sleep=5 ) |
| 302 | main.pingChart[ 'leaf1' ][ 'expect' ] = True |
| 303 | run.pingAll( main, '%s_4' % TAG, retryAttempts=2 ) |
| 304 | |
| 305 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 306 | [ '10.0.2.254/24', ], tagged=[ 20, ] ) |
| 307 | for dpid in leaf_dpid: |
| 308 | run.checkFlowsByDpid( main, dpid, minFlowCountPerLeaf, sleep=5 ) |
| 309 | main.pingChart[ 'leaf1' ][ 'expect' ] = False |
| 310 | run.pingAll( main, '%s_5' % TAG, retryAttempts=2 ) |
| 311 | |
| 312 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 313 | [ '10.0.2.254/24', ], untagged= 20 ) |
| 314 | for dpid in leaf_dpid: |
| 315 | run.checkFlowsByDpid( main, dpid, minFlowCountPerLeaf, sleep=5 ) |
| 316 | run.pingAll( main, '%s_6' % TAG, retryAttempts=2 ) |
| 317 | |
| 318 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 319 | [ '10.0.2.254/24', ], untagged= 10 ) |
| 320 | for dpid in leaf_dpid: |
| 321 | run.checkFlowsByDpid( main, dpid, minFlowCountPerLeaf, sleep=5 ) |
| 322 | main.pingChart[ 'leaf1' ][ 'expect' ] = True |
| 323 | elif testIndex / 10 == 24: |
| 324 | # CASE243-244 |
| 325 | # Only for 2x2 and 2x4 topology, to test reachability from other leaf |
| 326 | if hasattr( main, "Mininet1" ): |
| 327 | # Update host IP and default GW |
| 328 | main.Mininet1.changeIP( 'h1', 'h1-%s' % defaultIntf, '10.0.6.1', '255.255.255.0' ) |
| 329 | main.Mininet1.changeDefaultGateway( 'h1', '10.0.6.254' ) |
| 330 | # Update port configuration |
| 331 | SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed, |
| 332 | [ '10.0.6.254/24', ], untagged=60 ) |
| 333 | |
| 334 | # Update ping chart in case it is changed |
| 335 | try: |
| 336 | with open( "%s%sCASE%d_after.chart" % (main.configPath, main.forChart, testIndex / 10 * 10 ) ) as chart: |
| 337 | main.pingChart = json.load(chart) |
| 338 | except IOError: |
| 339 | main.log.debug( "Ping chart is not changed" ) |
| 340 | |
| 341 | # Check connectivity after changing interface configuration |
| 342 | run.checkFlows( main, minFlowCount=minFlowCountPerLeaf * topo[ topology ][ 1 ], sleep=5, dumpflows=False ) |
| 343 | run.pingAll( main, '%s_After' % TAG, retryAttempts=2 ) |
| 344 | |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 345 | run.cleanup( main ) |
Jonghwan Hyun | 812c70f | 2018-02-16 16:33:16 -0800 | [diff] [blame] | 346 | |
| 347 | @staticmethod |
| 348 | def updateIntfCfg( main, portNum, dualHomed, ips=[], untagged=0, tagged=[], native=0 ): |
| 349 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as run |
| 350 | run.updateIntfCfg( main, "of:0000000000000001/%d" % portNum, |
| 351 | ips=ips, untagged=untagged, tagged=tagged, native=native ) |
| 352 | if dualHomed: |
| 353 | run.updateIntfCfg( main, "of:0000000000000002/%d" % portNum, |
| 354 | ips=ips, untagged=untagged, tagged=tagged, native=native ) |