blob: 23b7f99b2a9a4910cd0d83577d0e2c92047b6778 [file] [log] [blame]
kelvin-onlaba0ce3222015-01-27 17:25:15 -08001"""
2Description: This test is an example of a simple single node ONOS test
kelvin-onlab97d64e72015-01-28 11:14:55 -08003with 2 different topology on one test test
kelvin-onlaba0ce3222015-01-27 17:25:15 -08004List of test cases:
kelvin-onlab97d64e72015-01-28 11:14:55 -08005CASE1: Compile ONOS and push it to the test machine: Also starts first topology
6CASE2: Assign mastership to controller: first topology
kelvin-onlaba0ce3222015-01-27 17:25:15 -08007CASE3: Pingall
kelvin-onlab97d64e72015-01-28 11:14:55 -08008CASE4: Creates new topology: second topology
9CASE5: Assign mastership to controller: second topology
kelvin-onlaba0ce3222015-01-27 17:25:15 -080010"""
11class Ping2topoExample:
12
13 def __init__( self ):
14 self.default = ''
15
16 def CASE1( self, main ):
17 """
18 CASE1 is to compile ONOS and push it to the test machines
19
20 Startup sequence:
21 git pull
22 mvn clean install
23 onos-package
24 cell <name>
25 onos-verify-cell
26 onos-install -f
27 onos-wait-for-start
28 """
29 desc = "Testing ping all function on two topology in one test run"
30 main.log.report( desc )
31 main.case( "Setting up test environment" )
32
33 # load some vairables from the params file
34 PULLCODE = False
35 if main.params[ 'Git' ] == 'True':
36 PULLCODE = True
37 cellName = main.params[ 'ENV' ][ 'cellName' ]
38
39 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
40
41 main.step( "Applying cell variable to environment" )
42 cellResult = main.ONOSbench.setCell( cellName )
43 verifyResult = main.ONOSbench.verifyCell()
44
45 main.log.report( "Uninstalling ONOS" )
46 main.ONOSbench.onosUninstall( ONOS1Ip )
47
48 cleanInstallResult = main.TRUE
49 gitPullResult = main.TRUE
50
51 main.step( "Compiling the latest version of ONOS" )
52 if PULLCODE:
53 main.step( "Git checkout and pull master" )
54 main.ONOSbench.gitCheckout( "master" )
55 gitPullResult = main.ONOSbench.gitPull()
56
57 main.step( "Using mvn clean & install" )
58 cleanInstallResult = main.TRUE
59 if gitPullResult == main.TRUE:
60 cleanInstallResult = main.ONOSbench.cleanInstall()
61 else:
62 main.log.warn( "Did not pull new code so skipping mvn " +
63 "clean install" )
64 main.ONOSbench.getVersion( report=True )
65
66 cellResult = main.ONOSbench.setCell( cellName )
67 verifyResult = main.ONOSbench.verifyCell()
68 main.step( "Creating ONOS package" )
69 packageResult = main.ONOSbench.onosPackage()
70
71 main.step( "Installing ONOS package" )
72 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
73 node=ONOS1Ip )
74
75 main.step( "Checking if ONOS is up yet" )
76 for i in range( 2 ):
77 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
78 if onos1Isup:
79 break
80 if not onos1Isup:
81 main.log.report( "ONOS1 didn't start!" )
82
83 # TODO: if it becomes an issue, we can retry this step a few times
84
85 cliResult = main.ONOScli1.startOnosCli( ONOS1Ip )
86
87 case1Result = ( cleanInstallResult and packageResult and
88 cellResult and verifyResult and
89 onos1InstallResult and
90 onos1Isup and cliResult )
91
92 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
93 onpass="Test startup successful",
94 onfail="Test startup NOT successful" )
95
96 if case1Result == main.FALSE:
97 main.cleanup()
98 main.exit()
99
kelvin-onlab4576b972015-01-29 16:35:16 -0800100 main.step( "Starting Mininet Topology..." )
kelvin-onlaba0ce3222015-01-27 17:25:15 -0800101 netIsUp = main.Mininet1.startNet()
102 if netIsUp:
kelvin-onlab4576b972015-01-29 16:35:16 -0800103 main.log.info("Mininet topology is up")
kelvin-onlaba0ce3222015-01-27 17:25:15 -0800104 else:
kelvin-onlab4576b972015-01-29 16:35:16 -0800105 main.log.info("Mininet did not start")
kelvin-onlaba0ce3222015-01-27 17:25:15 -0800106
107 def CASE2( self, main ):
108 """
kelvin-onlab97d64e72015-01-28 11:14:55 -0800109 Assign mastership to controller : topology 1 has 13 switches
kelvin-onlaba0ce3222015-01-27 17:25:15 -0800110 """
111 import re
112
113 main.log.report( "Assigning switches to controller" )
114 main.case( "Assigning Controller" )
115 main.step( "Assign switches to controller" )
116
117 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
118 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
119
120 for i in range( 1, 14 ):
121 main.Mininet1.assignSwController(
122 sw=str( i ),
123 ip1=ONOS1Ip,
124 port1=ONOS1Port )
125
126 mastershipCheck = main.TRUE
127 for i in range( 1, 14 ):
128 response = main.Mininet1.getSwController( "s" + str( i ) )
129 try:
130 main.log.info( str( response ) )
131 except:
132 main.log.info( repr( response ) )
133 if re.search( "tcp:" + ONOS1Ip, response ):
134 mastershipCheck = mastershipCheck and main.TRUE
135 else:
136 mastershipCheck = main.FALSE
137 if mastershipCheck == main.TRUE:
138 main.log.report( "Switch mastership assigned correctly" )
139 utilities.assert_equals(
140 expect=main.TRUE,
141 actual=mastershipCheck,
142 onpass="Switch mastership assigned correctly",
143 onfail="Switches not assigned correctly to controllers" )
144
145 def CASE3( self, main ):
146 """
147 Assign intents
148 """
149 import time
150
151 main.log.report( "Run Pingall" )
152 main.case( "Run Pingall" )
153
154 # install onos-app-fwd
155 main.log.info( "Install reactive forwarding app" )
156 main.ONOScli1.featureInstall( "onos-app-fwd" )
157
158 # REACTIVE FWD test
159 pingResult = main.FALSE
160 time1 = time.time()
161 pingResult = main.Mininet1.pingall()
162 time2 = time.time()
163 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
164
165 # uninstall onos-app-fwd
166 main.log.info( "Uninstall reactive forwarding app" )
167 main.ONOScli1.featureUninstall( "onos-app-fwd" )
168
169 utilities.assert_equals( expect=main.TRUE, actual=pingResult,
170 onpass="All hosts are reachable",
171 onfail="Some pings failed" )
172
173 def CASE4( self, main):
174 """
175 Stop mininet and start a new one using different topology
176 """
kelvin-onlab97d64e72015-01-28 11:14:55 -0800177 main.log.info ("Starts new topology")
kelvin-onlaba0ce3222015-01-27 17:25:15 -0800178 main.log.info( "Stopping Mininet..." )
179 main.Mininet1.stopNet()
180
181 main.log.info( "Starting Mininet..." )
182 topoFile = main.params[ 'TOPO1' ][ 'file' ]
183 args = main.params[ 'TOPO1' ][ 'args' ]
184
185 isMnUp = main.FALSE
186 isMnUp = main.Mininet1.startNet(topoFile = topoFile, args = args)
187 utilities.assert_equals(
188 expect=main.TRUE,
189 actual=isMnUp,
190 onpass="New mininet topology is up and runing",
191 onfail="New mininet topology failed to run" )
192
193
194
195 def CASE5( self, main ):
196 """
kelvin-onlab97d64e72015-01-28 11:14:55 -0800197 Assign mastership to controller: topology 2 has 25 switches
kelvin-onlaba0ce3222015-01-27 17:25:15 -0800198 """
199 import re
200
201 main.log.report( "Assigning switches to controller" )
202 main.case( "Assigning Controller" )
203 main.step( "Assign switches to controller" )
204
205 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
206 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
207
kelvin-onlab97d64e72015-01-28 11:14:55 -0800208 for i in range( 1, 26 ):
kelvin-onlaba0ce3222015-01-27 17:25:15 -0800209 main.Mininet1.assignSwController(
210 sw=str( i ),
211 ip1=ONOS1Ip,
212 port1=ONOS1Port )
213
214 mastershipCheck = main.TRUE
kelvin-onlab97d64e72015-01-28 11:14:55 -0800215 for i in range( 1, 26 ):
kelvin-onlaba0ce3222015-01-27 17:25:15 -0800216 response = main.Mininet1.getSwController( "s" + str( i ) )
217 try:
218 main.log.info( str( response ) )
219 except:
220 main.log.info( repr( response ) )
221 if re.search( "tcp:" + ONOS1Ip, response ):
222 mastershipCheck = mastershipCheck and main.TRUE
223 else:
224 mastershipCheck = main.FALSE
225 if mastershipCheck == main.TRUE:
226 main.log.report( "Switch mastership assigned correctly" )
227 utilities.assert_equals(
228 expect=main.TRUE,
229 actual=mastershipCheck,
230 onpass="Switch mastership assigned correctly",
231 onfail="Switches not assigned correctly to controllers" )