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 | |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 10 | class FuncIntent: |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 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 | """ |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 29 | global init |
cameron@onlab.us | 59d29d9 | 2015-05-11 14:31:54 -0700 | [diff] [blame] | 30 | global globalONOSip |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 31 | try: |
| 32 | if type(init) is not bool: |
| 33 | init = False |
| 34 | except NameError: |
| 35 | init = False |
cameron@onlab.us | 59d29d9 | 2015-05-11 14:31:54 -0700 | [diff] [blame] | 36 | |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 37 | #Local variables |
| 38 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 39 | apps = main.params[ 'ENV' ][ 'cellApps' ] |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 40 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
cameron@onlab.us | 59d29d9 | 2015-05-11 14:31:54 -0700 | [diff] [blame] | 41 | benchIp = os.environ[ 'OCN' ] |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 42 | benchUser = main.params[ 'BENCH' ][ 'user' ] |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 43 | topology = main.params[ 'MININET' ][ 'topo' ] |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 44 | main.numSwitch = int( main.params[ 'MININET' ][ 'switch' ] ) |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 45 | main.numLinks = int( main.params[ 'MININET' ][ 'links' ] ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 46 | main.numCtrls = main.params[ 'CTRL' ][ 'num' ] |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 47 | PULLCODE = False |
| 48 | if main.params[ 'GIT' ][ 'pull' ] == 'True': |
| 49 | PULLCODE = True |
| 50 | main.case( "Setting up test environment" ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 51 | main.CLIs = [] |
| 52 | for i in range( 1, int( main.numCtrls ) + 1 ): |
| 53 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 54 | |
cameron@onlab.us | 7fd2a52 | 2015-05-14 11:20:33 -0700 | [diff] [blame] | 55 | main.errors = [0]*11 |
| 56 | main.warnings = [0]*11 |
| 57 | main.exceptions = [0]*11 |
| 58 | |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 59 | # -- INIT SECTION, ONLY RUNS ONCE -- # |
| 60 | if init == False: |
| 61 | init = True |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 62 | |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 63 | main.ONOSport = [] |
| 64 | main.scale = ( main.params[ 'SCALE' ] ).split( "," ) |
| 65 | main.numCtrls = int( main.scale[ 0 ] ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 66 | |
| 67 | if PULLCODE: |
| 68 | main.step( "Git checkout and pull " + gitBranch ) |
| 69 | main.ONOSbench.gitCheckout( gitBranch ) |
| 70 | gitPullResult = main.ONOSbench.gitPull() |
| 71 | if gitPullResult == main.ERROR: |
| 72 | main.log.error( "Error pulling git branch" ) |
| 73 | main.step( "Using mvn clean & install" ) |
| 74 | cleanInstallResult = main.ONOSbench.cleanInstall() |
| 75 | stepResult = cleanInstallResult |
| 76 | utilities.assert_equals( expect=main.TRUE, |
| 77 | actual=stepResult, |
| 78 | onpass="Successfully compiled " + |
| 79 | "latest ONOS", |
| 80 | onfail="Failed to compile " + |
| 81 | "latest ONOS" ) |
| 82 | else: |
| 83 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 84 | "clean install" ) |
cameron@onlab.us | 59d29d9 | 2015-05-11 14:31:54 -0700 | [diff] [blame] | 85 | |
| 86 | globalONOSip = main.ONOSbench.getOnosIpFromEnv() |
| 87 | |
| 88 | maxNodes = ( len(globalONOSip) - 3 ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 89 | |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 90 | main.numCtrls = int( main.scale[ 0 ] ) |
| 91 | main.scale.remove( main.scale[ 0 ] ) |
cameron@onlab.us | 59d29d9 | 2015-05-11 14:31:54 -0700 | [diff] [blame] | 92 | |
| 93 | main.ONOSip = [0] |
| 94 | for i in range( 1, maxNodes + 1 ): |
| 95 | main.ONOSip.append( globalONOSip[i] ) |
| 96 | |
| 97 | |
| 98 | |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 99 | #kill off all onos processes |
| 100 | main.log.info( "Safety check, killing all ONOS processes" + |
| 101 | " before initiating enviornment setup" ) |
cameron@onlab.us | 59d29d9 | 2015-05-11 14:31:54 -0700 | [diff] [blame] | 102 | for i in range(1, maxNodes+1): |
| 103 | main.ONOSbench.onosDie( globalONOSip[ i ] ) |
| 104 | |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 105 | """ |
| 106 | main.step( "Apply cell to environment" ) |
| 107 | cellResult = main.ONOSbench.setCell( cellName ) |
| 108 | verifyResult = main.ONOSbench.verifyCell() |
| 109 | stepResult = cellResult and verifyResult |
| 110 | utilities.assert_equals( expect=main.TRUE, |
| 111 | actual=stepResult, |
| 112 | onpass="Successfully applied cell to " + \ |
| 113 | "environment", |
| 114 | onfail="Failed to apply cell to environment " ) |
| 115 | """ |
| 116 | """main.step( "Removing raft logs" ) |
| 117 | removeRaftResult = main.ONOSbench.onosRemoveRaftLogs() |
| 118 | stepResult = removeRaftResult |
| 119 | utilities.assert_equals( expect=main.TRUE, |
| 120 | actual=stepResult, |
| 121 | onpass="Successfully removed raft logs", |
| 122 | onfail="Failed to remove raft logs" ) |
| 123 | """ |
cameron@onlab.us | 59d29d9 | 2015-05-11 14:31:54 -0700 | [diff] [blame] | 124 | |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 125 | print "NODE COUNT = ", main.numCtrls |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 126 | main.log.info( "Creating cell file" ) |
| 127 | cellIp = [] |
cameron@onlab.us | 684cee3 | 2015-05-11 17:14:04 -0700 | [diff] [blame] | 128 | for i in range( 1, main.numCtrls + 1 ): |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 129 | cellIp.append( str( main.ONOSip[ i ] ) ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 130 | print cellIp |
| 131 | main.ONOSbench.createCellFile( benchIp, cellName, "", |
| 132 | str( apps ), *cellIp ) |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 133 | |
| 134 | main.step( "Apply cell to environment" ) |
| 135 | cellResult = main.ONOSbench.setCell( cellName ) |
| 136 | verifyResult = main.ONOSbench.verifyCell() |
| 137 | stepResult = cellResult and verifyResult |
| 138 | utilities.assert_equals( expect=main.TRUE, |
| 139 | actual=stepResult, |
| 140 | onpass="Successfully applied cell to " + \ |
| 141 | "environment", |
| 142 | onfail="Failed to apply cell to environment " ) |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 143 | |
| 144 | main.step( "Creating ONOS package" ) |
| 145 | packageResult = main.ONOSbench.onosPackage() |
| 146 | stepResult = packageResult |
| 147 | utilities.assert_equals( expect=main.TRUE, |
| 148 | actual=stepResult, |
| 149 | onpass="Successfully created ONOS package", |
| 150 | onfail="Failed to create ONOS package" ) |
| 151 | |
| 152 | main.step( "Uninstalling ONOS package" ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 153 | onosUninstallResult = main.TRUE |
cameron@onlab.us | 59d29d9 | 2015-05-11 14:31:54 -0700 | [diff] [blame] | 154 | for i in range( 1, main.numCtrls + 1): |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 155 | onosUninstallResult = onosUninstallResult and \ |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 156 | main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] ) |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 157 | stepResult = onosUninstallResult |
| 158 | utilities.assert_equals( expect=main.TRUE, |
| 159 | actual=stepResult, |
| 160 | onpass="Successfully uninstalled ONOS package", |
| 161 | onfail="Failed to uninstall ONOS package" ) |
| 162 | time.sleep( 5 ) |
| 163 | main.step( "Installing ONOS package" ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 164 | onosInstallResult = main.TRUE |
cameron@onlab.us | 59d29d9 | 2015-05-11 14:31:54 -0700 | [diff] [blame] | 165 | for i in range( 1, main.numCtrls+1): |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 166 | onosInstallResult = onosInstallResult and \ |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 167 | main.ONOSbench.onosInstall( node=main.ONOSip[ i ] ) |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 168 | stepResult = onosInstallResult |
| 169 | utilities.assert_equals( expect=main.TRUE, |
| 170 | actual=stepResult, |
| 171 | onpass="Successfully installed ONOS package", |
| 172 | onfail="Failed to install ONOS package" ) |
| 173 | |
cameron@onlab.us | 59d29d9 | 2015-05-11 14:31:54 -0700 | [diff] [blame] | 174 | time.sleep( 20 ) |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 175 | main.step( "Starting ONOS service" ) |
| 176 | stopResult = main.TRUE |
| 177 | startResult = main.TRUE |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 178 | onosIsUp = main.TRUE |
cameron@onlab.us | 59d29d9 | 2015-05-11 14:31:54 -0700 | [diff] [blame] | 179 | for i in range( 1, main.numCtrls+1 ): |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 180 | onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] ) |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 181 | if onosIsUp == main.TRUE: |
| 182 | main.log.report( "ONOS instance is up and ready" ) |
| 183 | else: |
| 184 | main.log.report( "ONOS instance may not be up, stop and " + |
| 185 | "start ONOS again " ) |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 186 | for i in range( main.numCtrls ): |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 187 | stopResult = stopResult and \ |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 188 | main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 189 | for i in range( main.numCtrls ): |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 190 | startResult = startResult and \ |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 191 | main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 192 | stepResult = onosIsUp and stopResult and startResult |
| 193 | utilities.assert_equals( expect=main.TRUE, |
| 194 | actual=stepResult, |
| 195 | onpass="ONOS service is ready", |
| 196 | onfail="ONOS service did not start properly" ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 197 | |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 198 | main.step( "Start ONOS cli" ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 199 | cliResult = main.TRUE |
cameron@onlab.us | d68865d | 2015-05-13 15:45:39 -0700 | [diff] [blame] | 200 | for i in range( 1, main.numCtrls + 1 ): |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 201 | cliResult = cliResult and \ |
| 202 | main.CLIs[i].startOnosCli( main.ONOSip[ i ] ) |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 203 | stepResult = cliResult |
| 204 | utilities.assert_equals( expect=main.TRUE, |
| 205 | actual=stepResult, |
| 206 | onpass="Successfully start ONOS cli", |
| 207 | onfail="Failed to start ONOS cli" ) |
cameron@onlab.us | 7fd2a52 | 2015-05-14 11:20:33 -0700 | [diff] [blame] | 208 | |
| 209 | def CASE9( self, main ): |
| 210 | main.log.info("Error report: \n") |
| 211 | main.ONOSbench.onosErrorLog(globalONOSip[1]) |
| 212 | |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 213 | |
| 214 | def CASE11( self, main ): |
| 215 | """ |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 216 | Start mininet |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 217 | """ |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 218 | main.log.report( "Start Mininet topology" ) |
| 219 | main.log.case( "Start Mininet topology" ) |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 220 | |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 221 | main.step( "Starting Mininet Topology" ) |
| 222 | topoResult = main.Mininet1.startNet( topoFile=topology ) |
| 223 | stepResult = topoResult |
| 224 | utilities.assert_equals( expect=main.TRUE, |
| 225 | actual=stepResult, |
| 226 | onpass="Successfully loaded topology", |
| 227 | onfail="Failed to load topology" ) |
| 228 | # Exit if topology did not load properly |
| 229 | if not topoResult: |
| 230 | main.cleanup() |
| 231 | main.exit() |
| 232 | |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 233 | def CASE12( self, main ): |
| 234 | """ |
| 235 | Assign mastership to controllers |
| 236 | """ |
| 237 | import re |
| 238 | |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 239 | main.step( "Assigning switches to controllers" ) |
| 240 | assignResult = main.TRUE |
kelvin-onlab | 5cbf999 | 2015-05-05 14:34:07 -0700 | [diff] [blame] | 241 | for i in range( 1, ( main.numSwitch + 1 ) ): |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 242 | main.Mininet1.assignSwController( sw=str( i ), |
| 243 | count=1, |
cameron@onlab.us | d68865d | 2015-05-13 15:45:39 -0700 | [diff] [blame] | 244 | ip1=main.ONOSip[ 1 ], |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 245 | port1=main.ONOSport[ 0 ] ) |
kelvin-onlab | 5cbf999 | 2015-05-05 14:34:07 -0700 | [diff] [blame] | 246 | for i in range( 1, ( main.numSwitch + 1 ) ): |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 247 | response = main.Mininet1.getSwController( "s" + str( i ) ) |
| 248 | print( "Response is " + str( response ) ) |
cameron@onlab.us | d68865d | 2015-05-13 15:45:39 -0700 | [diff] [blame] | 249 | if re.search( "tcp:" + main.ONOSip[ 1 ], response ): |
kelvin-onlab | 4ff9cc1 | 2015-05-05 11:14:42 -0700 | [diff] [blame] | 250 | assignResult = assignResult and main.TRUE |
| 251 | else: |
| 252 | assignResult = main.FALSE |
| 253 | stepResult = assignResult |
| 254 | utilities.assert_equals( expect=main.TRUE, |
| 255 | actual=stepResult, |
| 256 | onpass="Successfully assigned switches" + |
| 257 | "to controller", |
| 258 | onfail="Failed to assign switches to " + |
| 259 | "controller" ) |
| 260 | |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 261 | def CASE1001( self, main ): |
kelvin-onlab | 7c577e8 | 2015-05-07 10:45:16 -0700 | [diff] [blame] | 262 | """ |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 263 | Add host intents between 2 host: |
| 264 | - Discover hosts |
| 265 | - Add host intents |
| 266 | - Check intents |
| 267 | - Check flows |
| 268 | - Ping hosts |
| 269 | - Reroute |
| 270 | - Link down |
| 271 | - Ping hosts |
| 272 | - Link up |
| 273 | - Ping hosts |
| 274 | - Remove intents |
kelvin-onlab | 7c577e8 | 2015-05-07 10:45:16 -0700 | [diff] [blame] | 275 | """ |
| 276 | import time |
| 277 | import json |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 278 | import re |
| 279 | """ |
| 280 | Create your item(s) here |
| 281 | item = { 'name': '', 'host1': |
| 282 | { 'name': '', 'MAC': '00:00:00:00:00:0X', |
| 283 | 'id':'00:00:00:00:00:0X/-X' } , 'host2': |
| 284 | { 'name': '', 'MAC': '00:00:00:00:00:0X', |
| 285 | 'id':'00:00:00:00:00:0X/-X'}, 'link': { 'switch1': '', |
| 286 | 'switch2': '', 'num':'' } } |
| 287 | """ |
| 288 | # Local variables |
| 289 | items = [] |
| 290 | ipv4 = { 'name': 'IPV4', 'host1': |
| 291 | { 'name': 'h1', 'MAC': '00:00:00:00:00:01', |
| 292 | 'id':'00:00:00:00:00:01/-1' } , 'host2': |
| 293 | { 'name': 'h9', 'MAC': '00:00:00:00:00:09', |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 294 | 'id':'00:00:00:00:00:09/-1'}, 'link': { 'switch1': 's5', |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 295 | 'switch2': 's2', 'num':'18' } } |
| 296 | dualStack1 = { 'name': 'DUALSTACK1', 'host1': |
| 297 | { 'name': 'h3', 'MAC': '00:00:00:00:00:03', |
| 298 | 'id':'00:00:00:00:00:03/-1' } , 'host2': |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 299 | { 'name': 'h11', 'MAC': '00:00:00:00:00:0B', |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 300 | 'id':'00:00:00:00:00:0B/-1'}, 'link': { 'switch1': 's5', |
| 301 | 'switch2': 's2', 'num':'18' } } |
| 302 | items.append( ipv4 ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 303 | items.append( dualStack1 ) |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 304 | # Global variables |
kelvin-onlab | 7c577e8 | 2015-05-07 10:45:16 -0700 | [diff] [blame] | 305 | |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 306 | main.log.case( "Add host intents between 2 host" ) |
kelvin-onlab | 7c577e8 | 2015-05-07 10:45:16 -0700 | [diff] [blame] | 307 | |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 308 | for item in items: |
| 309 | stepResult = main.TRUE |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 310 | itemName = item[ 'name' ] |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 311 | h1Name = item[ 'host1' ][ 'name' ] |
| 312 | h2Name = item[ 'host2' ][ 'name' ] |
| 313 | h1Mac = item[ 'host1' ][ 'MAC' ] |
| 314 | h2Mac = item[ 'host2' ][ 'MAC' ] |
| 315 | h1Id = item[ 'host1' ][ 'id'] |
| 316 | h2Id = item[ 'host2' ][ 'id'] |
| 317 | # Link down/up for rerouting |
| 318 | sw1 = item[ 'link' ][ 'switch1' ] |
| 319 | sw2 = item[ 'link' ][ 'switch2' ] |
| 320 | remLink = item[ 'link' ][ 'num' ] |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 321 | pingResult = main.TRUE |
| 322 | statusResult = main.TRUE |
| 323 | linkDownResult = main.TRUE |
| 324 | linkUpResult = main.TRUE |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 325 | intentsId = [] |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 326 | main.step( itemName + ": Add host intents between " + h1Name |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 327 | + " and " + h2Name ) |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 328 | main.log.info( itemName + ": Discover host using arping" ) |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 329 | main.Mininet1.arping( host=h1Name ) |
| 330 | main.Mininet1.arping( host=h2Name ) |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 331 | host1 = main.CLIs[ 0 ].getHost( mac=h1Mac ) |
| 332 | host2 = main.CLIs[ 0 ].getHost( mac=h2Mac ) |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 333 | print host1 |
| 334 | print host2 |
| 335 | # Adding intents |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 336 | main.log.info( itemName + ": Adding host intents" ) |
| 337 | intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h1Id, |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 338 | hostIdTwo=h2Id ) |
| 339 | intentsId.append( intent1 ) |
| 340 | time.sleep( 5 ) |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 341 | intent2 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h2Id, |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 342 | hostIdTwo=h1Id ) |
| 343 | intentsId.append( intent2 ) |
| 344 | # Checking intents |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 345 | main.log.info( itemName + ": Check host intents state" ) |
| 346 | time.sleep( 30 ) |
| 347 | for i in range( main.numCtrls ): |
| 348 | intentResult = main.CLIs[ i ].checkIntentState( |
| 349 | intentsId=intentsId ) |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 350 | if not intentResult: |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 351 | main.log.info( itemName + ": Check host intents state" + |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 352 | " again") |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 353 | for i in range( main.numCtrls ): |
| 354 | intentResult = main.CLIs[ i ].checkIntentState( |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 355 | intentsId=intentsId ) |
| 356 | # Ping hosts |
| 357 | time.sleep( 10 ) |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 358 | main.log.info( itemName + ": Ping " + h1Name + " and " + |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 359 | h2Name ) |
| 360 | pingResult1 = main.Mininet1.pingHost( src=h1Name , target=h2Name ) |
| 361 | if not pingResult1: |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 362 | main.log.info( itemName + ": " + h1Name + " cannot ping " |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 363 | + h2Name ) |
| 364 | pingResult2 = main.Mininet1.pingHost( src=h2Name , target=h1Name ) |
| 365 | if not pingResult2: |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 366 | main.log.info( itemName + ": " + h2Name + " cannot ping " |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 367 | + h1Name ) |
| 368 | pingResult = pingResult1 and pingResult2 |
| 369 | if pingResult: |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 370 | main.log.info( itemName + ": Successfully pinged " + |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 371 | "both hosts" ) |
| 372 | else: |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 373 | main.log.info( itemName + ": Failed to ping " + |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 374 | "both hosts" ) |
| 375 | # Rerouting ( link down ) |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 376 | main.log.info( itemName + ": Bring link down between " + |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 377 | sw1 + " and " + sw2 ) |
| 378 | main.Mininet1.link( end1=sw1, |
| 379 | end2=sw2, |
| 380 | option="down" ) |
| 381 | time.sleep( 5 ) |
kelvin-onlab | 7c577e8 | 2015-05-07 10:45:16 -0700 | [diff] [blame] | 382 | |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 383 | # Check onos topology |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 384 | main.log.info( itemName + ": Checking ONOS topology " ) |
| 385 | |
| 386 | for i in range( main.numCtrls ): |
| 387 | topologyResult = main.CLIs[ i ].topology() |
| 388 | linkDownResult = main.ONOSbench.checkStatus( topologyResult, |
| 389 | main.numSwitch, |
| 390 | remLink )\ |
| 391 | and linkDownResult |
| 392 | if not linkDownResult: |
| 393 | main.log.info( itemName + ": Topology mismatch" ) |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 394 | else: |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 395 | main.log.info( itemName + ": Topology match" ) |
kelvin-onlab | 7c577e8 | 2015-05-07 10:45:16 -0700 | [diff] [blame] | 396 | |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 397 | # Ping hosts |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 398 | main.log.info( itemName + ": Ping " + h1Name + " and " + |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 399 | h2Name ) |
| 400 | pingResult1 = main.Mininet1.pingHost( src=h1Name , target=h2Name ) |
| 401 | if not pingResult1: |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 402 | main.log.info( itemName + ": " + h1Name + " cannot ping " |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 403 | + h2Name ) |
| 404 | pingResult2 = main.Mininet1.pingHost( src=h2Name , target=h1Name ) |
| 405 | if not pingResult2: |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 406 | main.log.info( itemName + ": " + h2Name + " cannot ping " |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 407 | + h1Name ) |
| 408 | pingResult = pingResult1 and pingResult2 |
| 409 | if pingResult: |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 410 | main.log.info( itemName + ": Successfully pinged " + |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 411 | "both hosts" ) |
| 412 | else: |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 413 | main.log.info( itemName + ": Failed to ping " + |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 414 | "both hosts" ) |
| 415 | # link up |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 416 | main.log.info( itemName + ": Bring link up between " + |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 417 | sw1 + " and " + sw2 ) |
| 418 | main.Mininet1.link( end1=sw1, |
| 419 | end2=sw2, |
| 420 | option="up" ) |
| 421 | time.sleep( 5 ) |
kelvin-onlab | 7c577e8 | 2015-05-07 10:45:16 -0700 | [diff] [blame] | 422 | |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 423 | # Check onos topology |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 424 | main.log.info( itemName + ": Checking ONOS topology " ) |
| 425 | for i in range( main.numCtrls ): |
| 426 | topologyResult = main.CLIs[ i ].topology() |
| 427 | linkUpResult = main.ONOSbench.checkStatus( topologyResult, |
| 428 | main.numSwitch, |
| 429 | main.numLinks )\ |
| 430 | and linkUpResult |
| 431 | if not linkUpResult: |
| 432 | main.log.info( itemName + ": Topology mismatch" ) |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 433 | else: |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 434 | main.log.info( itemName + ": Topology match" ) |
kelvin-onlab | 7c577e8 | 2015-05-07 10:45:16 -0700 | [diff] [blame] | 435 | |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 436 | # Ping hosts |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 437 | main.log.info( itemName + ": Ping " + h1Name + " and " + |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 438 | h2Name ) |
| 439 | pingResult1 = main.Mininet1.pingHost( src=h1Name , target=h2Name ) |
| 440 | if not pingResult1: |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 441 | main.log.info( itemName + ": " + h1Name + " cannot ping " |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 442 | + h2Name ) |
| 443 | pingResult2 = main.Mininet1.pingHost( src=h2Name , target=h1Name ) |
| 444 | if not pingResult2: |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 445 | main.log.info( itemName + ": " + h2Name + " cannot ping " |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 446 | + h1Name ) |
| 447 | pingResult = pingResult1 and pingResult2 |
| 448 | if pingResult: |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 449 | main.log.info( itemName + ": Successfully pinged " + |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 450 | "both hosts" ) |
| 451 | else: |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 452 | main.log.info( itemName + ": Failed to ping " + |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 453 | "both hosts" ) |
| 454 | |
| 455 | # Remove intents |
| 456 | for intent in intentsId: |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 457 | main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True ) |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 458 | |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 459 | print main.CLIs[ 0 ].intents() |
| 460 | stepResult = pingResult and linkDownResult and linkUpResult \ |
| 461 | and intentResult |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 462 | utilities.assert_equals( expect=main.TRUE, |
| 463 | actual=stepResult, |
kelvin-onlab | 05cf773 | 2015-05-08 14:25:46 -0700 | [diff] [blame] | 464 | onpass=itemName + |
| 465 | ": host intent successful", |
| 466 | onfail=itemName + |
| 467 | ": Add host intent failed" ) |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 468 | def CASE1002( self, main ): |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 469 | """ |
| 470 | Add point intents between 2 hosts: |
| 471 | - Get device ids |
| 472 | - Add point intents |
| 473 | - Check intents |
| 474 | - Check flows |
| 475 | - Ping hosts |
| 476 | - Reroute |
| 477 | - Link down |
| 478 | - Ping hosts |
| 479 | - Link up |
| 480 | - Ping hosts |
| 481 | - Remove intents |
| 482 | """ |
| 483 | |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 484 | def CASE1003( self, main ): |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 485 | """ |
| 486 | Add single point to multi point intents |
| 487 | - Get device ids |
| 488 | - Add single point to multi point intents |
| 489 | - Check intents |
| 490 | - Check flows |
| 491 | - Ping hosts |
| 492 | - Reroute |
| 493 | - Link down |
| 494 | - Ping hosts |
| 495 | - Link up |
| 496 | - Ping hosts |
| 497 | - Remove intents |
| 498 | """ |
| 499 | |
kelvin-onlab | f70fd54 | 2015-05-07 18:41:40 -0700 | [diff] [blame] | 500 | def CASE1004( self, main ): |
kelvin-onlab | 65782a8 | 2015-05-07 14:12:13 -0700 | [diff] [blame] | 501 | """ |
| 502 | Add multi point to single point intents |
| 503 | - Get device ids |
| 504 | - Add multi point to single point intents |
| 505 | - Check intents |
| 506 | - Check flows |
| 507 | - Ping hosts |
| 508 | - Reroute |
| 509 | - Link down |
| 510 | - Ping hosts |
| 511 | - Link up |
| 512 | - Ping hosts |
| 513 | - Remove intents |
| 514 | """ |