blob: f5a7dfb2cb29013e6b0e6ac0ea4f06a8f950ed32 [file] [log] [blame]
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -08001"""
2Copyright 2017 Open Networking Foundation ( ONF )
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or 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
22from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as run
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -080023import time
Jon Hall3c910162018-03-07 14:42:16 -080024import json
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080025
26class SRRoutingTest ():
27
28 topo = {}
29
30 def __init__( self ):
31 self.default = ''
32
33 @staticmethod
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -080034 def runTest( main, test_idx, onosNodes, dhcp, routers, ipv4, ipv6,
35 description, countFlowsGroups=False, checkExternalHost=False,
Jon Hall3c910162018-03-07 14:42:16 -080036 staticRouteConfigure=False, switchFailure=False, linkFailure=False,
37 nodeFailure=False ):
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080038
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
Devin Lim57221b02018-02-14 15:45:36 -080049 main.case( '%s, ONOS instance%s' % ( description, onosNodes ) )
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080050
51 main.cfgName = 'COMCAST_CONFIG_ipv4=%d_ipv6=%d_dhcp=%d_routers=%d' % \
Devin Lim57221b02018-02-14 15:45:36 -080052 ( ipv4, ipv6, dhcp, routers )
You Wangba231e72018-03-01 13:18:21 -080053 if checkExternalHost:
54 main.cfgName += '_external=1'
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -080055 if staticRouteConfigure:
56 main.cfgName += '_static=1'
57
Jon Hall3c910162018-03-07 14:42:16 -080058 main.resultFileName = 'CASE%03d' % test_idx
Devin Lim57221b02018-02-14 15:45:36 -080059 main.Cluster.setRunningNode( onosNodes )
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080060
Devin Lim57221b02018-02-14 15:45:36 -080061 run.installOnos( main, skipPackage=skipPackage, cliSleep=5,
62 parallel=False )
You Wang27317572018-03-06 12:13:11 -080063
64 # Load configuration files
Devin Lim57221b02018-02-14 15:45:36 -080065 run.loadJson( main )
66 run.loadChart( main )
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080067
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -080068 # if static route flag add routes
69 # these routes are topology specific
70 if (staticRouteConfigure):
71 if (ipv4):
72 run.addStaticOnosRoute( main, "10.0.88.0/24", "10.0.1.1")
73 if (ipv6):
74 run.addStaticOnosRoute( main, "2000::8700/120", "2000::101")
75
You Wang27317572018-03-06 12:13:11 -080076 if countFlowsGroups:
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -080077 run.loadCount( main )
You Wang27317572018-03-06 12:13:11 -080078 if switchFailure:
79 run.loadSwitchFailureChart( main )
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -080080 if linkFailure:
81 run.loadLinkFailureChart( main )
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -080082
You Wang27317572018-03-06 12:13:11 -080083 # wait some time
Devin Lim57221b02018-02-14 15:45:36 -080084 time.sleep( 5 )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -080085
Devin Lim57221b02018-02-14 15:45:36 -080086 if hasattr( main, 'Mininet1' ):
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080087 # Run the test with Mininet
Devin Lim57221b02018-02-14 15:45:36 -080088 mininet_args = ' --dhcp=%s --routers=%s --ipv6=%s --ipv4=%s' % ( dhcp, routers, ipv6, ipv4 )
89 run.startMininet( main, 'comcast_fabric.py', args=mininet_args )
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080090 else:
91 # Run the test with physical devices
92 # TODO: connect TestON to the physical network
93 pass
94
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -080095 # wait some time for onos to install the rules!
Devin Lim57221b02018-02-14 15:45:36 -080096 time.sleep( 25 )
Andreas Pantelopoulos971c91d2018-02-12 11:28:10 -080097
Devin Lim57221b02018-02-14 15:45:36 -080098 if ( dhcp ):
99 time.sleep( 60 )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800100
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -0800101 # ping hosts
Jon Hall3c910162018-03-07 14:42:16 -0800102 run.pingAll( main, 'CASE%03d' % test_idx, acceptableFailed=5, basedOnIp=True )
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800103
104 # check flows / groups numbers
You Wang27317572018-03-06 12:13:11 -0800105 if countFlowsGroups:
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800106 run.checkFlowsGroupsFromFile(main)
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -0800107
You Wang27317572018-03-06 12:13:11 -0800108 # Test switch failures
109 if switchFailure:
110 for switch, expected in main.switchFailureChart.items():
111 run.killSwitch( main, switch, expected['switches_after_failure'], expected['links_after_failure'] )
Jon Hall3c910162018-03-07 14:42:16 -0800112 run.pingAll( main, 'CASE%03d' % test_idx, acceptableFailed=5, basedOnIp=True )
You Wang27317572018-03-06 12:13:11 -0800113 if countFlowsGroups:
114 run.checkFlowsGroupsFromFile(main)
115 run.recoverSwitch( main, switch, expected['switches_before_failure'], expected['links_before_failure'] )
Jon Hall3c910162018-03-07 14:42:16 -0800116 run.pingAll( main, 'CASE%03d' % test_idx, acceptableFailed=5, basedOnIp=True )
You Wang27317572018-03-06 12:13:11 -0800117 if countFlowsGroups:
118 run.checkFlowsGroupsFromFile(main)
119
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800120 # Test link failures
121 if linkFailure:
122 for link_batch_name, info in main.linkFailureChart.items():
123
124 linksToRemove = info['links'].values()
125 linksBefore = info['links_before']
126 linksAfter = info['links_after']
127
128 run.killLinkBatch( main, linksToRemove, linksAfter )
Jon Hall3c910162018-03-07 14:42:16 -0800129 run.pingAll( main, 'CASE%03d' % test_idx, acceptableFailed=5, basedOnIp=True )
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800130
131 run.restoreLinkBatch( main, linksToRemove, linksBefore )
Jon Hall3c910162018-03-07 14:42:16 -0800132 run.pingAll( main, 'CASE%03d' % test_idx, acceptableFailed=5, basedOnIp=True )
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800133 if countFlowsGroups:
134 run.checkFlowsGroupsFromFile(main)
135
Jon Hall3c910162018-03-07 14:42:16 -0800136 # Test node failures
137 if nodeFailure:
138 numCtrls = len( main.Cluster.runningNodes )
139 links = len( json.loads( main.Cluster.next().links() ) )
140 switches = len( json.loads( main.Cluster.next().devices() ) )
141 for ctrl in xrange( numCtrls ):
Jon Halldd246642018-03-08 15:02:59 -0800142 # Kill node
Jon Hall3c910162018-03-07 14:42:16 -0800143 run.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) )
Jon Halldd246642018-03-08 15:02:59 -0800144 time.sleep( float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) )
Jon Hall3c910162018-03-07 14:42:16 -0800145 main.Cluster.active(0).CLI.balanceMasters()
Jon Halldd246642018-03-08 15:02:59 -0800146 time.sleep( float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) )
Jon Hall3c910162018-03-07 14:42:16 -0800147 run.pingAll( main, 'CASE%03d' % test_idx, acceptableFailed=5, basedOnIp=True )
148 if countFlowsGroups:
149 run.checkFlowsGroupsFromFile( main )
150
Jon Halldd246642018-03-08 15:02:59 -0800151 # Recover node
Jon Hall3c910162018-03-07 14:42:16 -0800152 run.recoverOnos( main, [ ctrl ], switches, links, numCtrls )
Jon Halldd246642018-03-08 15:02:59 -0800153 time.sleep( float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) )
Jon Hall3c910162018-03-07 14:42:16 -0800154 main.Cluster.active(0).CLI.balanceMasters()
Jon Halldd246642018-03-08 15:02:59 -0800155 time.sleep( float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) )
Jon Hall3c910162018-03-07 14:42:16 -0800156 run.pingAll( main, 'CASE%03d' % test_idx, acceptableFailed=5, basedOnIp=True )
157 if countFlowsGroups:
158 run.checkFlowsGroupsFromFile( main )
159
160 # Cleanup
Devin Lim57221b02018-02-14 15:45:36 -0800161 if hasattr( main, 'Mininet1' ):
162 run.cleanup( main )
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -0800163 else:
164 # TODO: disconnect TestON from the physical network
165 pass