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="", |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 274 | hostNames="", |
| 275 | devices="", |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 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 |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 289 | If main.hostsData is not defined, variables data should be passed in the |
| 290 | same order index wise. |
| 291 | eg. hostName = [ 'h1', 'h2' ,.. ] |
| 292 | devices = [ 'of:0000000000000001', 'of:0000000000000002', ...] |
| 293 | ports = [ '1', '1', ..] |
| 294 | ... |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 295 | """ |
| 296 | import time |
| 297 | assert main, "There is no main variable" |
| 298 | assert name, "variable name is empty" |
| 299 | assert hostNames, "You must specify hosts" |
| 300 | assert devices or main.hostsData, "You must specify devices" |
| 301 | |
| 302 | global itemName |
| 303 | itemName = name |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 304 | tempHostsData = {} |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 305 | intentsId = [] |
| 306 | |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 307 | if hostNames and devices: |
| 308 | if len( hostNames ) != len( devices ): |
| 309 | main.log.error( "hosts and devices does not have the same length" ) |
| 310 | print "hostNames = ", len( hostNames ) |
| 311 | print "devices = ", len( devices ) |
| 312 | return main.FALSE |
| 313 | if ports: |
| 314 | if len( ports ) != len( devices ): |
| 315 | main.log.error( "Ports and devices does " + |
| 316 | "not have the same length" ) |
| 317 | print "devices = ", len( devices ) |
| 318 | print "ports = ", len( ports ) |
| 319 | return main.FALSE |
| 320 | else: |
| 321 | main.log.info( "Device Ports are not specified" ) |
| 322 | elif hostNames and not devices and main.hostsData: |
| 323 | main.log.info( "singleToMultiIntent function is using main.hostsData" ) |
| 324 | print main.hostsData |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 325 | |
| 326 | pingResult = main.TRUE |
| 327 | intentResult = main.TRUE |
| 328 | flowResult = main.TRUE |
| 329 | topoResult = main.TRUE |
| 330 | linkDownResult = main.TRUE |
| 331 | linkUpResult = main.TRUE |
| 332 | |
| 333 | # Adding bidirectional point intents |
| 334 | main.log.info( itemName + ": Adding host intents" ) |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 335 | intent1 = main.CLIs[ 0 ].addSinglepointToMultipointIntent( |
| 336 | ingressDevice=deviceId1, |
| 337 | egressDevice=deviceId2, |
| 338 | portIngress=port1, |
| 339 | portEgress=port2, |
| 340 | ethType=ethType, |
| 341 | ethSrc=mac1, |
| 342 | ethDst=mac2, |
| 343 | bandwidth=bandwidth, |
| 344 | lambdaAlloc=lambdaAlloc, |
| 345 | ipProto=ipProto, |
| 346 | ipSrc=ip1, |
| 347 | ipDst=ip2, |
| 348 | tcpSrc=tcp1, |
| 349 | tcpDst=tcp2 ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 350 | |
| 351 | intentsId.append( intent1 ) |
| 352 | time.sleep( 5 ) |
| 353 | intent2 = main.CLIs[ 0 ].addPointIntent( ingressDevice=deviceId2, |
| 354 | egressDevice=deviceId1, |
| 355 | portIngress=port2, |
| 356 | portEgress=port1, |
| 357 | ethType=ethType, |
| 358 | ethSrc=mac2, |
| 359 | ethDst=mac1, |
| 360 | bandwidth=bandwidth, |
| 361 | lambdaAlloc=lambdaAlloc, |
| 362 | ipProto=ipProto, |
| 363 | ipSrc=ip2, |
| 364 | ipDst=ip1, |
| 365 | tcpSrc=tcp2, |
| 366 | tcpDst=tcp1 ) |
| 367 | intentsId.append( intent2 ) |
| 368 | |
| 369 | # Check intents state |
| 370 | time.sleep( 50 ) |
| 371 | intentResult = checkIntentState( main, intentsId ) |
| 372 | |
| 373 | # Verify flows |
| 374 | checkFlowsState( main ) |
| 375 | |
| 376 | # Ping hosts |
| 377 | pingHost( main, h1Name, h2Name ) |
| 378 | # Ping hosts again... |
| 379 | pingResult = pingHost( main, h1Name, h2Name ) |
| 380 | time.sleep( 5 ) |
| 381 | |
| 382 | if sw1 and sw2 and expectedLink: |
| 383 | # link down |
| 384 | link( main, sw1, sw2, "down" ) |
| 385 | intentResult = intentResult and checkIntentState( main, intentsId ) |
| 386 | |
| 387 | # Verify flows |
| 388 | checkFlowsState( main ) |
| 389 | |
| 390 | # Check OnosTopology |
| 391 | topoResult = checkTopology( main, expectedLink ) |
| 392 | |
| 393 | # Ping hosts |
| 394 | pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
| 395 | |
| 396 | intentResult = checkIntentState( main, intentsId ) |
| 397 | |
| 398 | # link up |
| 399 | link( main, sw1, sw2, "up" ) |
| 400 | time.sleep( 5 ) |
| 401 | |
| 402 | # Verify flows |
| 403 | checkFlowsState( main ) |
| 404 | |
| 405 | # Check OnosTopology |
| 406 | topoResult = checkTopology( main, expectedLink ) |
| 407 | |
| 408 | # Ping hosts |
| 409 | pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
| 410 | |
| 411 | # Remove intents |
| 412 | for intent in intentsId: |
| 413 | main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True ) |
| 414 | |
| 415 | print main.CLIs[ 0 ].intents() |
| 416 | stepResult = pingResult and linkDownResult and linkUpResult \ |
| 417 | and intentResult |
| 418 | |
| 419 | return stepResult |
| 420 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 421 | def link( main, sw1, sw2, option): |
| 422 | |
| 423 | # link down |
| 424 | main.log.info( itemName + ": Bring link " + option + "between " + |
| 425 | sw1 + " and " + sw2 ) |
| 426 | main.Mininet1.link( end1=sw1, end2=sw2, option=option ) |
| 427 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 428 | def pingAllHost( main, hosts ): |
| 429 | # Ping all host in the hosts list variable |
| 430 | import itertools |
| 431 | |
| 432 | main.log.info( itemName + ": Ping host list - " + hosts ) |
| 433 | hostCombination = itertools.permutation( hosts, 2 ) |
| 434 | pingResult = main.TRUE |
| 435 | for hostPair in hostCombination: |
| 436 | pingResult = pingResult and main.Mininet.pingHost( |
| 437 | src=hostPair[ 0 ], |
| 438 | target=hostPair[ 1 ] ) |
| 439 | return pingResult |
| 440 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 441 | def pingHost( main, h1Name, h2Name ): |
| 442 | |
| 443 | # Ping hosts |
| 444 | main.log.info( itemName + ": Ping " + h1Name + " and " + |
| 445 | h2Name ) |
| 446 | pingResult1 = main.Mininet1.pingHost( src=h1Name , target=h2Name ) |
| 447 | if not pingResult1: |
| 448 | main.log.info( itemName + ": " + h1Name + " cannot ping " |
| 449 | + h2Name ) |
| 450 | pingResult2 = main.Mininet1.pingHost( src=h2Name , target=h1Name ) |
| 451 | if not pingResult2: |
| 452 | main.log.info( itemName + ": " + h2Name + " cannot ping " |
| 453 | + h1Name ) |
| 454 | pingResult = pingResult1 and pingResult2 |
| 455 | if pingResult: |
| 456 | main.log.info( itemName + ": Successfully pinged " + |
| 457 | "both hosts" ) |
| 458 | else: |
| 459 | main.log.info( itemName + ": Failed to ping " + |
| 460 | "both hosts" ) |
| 461 | return pingResult |
| 462 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 463 | def getHostsData( main ): |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 464 | """ |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 465 | Use fwd app and pingall to discover all the hosts |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 466 | """ |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 467 | """ |
| 468 | hosts json format: |
| 469 | """ |
| 470 | import json |
| 471 | activateResult = main.TRUE |
| 472 | appCheck = main.TRUE |
| 473 | main.log.info( "Activating reactive forwarding app " ) |
| 474 | activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" ) |
| 475 | |
| 476 | for i in range( main.numCtrls ): |
| 477 | appCheck = appCheck and main.CLIs[ i ].appToIDCheck() |
| 478 | |
| 479 | if appCheck != main.TRUE: |
| 480 | main.log.warn( main.CLIs[ 0 ].apps() ) |
| 481 | main.log.warn( main.CLIs[ 0 ].appIDs() ) |
| 482 | |
| 483 | pingResult = main.Mininet1.pingall() |
| 484 | hostsJson = json.loads( main.CLIs[ 0 ].hosts() ) |
| 485 | hosts = main.Mininet1.getHosts() |
| 486 | for host in hosts: |
| 487 | main.hostsData[ host ] = {} |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 488 | main.hostsData[ host ][ 'mac' ] = \ |
| 489 | main.Mininet1.getMacAddress( host ).upper() |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 490 | for hostj in hostsJson: |
| 491 | if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]: |
| 492 | main.hostsData[ host ][ 'id' ] = hostj[ 'id' ] |
| 493 | main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ] |
| 494 | main.hostsData[ host ][ 'location' ] = \ |
| 495 | hostj[ 'location' ][ 'elementId' ] + '/' + \ |
| 496 | hostj[ 'location' ][ 'port' ] |
| 497 | main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ] |
| 498 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 499 | main.log.info( "Deactivating reactive forwarding app " ) |
| 500 | activateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 501 | print main.hostsData |
| 502 | return pingResult |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 503 | |
| 504 | def checkTopology( main, expectedLink ): |
| 505 | statusResult = main.TRUE |
| 506 | # Check onos topology |
| 507 | main.log.info( itemName + ": Checking ONOS topology " ) |
| 508 | |
| 509 | for i in range( main.numCtrls ): |
| 510 | topologyResult = main.CLIs[ i ].topology() |
| 511 | statusResult = main.ONOSbench.checkStatus( topologyResult, |
| 512 | main.numSwitch, |
| 513 | expectedLink )\ |
| 514 | and statusResult |
| 515 | if not statusResult: |
| 516 | main.log.info( itemName + ": Topology mismatch" ) |
| 517 | else: |
| 518 | main.log.info( itemName + ": Topology match" ) |
| 519 | return statusResult |
| 520 | |
| 521 | def checkIntentState( main, intentsId ): |
| 522 | |
| 523 | main.log.info( itemName + ": Check host intents state" ) |
| 524 | for i in range( main.numCtrls ): |
| 525 | intentResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId ) |
| 526 | if not intentResult: |
| 527 | main.log.info( itemName + ": Check host intents state again") |
| 528 | for i in range( main.numCtrls ): |
| 529 | intentResult = main.CLIs[ i ].checkIntentState( |
| 530 | intentsId=intentsId ) |
| 531 | return intentResult |
| 532 | |
| 533 | def checkFlowsState( main ): |
| 534 | |
| 535 | main.log.info( itemName + ": Check flows state" ) |
| 536 | checkFlowsResult = main.CLIs[ 0 ].checkFlowsState() |
| 537 | return checkFlowsResult |
| 538 | |
| 539 | def printMsg( main, h1Name, h2Name ): |
| 540 | main.log.info("PINGING HOST INSIDE printMSG") |
| 541 | pingHost( main, itemName, h1Name, h2Name ) |
| 542 | print 'lala' |
| 543 | |