Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1 | # Testing the basic intent for ipv6 functionality of ONOS |
| 2 | |
| 3 | class FUNCipv6Intent: |
| 4 | |
| 5 | def __init__( self ): |
| 6 | self.default = '' |
| 7 | |
| 8 | def CASE1( self, main ): |
| 9 | import time |
| 10 | import imp |
| 11 | import re |
| 12 | |
| 13 | """ |
| 14 | - Construct tests variables |
| 15 | - GIT ( optional ) |
| 16 | - Checkout ONOS master branch |
| 17 | - Pull latest ONOS code |
| 18 | - Building ONOS ( optional ) |
| 19 | - Install ONOS package |
| 20 | - Build ONOS package |
| 21 | """ |
| 22 | |
| 23 | main.case( "Constructing test variables and building ONOS package" ) |
| 24 | main.step( "Constructing test variables" ) |
| 25 | main.caseExplanation = "This test case is mainly for loading " +\ |
| 26 | "from params file, and pull and build the " +\ |
| 27 | " latest ONOS package" |
| 28 | stepResult = main.FALSE |
| 29 | |
| 30 | # Test variables |
| 31 | try: |
| 32 | main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir ) |
| 33 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
| 34 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
| 35 | main.dependencyPath = main.testOnDirectory + \ |
| 36 | main.params[ 'DEPENDENCY' ][ 'path' ] |
| 37 | main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ] |
| 38 | main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," ) |
| 39 | if main.ONOSbench.maxNodes: |
| 40 | main.maxNodes = int( main.ONOSbench.maxNodes ) |
| 41 | else: |
| 42 | main.maxNodes = 0 |
| 43 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
| 44 | wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ] |
| 45 | wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ] |
| 46 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
| 47 | main.checkIntentSleep = int( main.params[ 'SLEEP' ][ 'checkintent' ] ) |
| 48 | main.removeIntentSleep = int( main.params[ 'SLEEP' ][ 'removeintent' ] ) |
| 49 | main.rerouteSleep = int( main.params[ 'SLEEP' ][ 'reroute' ] ) |
| 50 | main.fwdSleep = int( main.params[ 'SLEEP' ][ 'fwd' ] ) |
| 51 | main.checkTopoAttempts = int( main.params[ 'SLEEP' ][ 'topoAttempts' ] ) |
| 52 | gitPull = main.params[ 'GIT' ][ 'pull' ] |
| 53 | main.numSwitch = int( main.params[ 'MININET' ][ 'switch' ] ) |
| 54 | main.numLinks = int( main.params[ 'MININET' ][ 'links' ] ) |
| 55 | main.cellData = {} # for creating cell file |
| 56 | main.hostsData = {} |
| 57 | main.CLIs = [] |
| 58 | main.ONOSip = [] |
| 59 | main.assertReturnString = '' # Assembled assert return string |
| 60 | |
| 61 | main.ONOSip = main.ONOSbench.getOnosIps() |
| 62 | print main.ONOSip |
| 63 | |
| 64 | # Assigning ONOS cli handles to a list |
| 65 | for i in range( 1, main.maxNodes + 1 ): |
| 66 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 67 | |
| 68 | # -- INIT SECTION, ONLY RUNS ONCE -- # |
| 69 | main.startUp = imp.load_source( wrapperFile1, |
| 70 | main.dependencyPath + |
| 71 | wrapperFile1 + |
| 72 | ".py" ) |
| 73 | |
| 74 | main.intentFunction = imp.load_source( wrapperFile2, |
| 75 | main.dependencyPath + |
| 76 | wrapperFile2 + |
| 77 | ".py" ) |
| 78 | |
| 79 | main.topo = imp.load_source( wrapperFile3, |
| 80 | main.dependencyPath + |
| 81 | wrapperFile3 + |
| 82 | ".py" ) |
| 83 | |
| 84 | copyResult1 = main.ONOSbench.scp( main.Mininet1, |
| 85 | main.dependencyPath + |
| 86 | main.topology, |
| 87 | main.Mininet1.home, |
| 88 | direction="to" ) |
| 89 | if main.CLIs: |
| 90 | stepResult = main.TRUE |
| 91 | else: |
| 92 | main.log.error( "Did not properly created list of ONOS CLI handle" ) |
| 93 | stepResult = main.FALSE |
| 94 | except Exception as e: |
| 95 | main.log.exception(e) |
| 96 | main.cleanup() |
| 97 | main.exit() |
| 98 | |
| 99 | utilities.assert_equals( expect=main.TRUE, |
| 100 | actual=stepResult, |
| 101 | onpass="Successfully construct " + |
| 102 | "test variables ", |
| 103 | onfail="Failed to construct test variables" ) |
| 104 | |
| 105 | if gitPull == 'True': |
| 106 | main.step( "Building ONOS in " + gitBranch + " branch" ) |
| 107 | onosBuildResult = main.startUp.onosBuild( main, gitBranch ) |
| 108 | stepResult = onosBuildResult |
| 109 | utilities.assert_equals( expect=main.TRUE, |
| 110 | actual=stepResult, |
| 111 | onpass="Successfully compiled " + |
| 112 | "latest ONOS", |
| 113 | onfail="Failed to compile " + |
| 114 | "latest ONOS" ) |
| 115 | else: |
| 116 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 117 | "clean install" ) |
| 118 | main.ONOSbench.getVersion( report=True ) |
| 119 | |
| 120 | def CASE2( self, main ): |
| 121 | """ |
| 122 | - Set up cell |
| 123 | - Create cell file |
| 124 | - Set cell file |
| 125 | - Verify cell file |
| 126 | - Kill ONOS process |
| 127 | - Uninstall ONOS cluster |
| 128 | - Verify ONOS start up |
| 129 | - Install ONOS cluster |
| 130 | - Connect to cli |
| 131 | """ |
| 132 | |
| 133 | # main.scale[ 0 ] determines the current number of ONOS controller |
| 134 | main.numCtrls = int( main.scale[ 0 ] ) |
| 135 | |
| 136 | main.case( "Starting up " + str( main.numCtrls ) + |
| 137 | " node(s) ONOS cluster" ) |
| 138 | main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\ |
| 139 | " node(s) ONOS cluster" |
| 140 | |
| 141 | |
| 142 | |
| 143 | #kill off all onos processes |
| 144 | main.log.info( "Safety check, killing all ONOS processes" + |
Jon Hall | 70b2ff4 | 2015-11-17 15:49:44 -0800 | [diff] [blame] | 145 | " before initiating environment setup" ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 146 | |
| 147 | for i in range( main.maxNodes ): |
| 148 | main.ONOSbench.onosDie( main.ONOSip[ i ] ) |
| 149 | |
| 150 | print "NODE COUNT = ", main.numCtrls |
| 151 | |
| 152 | tempOnosIp = [] |
| 153 | for i in range( main.numCtrls ): |
| 154 | tempOnosIp.append( main.ONOSip[i] ) |
| 155 | |
| 156 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, |
| 157 | "temp", main.Mininet1.ip_address, |
| 158 | main.apps, tempOnosIp ) |
| 159 | |
| 160 | main.step( "Apply cell to environment" ) |
| 161 | cellResult = main.ONOSbench.setCell( "temp" ) |
| 162 | verifyResult = main.ONOSbench.verifyCell() |
| 163 | stepResult = cellResult and verifyResult |
| 164 | utilities.assert_equals( expect=main.TRUE, |
| 165 | actual=stepResult, |
| 166 | onpass="Successfully applied cell to " + \ |
| 167 | "environment", |
| 168 | onfail="Failed to apply cell to environment " ) |
| 169 | |
| 170 | main.step( "Creating ONOS package" ) |
| 171 | packageResult = main.ONOSbench.onosPackage() |
| 172 | stepResult = packageResult |
| 173 | utilities.assert_equals( expect=main.TRUE, |
| 174 | actual=stepResult, |
| 175 | onpass="Successfully created ONOS package", |
| 176 | onfail="Failed to create ONOS package" ) |
| 177 | |
| 178 | time.sleep( main.startUpSleep ) |
| 179 | main.step( "Uninstalling ONOS package" ) |
| 180 | onosUninstallResult = main.TRUE |
| 181 | for ip in main.ONOSip: |
| 182 | onosUninstallResult = onosUninstallResult and \ |
| 183 | main.ONOSbench.onosUninstall( nodeIp=ip ) |
| 184 | stepResult = onosUninstallResult |
| 185 | utilities.assert_equals( expect=main.TRUE, |
| 186 | actual=stepResult, |
| 187 | onpass="Successfully uninstalled ONOS package", |
| 188 | onfail="Failed to uninstall ONOS package" ) |
| 189 | |
| 190 | time.sleep( main.startUpSleep ) |
| 191 | main.step( "Installing ONOS package" ) |
| 192 | onosInstallResult = main.TRUE |
| 193 | for i in range( main.numCtrls ): |
| 194 | onosInstallResult = onosInstallResult and \ |
| 195 | main.ONOSbench.onosInstall( node=main.ONOSip[ i ] ) |
| 196 | stepResult = onosInstallResult |
| 197 | utilities.assert_equals( expect=main.TRUE, |
| 198 | actual=stepResult, |
| 199 | onpass="Successfully installed ONOS package", |
| 200 | onfail="Failed to install ONOS package" ) |
| 201 | |
| 202 | time.sleep( main.startUpSleep ) |
| 203 | main.step( "Starting ONOS service" ) |
| 204 | stopResult = main.TRUE |
| 205 | startResult = main.TRUE |
| 206 | onosIsUp = main.TRUE |
| 207 | |
| 208 | for i in range( main.numCtrls ): |
| 209 | onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] ) |
| 210 | if onosIsUp == main.TRUE: |
| 211 | main.log.report( "ONOS instance is up and ready" ) |
| 212 | else: |
| 213 | main.log.report( "ONOS instance may not be up, stop and " + |
| 214 | "start ONOS again " ) |
| 215 | |
| 216 | for i in range( main.numCtrls ): |
| 217 | stopResult = stopResult and \ |
| 218 | main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 219 | for i in range( main.numCtrls ): |
| 220 | startResult = startResult and \ |
| 221 | main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
| 222 | stepResult = onosIsUp and stopResult and startResult |
| 223 | utilities.assert_equals( expect=main.TRUE, |
| 224 | actual=stepResult, |
| 225 | onpass="ONOS service is ready", |
| 226 | onfail="ONOS service did not start properly" ) |
| 227 | |
| 228 | main.step( "Start ONOS cli" ) |
| 229 | cliResult = main.TRUE |
| 230 | for i in range( main.numCtrls ): |
| 231 | cliResult = cliResult and \ |
| 232 | main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] ) |
| 233 | stepResult = cliResult |
| 234 | utilities.assert_equals( expect=main.TRUE, |
| 235 | actual=stepResult, |
| 236 | onpass="Successfully start ONOS cli", |
| 237 | onfail="Failed to start ONOS cli" ) |
| 238 | |
| 239 | # Remove the first element in main.scale list |
| 240 | main.scale.remove( main.scale[ 0 ] ) |
| 241 | |
| 242 | main.intentFunction.report( main ) |
| 243 | |
| 244 | def CASE11( self, main ): |
| 245 | """ |
| 246 | Start Mininet topology with OF 1.3 switches |
| 247 | """ |
| 248 | main.OFProtocol = "1.3" |
| 249 | main.log.report( "Start Mininet topology with OF 1.3 switches" ) |
| 250 | main.case( "Start Mininet topology with OF 1.3 switches" ) |
| 251 | main.caseExplanation = "Start mininet topology with OF 1.3 " +\ |
| 252 | "switches to test intents, exits out if " +\ |
| 253 | "topology did not start correctly" |
| 254 | |
| 255 | main.step( "Starting Mininet topology with OF 1.3 switches" ) |
| 256 | args = "--switch ovs,protocols=OpenFlow13" |
| 257 | topoResult = main.Mininet1.startNet( topoFile=main.dependencyPath + |
| 258 | main.topology, |
| 259 | args=args ) |
| 260 | stepResult = topoResult |
| 261 | utilities.assert_equals( expect=main.TRUE, |
| 262 | actual=stepResult, |
| 263 | onpass="Successfully loaded topology", |
| 264 | onfail="Failed to load topology" ) |
| 265 | # Exit if topology did not load properly |
| 266 | if not topoResult: |
| 267 | main.cleanup() |
| 268 | main.exit() |
| 269 | |
| 270 | def CASE12( self, main ): |
| 271 | """ |
| 272 | Assign mastership to controllers |
| 273 | """ |
| 274 | import re |
| 275 | |
| 276 | main.case( "Assign switches to controllers" ) |
| 277 | main.step( "Assigning switches to controllers" ) |
| 278 | main.caseExplanation = "Assign OF " + main.OFProtocol +\ |
| 279 | " switches to ONOS nodes" |
| 280 | |
| 281 | assignResult = main.TRUE |
| 282 | switchList = [] |
| 283 | |
| 284 | # Creates a list switch name, use getSwitch() function later... |
| 285 | for i in range( 1, ( main.numSwitch + 1 ) ): |
| 286 | switchList.append( 's' + str( i ) ) |
| 287 | |
| 288 | tempONOSip = [] |
| 289 | for i in range( main.numCtrls ): |
| 290 | tempONOSip.append( main.ONOSip[ i ] ) |
| 291 | |
| 292 | assignResult = main.Mininet1.assignSwController( sw=switchList, |
| 293 | ip=tempONOSip, |
| 294 | port='6653' ) |
| 295 | if not assignResult: |
| 296 | main.cleanup() |
| 297 | main.exit() |
| 298 | |
| 299 | for i in range( 1, ( main.numSwitch + 1 ) ): |
| 300 | response = main.Mininet1.getSwController( "s" + str( i ) ) |
| 301 | print( "Response is " + str( response ) ) |
| 302 | if re.search( "tcp:" + main.ONOSip[ 0 ], response ): |
| 303 | assignResult = assignResult and main.TRUE |
| 304 | else: |
| 305 | assignResult = main.FALSE |
| 306 | stepResult = assignResult |
| 307 | utilities.assert_equals( expect=main.TRUE, |
| 308 | actual=stepResult, |
| 309 | onpass="Successfully assigned switches" + |
| 310 | "to controller", |
| 311 | onfail="Failed to assign switches to " + |
| 312 | "controller" ) |
| 313 | |
| 314 | def CASE14( self, main ): |
| 315 | """ |
| 316 | Stop mininet |
| 317 | """ |
| 318 | main.log.report( "Stop Mininet topology" ) |
| 319 | main.case( "Stop Mininet topology" ) |
| 320 | main.caseExplanation = "Stopping the current mininet topology " +\ |
| 321 | "to start up fresh" |
| 322 | |
| 323 | main.step( "Stopping Mininet Topology" ) |
| 324 | topoResult = main.Mininet1.stopNet( ) |
| 325 | stepResult = topoResult |
| 326 | utilities.assert_equals( expect=main.TRUE, |
| 327 | actual=stepResult, |
| 328 | onpass="Successfully stop mininet", |
| 329 | onfail="Failed to stop mininet" ) |
| 330 | # Exit if topology did not load properly |
| 331 | if not topoResult: |
| 332 | main.cleanup() |
| 333 | main.exit() |