Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [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 | ac02b14 | 2018-01-26 14:57:28 -0800 | [diff] [blame] | 22 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as run |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 23 | import tests.USECASE.SegmentRouting.dependencies.cfgtranslator as translator |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 24 | |
| 25 | class SRBridgingTest (): |
| 26 | |
| 27 | def __init__( self ): |
| 28 | self.default = '' |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 29 | self.topo = dict() |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 30 | # TODO: Check minFlowCount of leaf for BMv2 switch |
| 31 | # (number of spine switch, number of leaf switch, dual-homed, description, minFlowCount - leaf (OvS), minFlowCount - leaf (BMv2)) |
| 32 | self.topo[ '0x1' ] = ( 0, 1, False, 'single ToR', 28, 28 ) |
| 33 | self.topo[ '0x2' ] = ( 0, 2, True, 'dual-homed ToR', 37, 37 ) |
| 34 | self.topo[ '2x2' ] = ( 2, 2, False, '2x2 leaf-spine topology', 37, 32 ) |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 35 | # TODO: Implement 2x3 topology |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 36 | # topo[ '2x3' ] = ( 2, 3, True, '2x3 leaf-spine topology with dual ToR and single ToR', 28 ) |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 37 | self.topo[ '2x4' ] = ( 2, 4, True, '2x4 dual-homed leaf-spine topology', 53, 53 ) |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 38 | self.switchNames = {} |
| 39 | self.switchNames[ '2x2' ] = [ "leaf1", "leaf2", "spine101", "spine102" ] |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 40 | |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 41 | def runTest( self, main, test_idx, topology, onosNodes, description, vlan = [] ): |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 42 | skipPackage = False |
| 43 | init = False |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 44 | if not hasattr( main, 'apps' ): |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 45 | init = True |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 46 | run.initTest( main ) |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 47 | # Skip onos packaging if the clusrer size stays the same |
| 48 | if not init and onosNodes == main.Cluster.numCtrls: |
| 49 | skipPackage = True |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 50 | |
| 51 | main.case( '%s, with %s and %d ONOS instance%s' % |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 52 | ( description, self.topo[ topology ][ 3 ], onosNodes, 's' if onosNodes > 1 else '' ) ) |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 53 | |
| 54 | main.cfgName = 'CASE%01d%01d' % ( test_idx / 10, ( ( test_idx - 1 ) % 10 ) % 4 + 1 ) |
| 55 | main.Cluster.setRunningNode( onosNodes ) |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 56 | run.installOnos( main, skipPackage=skipPackage, cliSleep=5 ) |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 57 | if main.useBmv2: |
| 58 | # Translate configuration file from OVS-OFDPA to BMv2 driver |
| 59 | translator.ofdpaToBmv2( main ) |
| 60 | else: |
| 61 | translator.bmv2ToOfdpa( main ) |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 62 | run.loadJson( main ) |
| 63 | run.loadChart( main ) |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 64 | if hasattr( main, 'Mininet1' ): |
Jon Hall | dac3eae | 2020-06-05 12:04:06 -0700 | [diff] [blame^] | 65 | if 'MN_DOCKER' in main.params and main.params['MN_DOCKER']['args']: |
| 66 | main.log.info( "Creating Mininet Docker" ) |
| 67 | main.Mininet1.dockerPrompt = '#' |
| 68 | # Start docker container |
| 69 | handle = main.Mininet1.handle |
| 70 | handle.sendline( "docker run %s %s" % ( main.params[ 'MN_DOCKER' ][ 'args' ], main.params[ 'MN_DOCKER' ][ 'name' ] ) ) |
| 71 | handle.expect( main.Mininet1.bashPrompt ) |
| 72 | output = handle.before + handle.after |
| 73 | main.log.debug( repr(output) ) |
| 74 | startStr = main.params[ 'MN_DOCKER' ][ 'name' ] |
| 75 | endStr = main.Mininet1.user_name |
| 76 | start = output.find( startStr ) + len( startStr ) |
| 77 | end = output.find( endStr ) |
| 78 | containerId = output[start:end].strip() |
| 79 | main.log.debug( repr( containerId ) ) |
| 80 | |
| 81 | handle = main.Mininet1.handle |
| 82 | handle.sendline( "docker attach %s " % containerId ) # Strip? |
| 83 | handle.expect( main.Mininet1.dockerPrompt ) |
| 84 | main.log.debug( handle.before + handle.after ) |
| 85 | # We should be good to go |
| 86 | main.Mininet1.prompt = main.Mininet1.dockerPrompt |
| 87 | main.Mininet1.sudoRequired = False |
| 88 | |
| 89 | |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 90 | # Run the test with Mininet |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 91 | mininet_args = ' --spine=%d --leaf=%d' % ( self.topo[ topology ][ 0 ], self.topo[ topology ][ 1 ] ) |
| 92 | if self.topo[ topology ][ 2 ]: |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 93 | mininet_args += ' --dual-homed' |
| 94 | if len( vlan ) > 0 : |
| 95 | mininet_args += ' --vlan=%s' % ( ','.join( ['%d' % vlanId for vlanId in vlan ] ) ) |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 96 | if main.useBmv2: |
Jon Hall | dac3eae | 2020-06-05 12:04:06 -0700 | [diff] [blame^] | 97 | switchType = main.params[ 'DEPENDENCY' ].get( 'bmv2SwitchType', 'stratum' ) |
| 98 | mininet_args += ' --switch %s' % switchType |
| 99 | main.log.info( "Using %s switch" % switchType ) |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 100 | |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 101 | run.startMininet( main, 'trellis_fabric.py', args=mininet_args ) |
Jon Hall | dac3eae | 2020-06-05 12:04:06 -0700 | [diff] [blame^] | 102 | |
| 103 | if main.useBmv2: |
| 104 | filename = "onos-netcfg.json" |
| 105 | for switch in main.Mininet1.getSwitches(switchRegex=r"(StratumBmv2Switch)|(Bmv2Switch)").keys(): |
| 106 | path = "/tmp/mn-stratum/%s/" % switch |
| 107 | main.ONOSbench1.handle.sendline( "sudo sed -i 's/localhost/%s/g' %s%s" % ( main.Mininet1.ip_address, path, filename ) ) |
| 108 | main.ONOSbench1.handle.expect( main.ONOSbench1.prompt ) |
| 109 | main.log.debug( main.ONOSbench1.handle.before + main.ONOSbench1.handle.after ) |
| 110 | main.ONOSbench1.handle.sendline( "sudo sed -i 's/device:%s/device:bmv2:%s/g' %s%s" % ( switch, switch, path, filename ) ) |
| 111 | main.ONOSbench1.handle.expect( main.ONOSbench1.prompt ) |
| 112 | main.log.debug( main.ONOSbench1.handle.before + main.ONOSbench1.handle.after ) |
| 113 | main.ONOSbench1.onosNetCfg( main.ONOSserver1.ip_address, path, filename ) |
| 114 | |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 115 | else: |
| 116 | # Run the test with physical devices |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 117 | run.connectToPhysicalNetwork( main, self.switchNames[ topology ] ) |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 118 | |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 119 | run.checkFlows( main, minFlowCount=self.topo[ topology ][ 5 if main.useBmv2 else 4 ] * self.topo[ topology ][ 1 ], sleep=5 ) |
| 120 | if main.useBmv2: |
| 121 | leaf_dpid = [ "device:bmv2:leaf%d" % ( ls + 1 ) for ls in range( self.topo[ topology ][ 1 ]) ] |
| 122 | else: |
| 123 | leaf_dpid = [ "of:%016d" % ( ls + 1 ) for ls in range( self.topo[ topology ][ 1 ] ) ] |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 124 | for dpid in leaf_dpid: |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 125 | run.checkFlowsByDpid( main, dpid, self.topo[ topology ][ 5 if main.useBmv2 else 4 ], sleep=5 ) |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 126 | run.pingAll( main ) |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 127 | |
You Wang | 5df1c6d | 2018-04-06 18:02:02 -0700 | [diff] [blame] | 128 | run.cleanup( main ) |
Jon Hall | dac3eae | 2020-06-05 12:04:06 -0700 | [diff] [blame^] | 129 | if 'MN_DOCKER' in main.params and main.params['MN_DOCKER']['args']: |
| 130 | main.log.info( "Deleting Mininet Docker" ) |
| 131 | |
| 132 | # Detach from container |
| 133 | handle = main.Mininet1.handle |
| 134 | try: |
| 135 | handle.sendline( "exit" ) # ctrl-p ctrk-q to detach from container |
| 136 | import time |
| 137 | time.sleep(5) |
| 138 | handle.expect( main.Mininet1.dockerPrompt ) |
| 139 | main.log.debug( handle.before + handle.after ) |
| 140 | main.Mininet1.prompt = main.Mininet1.bashPrompt |
| 141 | handle.expect( main.Mininet1.prompt ) |
| 142 | main.log.debug( handle.before + handle.after ) |
| 143 | main.Mininet1.sudoRequired = True |
| 144 | except Exception as e: |
| 145 | main.log.error( e ) |
| 146 | |
| 147 | # We should be good to go |