kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 1 | """ |
| 2 | Wrapper functions for FuncIntent |
| 3 | This functions include Onosclidriver and Mininetclidriver driver functions |
| 4 | """ |
| 5 | def __init__( self ): |
| 6 | self.default = '' |
| 7 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 8 | def hostIntent( main, |
| 9 | name="", |
| 10 | host1="", |
| 11 | host2="", |
| 12 | host1Id="", |
| 13 | host2Id="", |
| 14 | mac1="", |
| 15 | mac2="", |
| 16 | vlan1="-1", |
| 17 | vlan2="-1", |
| 18 | sw1="", |
| 19 | sw2="", |
| 20 | expectedLink=0 ): |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 21 | """ |
| 22 | Add host intents |
| 23 | """ |
| 24 | import time |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 25 | |
| 26 | # Assert variables |
| 27 | assert main, "There is no main variable" |
| 28 | assert name, "variable name is empty" |
| 29 | assert host1 and host2, "You must specify hosts" |
| 30 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 31 | global itemName |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 32 | itemName = name |
| 33 | h1Name = host1 |
| 34 | h2Name = host2 |
| 35 | h1Id = host1Id |
| 36 | h2Id = host2Id |
| 37 | h1Mac = mac1 |
| 38 | h2Mac = mac2 |
| 39 | vlan1 = vlan1 |
| 40 | vlan2 = vlan2 |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 41 | intentsId = [] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 42 | stepResult = main.TRUE |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 43 | pingResult = main.TRUE |
| 44 | intentResult = main.TRUE |
| 45 | flowResult = main.TRUE |
| 46 | topoResult = main.TRUE |
| 47 | linkDownResult = main.TRUE |
| 48 | linkUpResult = main.TRUE |
| 49 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 50 | if main.hostsData: |
| 51 | if not h1Mac: |
| 52 | h1Mac = main.hostsData[ h1Name ][ 'mac' ] |
| 53 | if not h2Mac: |
| 54 | h2Mac = main.hostsData[ h2Name ][ 'mac' ] |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 55 | print '1', main.hostsData[ h1Name ] |
| 56 | print '2', main.hostsData[ h2Name ] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 57 | if main.hostsData[ h1Name ][ 'vlan' ] != '-1': |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 58 | print 'vlan1', main.hostsData[ h1Name ][ 'vlan' ] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 59 | vlan1 = main.hostsData[ h1Name ][ 'vlan' ] |
| 60 | if main.hostsData[ h2Name ][ 'vlan' ] != '-1': |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 61 | print 'vlan2', main.hostsData[ h2Name ][ 'vlan' ] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 62 | vlan2 = main.hostsData[ h2Name ][ 'vlan' ] |
| 63 | if not h1Id: |
| 64 | h1Id = main.hostsData[ h1Name ][ 'id' ] |
| 65 | if not h2Id: |
| 66 | h2Id = main.hostsData[ h2Name ][ 'id' ] |
| 67 | |
| 68 | assert h1Id and h2Id, "You must specify host IDs" |
| 69 | if not ( h1Id and h2Id ): |
| 70 | main.log.info( "There are no host IDs" ) |
| 71 | return main.FALSE |
| 72 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 73 | # Discover hosts using arping |
| 74 | main.log.info( itemName + ": Discover host using arping" ) |
| 75 | main.Mininet1.arping( host=h1Name ) |
| 76 | main.Mininet1.arping( host=h2Name ) |
| 77 | host1 = main.CLIs[ 0 ].getHost( mac=h1Mac ) |
| 78 | host2 = main.CLIs[ 0 ].getHost( mac=h2Mac ) |
| 79 | |
| 80 | # Adding host intents |
| 81 | main.log.info( itemName + ": Adding host intents" ) |
| 82 | intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h1Id, |
| 83 | hostIdTwo=h2Id ) |
| 84 | intentsId.append( intent1 ) |
| 85 | time.sleep( 5 ) |
| 86 | intent2 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h2Id, |
| 87 | hostIdTwo=h1Id ) |
| 88 | intentsId.append( intent2 ) |
| 89 | |
| 90 | # Check intents state |
| 91 | time.sleep( 50 ) |
| 92 | intentResult = checkIntentState( main, intentsId ) |
| 93 | |
| 94 | # Verify flows |
| 95 | checkFlowsState( main ) |
| 96 | |
| 97 | # Ping hosts |
| 98 | pingHost( main, h1Name, h2Name ) |
| 99 | # Ping hosts again... |
| 100 | pingResult = pingHost( main, h1Name, h2Name ) |
| 101 | time.sleep( 5 ) |
| 102 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 103 | # Test rerouting if these variables exist |
| 104 | if sw1 and sw2 and expectedLink: |
| 105 | # link down |
| 106 | link( main, sw1, sw2, "down" ) |
| 107 | intentResult = intentResult and checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 108 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 109 | # Verify flows |
| 110 | checkFlowsState( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 111 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 112 | # Check OnosTopology |
| 113 | topoResult = checkTopology( main, expectedLink ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 114 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 115 | # Ping hosts |
| 116 | pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 117 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 118 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 119 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 120 | # link up |
| 121 | link( main, sw1, sw2, "up" ) |
| 122 | time.sleep( 5 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 123 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 124 | # Verify flows |
| 125 | checkFlowsState( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 126 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 127 | # Check OnosTopology |
| 128 | topoResult = checkTopology( main, expectedLink ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 129 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 130 | # Ping hosts |
| 131 | pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 132 | |
| 133 | # Remove intents |
| 134 | for intent in intentsId: |
| 135 | main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True ) |
| 136 | |
| 137 | print main.CLIs[ 0 ].intents() |
| 138 | stepResult = pingResult and linkDownResult and linkUpResult \ |
| 139 | and intentResult |
| 140 | |
| 141 | return stepResult |
| 142 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 143 | def pointIntent( main, |
| 144 | name="", |
| 145 | host1="", |
| 146 | host2="", |
| 147 | deviceId1="", |
| 148 | deviceId2="", |
| 149 | port1="", |
| 150 | port2="", |
| 151 | ethType="", |
| 152 | mac1="", |
| 153 | mac2="", |
| 154 | bandwidth="", |
| 155 | lambdaAlloc=False, |
| 156 | ipProto="", |
| 157 | ip1="", |
| 158 | ip2="", |
| 159 | tcp1="", |
| 160 | tcp2="", |
| 161 | sw1="", |
| 162 | sw2="", |
| 163 | expectedLink=0 ): |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 164 | """ |
| 165 | Add Point intents |
| 166 | """ |
| 167 | import time |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 168 | assert main, "There is no main variable" |
| 169 | assert name, "variable name is empty" |
| 170 | assert host1 and host2, "You must specify hosts" |
| 171 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 172 | global itemName |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 173 | itemName = name |
| 174 | h1Name = host1 |
| 175 | h2Name = host2 |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 176 | intentsId = [] |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 177 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 178 | pingResult = main.TRUE |
| 179 | intentResult = main.TRUE |
| 180 | flowResult = main.TRUE |
| 181 | topoResult = main.TRUE |
| 182 | linkDownResult = main.TRUE |
| 183 | linkUpResult = main.TRUE |
| 184 | |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 185 | # Adding bidirectional point intents |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 186 | main.log.info( itemName + ": Adding host intents" ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 187 | intent1 = main.CLIs[ 0 ].addPointIntent( ingressDevice=deviceId1, |
| 188 | egressDevice=deviceId2, |
| 189 | portIngress=port1, |
| 190 | portEgress=port2, |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 191 | ethType=ethType, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 192 | ethSrc=mac1, |
| 193 | ethDst=mac2, |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 194 | bandwidth=bandwidth, |
| 195 | lambdaAlloc=lambdaAlloc, |
| 196 | ipProto=ipProto, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 197 | ipSrc=ip1, |
| 198 | ipDst=ip2, |
| 199 | tcpSrc=tcp1, |
| 200 | tcpDst=tcp2 ) |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 201 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 202 | intentsId.append( intent1 ) |
| 203 | time.sleep( 5 ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 204 | intent2 = main.CLIs[ 0 ].addPointIntent( ingressDevice=deviceId2, |
| 205 | egressDevice=deviceId1, |
| 206 | portIngress=port2, |
| 207 | portEgress=port1, |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 208 | ethType=ethType, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 209 | ethSrc=mac2, |
| 210 | ethDst=mac1, |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 211 | bandwidth=bandwidth, |
| 212 | lambdaAlloc=lambdaAlloc, |
| 213 | ipProto=ipProto, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 214 | ipSrc=ip2, |
| 215 | ipDst=ip1, |
| 216 | tcpSrc=tcp2, |
| 217 | tcpDst=tcp1 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 218 | intentsId.append( intent2 ) |
| 219 | |
| 220 | # Check intents state |
| 221 | time.sleep( 50 ) |
| 222 | intentResult = checkIntentState( main, intentsId ) |
| 223 | |
| 224 | # Verify flows |
| 225 | checkFlowsState( main ) |
| 226 | |
| 227 | # Ping hosts |
| 228 | pingHost( main, h1Name, h2Name ) |
| 229 | # Ping hosts again... |
| 230 | pingResult = pingHost( main, h1Name, h2Name ) |
| 231 | time.sleep( 5 ) |
| 232 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 233 | if sw1 and sw2 and expectedLink: |
| 234 | # link down |
| 235 | link( main, sw1, sw2, "down" ) |
| 236 | intentResult = intentResult and checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 237 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 238 | # Verify flows |
| 239 | checkFlowsState( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 240 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 241 | # Check OnosTopology |
| 242 | topoResult = checkTopology( main, expectedLink ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 243 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 244 | # Ping hosts |
| 245 | pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 246 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 247 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 248 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 249 | # link up |
| 250 | link( main, sw1, sw2, "up" ) |
| 251 | time.sleep( 5 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 252 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 253 | # Verify flows |
| 254 | checkFlowsState( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 255 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 256 | # Check OnosTopology |
| 257 | topoResult = checkTopology( main, expectedLink ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 258 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 259 | # Ping hosts |
| 260 | pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 261 | |
| 262 | # Remove intents |
| 263 | for intent in intentsId: |
| 264 | main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True ) |
| 265 | |
| 266 | print main.CLIs[ 0 ].intents() |
| 267 | stepResult = pingResult and linkDownResult and linkUpResult \ |
| 268 | and intentResult |
| 269 | |
| 270 | return stepResult |
| 271 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 272 | def singleToMultiIntent( main, |
| 273 | name="", |
| 274 | hostNames=None, |
| 275 | devices=None, |
| 276 | ports=None, |
| 277 | ethType="", |
| 278 | macs=None, |
| 279 | bandwidth="", |
| 280 | lambdaAlloc=False, |
| 281 | ipProto="", |
| 282 | ipAddresses="", |
| 283 | tcp="", |
| 284 | sw1="", |
| 285 | sw2="", |
| 286 | expectedLink=0 ): |
| 287 | """ |
| 288 | Add Single to Multi Point intents |
| 289 | """ |
| 290 | import time |
| 291 | assert main, "There is no main variable" |
| 292 | assert name, "variable name is empty" |
| 293 | assert hostNames, "You must specify hosts" |
| 294 | assert devices or main.hostsData, "You must specify devices" |
| 295 | |
| 296 | global itemName |
| 297 | itemName = name |
| 298 | h1Name = host1 |
| 299 | h2Name = host2 |
| 300 | intentsId = [] |
| 301 | |
| 302 | if devices and ports: |
| 303 | if len( devices ) and len( ports ): |
| 304 | main.log.info( itemName + |
| 305 | ": devices and ports are not the same lenght " + |
| 306 | "devices - " + str( len( devices ) ) + " ports - " |
| 307 | + str( len( ports ) ) ) |
| 308 | |
| 309 | |
| 310 | |
| 311 | pingResult = main.TRUE |
| 312 | intentResult = main.TRUE |
| 313 | flowResult = main.TRUE |
| 314 | topoResult = main.TRUE |
| 315 | linkDownResult = main.TRUE |
| 316 | linkUpResult = main.TRUE |
| 317 | |
| 318 | # Adding bidirectional point intents |
| 319 | main.log.info( itemName + ": Adding host intents" ) |
| 320 | intent1 = main.CLIs[ 0 ].addPointIntent( ingressDevice=deviceId1, |
| 321 | egressDevice=deviceId2, |
| 322 | portIngress=port1, |
| 323 | portEgress=port2, |
| 324 | ethType=ethType, |
| 325 | ethSrc=mac1, |
| 326 | ethDst=mac2, |
| 327 | bandwidth=bandwidth, |
| 328 | lambdaAlloc=lambdaAlloc, |
| 329 | ipProto=ipProto, |
| 330 | ipSrc=ip1, |
| 331 | ipDst=ip2, |
| 332 | tcpSrc=tcp1, |
| 333 | tcpDst=tcp2 ) |
| 334 | |
| 335 | intentsId.append( intent1 ) |
| 336 | time.sleep( 5 ) |
| 337 | intent2 = main.CLIs[ 0 ].addPointIntent( ingressDevice=deviceId2, |
| 338 | egressDevice=deviceId1, |
| 339 | portIngress=port2, |
| 340 | portEgress=port1, |
| 341 | ethType=ethType, |
| 342 | ethSrc=mac2, |
| 343 | ethDst=mac1, |
| 344 | bandwidth=bandwidth, |
| 345 | lambdaAlloc=lambdaAlloc, |
| 346 | ipProto=ipProto, |
| 347 | ipSrc=ip2, |
| 348 | ipDst=ip1, |
| 349 | tcpSrc=tcp2, |
| 350 | tcpDst=tcp1 ) |
| 351 | intentsId.append( intent2 ) |
| 352 | |
| 353 | # Check intents state |
| 354 | time.sleep( 50 ) |
| 355 | intentResult = checkIntentState( main, intentsId ) |
| 356 | |
| 357 | # Verify flows |
| 358 | checkFlowsState( main ) |
| 359 | |
| 360 | # Ping hosts |
| 361 | pingHost( main, h1Name, h2Name ) |
| 362 | # Ping hosts again... |
| 363 | pingResult = pingHost( main, h1Name, h2Name ) |
| 364 | time.sleep( 5 ) |
| 365 | |
| 366 | if sw1 and sw2 and expectedLink: |
| 367 | # link down |
| 368 | link( main, sw1, sw2, "down" ) |
| 369 | intentResult = intentResult and checkIntentState( main, intentsId ) |
| 370 | |
| 371 | # Verify flows |
| 372 | checkFlowsState( main ) |
| 373 | |
| 374 | # Check OnosTopology |
| 375 | topoResult = checkTopology( main, expectedLink ) |
| 376 | |
| 377 | # Ping hosts |
| 378 | pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
| 379 | |
| 380 | intentResult = checkIntentState( main, intentsId ) |
| 381 | |
| 382 | # link up |
| 383 | link( main, sw1, sw2, "up" ) |
| 384 | time.sleep( 5 ) |
| 385 | |
| 386 | # Verify flows |
| 387 | checkFlowsState( main ) |
| 388 | |
| 389 | # Check OnosTopology |
| 390 | topoResult = checkTopology( main, expectedLink ) |
| 391 | |
| 392 | # Ping hosts |
| 393 | pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
| 394 | |
| 395 | # Remove intents |
| 396 | for intent in intentsId: |
| 397 | main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True ) |
| 398 | |
| 399 | print main.CLIs[ 0 ].intents() |
| 400 | stepResult = pingResult and linkDownResult and linkUpResult \ |
| 401 | and intentResult |
| 402 | |
| 403 | return stepResult |
| 404 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 405 | def link( main, sw1, sw2, option): |
| 406 | |
| 407 | # link down |
| 408 | main.log.info( itemName + ": Bring link " + option + "between " + |
| 409 | sw1 + " and " + sw2 ) |
| 410 | main.Mininet1.link( end1=sw1, end2=sw2, option=option ) |
| 411 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 412 | def pingAllHost( main, hosts ): |
| 413 | # Ping all host in the hosts list variable |
| 414 | import itertools |
| 415 | |
| 416 | main.log.info( itemName + ": Ping host list - " + hosts ) |
| 417 | hostCombination = itertools.permutation( hosts, 2 ) |
| 418 | pingResult = main.TRUE |
| 419 | for hostPair in hostCombination: |
| 420 | pingResult = pingResult and main.Mininet.pingHost( |
| 421 | src=hostPair[ 0 ], |
| 422 | target=hostPair[ 1 ] ) |
| 423 | return pingResult |
| 424 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 425 | def pingHost( main, h1Name, h2Name ): |
| 426 | |
| 427 | # Ping hosts |
| 428 | main.log.info( itemName + ": Ping " + h1Name + " and " + |
| 429 | h2Name ) |
| 430 | pingResult1 = main.Mininet1.pingHost( src=h1Name , target=h2Name ) |
| 431 | if not pingResult1: |
| 432 | main.log.info( itemName + ": " + h1Name + " cannot ping " |
| 433 | + h2Name ) |
| 434 | pingResult2 = main.Mininet1.pingHost( src=h2Name , target=h1Name ) |
| 435 | if not pingResult2: |
| 436 | main.log.info( itemName + ": " + h2Name + " cannot ping " |
| 437 | + h1Name ) |
| 438 | pingResult = pingResult1 and pingResult2 |
| 439 | if pingResult: |
| 440 | main.log.info( itemName + ": Successfully pinged " + |
| 441 | "both hosts" ) |
| 442 | else: |
| 443 | main.log.info( itemName + ": Failed to ping " + |
| 444 | "both hosts" ) |
| 445 | return pingResult |
| 446 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 447 | def getHostsData( main ): |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 448 | """ |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 449 | Use fwd app and pingall to discover all the hosts |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 450 | """ |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 451 | """ |
| 452 | hosts json format: |
| 453 | """ |
| 454 | import json |
| 455 | activateResult = main.TRUE |
| 456 | appCheck = main.TRUE |
| 457 | main.log.info( "Activating reactive forwarding app " ) |
| 458 | activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" ) |
| 459 | |
| 460 | for i in range( main.numCtrls ): |
| 461 | appCheck = appCheck and main.CLIs[ i ].appToIDCheck() |
| 462 | |
| 463 | if appCheck != main.TRUE: |
| 464 | main.log.warn( main.CLIs[ 0 ].apps() ) |
| 465 | main.log.warn( main.CLIs[ 0 ].appIDs() ) |
| 466 | |
| 467 | pingResult = main.Mininet1.pingall() |
| 468 | hostsJson = json.loads( main.CLIs[ 0 ].hosts() ) |
| 469 | hosts = main.Mininet1.getHosts() |
| 470 | for host in hosts: |
| 471 | main.hostsData[ host ] = {} |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 472 | main.hostsData[ host ][ 'mac' ] = \ |
| 473 | main.Mininet1.getMacAddress( host ).upper() |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 474 | for hostj in hostsJson: |
| 475 | if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]: |
| 476 | main.hostsData[ host ][ 'id' ] = hostj[ 'id' ] |
| 477 | main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ] |
| 478 | main.hostsData[ host ][ 'location' ] = \ |
| 479 | hostj[ 'location' ][ 'elementId' ] + '/' + \ |
| 480 | hostj[ 'location' ][ 'port' ] |
| 481 | main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ] |
| 482 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 483 | main.log.info( "Deactivating reactive forwarding app " ) |
| 484 | activateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 485 | print main.hostsData |
| 486 | return pingResult |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 487 | |
| 488 | def checkTopology( main, expectedLink ): |
| 489 | statusResult = main.TRUE |
| 490 | # Check onos topology |
| 491 | main.log.info( itemName + ": Checking ONOS topology " ) |
| 492 | |
| 493 | for i in range( main.numCtrls ): |
| 494 | topologyResult = main.CLIs[ i ].topology() |
| 495 | statusResult = main.ONOSbench.checkStatus( topologyResult, |
| 496 | main.numSwitch, |
| 497 | expectedLink )\ |
| 498 | and statusResult |
| 499 | if not statusResult: |
| 500 | main.log.info( itemName + ": Topology mismatch" ) |
| 501 | else: |
| 502 | main.log.info( itemName + ": Topology match" ) |
| 503 | return statusResult |
| 504 | |
| 505 | def checkIntentState( main, intentsId ): |
| 506 | |
| 507 | main.log.info( itemName + ": Check host intents state" ) |
| 508 | for i in range( main.numCtrls ): |
| 509 | intentResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId ) |
| 510 | if not intentResult: |
| 511 | main.log.info( itemName + ": Check host intents state again") |
| 512 | for i in range( main.numCtrls ): |
| 513 | intentResult = main.CLIs[ i ].checkIntentState( |
| 514 | intentsId=intentsId ) |
| 515 | return intentResult |
| 516 | |
| 517 | def checkFlowsState( main ): |
| 518 | |
| 519 | main.log.info( itemName + ": Check flows state" ) |
| 520 | checkFlowsResult = main.CLIs[ 0 ].checkFlowsState() |
| 521 | return checkFlowsResult |
| 522 | |
| 523 | def printMsg( main, h1Name, h2Name ): |
| 524 | main.log.info("PINGING HOST INSIDE printMSG") |
| 525 | pingHost( main, itemName, h1Name, h2Name ) |
| 526 | print 'lala' |
| 527 | |