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 |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame^] | 4 | Author: kelvin@onlab.us |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 5 | """ |
| 6 | def __init__( self ): |
| 7 | self.default = '' |
| 8 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 9 | def hostIntent( main, |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 10 | name, |
| 11 | host1, |
| 12 | host2, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 13 | host1Id="", |
| 14 | host2Id="", |
| 15 | mac1="", |
| 16 | mac2="", |
| 17 | vlan1="-1", |
| 18 | vlan2="-1", |
| 19 | sw1="", |
| 20 | sw2="", |
| 21 | expectedLink=0 ): |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 22 | """ |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame^] | 23 | Description: |
| 24 | Verify add-host-intent |
| 25 | Steps: |
| 26 | - Discover hosts |
| 27 | - Add host intents |
| 28 | - Check intents |
| 29 | - Verify flows |
| 30 | - Ping hosts |
| 31 | - Reroute |
| 32 | - Link down |
| 33 | - Verify flows |
| 34 | - Check topology |
| 35 | - Ping hosts |
| 36 | - Link up |
| 37 | - Verify flows |
| 38 | - Check topology |
| 39 | - Ping hosts |
| 40 | - Remove intents |
| 41 | Required: |
| 42 | name - Type of host intent to add eg. IPV4 | VLAN | Dualstack |
| 43 | host1 - Name of first host |
| 44 | host2 - Name of second host |
| 45 | Optional: |
| 46 | host1Id - ONOS id of the first host eg. 00:00:00:00:00:01/-1 |
| 47 | host2Id - ONOS id of the second host |
| 48 | mac1 - Mac address of first host |
| 49 | mac2 - Mac address of the second host |
| 50 | vlan1 - Vlan tag of first host, defaults to -1 |
| 51 | vlan2 - Vlan tag of second host, defaults to -1 |
| 52 | sw1 - First switch to bring down & up for rerouting purpose |
| 53 | sw2 - Second switch to bring down & up for rerouting purpose |
| 54 | expectedLink - Expected link when the switches are down, it should |
| 55 | be two links lower than the links before the two |
| 56 | switches are down |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 57 | """ |
| 58 | import time |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 59 | |
| 60 | # Assert variables |
| 61 | assert main, "There is no main variable" |
| 62 | assert name, "variable name is empty" |
| 63 | assert host1 and host2, "You must specify hosts" |
| 64 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 65 | global itemName |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 66 | itemName = name |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 67 | h1Id = host1Id |
| 68 | h2Id = host2Id |
| 69 | h1Mac = mac1 |
| 70 | h2Mac = mac2 |
| 71 | vlan1 = vlan1 |
| 72 | vlan2 = vlan2 |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 73 | hostNames = [ host1 , host2 ] |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 74 | intentsId = [] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 75 | stepResult = main.TRUE |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 76 | pingResult = main.TRUE |
| 77 | intentResult = main.TRUE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 78 | removeIntentResult = main.TRUE |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 79 | flowResult = main.TRUE |
| 80 | topoResult = main.TRUE |
| 81 | linkDownResult = main.TRUE |
| 82 | linkUpResult = main.TRUE |
| 83 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 84 | if main.hostsData: |
| 85 | if not h1Mac: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 86 | h1Mac = main.hostsData[ host1 ][ 'mac' ] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 87 | if not h2Mac: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 88 | h2Mac = main.hostsData[ host2 ][ 'mac' ] |
| 89 | if main.hostsData[ host1 ][ 'vlan' ] != '-1': |
| 90 | vlan1 = main.hostsData[ host1 ][ 'vlan' ] |
| 91 | if main.hostsData[ host2 ][ 'vlan' ] != '-1': |
| 92 | vlan2 = main.hostsData[ host2 ][ 'vlan' ] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 93 | if not h1Id: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 94 | h1Id = main.hostsData[ host1 ][ 'id' ] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 95 | if not h2Id: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 96 | h2Id = main.hostsData[ host2 ][ 'id' ] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 97 | |
| 98 | assert h1Id and h2Id, "You must specify host IDs" |
| 99 | if not ( h1Id and h2Id ): |
| 100 | main.log.info( "There are no host IDs" ) |
| 101 | return main.FALSE |
| 102 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 103 | # Discover hosts using arping |
| 104 | main.log.info( itemName + ": Discover host using arping" ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 105 | main.Mininet1.arping( host=host1 ) |
| 106 | main.Mininet1.arping( host=host2 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 107 | host1 = main.CLIs[ 0 ].getHost( mac=h1Mac ) |
| 108 | host2 = main.CLIs[ 0 ].getHost( mac=h2Mac ) |
| 109 | |
| 110 | # Adding host intents |
| 111 | main.log.info( itemName + ": Adding host intents" ) |
| 112 | intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h1Id, |
| 113 | hostIdTwo=h2Id ) |
| 114 | intentsId.append( intent1 ) |
| 115 | time.sleep( 5 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 116 | |
| 117 | # Check intents state |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 118 | time.sleep( 30 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 119 | intentResult = checkIntentState( main, intentsId ) |
| 120 | |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame^] | 121 | # Check intents state again if first check fails... |
| 122 | if not intentResult: |
| 123 | intentResult = checkIntentState( main, intentsId ) |
| 124 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 125 | # Verify flows |
| 126 | checkFlowsState( main ) |
| 127 | |
| 128 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 129 | firstPingResult = pingallHosts( main, hostNames ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 130 | if not firstPingResult: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 131 | main.log.debug( "First ping failed, there must be" + |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 132 | " something wrong with ONOS performance" ) |
| 133 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 134 | # Ping hosts again... |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 135 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 136 | time.sleep( 5 ) |
| 137 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 138 | # Test rerouting if these variables exist |
| 139 | if sw1 and sw2 and expectedLink: |
| 140 | # link down |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 141 | linkDownResult = link( main, sw1, sw2, "down" ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 142 | intentResult = intentResult and checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 143 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 144 | # Verify flows |
| 145 | checkFlowsState( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 146 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 147 | # Check OnosTopology |
| 148 | topoResult = checkTopology( main, expectedLink ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 149 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 150 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 151 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 152 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 153 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 154 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 155 | # Checks ONOS state in link down |
| 156 | if linkDownResult and topoResult and pingResult and intentResult: |
| 157 | main.log.info( itemName + ": Successfully brought link down" ) |
| 158 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 159 | main.log.error( itemName + ": Failed to bring link down" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 160 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 161 | # link up |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 162 | linkUpResult = link( main, sw1, sw2, "up" ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 163 | time.sleep( 5 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 164 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 165 | # Verify flows |
| 166 | checkFlowsState( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 167 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 168 | # Check OnosTopology |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 169 | topoResult = checkTopology( main, main.numLinks ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 170 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 171 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 172 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 173 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 174 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 175 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 176 | # Checks ONOS state in link up |
| 177 | if linkUpResult and topoResult and pingResult and intentResult: |
| 178 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 179 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 180 | main.log.error( itemName + ": Failed to bring link back up" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 181 | |
| 182 | # Remove all intents |
| 183 | removeIntentResult = removeAllIntents( main, intentsId ) |
| 184 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 185 | stepResult = pingResult and linkDownResult and linkUpResult \ |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 186 | and intentResult and removeIntentResult |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 187 | |
| 188 | return stepResult |
| 189 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 190 | def pointIntent( main, |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 191 | name, |
| 192 | host1, |
| 193 | host2, |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame^] | 194 | deviceId1="", |
| 195 | deviceId2="", |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 196 | port1="", |
| 197 | port2="", |
| 198 | ethType="", |
| 199 | mac1="", |
| 200 | mac2="", |
| 201 | bandwidth="", |
| 202 | lambdaAlloc=False, |
| 203 | ipProto="", |
| 204 | ip1="", |
| 205 | ip2="", |
| 206 | tcp1="", |
| 207 | tcp2="", |
| 208 | sw1="", |
| 209 | sw2="", |
| 210 | expectedLink=0 ): |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame^] | 211 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 212 | """ |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame^] | 213 | Description: |
| 214 | Verify add-point-intent |
| 215 | Steps: |
| 216 | - Get device ids | ports |
| 217 | - Add point intents |
| 218 | - Check intents |
| 219 | - Verify flows |
| 220 | - Ping hosts |
| 221 | - Reroute |
| 222 | - Link down |
| 223 | - Verify flows |
| 224 | - Check topology |
| 225 | - Ping hosts |
| 226 | - Link up |
| 227 | - Verify flows |
| 228 | - Check topology |
| 229 | - Ping hosts |
| 230 | - Remove intents |
| 231 | Required: |
| 232 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
| 233 | host1 - Name of first host |
| 234 | host2 - Name of second host |
| 235 | Optional: |
| 236 | deviceId1 - ONOS device id of the first switch, the same as the |
| 237 | location of the first host eg. of:0000000000000001/1, |
| 238 | located at device 1 port 1 |
| 239 | deviceId2 - ONOS device id of the second switch |
| 240 | port1 - The port number where the first host is attached |
| 241 | port2 - The port number where the second host is attached |
| 242 | ethType - Ethernet type eg. IPV4, IPV6 |
| 243 | mac1 - Mac address of first host |
| 244 | mac2 - Mac address of the second host |
| 245 | bandwidth - Bandwidth capacity |
| 246 | lambdaAlloc - Allocate lambda, defaults to False |
| 247 | ipProto - IP protocol |
| 248 | ip1 - IP address of first host |
| 249 | ip2 - IP address of second host |
| 250 | tcp1 - TCP port of first host |
| 251 | tcp2 - TCP port of second host |
| 252 | sw1 - First switch to bring down & up for rerouting purpose |
| 253 | sw2 - Second switch to bring down & up for rerouting purpose |
| 254 | expectedLink - Expected link when the switches are down, it should |
| 255 | be two links lower than the links before the two |
| 256 | switches are down |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 257 | """ |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame^] | 258 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 259 | import time |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 260 | assert main, "There is no main variable" |
| 261 | assert name, "variable name is empty" |
| 262 | assert host1 and host2, "You must specify hosts" |
| 263 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 264 | global itemName |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 265 | itemName = name |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 266 | host1 = host1 |
| 267 | host2 = host2 |
| 268 | hostNames = [ host1, host2 ] |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 269 | intentsId = [] |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 270 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 271 | pingResult = main.TRUE |
| 272 | intentResult = main.TRUE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 273 | removeIntentResult = main.TRUE |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 274 | flowResult = main.TRUE |
| 275 | topoResult = main.TRUE |
| 276 | linkDownResult = main.TRUE |
| 277 | linkUpResult = main.TRUE |
| 278 | |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 279 | # Adding bidirectional point intents |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 280 | main.log.info( itemName + ": Adding point intents" ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 281 | intent1 = main.CLIs[ 0 ].addPointIntent( ingressDevice=deviceId1, |
| 282 | egressDevice=deviceId2, |
| 283 | portIngress=port1, |
| 284 | portEgress=port2, |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 285 | ethType=ethType, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 286 | ethSrc=mac1, |
| 287 | ethDst=mac2, |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 288 | bandwidth=bandwidth, |
| 289 | lambdaAlloc=lambdaAlloc, |
| 290 | ipProto=ipProto, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 291 | ipSrc=ip1, |
| 292 | ipDst=ip2, |
| 293 | tcpSrc=tcp1, |
| 294 | tcpDst=tcp2 ) |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 295 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 296 | intentsId.append( intent1 ) |
| 297 | time.sleep( 5 ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 298 | intent2 = main.CLIs[ 0 ].addPointIntent( ingressDevice=deviceId2, |
| 299 | egressDevice=deviceId1, |
| 300 | portIngress=port2, |
| 301 | portEgress=port1, |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 302 | ethType=ethType, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 303 | ethSrc=mac2, |
| 304 | ethDst=mac1, |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 305 | bandwidth=bandwidth, |
| 306 | lambdaAlloc=lambdaAlloc, |
| 307 | ipProto=ipProto, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 308 | ipSrc=ip2, |
| 309 | ipDst=ip1, |
| 310 | tcpSrc=tcp2, |
| 311 | tcpDst=tcp1 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 312 | intentsId.append( intent2 ) |
| 313 | |
| 314 | # Check intents state |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 315 | time.sleep( 30 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 316 | intentResult = checkIntentState( main, intentsId ) |
| 317 | |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame^] | 318 | # Check intents state again if first check fails... |
| 319 | if not intentResult: |
| 320 | intentResult = checkIntentState( main, intentsId ) |
| 321 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 322 | # Verify flows |
| 323 | checkFlowsState( main ) |
| 324 | |
| 325 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 326 | firstPingResult = pingallHosts( main, hostNames ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 327 | if not firstPingResult: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 328 | main.log.debug( "First ping failed, there must be" + |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 329 | " something wrong with ONOS performance" ) |
| 330 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 331 | # Ping hosts again... |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 332 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 333 | time.sleep( 5 ) |
| 334 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 335 | # Test rerouting if these variables exist |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 336 | if sw1 and sw2 and expectedLink: |
| 337 | # link down |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 338 | linkDownResult = link( main, sw1, sw2, "down" ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 339 | intentResult = intentResult and checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 340 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 341 | # Verify flows |
| 342 | checkFlowsState( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 343 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 344 | # Check OnosTopology |
| 345 | topoResult = checkTopology( main, expectedLink ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 346 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 347 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 348 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 349 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 350 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 351 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 352 | # Checks ONOS state in link down |
| 353 | if linkDownResult and topoResult and pingResult and intentResult: |
| 354 | main.log.info( itemName + ": Successfully brought link down" ) |
| 355 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 356 | main.log.error( itemName + ": Failed to bring link down" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 357 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 358 | # link up |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 359 | linkUpResult = link( main, sw1, sw2, "up" ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 360 | time.sleep( 5 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 361 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 362 | # Verify flows |
| 363 | checkFlowsState( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 364 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 365 | # Check OnosTopology |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 366 | topoResult = checkTopology( main, main.numLinks ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 367 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 368 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 369 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 370 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 371 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 372 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 373 | # Checks ONOS state in link up |
| 374 | if linkUpResult and topoResult and pingResult and intentResult: |
| 375 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 376 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 377 | main.log.error( itemName + ": Failed to bring link back up" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 378 | |
| 379 | # Remove all intents |
| 380 | removeIntentResult = removeAllIntents( main, intentsId ) |
| 381 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 382 | stepResult = pingResult and linkDownResult and linkUpResult \ |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 383 | and intentResult and removeIntentResult |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 384 | |
| 385 | return stepResult |
| 386 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 387 | def singleToMultiIntent( main, |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 388 | name, |
| 389 | hostNames, |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 390 | devices="", |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 391 | ports=None, |
| 392 | ethType="", |
| 393 | macs=None, |
| 394 | bandwidth="", |
| 395 | lambdaAlloc=False, |
| 396 | ipProto="", |
| 397 | ipAddresses="", |
| 398 | tcp="", |
| 399 | sw1="", |
| 400 | sw2="", |
| 401 | expectedLink=0 ): |
| 402 | """ |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame^] | 403 | Verify Single to Multi Point intents |
| 404 | NOTE:If main.hostsData is not defined, variables data should be passed in the |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 405 | same order index wise. All devices in the list should have the same |
| 406 | format, either all the devices have its port or it doesn't. |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 407 | eg. hostName = [ 'h1', 'h2' ,.. ] |
| 408 | devices = [ 'of:0000000000000001', 'of:0000000000000002', ...] |
| 409 | ports = [ '1', '1', ..] |
| 410 | ... |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame^] | 411 | Description: |
| 412 | Verify add-single-to-multi-intent |
| 413 | Steps: |
| 414 | - Get device ids | ports |
| 415 | - Add single to multi point intents |
| 416 | - Check intents |
| 417 | - Verify flows |
| 418 | - Ping hosts |
| 419 | - Reroute |
| 420 | - Link down |
| 421 | - Verify flows |
| 422 | - Check topology |
| 423 | - Ping hosts |
| 424 | - Link up |
| 425 | - Verify flows |
| 426 | - Check topology |
| 427 | - Ping hosts |
| 428 | - Remove intents |
| 429 | Required: |
| 430 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
| 431 | hostNames - List of host names |
| 432 | Optional: |
| 433 | devices - List of device ids in the same order as the hosts |
| 434 | in hostNames |
| 435 | ports - List of port numbers in the same order as the device in |
| 436 | devices |
| 437 | ethType - Ethernet type eg. IPV4, IPV6 |
| 438 | macs - List of hosts mac address in the same order as the hosts in |
| 439 | hostNames |
| 440 | bandwidth - Bandwidth capacity |
| 441 | lambdaAlloc - Allocate lambda, defaults to False |
| 442 | ipProto - IP protocol |
| 443 | ipAddresses - IP addresses of host in the same order as the hosts in |
| 444 | hostNames |
| 445 | tcp - TCP ports in the same order as the hosts in hostNames |
| 446 | sw1 - First switch to bring down & up for rerouting purpose |
| 447 | sw2 - Second switch to bring down & up for rerouting purpose |
| 448 | expectedLink - Expected link when the switches are down, it should |
| 449 | be two links lower than the links before the two |
| 450 | switches are down |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 451 | """ |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame^] | 452 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 453 | import time |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 454 | import copy |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 455 | assert main, "There is no main variable" |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 456 | assert hostNames, "You must specify hosts" |
| 457 | assert devices or main.hostsData, "You must specify devices" |
| 458 | |
| 459 | global itemName |
| 460 | itemName = name |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 461 | tempHostsData = {} |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 462 | intentsId = [] |
| 463 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 464 | macsDict = {} |
| 465 | ipDict = {} |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 466 | if hostNames and devices: |
| 467 | if len( hostNames ) != len( devices ): |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 468 | main.log.debug( "hosts and devices does not have the same length" ) |
| 469 | #print "len hostNames = ", len( hostNames ) |
| 470 | #print "len devices = ", len( devices ) |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 471 | return main.FALSE |
| 472 | if ports: |
| 473 | if len( ports ) != len( devices ): |
| 474 | main.log.error( "Ports and devices does " + |
| 475 | "not have the same length" ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 476 | #print "len devices = ", len( devices ) |
| 477 | #print "len ports = ", len( ports ) |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 478 | return main.FALSE |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 479 | for i in range( len( devices ) ): |
| 480 | macsDict[ devices[ i ] ] = macs[ i ] |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 481 | else: |
| 482 | main.log.info( "Device Ports are not specified" ) |
| 483 | elif hostNames and not devices and main.hostsData: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 484 | devices = [] |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 485 | main.log.info( "singleToMultiIntent function is using main.hostsData" ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 486 | for host in hostNames: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 487 | devices.append( main.hostsData.get( host ).get( 'location' ) ) |
| 488 | macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \ |
| 489 | main.hostsData.get( host ).get( 'mac' ) |
| 490 | ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \ |
| 491 | main.hostsData.get( host ).get( 'ipAddresses' ) |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame^] | 492 | #print main.hostsData |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 493 | |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame^] | 494 | #print 'host names = ', hostNames |
| 495 | #print 'devices = ', devices |
| 496 | #print "macsDict = ", macsDict |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 497 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 498 | pingResult = main.TRUE |
| 499 | intentResult = main.TRUE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 500 | removeIntentResult = main.TRUE |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 501 | flowResult = main.TRUE |
| 502 | topoResult = main.TRUE |
| 503 | linkDownResult = main.TRUE |
| 504 | linkUpResult = main.TRUE |
| 505 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 506 | devicesCopy = copy.copy( devices ) |
| 507 | if ports: |
| 508 | portsCopy = copy.copy( ports ) |
| 509 | main.log.info( itemName + ": Adding single point to multi point intents" ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 510 | # Adding bidirectional point intents |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 511 | for i in range( len( devices ) ): |
| 512 | ingressDevice = devicesCopy[ i ] |
| 513 | egressDeviceList = copy.copy( devicesCopy ) |
| 514 | egressDeviceList.remove( ingressDevice ) |
| 515 | if ports: |
| 516 | portIngress = portsCopy[ i ] |
| 517 | portEgressList = copy.copy( portsCopy ) |
| 518 | del portEgressList[ i ] |
| 519 | else: |
| 520 | portIngress = "" |
| 521 | portEgressList = None |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 522 | if not macsDict: |
| 523 | srcMac = "" |
| 524 | else: |
| 525 | srcMac = macsDict[ ingressDevice ] |
| 526 | if srcMac == None: |
| 527 | srcMac = "" |
| 528 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 529 | intentsId.append( main.CLIs[ 0 ].addSinglepointToMultipointIntent( |
| 530 | ingressDevice=ingressDevice, |
| 531 | egressDeviceList=egressDeviceList, |
| 532 | portIngress=portIngress, |
| 533 | portEgressList=portEgressList, |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 534 | ethType=ethType, |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 535 | ethSrc=srcMac, |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 536 | bandwidth=bandwidth, |
| 537 | lambdaAlloc=lambdaAlloc, |
| 538 | ipProto=ipProto, |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 539 | ipSrc="", |
| 540 | ipDst="", |
| 541 | tcpSrc="", |
| 542 | tcpDst="" ) ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 543 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 544 | pingResult = pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 545 | |
| 546 | # Check intents state |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 547 | time.sleep( 30 ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 548 | intentResult = checkIntentState( main, intentsId ) |
| 549 | |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame^] | 550 | # Check intents state again if first check fails... |
| 551 | if not intentResult: |
| 552 | intentResult = checkIntentState( main, intentsId ) |
| 553 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 554 | # Verify flows |
| 555 | checkFlowsState( main ) |
| 556 | |
| 557 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 558 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 559 | # Ping hosts again... |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 560 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 561 | time.sleep( 5 ) |
| 562 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 563 | # Test rerouting if these variables exist |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 564 | if sw1 and sw2 and expectedLink: |
| 565 | # link down |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 566 | linkDownResult = link( main, sw1, sw2, "down" ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 567 | intentResult = intentResult and checkIntentState( main, intentsId ) |
| 568 | |
| 569 | # Verify flows |
| 570 | checkFlowsState( main ) |
| 571 | |
| 572 | # Check OnosTopology |
| 573 | topoResult = checkTopology( main, expectedLink ) |
| 574 | |
| 575 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 576 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 577 | |
| 578 | intentResult = checkIntentState( main, intentsId ) |
| 579 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 580 | # Checks ONOS state in link down |
| 581 | if linkDownResult and topoResult and pingResult and intentResult: |
| 582 | main.log.info( itemName + ": Successfully brought link down" ) |
| 583 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 584 | main.log.error( itemName + ": Failed to bring link down" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 585 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 586 | # link up |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 587 | linkUpResult = link( main, sw1, sw2, "up" ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 588 | time.sleep( 5 ) |
| 589 | |
| 590 | # Verify flows |
| 591 | checkFlowsState( main ) |
| 592 | |
| 593 | # Check OnosTopology |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 594 | topoResult = checkTopology( main, main.numLinks ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 595 | |
| 596 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 597 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 598 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 599 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 600 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 601 | # Checks ONOS state in link up |
| 602 | if linkUpResult and topoResult and pingResult and intentResult: |
| 603 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 604 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 605 | main.log.error( itemName + ": Failed to bring link back up" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 606 | |
| 607 | # Remove all intents |
| 608 | removeIntentResult = removeAllIntents( main, intentsId ) |
| 609 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 610 | stepResult = pingResult and linkDownResult and linkUpResult \ |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 611 | and intentResult and removeIntentResult |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 612 | |
| 613 | return stepResult |
| 614 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 615 | def pingallHosts( main, hostList, pingType="ipv4" ): |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 616 | # Ping all host in the hosts list variable |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 617 | print "Pinging : ", hostList |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 618 | pingResult = main.TRUE |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 619 | pingResult = main.Mininet1.pingallHosts( hostList, pingType ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 620 | return pingResult |
| 621 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 622 | def getHostsData( main ): |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 623 | """ |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 624 | Use fwd app and pingall to discover all the hosts |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 625 | """ |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 626 | import json |
| 627 | activateResult = main.TRUE |
| 628 | appCheck = main.TRUE |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 629 | getDataResult = main.TRUE |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 630 | main.log.info( "Activating reactive forwarding app " ) |
| 631 | activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" ) |
| 632 | |
| 633 | for i in range( main.numCtrls ): |
| 634 | appCheck = appCheck and main.CLIs[ i ].appToIDCheck() |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 635 | if appCheck != main.TRUE: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 636 | main.log.warn( main.CLIs[ i ].apps() ) |
| 637 | main.log.warn( main.CLIs[ i ].appIDs() ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 638 | |
| 639 | pingResult = main.Mininet1.pingall() |
| 640 | hostsJson = json.loads( main.CLIs[ 0 ].hosts() ) |
| 641 | hosts = main.Mininet1.getHosts() |
| 642 | for host in hosts: |
| 643 | main.hostsData[ host ] = {} |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 644 | main.hostsData[ host ][ 'mac' ] = \ |
| 645 | main.Mininet1.getMacAddress( host ).upper() |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 646 | for hostj in hostsJson: |
| 647 | if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]: |
| 648 | main.hostsData[ host ][ 'id' ] = hostj[ 'id' ] |
| 649 | main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ] |
| 650 | main.hostsData[ host ][ 'location' ] = \ |
| 651 | hostj[ 'location' ][ 'elementId' ] + '/' + \ |
| 652 | hostj[ 'location' ][ 'port' ] |
| 653 | main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ] |
| 654 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 655 | main.log.info( "Deactivating reactive forwarding app " ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 656 | deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 657 | if activateResult and deactivateResult and main.hostsData: |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 658 | main.log.info( "Successfully used fwd app to discover hosts " ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 659 | getDataResult = main.TRUE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 660 | else: |
| 661 | main.log.info( "Failed to use fwd app to discover hosts " ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 662 | getDataResult = main.FALSE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 663 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 664 | print main.hostsData |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 665 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 666 | return getDataResult |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 667 | |
| 668 | def checkTopology( main, expectedLink ): |
| 669 | statusResult = main.TRUE |
| 670 | # Check onos topology |
| 671 | main.log.info( itemName + ": Checking ONOS topology " ) |
| 672 | |
| 673 | for i in range( main.numCtrls ): |
| 674 | topologyResult = main.CLIs[ i ].topology() |
| 675 | statusResult = main.ONOSbench.checkStatus( topologyResult, |
| 676 | main.numSwitch, |
| 677 | expectedLink )\ |
| 678 | and statusResult |
| 679 | if not statusResult: |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame^] | 680 | main.log.error( itemName + ": Topology mismatch" ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 681 | else: |
| 682 | main.log.info( itemName + ": Topology match" ) |
| 683 | return statusResult |
| 684 | |
| 685 | def checkIntentState( main, intentsId ): |
| 686 | |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame^] | 687 | intentResult = main.TRUE |
| 688 | |
| 689 | main.log.info( itemName + ": Checking intents state" ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 690 | for i in range( main.numCtrls ): |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame^] | 691 | intentResult = intentResult and \ |
| 692 | main.CLIs[ i ].checkIntentState( intentsId=intentsId ) |
| 693 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 694 | return intentResult |
| 695 | |
| 696 | def checkFlowsState( main ): |
| 697 | |
| 698 | main.log.info( itemName + ": Check flows state" ) |
| 699 | checkFlowsResult = main.CLIs[ 0 ].checkFlowsState() |
| 700 | return checkFlowsResult |
| 701 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 702 | def link( main, sw1, sw2, option): |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 703 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 704 | # link down |
| 705 | main.log.info( itemName + ": Bring link " + option + "between " + |
| 706 | sw1 + " and " + sw2 ) |
| 707 | linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option ) |
| 708 | return linkResult |
| 709 | |
| 710 | def removeAllIntents( main, intentsId ): |
| 711 | """ |
| 712 | Remove all intents in the intentsId |
| 713 | """ |
| 714 | import time |
| 715 | intentsRemaining = [] |
| 716 | removeIntentResult = main.TRUE |
| 717 | # Remove intents |
| 718 | for intent in intentsId: |
| 719 | main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True ) |
| 720 | |
| 721 | time.sleep( 5 ) |
| 722 | # Checks if there is remaining intents using intents() |
| 723 | intentsRemaining = main.CLIs[ 0 ].intents() |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 724 | # If there is remianing intents then remove intents should fail |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 725 | if intentsRemaining == []: |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 726 | main.log.info( itemName + ": There are " + |
| 727 | str( len( intentsRemaining ) ) + " intents remaining, " |
| 728 | + "failed to remove all the intents " ) |
| 729 | removeIntentResult = main.FALSE |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 730 | main.log.info( intentsRemaining ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 731 | else: |
| 732 | main.log.info( itemName + ": There are no intents remaining, " + |
| 733 | "successfully removed all the intents." ) |
| 734 | removeIntentResult = main.TRUE |
| 735 | return removeIntentResult |