kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 1 | |
| 2 | # Testing the basic functionality of ONOS Next |
| 3 | # For sanity and driver functionality excercises only. |
| 4 | |
| 5 | import time |
| 6 | import json |
| 7 | |
| 8 | time.sleep( 1 ) |
| 9 | |
| 10 | class SingleFunc: |
| 11 | |
| 12 | def __init__( self ): |
| 13 | self.default = '' |
| 14 | |
| 15 | def CASE10( self, main ): |
| 16 | import time |
| 17 | import os |
| 18 | """ |
| 19 | Startup sequence: |
| 20 | cell <name> |
| 21 | onos-verify-cell |
| 22 | onos-remove-raft-log |
| 23 | git pull |
| 24 | mvn clean install |
| 25 | onos-package |
| 26 | onos-install -f |
| 27 | onos-wait-for-start |
| 28 | """ |
| 29 | #Local variables |
| 30 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 31 | main.ONOS1ip = os.environ[ 'OC1' ] |
| 32 | main.ONOS1port = main.params[ 'CTRL' ][ 'port1' ] |
| 33 | main.numSwitch = int( main.params[ 'MININET' ][ 'switch' ] ) |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame^] | 34 | main.numLinks = int( main.params[ 'MININET' ][ 'links' ] ) |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 35 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
| 36 | topology = main.params[ 'MININET' ][ 'topo' ] |
| 37 | PULLCODE = False |
| 38 | if main.params[ 'GIT' ][ 'pull' ] == 'True': |
| 39 | PULLCODE = True |
| 40 | main.case( "Setting up test environment" ) |
| 41 | |
| 42 | main.step( "Apply cell to environment" ) |
| 43 | cellResult = main.ONOSbench.setCell( cellName ) |
| 44 | verifyResult = main.ONOSbench.verifyCell() |
| 45 | stepResult = cellResult and verifyResult |
| 46 | utilities.assert_equals( expect=main.TRUE, |
| 47 | actual=stepResult, |
| 48 | onpass="Successfully applied cell to " + \ |
| 49 | "environment", |
| 50 | onfail="Failed to apply cell to environment " ) |
| 51 | """main.step( "Removing raft logs" ) |
| 52 | removeRaftResult = main.ONOSbench.onosRemoveRaftLogs() |
| 53 | stepResult = removeRaftResult |
| 54 | utilities.assert_equals( expect=main.TRUE, |
| 55 | actual=stepResult, |
| 56 | onpass="Successfully removed raft logs", |
| 57 | onfail="Failed to remove raft logs" ) |
| 58 | """ |
| 59 | if PULLCODE: |
| 60 | main.step( "Git checkout and pull " + gitBranch ) |
| 61 | main.ONOSbench.gitCheckout( gitBranch ) |
| 62 | gitPullResult = main.ONOSbench.gitPull() |
| 63 | if gitPullResult == main.ERROR: |
| 64 | main.log.error( "Error pulling git branch" ) |
| 65 | main.step( "Using mvn clean & install" ) |
| 66 | cleanInstallResult = main.ONOSbench.cleanInstall() |
| 67 | stepResult = cleanInstallResult |
| 68 | utilities.assert_equals( expect=main.TRUE, |
| 69 | actual=stepResult, |
| 70 | onpass="Successfully compiled latest ONOS", |
| 71 | onfail="Failed to compile latest ONOS" ) |
| 72 | else: |
| 73 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 74 | "clean install" ) |
| 75 | |
| 76 | main.step( "Creating ONOS package" ) |
| 77 | packageResult = main.ONOSbench.onosPackage() |
| 78 | stepResult = packageResult |
| 79 | utilities.assert_equals( expect=main.TRUE, |
| 80 | actual=stepResult, |
| 81 | onpass="Successfully created ONOS package", |
| 82 | onfail="Failed to create ONOS package" ) |
| 83 | |
| 84 | main.step( "Uninstalling ONOS package" ) |
| 85 | onosUninstallResult = main.ONOSbench.onosUninstall( |
| 86 | nodeIp=main.ONOS1ip ) |
| 87 | stepResult = onosUninstallResult |
| 88 | utilities.assert_equals( expect=main.TRUE, |
| 89 | actual=stepResult, |
| 90 | onpass="Successfully uninstalled ONOS package", |
| 91 | onfail="Failed to uninstall ONOS package" ) |
| 92 | time.sleep( 5 ) |
| 93 | main.step( "Installing ONOS package" ) |
| 94 | onosInstallResult = main.ONOSbench.onosInstall( node=main.ONOS1ip ) |
| 95 | stepResult = onosInstallResult |
| 96 | utilities.assert_equals( expect=main.TRUE, |
| 97 | actual=stepResult, |
| 98 | onpass="Successfully installed ONOS package", |
| 99 | onfail="Failed to install ONOS package" ) |
| 100 | |
| 101 | main.step( "Starting ONOS service" ) |
| 102 | stopResult = main.TRUE |
| 103 | startResult = main.TRUE |
| 104 | onosIsUp = main.ONOSbench.isup() |
| 105 | if onosIsUp == main.TRUE: |
| 106 | main.log.report( "ONOS instance is up and ready" ) |
| 107 | else: |
| 108 | main.log.report( "ONOS instance may not be up, stop and " + |
| 109 | "start ONOS again " ) |
| 110 | stopResult = main.ONOSbench.onosStop( main.ONOS1ip ) |
| 111 | startResult = main.ONOSbench.onosStart( main.ONOS1ip ) |
| 112 | stepResult = onosIsUp and stopResult and startResult |
| 113 | utilities.assert_equals( expect=main.TRUE, |
| 114 | actual=stepResult, |
| 115 | onpass="ONOS service is ready", |
| 116 | onfail="ONOS service did not start properly" ) |
| 117 | |
| 118 | main.step( "Starting Mininet Topology" ) |
| 119 | topoResult = main.Mininet1.startNet( topoFile=topology ) |
| 120 | stepResult = topoResult |
| 121 | utilities.assert_equals( expect=main.TRUE, |
| 122 | actual=stepResult, |
| 123 | onpass="Successfully loaded topology", |
| 124 | onfail="Failed to load topology" ) |
| 125 | # Exit if topology did not load properly |
| 126 | if not topoResult: |
| 127 | main.cleanup() |
| 128 | main.exit() |
| 129 | |
| 130 | main.step( "Start ONOS cli" ) |
| 131 | cliResult = main.ONOScli1.startOnosCli( ONOSIp=main.ONOS1ip ) |
| 132 | stepResult = cliResult |
| 133 | utilities.assert_equals( expect=main.TRUE, |
| 134 | actual=stepResult, |
| 135 | onpass="Successfully start ONOS cli", |
| 136 | onfail="Failed to start ONOS cli" ) |
| 137 | |
| 138 | def CASE11( self, main ): |
| 139 | """ |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame^] | 140 | Assign mastership to controllers |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 141 | """ |
kelvin-onlab | 5cbf999 | 2015-05-05 14:34:07 -0700 | [diff] [blame] | 142 | import re |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 143 | main.log.report( "Assigning switches to controllers" ) |
| 144 | main.log.case( "Assigning swithes to controllers" ) |
| 145 | |
| 146 | main.step( "Assigning switches to controllers" ) |
| 147 | assignResult = main.TRUE |
kelvin-onlab | 5cbf999 | 2015-05-05 14:34:07 -0700 | [diff] [blame] | 148 | for i in range( 1, ( main.numSwitch + 1 ) ): |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 149 | main.Mininet1.assignSwController( sw=str( i ), |
| 150 | count=1, |
kelvin-onlab | 5cbf999 | 2015-05-05 14:34:07 -0700 | [diff] [blame] | 151 | ip1=main.ONOS1ip, |
| 152 | port1=main.ONOS1port ) |
| 153 | for i in range( 1, ( main.numSwitch + 1 ) ): |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 154 | response = main.Mininet1.getSwController( "s" + str( i ) ) |
| 155 | print( "Response is " + str( response ) ) |
kelvin-onlab | 5cbf999 | 2015-05-05 14:34:07 -0700 | [diff] [blame] | 156 | if re.search( "tcp:" + main.ONOS1ip, response ): |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 157 | assignResult = assignResult and main.TRUE |
| 158 | else: |
| 159 | assignResult = main.FALSE |
| 160 | stepResult = assignResult |
| 161 | utilities.assert_equals( expect=main.TRUE, |
| 162 | actual=stepResult, |
| 163 | onpass="Successfully assigned switches" + |
| 164 | "to controller", |
| 165 | onfail="Failed to assign switches to " + |
| 166 | "controller" ) |
| 167 | |
kelvin-onlab | 7c577e8 | 2015-05-07 10:45:16 -0700 | [diff] [blame] | 168 | |
| 169 | def CASE1000( self, main ): |
| 170 | """ |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame^] | 171 | Add host intents between 2 host: |
| 172 | - Discover hosts |
| 173 | - Add host intents |
| 174 | - Check intents |
| 175 | - Check flows |
| 176 | - Ping hosts |
| 177 | - Reroute |
| 178 | - Link down |
| 179 | - Ping hosts |
| 180 | - Link up |
| 181 | - Ping hosts |
| 182 | - Remove intents |
kelvin-onlab | 7c577e8 | 2015-05-07 10:45:16 -0700 | [diff] [blame] | 183 | """ |
| 184 | import time |
| 185 | import json |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame^] | 186 | import re |
| 187 | """ |
| 188 | Create your item(s) here |
| 189 | item = { 'name': '', 'host1': |
| 190 | { 'name': '', 'MAC': '00:00:00:00:00:0X', |
| 191 | 'id':'00:00:00:00:00:0X/-X' } , 'host2': |
| 192 | { 'name': '', 'MAC': '00:00:00:00:00:0X', |
| 193 | 'id':'00:00:00:00:00:0X/-X'}, 'link': { 'switch1': '', |
| 194 | 'switch2': '', 'num':'' } } |
| 195 | """ |
| 196 | # Local variables |
| 197 | items = [] |
| 198 | ipv4 = { 'name': 'IPV4', 'host1': |
| 199 | { 'name': 'h1', 'MAC': '00:00:00:00:00:01', |
| 200 | 'id':'00:00:00:00:00:01/-1' } , 'host2': |
| 201 | { 'name': 'h9', 'MAC': '00:00:00:00:00:09', |
| 202 | 'id':'00:00:00:00:00:01/-1'}, 'link': { 'switch1': 's5', |
| 203 | 'switch2': 's2', 'num':'18' } } |
| 204 | dualStack1 = { 'name': 'DUALSTACK1', 'host1': |
| 205 | { 'name': 'h3', 'MAC': '00:00:00:00:00:03', |
| 206 | 'id':'00:00:00:00:00:03/-1' } , 'host2': |
| 207 | { 'name': '', 'MAC': '00:00:00:00:00:0B', |
| 208 | 'id':'00:00:00:00:00:0B/-1'}, 'link': { 'switch1': 's5', |
| 209 | 'switch2': 's2', 'num':'18' } } |
| 210 | items.append( ipv4 ) |
| 211 | # Global variables |
kelvin-onlab | 7c577e8 | 2015-05-07 10:45:16 -0700 | [diff] [blame] | 212 | |
kelvin-onlab | 7c577e8 | 2015-05-07 10:45:16 -0700 | [diff] [blame] | 213 | main.case( "Add host intents between 2 host" ) |
kelvin-onlab | 7c577e8 | 2015-05-07 10:45:16 -0700 | [diff] [blame] | 214 | |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame^] | 215 | for item in items: |
| 216 | stepResult = main.TRUE |
| 217 | h1Name = item[ 'host1' ][ 'name' ] |
| 218 | h2Name = item[ 'host2' ][ 'name' ] |
| 219 | h1Mac = item[ 'host1' ][ 'MAC' ] |
| 220 | h2Mac = item[ 'host2' ][ 'MAC' ] |
| 221 | h1Id = item[ 'host1' ][ 'id'] |
| 222 | h2Id = item[ 'host2' ][ 'id'] |
| 223 | # Link down/up for rerouting |
| 224 | sw1 = item[ 'link' ][ 'switch1' ] |
| 225 | sw2 = item[ 'link' ][ 'switch2' ] |
| 226 | remLink = item[ 'link' ][ 'num' ] |
| 227 | intentsId = [] |
| 228 | main.step( item[ 'name' ] + ": Add host intents between " + h1Name |
| 229 | + " and " + h2Name ) |
| 230 | main.log.info( item[ 'name' ] + ": Discover host using arping" ) |
| 231 | main.Mininet1.arping( host=h1Name ) |
| 232 | main.Mininet1.arping( host=h2Name ) |
| 233 | host1 = main.ONOScli1.getHost( mac=h1Mac ) |
| 234 | host2 = main.ONOScli1.getHost( mac=h2Mac ) |
| 235 | print host1 |
| 236 | print host2 |
| 237 | # Adding intents |
| 238 | main.log.info( item[ 'name' ] + ": Adding host intents" ) |
| 239 | intent1 = main.ONOScli1.addHostIntent( hostIdOne=h1Id, |
| 240 | hostIdTwo=h2Id ) |
| 241 | intentsId.append( intent1 ) |
| 242 | time.sleep( 5 ) |
| 243 | intent2 = main.ONOScli1.addHostIntent( hostIdOne=h2Id, |
| 244 | hostIdTwo=h1Id ) |
| 245 | intentsId.append( intent2 ) |
| 246 | # Checking intents |
| 247 | main.log.info( item[ 'name' ] + ": Check host intents state" ) |
| 248 | time.sleep( 20 ) |
| 249 | intentResult = main.ONOScli1.checkIntentState( intentsId=intentsId ) |
| 250 | if not intentResult: |
| 251 | main.log.info( item[ 'name' ] + ": Check host intents state" + |
| 252 | " again") |
| 253 | intentResult = main.ONOScli1.checkIntentState( |
| 254 | intentsId=intentsId ) |
| 255 | # Ping hosts |
| 256 | time.sleep( 10 ) |
| 257 | main.log.info( item[ 'name' ] + ": Ping " + h1Name + " and " + |
| 258 | h2Name ) |
| 259 | pingResult1 = main.Mininet1.pingHost( src=h1Name , target=h2Name ) |
| 260 | if not pingResult1: |
| 261 | main.log.info( item[ 'name' ] + ": " + h1Name + " cannot ping " |
| 262 | + h2Name ) |
| 263 | pingResult2 = main.Mininet1.pingHost( src=h2Name , target=h1Name ) |
| 264 | if not pingResult2: |
| 265 | main.log.info( item[ 'name' ] + ": " + h2Name + " cannot ping " |
| 266 | + h1Name ) |
| 267 | pingResult = pingResult1 and pingResult2 |
| 268 | if pingResult: |
| 269 | main.log.info( item[ 'name' ] + ": Successfully pinged " + |
| 270 | "both hosts" ) |
| 271 | else: |
| 272 | main.log.info( item[ 'name' ] + ": Failed to ping " + |
| 273 | "both hosts" ) |
| 274 | # Rerouting ( link down ) |
| 275 | main.log.info( item[ 'name' ] + ": Bring link down between " + |
| 276 | sw1 + " and " + sw2 ) |
| 277 | main.Mininet1.link( end1=sw1, |
| 278 | end2=sw2, |
| 279 | option="down" ) |
| 280 | time.sleep( 5 ) |
kelvin-onlab | 7c577e8 | 2015-05-07 10:45:16 -0700 | [diff] [blame] | 281 | |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame^] | 282 | # Check onos topology |
| 283 | main.log.info( item[ 'name' ] + ": Checking ONOS topology " ) |
| 284 | topologyResult = main.ONOScli1.topology() |
| 285 | statusResult = main.ONOSbench.checkStatus( topologyResult, |
| 286 | main.numSwitch, |
| 287 | remLink ) |
| 288 | if not statusResult: |
| 289 | main.log.info( item[ 'name' ] + ": Topology mismatch" ) |
| 290 | else: |
| 291 | main.log.info( item[ 'name' ] + ": Topology match" ) |
kelvin-onlab | 7c577e8 | 2015-05-07 10:45:16 -0700 | [diff] [blame] | 292 | |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame^] | 293 | # Ping hosts |
| 294 | main.log.info( item[ 'name' ] + ": Ping " + h1Name + " and " + |
| 295 | h2Name ) |
| 296 | pingResult1 = main.Mininet1.pingHost( src=h1Name , target=h2Name ) |
| 297 | if not pingResult1: |
| 298 | main.log.info( item[ 'name' ] + ": " + h1Name + " cannot ping " |
| 299 | + h2Name ) |
| 300 | pingResult2 = main.Mininet1.pingHost( src=h2Name , target=h1Name ) |
| 301 | if not pingResult2: |
| 302 | main.log.info( item[ 'name' ] + ": " + h2Name + " cannot ping " |
| 303 | + h1Name ) |
| 304 | pingResult = pingResult1 and pingResult2 |
| 305 | if pingResult: |
| 306 | main.log.info( item[ 'name' ] + ": Successfully pinged " + |
| 307 | "both hosts" ) |
| 308 | else: |
| 309 | main.log.info( item[ 'name' ] + ": Failed to ping " + |
| 310 | "both hosts" ) |
| 311 | # link up |
| 312 | main.log.info( item[ 'name' ] + ": Bring link up between " + |
| 313 | sw1 + " and " + sw2 ) |
| 314 | main.Mininet1.link( end1=sw1, |
| 315 | end2=sw2, |
| 316 | option="up" ) |
| 317 | time.sleep( 5 ) |
kelvin-onlab | 7c577e8 | 2015-05-07 10:45:16 -0700 | [diff] [blame] | 318 | |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame^] | 319 | # Check onos topology |
| 320 | main.log.info( item[ 'name' ] + ": Checking ONOS topology " ) |
| 321 | topologyResult = main.ONOScli1.topology() |
| 322 | statusResult = main.ONOSbench.checkStatus( topologyResult, |
| 323 | main.numSwitch, |
| 324 | main.numLinks ) |
| 325 | if not statusResult: |
| 326 | main.log.info( item[ 'name' ] + ": Topology mismatch" ) |
| 327 | else: |
| 328 | main.log.info( item[ 'name' ] + ": Topology match" ) |
kelvin-onlab | 7c577e8 | 2015-05-07 10:45:16 -0700 | [diff] [blame] | 329 | |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame^] | 330 | # Ping hosts |
| 331 | main.log.info( item[ 'name' ] + ": Ping " + h1Name + " and " + |
| 332 | h2Name ) |
| 333 | pingResult1 = main.Mininet1.pingHost( src=h1Name , target=h2Name ) |
| 334 | if not pingResult1: |
| 335 | main.log.info( item[ 'name' ] + ": " + h1Name + " cannot ping " |
| 336 | + h2Name ) |
| 337 | pingResult2 = main.Mininet1.pingHost( src=h2Name , target=h1Name ) |
| 338 | if not pingResult2: |
| 339 | main.log.info( item[ 'name' ] + ": " + h2Name + " cannot ping " |
| 340 | + h1Name ) |
| 341 | pingResult = pingResult1 and pingResult2 |
| 342 | if pingResult: |
| 343 | main.log.info( item[ 'name' ] + ": Successfully pinged " + |
| 344 | "both hosts" ) |
| 345 | else: |
| 346 | main.log.info( item[ 'name' ] + ": Failed to ping " + |
| 347 | "both hosts" ) |
| 348 | |
| 349 | # Remove intents |
| 350 | for intent in intentsId: |
| 351 | main.ONOScli1.removeIntent( intentId=intent, purge=True ) |
| 352 | |
| 353 | print main.ONOScli1.intents() |
| 354 | stepResult = pingResult |
| 355 | utilities.assert_equals( expect=main.TRUE, |
| 356 | actual=stepResult, |
| 357 | onpass=item[ 'name' ] + |
| 358 | " host intent successful", |
| 359 | onfail=item[ 'name' ] + |
| 360 | "Add host intent failed" ) |
| 361 | def CASE2000( self, main ): |
| 362 | """ |
| 363 | Add point intents between 2 hosts: |
| 364 | - Get device ids |
| 365 | - Add point intents |
| 366 | - Check intents |
| 367 | - Check flows |
| 368 | - Ping hosts |
| 369 | - Reroute |
| 370 | - Link down |
| 371 | - Ping hosts |
| 372 | - Link up |
| 373 | - Ping hosts |
| 374 | - Remove intents |
| 375 | """ |
| 376 | |
| 377 | def CASE3000( self, main ): |
| 378 | """ |
| 379 | Add single point to multi point intents |
| 380 | - Get device ids |
| 381 | - Add single point to multi point intents |
| 382 | - Check intents |
| 383 | - Check flows |
| 384 | - Ping hosts |
| 385 | - Reroute |
| 386 | - Link down |
| 387 | - Ping hosts |
| 388 | - Link up |
| 389 | - Ping hosts |
| 390 | - Remove intents |
| 391 | """ |
| 392 | |
| 393 | def CASE4000( self, main ): |
| 394 | """ |
| 395 | Add multi point to single point intents |
| 396 | - Get device ids |
| 397 | - Add multi point to single point intents |
| 398 | - Check intents |
| 399 | - Check flows |
| 400 | - Ping hosts |
| 401 | - Reroute |
| 402 | - Link down |
| 403 | - Ping hosts |
| 404 | - Link up |
| 405 | - Ping hosts |
| 406 | - Remove intents |
| 407 | """ |