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