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 | |
| 22 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as run |
Andreas Pantelopoulos | f6ed501 | 2018-02-08 21:26:01 -0800 | [diff] [blame] | 23 | import time |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 24 | import json |
Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 25 | |
| 26 | class SRRoutingTest (): |
| 27 | |
| 28 | topo = {} |
| 29 | |
| 30 | def __init__( self ): |
| 31 | self.default = '' |
| 32 | |
| 33 | @staticmethod |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 34 | def runTest( main, test_idx, onosNodes, dhcp, routers, ipv4, ipv6, |
| 35 | description, countFlowsGroups=False, checkExternalHost=False, |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 36 | staticRouteConfigure=False, switchFailure=False, linkFailure=False, |
| 37 | nodeFailure=False ): |
Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 38 | |
| 39 | skipPackage = False |
| 40 | init = False |
| 41 | if not hasattr( main, 'apps' ): |
| 42 | init = True |
| 43 | run.initTest( main ) |
| 44 | |
| 45 | # Skip onos packaging if the cluster size stays the same |
| 46 | if not init and onosNodes == main.Cluster.numCtrls: |
| 47 | skipPackage = True |
| 48 | |
Jon Hall | 098c0bf | 2018-03-23 14:15:04 -0700 | [diff] [blame] | 49 | main.case( '%s, ONOS cluster size: %s' % ( description, onosNodes ) ) |
Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 50 | |
| 51 | main.cfgName = 'COMCAST_CONFIG_ipv4=%d_ipv6=%d_dhcp=%d_routers=%d' % \ |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 52 | ( ipv4, ipv6, dhcp, routers ) |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 53 | if checkExternalHost: |
| 54 | main.cfgName += '_external=1' |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 55 | if staticRouteConfigure: |
| 56 | main.cfgName += '_static=1' |
| 57 | |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 58 | main.resultFileName = 'CASE%03d' % test_idx |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 59 | main.Cluster.setRunningNode( onosNodes ) |
Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 60 | |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 61 | run.installOnos( main, skipPackage=skipPackage, cliSleep=5, |
| 62 | parallel=False ) |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 63 | |
| 64 | # Load configuration files |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 65 | run.loadJson( main ) |
| 66 | run.loadChart( main ) |
You Wang | 86abda1 | 2018-03-09 18:10:54 -0800 | [diff] [blame] | 67 | run.loadHost( main ) |
Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 68 | |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 69 | # if static route flag add routes |
| 70 | # these routes are topology specific |
| 71 | if (staticRouteConfigure): |
| 72 | if (ipv4): |
| 73 | run.addStaticOnosRoute( main, "10.0.88.0/24", "10.0.1.1") |
| 74 | if (ipv6): |
| 75 | run.addStaticOnosRoute( main, "2000::8700/120", "2000::101") |
| 76 | |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 77 | if countFlowsGroups: |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 78 | run.loadCount( main ) |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 79 | if switchFailure: |
| 80 | run.loadSwitchFailureChart( main ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 81 | if linkFailure: |
| 82 | run.loadLinkFailureChart( main ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 83 | |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 84 | # wait some time |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 85 | time.sleep( 5 ) |
Andreas Pantelopoulos | f6ed501 | 2018-02-08 21:26:01 -0800 | [diff] [blame] | 86 | |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 87 | if hasattr( main, 'Mininet1' ): |
Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 88 | # Run the test with Mininet |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 89 | mininet_args = ' --dhcp=%s --routers=%s --ipv6=%s --ipv4=%s' % ( dhcp, routers, ipv6, ipv4 ) |
| 90 | run.startMininet( main, 'comcast_fabric.py', args=mininet_args ) |
Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 91 | else: |
| 92 | # Run the test with physical devices |
| 93 | # TODO: connect TestON to the physical network |
| 94 | pass |
| 95 | |
Andreas Pantelopoulos | f6ed501 | 2018-02-08 21:26:01 -0800 | [diff] [blame] | 96 | # wait some time for onos to install the rules! |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 97 | time.sleep( 25 ) |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 98 | if ( dhcp ): |
| 99 | time.sleep( 60 ) |
Andreas Pantelopoulos | f6ed501 | 2018-02-08 21:26:01 -0800 | [diff] [blame] | 100 | |
You Wang | 86abda1 | 2018-03-09 18:10:54 -0800 | [diff] [blame] | 101 | SRRoutingTest.runChecks( main, test_idx, countFlowsGroups ) |
Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 102 | |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 103 | # Test switch failures |
| 104 | if switchFailure: |
| 105 | for switch, expected in main.switchFailureChart.items(): |
Jon Hall | 098c0bf | 2018-03-23 14:15:04 -0700 | [diff] [blame] | 106 | main.step( "Killing switch {}" % switch ) |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 107 | run.killSwitch( main, switch, expected['switches_after_failure'], expected['links_after_failure'] ) |
You Wang | 86abda1 | 2018-03-09 18:10:54 -0800 | [diff] [blame] | 108 | SRRoutingTest.runChecks( main, test_idx, countFlowsGroups ) |
| 109 | |
Jon Hall | 098c0bf | 2018-03-23 14:15:04 -0700 | [diff] [blame] | 110 | main.step( "Restoring switch {}" % switch ) |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 111 | run.recoverSwitch( main, switch, expected['switches_before_failure'], expected['links_before_failure'] ) |
You Wang | 86abda1 | 2018-03-09 18:10:54 -0800 | [diff] [blame] | 112 | SRRoutingTest.runChecks( main, test_idx, countFlowsGroups ) |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 113 | |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 114 | # Test link failures |
| 115 | if linkFailure: |
| 116 | for link_batch_name, info in main.linkFailureChart.items(): |
| 117 | |
| 118 | linksToRemove = info['links'].values() |
| 119 | linksBefore = info['links_before'] |
| 120 | linksAfter = info['links_after'] |
| 121 | |
Jon Hall | 098c0bf | 2018-03-23 14:15:04 -0700 | [diff] [blame] | 122 | main.step( "Killing links {}" % linksToRemove ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 123 | run.killLinkBatch( main, linksToRemove, linksAfter ) |
You Wang | 86abda1 | 2018-03-09 18:10:54 -0800 | [diff] [blame] | 124 | SRRoutingTest.runChecks( main, test_idx, countFlowsGroups ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 125 | |
Jon Hall | 098c0bf | 2018-03-23 14:15:04 -0700 | [diff] [blame] | 126 | main.step( "Restoring links {}" % linksToRemove ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 127 | run.restoreLinkBatch( main, linksToRemove, linksBefore ) |
You Wang | 86abda1 | 2018-03-09 18:10:54 -0800 | [diff] [blame] | 128 | SRRoutingTest.runChecks( main, test_idx, countFlowsGroups ) |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 129 | |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 130 | # Test node failures |
| 131 | if nodeFailure: |
| 132 | numCtrls = len( main.Cluster.runningNodes ) |
| 133 | links = len( json.loads( main.Cluster.next().links() ) ) |
| 134 | switches = len( json.loads( main.Cluster.next().devices() ) ) |
| 135 | for ctrl in xrange( numCtrls ): |
Jon Hall | dd24664 | 2018-03-08 15:02:59 -0800 | [diff] [blame] | 136 | # Kill node |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 137 | run.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) ) |
Jon Hall | dd24664 | 2018-03-08 15:02:59 -0800 | [diff] [blame] | 138 | time.sleep( float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) ) |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 139 | main.Cluster.active(0).CLI.balanceMasters() |
Jon Hall | dd24664 | 2018-03-08 15:02:59 -0800 | [diff] [blame] | 140 | time.sleep( float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) ) |
You Wang | 86abda1 | 2018-03-09 18:10:54 -0800 | [diff] [blame] | 141 | SRRoutingTest.runChecks( main, test_idx, countFlowsGroups ) |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 142 | |
Jon Hall | dd24664 | 2018-03-08 15:02:59 -0800 | [diff] [blame] | 143 | # Recover node |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 144 | run.recoverOnos( main, [ ctrl ], switches, links, numCtrls ) |
Jon Hall | dd24664 | 2018-03-08 15:02:59 -0800 | [diff] [blame] | 145 | time.sleep( float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) ) |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 146 | main.Cluster.active(0).CLI.balanceMasters() |
Jon Hall | dd24664 | 2018-03-08 15:02:59 -0800 | [diff] [blame] | 147 | time.sleep( float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) ) |
You Wang | 86abda1 | 2018-03-09 18:10:54 -0800 | [diff] [blame] | 148 | SRRoutingTest.runChecks( main, test_idx, countFlowsGroups ) |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 149 | |
| 150 | # Cleanup |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 151 | if hasattr( main, 'Mininet1' ): |
| 152 | run.cleanup( main ) |
Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 153 | else: |
| 154 | # TODO: disconnect TestON from the physical network |
| 155 | pass |
You Wang | 86abda1 | 2018-03-09 18:10:54 -0800 | [diff] [blame] | 156 | |
| 157 | @staticmethod |
| 158 | def runChecks( main, test_idx, countFlowsGroups ): |
| 159 | # Verify host IP assignment |
| 160 | run.verifyOnosHostIp( main ) |
| 161 | run.verifyNetworkHostIp( main ) |
| 162 | # check flows / groups numbers |
| 163 | if countFlowsGroups: |
| 164 | run.checkFlowsGroupsFromFile( main ) |
| 165 | # ping hosts |
| 166 | run.pingAll( main, 'CASE%03d' % test_idx, acceptableFailed=5, basedOnIp=True ) |