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 | |
| 8 | def addHostIntent( main, item ): |
| 9 | """ |
| 10 | Add host intents |
| 11 | """ |
| 12 | import time |
| 13 | stepResult = main.TRUE |
| 14 | global itemName |
| 15 | itemName = item[ 'name' ] |
| 16 | h1Name = item[ 'host1' ][ 'name' ] |
| 17 | h2Name = item[ 'host2' ][ 'name' ] |
| 18 | h1Mac = item[ 'host1' ][ 'MAC' ] |
| 19 | h2Mac = item[ 'host2' ][ 'MAC' ] |
| 20 | h1Id = item[ 'host1' ][ 'id'] |
| 21 | h2Id = item[ 'host2' ][ 'id'] |
| 22 | sw1 = item[ 'link' ][ 'switch1' ] |
| 23 | sw2 = item[ 'link' ][ 'switch2' ] |
| 24 | expectLink = item[ 'link' ][ 'expect' ] |
| 25 | intentsId = [] |
| 26 | pingResult = main.TRUE |
| 27 | intentResult = main.TRUE |
| 28 | flowResult = main.TRUE |
| 29 | topoResult = main.TRUE |
| 30 | linkDownResult = main.TRUE |
| 31 | linkUpResult = main.TRUE |
| 32 | |
| 33 | # Discover hosts using arping |
| 34 | main.log.info( itemName + ": Discover host using arping" ) |
| 35 | main.Mininet1.arping( host=h1Name ) |
| 36 | main.Mininet1.arping( host=h2Name ) |
| 37 | host1 = main.CLIs[ 0 ].getHost( mac=h1Mac ) |
| 38 | host2 = main.CLIs[ 0 ].getHost( mac=h2Mac ) |
| 39 | |
| 40 | # Adding host intents |
| 41 | main.log.info( itemName + ": Adding host intents" ) |
| 42 | intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h1Id, |
| 43 | hostIdTwo=h2Id ) |
| 44 | intentsId.append( intent1 ) |
| 45 | time.sleep( 5 ) |
| 46 | intent2 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h2Id, |
| 47 | hostIdTwo=h1Id ) |
| 48 | intentsId.append( intent2 ) |
| 49 | |
| 50 | # Check intents state |
| 51 | time.sleep( 50 ) |
| 52 | intentResult = checkIntentState( main, intentsId ) |
| 53 | |
| 54 | # Verify flows |
| 55 | checkFlowsState( main ) |
| 56 | |
| 57 | # Ping hosts |
| 58 | pingHost( main, h1Name, h2Name ) |
| 59 | # Ping hosts again... |
| 60 | pingResult = pingHost( main, h1Name, h2Name ) |
| 61 | time.sleep( 5 ) |
| 62 | |
| 63 | # link down |
| 64 | link( main, sw1, sw2, "down" ) |
| 65 | intentResult = intentResult and checkIntentState( main, intentsId ) |
| 66 | |
| 67 | # Verify flows |
| 68 | checkFlowsState( main ) |
| 69 | |
| 70 | # Check OnosTopology |
| 71 | topoResult = checkTopology( main, expectLink ) |
| 72 | |
| 73 | # Ping hosts |
| 74 | pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
| 75 | |
| 76 | intentResult = checkIntentState( main, intentsId ) |
| 77 | |
| 78 | # link up |
| 79 | link( main, sw1, sw2, "up" ) |
| 80 | time.sleep( 5 ) |
| 81 | |
| 82 | # Verify flows |
| 83 | checkFlowsState( main ) |
| 84 | |
| 85 | # Check OnosTopology |
| 86 | topoResult = checkTopology( main, expectLink ) |
| 87 | |
| 88 | # Ping hosts |
| 89 | pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
| 90 | |
| 91 | # Remove intents |
| 92 | for intent in intentsId: |
| 93 | main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True ) |
| 94 | |
| 95 | print main.CLIs[ 0 ].intents() |
| 96 | stepResult = pingResult and linkDownResult and linkUpResult \ |
| 97 | and intentResult |
| 98 | |
| 99 | return stepResult |
| 100 | |
| 101 | def addPointIntent( main, item ): |
| 102 | """ |
| 103 | Add Point intents |
| 104 | """ |
| 105 | import time |
| 106 | stepResult = main.TRUE |
| 107 | global itemName |
| 108 | itemName = item[ 'name' ] |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame^] | 109 | h1Name = item[ 'host1' ][ 'name' ] |
| 110 | h2Name = item[ 'host2' ][ 'name' ] |
| 111 | ingressDevice = item[ 'ingressDevice' ] |
| 112 | egressDevice = item[ 'egressDevice' ] |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 113 | option = item[ 'option' ] |
| 114 | sw1 = item[ 'link' ][ 'switch1' ] |
| 115 | sw2 = item[ 'link' ][ 'switch2' ] |
| 116 | expectLink = item[ 'link' ][ 'expect' ] |
| 117 | intentsId = [] |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame^] | 118 | |
| 119 | # Assign options to variables |
| 120 | ingressPort = item.get( 'ingressPort' ) |
| 121 | egressPort = item.get( 'egressPort' ) |
| 122 | ethType = option.get( 'ethType' ) |
| 123 | ethSrc = option.get( 'ethSrc' ) |
| 124 | ethDst = option.get( 'ethDst' ) |
| 125 | bandwidth = option.get( 'bandwidth' ) |
| 126 | lambdaAlloc = option.get( 'lambdaAlloc' ) |
| 127 | ipProto = option.get( 'ipProto' ) |
| 128 | ipSrc = option.get( 'ipSrc' ) |
| 129 | ipDst = option.get( 'ipDst' ) |
| 130 | tcpSrc = option.get( 'tcpSrc' ) |
| 131 | tcpDst = option.get( 'tcpDst' ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 132 | |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame^] | 133 | if ingressPort == None: |
| 134 | ingressPort = "" |
| 135 | if egressPort == None: |
| 136 | egressPort = "" |
| 137 | if ethType == None: |
| 138 | ethType = "" |
| 139 | if ethSrc == None: |
| 140 | ethSrc = "" |
| 141 | if ethDst == None: |
| 142 | ethDst = "" |
| 143 | if bandwidth == None: |
| 144 | bandwidth = "" |
| 145 | if lambdaAlloc == None: |
| 146 | lambdaAlloc = False |
| 147 | if ipProto == None: |
| 148 | ipProto = "" |
| 149 | if ipSrc == None: |
| 150 | ipSrc = "" |
| 151 | if ipDst == None: |
| 152 | ipDst = "" |
| 153 | if tcpSrc == None: |
| 154 | tcpSrc = "" |
| 155 | if tcpDst == None: |
| 156 | tcpDst = "" |
| 157 | |
| 158 | """ |
| 159 | print 'ethType: ', ethType |
| 160 | print 'ethSrc: ', ethSrc |
| 161 | print 'ethDst: ', ethDst |
| 162 | print 'bandwidth', bandwidth |
| 163 | print 'lambdaAlloc: ', lambdaAlloc |
| 164 | print 'ipProto: ', ipProto |
| 165 | print 'ipSrc: ', ipSrc |
| 166 | print 'ipDst:', ipDst |
| 167 | print 'tcpSrc: ', tcpSrc |
| 168 | print 'tcpDst: ', tcpDst |
| 169 | """ |
| 170 | addedOption = "" |
| 171 | for i in range( len( option ) ): |
| 172 | addedOption = addedOption + option.keys()[ i ] + " = " + \ |
| 173 | option.values()[ i ] + "\n" |
| 174 | main.log.info( itemName + ": Printing added options...\n" + addedOption ) |
| 175 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 176 | pingResult = main.TRUE |
| 177 | intentResult = main.TRUE |
| 178 | flowResult = main.TRUE |
| 179 | topoResult = main.TRUE |
| 180 | linkDownResult = main.TRUE |
| 181 | linkUpResult = main.TRUE |
| 182 | |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame^] | 183 | # Adding bidirectional point intents |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 184 | main.log.info( itemName + ": Adding host intents" ) |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame^] | 185 | intent1 = main.CLIs[ 0 ].addPointIntent( ingressDevice=ingressDevice, |
| 186 | egressDevice=egressDevice, |
| 187 | portIngress=ingressPort, |
| 188 | portEgress=egressPort, |
| 189 | ethType=ethType, |
| 190 | ethSrc=ethSrc, |
| 191 | ethDst=ethDst, |
| 192 | bandwidth=bandwidth, |
| 193 | lambdaAlloc=lambdaAlloc, |
| 194 | ipProto=ipProto, |
| 195 | ipSrc=ipSrc, |
| 196 | ipDst=ipDst, |
| 197 | tcpSrc=tcpSrc, |
| 198 | tcpDst=tcpDst ) |
| 199 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 200 | intentsId.append( intent1 ) |
| 201 | time.sleep( 5 ) |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame^] | 202 | intent2 = main.CLIs[ 0 ].addPointIntent( ingressDevice=egressDevice, |
| 203 | egressDevice=ingressDevice, |
| 204 | portIngress=egressPort, |
| 205 | portEgress=ingressPort, |
| 206 | ethType=ethType, |
| 207 | ethSrc=ethDst, |
| 208 | ethDst=ethSrc, |
| 209 | bandwidth=bandwidth, |
| 210 | lambdaAlloc=lambdaAlloc, |
| 211 | ipProto=ipProto, |
| 212 | ipSrc=ipDst, |
| 213 | ipDst=ipSrc, |
| 214 | tcpSrc=tcpDst, |
| 215 | tcpDst=tcpSrc ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 216 | intentsId.append( intent2 ) |
| 217 | |
| 218 | # Check intents state |
| 219 | time.sleep( 50 ) |
| 220 | intentResult = checkIntentState( main, intentsId ) |
| 221 | |
| 222 | # Verify flows |
| 223 | checkFlowsState( main ) |
| 224 | |
| 225 | # Ping hosts |
| 226 | pingHost( main, h1Name, h2Name ) |
| 227 | # Ping hosts again... |
| 228 | pingResult = pingHost( main, h1Name, h2Name ) |
| 229 | time.sleep( 5 ) |
| 230 | |
| 231 | # link down |
| 232 | link( main, sw1, sw2, "down" ) |
| 233 | intentResult = intentResult and checkIntentState( main, intentsId ) |
| 234 | |
| 235 | # Verify flows |
| 236 | checkFlowsState( main ) |
| 237 | |
| 238 | # Check OnosTopology |
| 239 | topoResult = checkTopology( main, expectLink ) |
| 240 | |
| 241 | # Ping hosts |
| 242 | pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
| 243 | |
| 244 | intentResult = checkIntentState( main, intentsId ) |
| 245 | |
| 246 | # link up |
| 247 | link( main, sw1, sw2, "up" ) |
| 248 | time.sleep( 5 ) |
| 249 | |
| 250 | # Verify flows |
| 251 | checkFlowsState( main ) |
| 252 | |
| 253 | # Check OnosTopology |
| 254 | topoResult = checkTopology( main, expectLink ) |
| 255 | |
| 256 | # Ping hosts |
| 257 | pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
| 258 | |
| 259 | # Remove intents |
| 260 | for intent in intentsId: |
| 261 | main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True ) |
| 262 | |
| 263 | print main.CLIs[ 0 ].intents() |
| 264 | stepResult = pingResult and linkDownResult and linkUpResult \ |
| 265 | and intentResult |
| 266 | |
| 267 | return stepResult |
| 268 | |
| 269 | def link( main, sw1, sw2, option): |
| 270 | |
| 271 | # link down |
| 272 | main.log.info( itemName + ": Bring link " + option + "between " + |
| 273 | sw1 + " and " + sw2 ) |
| 274 | main.Mininet1.link( end1=sw1, end2=sw2, option=option ) |
| 275 | |
| 276 | def pingHost( main, h1Name, h2Name ): |
| 277 | |
| 278 | # Ping hosts |
| 279 | main.log.info( itemName + ": Ping " + h1Name + " and " + |
| 280 | h2Name ) |
| 281 | pingResult1 = main.Mininet1.pingHost( src=h1Name , target=h2Name ) |
| 282 | if not pingResult1: |
| 283 | main.log.info( itemName + ": " + h1Name + " cannot ping " |
| 284 | + h2Name ) |
| 285 | pingResult2 = main.Mininet1.pingHost( src=h2Name , target=h1Name ) |
| 286 | if not pingResult2: |
| 287 | main.log.info( itemName + ": " + h2Name + " cannot ping " |
| 288 | + h1Name ) |
| 289 | pingResult = pingResult1 and pingResult2 |
| 290 | if pingResult: |
| 291 | main.log.info( itemName + ": Successfully pinged " + |
| 292 | "both hosts" ) |
| 293 | else: |
| 294 | main.log.info( itemName + ": Failed to ping " + |
| 295 | "both hosts" ) |
| 296 | return pingResult |
| 297 | |
| 298 | def checkItem( item ): |
| 299 | """ |
| 300 | Checks the dictionary |
| 301 | """ |
| 302 | |
| 303 | def checkTopology( main, expectedLink ): |
| 304 | statusResult = main.TRUE |
| 305 | # Check onos topology |
| 306 | main.log.info( itemName + ": Checking ONOS topology " ) |
| 307 | |
| 308 | for i in range( main.numCtrls ): |
| 309 | topologyResult = main.CLIs[ i ].topology() |
| 310 | statusResult = main.ONOSbench.checkStatus( topologyResult, |
| 311 | main.numSwitch, |
| 312 | expectedLink )\ |
| 313 | and statusResult |
| 314 | if not statusResult: |
| 315 | main.log.info( itemName + ": Topology mismatch" ) |
| 316 | else: |
| 317 | main.log.info( itemName + ": Topology match" ) |
| 318 | return statusResult |
| 319 | |
| 320 | def checkIntentState( main, intentsId ): |
| 321 | |
| 322 | main.log.info( itemName + ": Check host intents state" ) |
| 323 | for i in range( main.numCtrls ): |
| 324 | intentResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId ) |
| 325 | if not intentResult: |
| 326 | main.log.info( itemName + ": Check host intents state again") |
| 327 | for i in range( main.numCtrls ): |
| 328 | intentResult = main.CLIs[ i ].checkIntentState( |
| 329 | intentsId=intentsId ) |
| 330 | return intentResult |
| 331 | |
| 332 | def checkFlowsState( main ): |
| 333 | |
| 334 | main.log.info( itemName + ": Check flows state" ) |
| 335 | checkFlowsResult = main.CLIs[ 0 ].checkFlowsState() |
| 336 | return checkFlowsResult |
| 337 | |
| 338 | def printMsg( main, h1Name, h2Name ): |
| 339 | main.log.info("PINGING HOST INSIDE printMSG") |
| 340 | pingHost( main, itemName, h1Name, h2Name ) |
| 341 | print 'lala' |
| 342 | |