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' ] |
| 109 | ingress = item[ 'ingress' ] |
| 110 | egress = item[ 'egress' ] |
| 111 | option = item[ 'option' ] |
| 112 | sw1 = item[ 'link' ][ 'switch1' ] |
| 113 | sw2 = item[ 'link' ][ 'switch2' ] |
| 114 | expectLink = item[ 'link' ][ 'expect' ] |
| 115 | intentsId = [] |
| 116 | |
| 117 | print 'OPTIONS ', option |
| 118 | return main.TRUE |
| 119 | pingResult = main.TRUE |
| 120 | intentResult = main.TRUE |
| 121 | flowResult = main.TRUE |
| 122 | topoResult = main.TRUE |
| 123 | linkDownResult = main.TRUE |
| 124 | linkUpResult = main.TRUE |
| 125 | |
| 126 | # Discover hosts using arping |
| 127 | main.log.info( itemName + ": Discover host using arping" ) |
| 128 | main.Mininet1.arping( host=h1Name ) |
| 129 | main.Mininet1.arping( host=h2Name ) |
| 130 | host1 = main.CLIs[ 0 ].getHost( mac=h1Mac ) |
| 131 | host2 = main.CLIs[ 0 ].getHost( mac=h2Mac ) |
| 132 | |
| 133 | # Adding host intents |
| 134 | main.log.info( itemName + ": Adding host intents" ) |
| 135 | intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h1Id, |
| 136 | hostIdTwo=h2Id ) |
| 137 | intentsId.append( intent1 ) |
| 138 | time.sleep( 5 ) |
| 139 | intent2 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h2Id, |
| 140 | hostIdTwo=h1Id ) |
| 141 | intentsId.append( intent2 ) |
| 142 | |
| 143 | # Check intents state |
| 144 | time.sleep( 50 ) |
| 145 | intentResult = checkIntentState( main, intentsId ) |
| 146 | |
| 147 | # Verify flows |
| 148 | checkFlowsState( main ) |
| 149 | |
| 150 | # Ping hosts |
| 151 | pingHost( main, h1Name, h2Name ) |
| 152 | # Ping hosts again... |
| 153 | pingResult = pingHost( main, h1Name, h2Name ) |
| 154 | time.sleep( 5 ) |
| 155 | |
| 156 | # link down |
| 157 | link( main, sw1, sw2, "down" ) |
| 158 | intentResult = intentResult and checkIntentState( main, intentsId ) |
| 159 | |
| 160 | # Verify flows |
| 161 | checkFlowsState( main ) |
| 162 | |
| 163 | # Check OnosTopology |
| 164 | topoResult = checkTopology( main, expectLink ) |
| 165 | |
| 166 | # Ping hosts |
| 167 | pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
| 168 | |
| 169 | intentResult = checkIntentState( main, intentsId ) |
| 170 | |
| 171 | # link up |
| 172 | link( main, sw1, sw2, "up" ) |
| 173 | time.sleep( 5 ) |
| 174 | |
| 175 | # Verify flows |
| 176 | checkFlowsState( main ) |
| 177 | |
| 178 | # Check OnosTopology |
| 179 | topoResult = checkTopology( main, expectLink ) |
| 180 | |
| 181 | # Ping hosts |
| 182 | pingResult = pingResult and pingHost( main, h1Name, h2Name ) |
| 183 | |
| 184 | # Remove intents |
| 185 | for intent in intentsId: |
| 186 | main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True ) |
| 187 | |
| 188 | print main.CLIs[ 0 ].intents() |
| 189 | stepResult = pingResult and linkDownResult and linkUpResult \ |
| 190 | and intentResult |
| 191 | |
| 192 | return stepResult |
| 193 | |
| 194 | def link( main, sw1, sw2, option): |
| 195 | |
| 196 | # link down |
| 197 | main.log.info( itemName + ": Bring link " + option + "between " + |
| 198 | sw1 + " and " + sw2 ) |
| 199 | main.Mininet1.link( end1=sw1, end2=sw2, option=option ) |
| 200 | |
| 201 | def pingHost( main, h1Name, h2Name ): |
| 202 | |
| 203 | # Ping hosts |
| 204 | main.log.info( itemName + ": Ping " + h1Name + " and " + |
| 205 | h2Name ) |
| 206 | pingResult1 = main.Mininet1.pingHost( src=h1Name , target=h2Name ) |
| 207 | if not pingResult1: |
| 208 | main.log.info( itemName + ": " + h1Name + " cannot ping " |
| 209 | + h2Name ) |
| 210 | pingResult2 = main.Mininet1.pingHost( src=h2Name , target=h1Name ) |
| 211 | if not pingResult2: |
| 212 | main.log.info( itemName + ": " + h2Name + " cannot ping " |
| 213 | + h1Name ) |
| 214 | pingResult = pingResult1 and pingResult2 |
| 215 | if pingResult: |
| 216 | main.log.info( itemName + ": Successfully pinged " + |
| 217 | "both hosts" ) |
| 218 | else: |
| 219 | main.log.info( itemName + ": Failed to ping " + |
| 220 | "both hosts" ) |
| 221 | return pingResult |
| 222 | |
| 223 | def checkItem( item ): |
| 224 | """ |
| 225 | Checks the dictionary |
| 226 | """ |
| 227 | |
| 228 | def checkTopology( main, expectedLink ): |
| 229 | statusResult = main.TRUE |
| 230 | # Check onos topology |
| 231 | main.log.info( itemName + ": Checking ONOS topology " ) |
| 232 | |
| 233 | for i in range( main.numCtrls ): |
| 234 | topologyResult = main.CLIs[ i ].topology() |
| 235 | statusResult = main.ONOSbench.checkStatus( topologyResult, |
| 236 | main.numSwitch, |
| 237 | expectedLink )\ |
| 238 | and statusResult |
| 239 | if not statusResult: |
| 240 | main.log.info( itemName + ": Topology mismatch" ) |
| 241 | else: |
| 242 | main.log.info( itemName + ": Topology match" ) |
| 243 | return statusResult |
| 244 | |
| 245 | def checkIntentState( main, intentsId ): |
| 246 | |
| 247 | main.log.info( itemName + ": Check host intents state" ) |
| 248 | for i in range( main.numCtrls ): |
| 249 | intentResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId ) |
| 250 | if not intentResult: |
| 251 | main.log.info( itemName + ": Check host intents state again") |
| 252 | for i in range( main.numCtrls ): |
| 253 | intentResult = main.CLIs[ i ].checkIntentState( |
| 254 | intentsId=intentsId ) |
| 255 | return intentResult |
| 256 | |
| 257 | def checkFlowsState( main ): |
| 258 | |
| 259 | main.log.info( itemName + ": Check flows state" ) |
| 260 | checkFlowsResult = main.CLIs[ 0 ].checkFlowsState() |
| 261 | return checkFlowsResult |
| 262 | |
| 263 | def printMsg( main, h1Name, h2Name ): |
| 264 | main.log.info("PINGING HOST INSIDE printMSG") |
| 265 | pingHost( main, itemName, h1Name, h2Name ) |
| 266 | print 'lala' |
| 267 | |