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: |
kelvin-onlab | 583fcb5 | 2015-05-21 13:10:46 -0700 | [diff] [blame] | 412 | Verify add-single-to-multi-intent iterates through the list of given |
| 413 | host | devices and add intents |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 414 | Steps: |
| 415 | - Get device ids | ports |
| 416 | - Add single to multi point intents |
| 417 | - Check intents |
| 418 | - Verify flows |
| 419 | - Ping hosts |
| 420 | - Reroute |
| 421 | - Link down |
| 422 | - Verify flows |
| 423 | - Check topology |
| 424 | - Ping hosts |
| 425 | - Link up |
| 426 | - Verify flows |
| 427 | - Check topology |
| 428 | - Ping hosts |
| 429 | - Remove intents |
| 430 | Required: |
| 431 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
| 432 | hostNames - List of host names |
| 433 | Optional: |
| 434 | devices - List of device ids in the same order as the hosts |
| 435 | in hostNames |
| 436 | ports - List of port numbers in the same order as the device in |
| 437 | devices |
| 438 | ethType - Ethernet type eg. IPV4, IPV6 |
| 439 | macs - List of hosts mac address in the same order as the hosts in |
| 440 | hostNames |
| 441 | bandwidth - Bandwidth capacity |
| 442 | lambdaAlloc - Allocate lambda, defaults to False |
| 443 | ipProto - IP protocol |
| 444 | ipAddresses - IP addresses of host in the same order as the hosts in |
| 445 | hostNames |
| 446 | tcp - TCP ports in the same order as the hosts in hostNames |
| 447 | sw1 - First switch to bring down & up for rerouting purpose |
| 448 | sw2 - Second switch to bring down & up for rerouting purpose |
| 449 | expectedLink - Expected link when the switches are down, it should |
| 450 | be two links lower than the links before the two |
| 451 | switches are down |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 452 | """ |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 453 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 454 | import time |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 455 | import copy |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 456 | assert main, "There is no main variable" |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 457 | assert hostNames, "You must specify hosts" |
| 458 | assert devices or main.hostsData, "You must specify devices" |
| 459 | |
| 460 | global itemName |
| 461 | itemName = name |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 462 | tempHostsData = {} |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 463 | intentsId = [] |
| 464 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 465 | macsDict = {} |
| 466 | ipDict = {} |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 467 | if hostNames and devices: |
| 468 | if len( hostNames ) != len( devices ): |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 469 | main.log.debug( "hosts and devices does not have the same length" ) |
| 470 | #print "len hostNames = ", len( hostNames ) |
| 471 | #print "len devices = ", len( devices ) |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 472 | return main.FALSE |
| 473 | if ports: |
| 474 | if len( ports ) != len( devices ): |
| 475 | main.log.error( "Ports and devices does " + |
| 476 | "not have the same length" ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 477 | #print "len devices = ", len( devices ) |
| 478 | #print "len ports = ", len( ports ) |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 479 | return main.FALSE |
| 480 | else: |
| 481 | main.log.info( "Device Ports are not specified" ) |
kelvin-onlab | f2ec6e0 | 2015-05-27 14:15:28 -0700 | [diff] [blame] | 482 | if macs: |
| 483 | for i in range( len( devices ) ): |
| 484 | macsDict[ devices[ i ] ] = macs[ i ] |
| 485 | |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 486 | elif hostNames and not devices and main.hostsData: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 487 | devices = [] |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 488 | main.log.info( "singleToMultiIntent function is using main.hostsData" ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 489 | for host in hostNames: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 490 | devices.append( main.hostsData.get( host ).get( 'location' ) ) |
| 491 | macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \ |
| 492 | main.hostsData.get( host ).get( 'mac' ) |
| 493 | ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \ |
| 494 | main.hostsData.get( host ).get( 'ipAddresses' ) |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 495 | #print main.hostsData |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 496 | |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 497 | #print 'host names = ', hostNames |
| 498 | #print 'devices = ', devices |
| 499 | #print "macsDict = ", macsDict |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 500 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 501 | pingResult = main.TRUE |
| 502 | intentResult = main.TRUE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 503 | removeIntentResult = main.TRUE |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 504 | flowResult = main.TRUE |
| 505 | topoResult = main.TRUE |
| 506 | linkDownResult = main.TRUE |
| 507 | linkUpResult = main.TRUE |
| 508 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 509 | devicesCopy = copy.copy( devices ) |
| 510 | if ports: |
| 511 | portsCopy = copy.copy( ports ) |
| 512 | main.log.info( itemName + ": Adding single point to multi point intents" ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 513 | # Adding bidirectional point intents |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 514 | for i in range( len( devices ) ): |
| 515 | ingressDevice = devicesCopy[ i ] |
| 516 | egressDeviceList = copy.copy( devicesCopy ) |
| 517 | egressDeviceList.remove( ingressDevice ) |
| 518 | if ports: |
| 519 | portIngress = portsCopy[ i ] |
| 520 | portEgressList = copy.copy( portsCopy ) |
| 521 | del portEgressList[ i ] |
| 522 | else: |
| 523 | portIngress = "" |
| 524 | portEgressList = None |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 525 | if not macsDict: |
| 526 | srcMac = "" |
| 527 | else: |
| 528 | srcMac = macsDict[ ingressDevice ] |
| 529 | if srcMac == None: |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 530 | main.log.debug( "There is no MAC in device - " + ingressDevice ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 531 | srcMac = "" |
| 532 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 533 | intentsId.append( main.CLIs[ 0 ].addSinglepointToMultipointIntent( |
| 534 | ingressDevice=ingressDevice, |
| 535 | egressDeviceList=egressDeviceList, |
| 536 | portIngress=portIngress, |
| 537 | portEgressList=portEgressList, |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 538 | ethType=ethType, |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 539 | ethSrc=srcMac, |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 540 | bandwidth=bandwidth, |
| 541 | lambdaAlloc=lambdaAlloc, |
| 542 | ipProto=ipProto, |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 543 | ipSrc="", |
| 544 | ipDst="", |
| 545 | tcpSrc="", |
| 546 | tcpDst="" ) ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 547 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 548 | pingResult = pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 549 | |
| 550 | # Check intents state |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 551 | time.sleep( 30 ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 552 | intentResult = checkIntentState( main, intentsId ) |
| 553 | |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 554 | # Check intents state again if first check fails... |
| 555 | if not intentResult: |
| 556 | intentResult = checkIntentState( main, intentsId ) |
| 557 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 558 | # Verify flows |
| 559 | checkFlowsState( main ) |
| 560 | |
| 561 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 562 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 563 | # Ping hosts again... |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 564 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 565 | time.sleep( 5 ) |
| 566 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 567 | # Test rerouting if these variables exist |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 568 | if sw1 and sw2 and expectedLink: |
| 569 | # link down |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 570 | linkDownResult = link( main, sw1, sw2, "down" ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 571 | intentResult = intentResult and checkIntentState( main, intentsId ) |
| 572 | |
| 573 | # Verify flows |
| 574 | checkFlowsState( main ) |
| 575 | |
| 576 | # Check OnosTopology |
| 577 | topoResult = checkTopology( main, expectedLink ) |
| 578 | |
| 579 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 580 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 581 | |
| 582 | intentResult = checkIntentState( main, intentsId ) |
| 583 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 584 | # Checks ONOS state in link down |
| 585 | if linkDownResult and topoResult and pingResult and intentResult: |
| 586 | main.log.info( itemName + ": Successfully brought link down" ) |
| 587 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 588 | main.log.error( itemName + ": Failed to bring link down" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 589 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 590 | # link up |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 591 | linkUpResult = link( main, sw1, sw2, "up" ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 592 | time.sleep( 5 ) |
| 593 | |
| 594 | # Verify flows |
| 595 | checkFlowsState( main ) |
| 596 | |
| 597 | # Check OnosTopology |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 598 | topoResult = checkTopology( main, main.numLinks ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 599 | |
| 600 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 601 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 602 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 603 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 604 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 605 | # Checks ONOS state in link up |
| 606 | if linkUpResult and topoResult and pingResult and intentResult: |
| 607 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 608 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 609 | main.log.error( itemName + ": Failed to bring link back up" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 610 | |
| 611 | # Remove all intents |
| 612 | removeIntentResult = removeAllIntents( main, intentsId ) |
| 613 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 614 | stepResult = pingResult and linkDownResult and linkUpResult \ |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 615 | and intentResult and removeIntentResult |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 616 | |
| 617 | return stepResult |
| 618 | |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 619 | def multiToSingleIntent( main, |
| 620 | name, |
| 621 | hostNames, |
| 622 | devices="", |
| 623 | ports=None, |
| 624 | ethType="", |
| 625 | macs=None, |
| 626 | bandwidth="", |
| 627 | lambdaAlloc=False, |
| 628 | ipProto="", |
| 629 | ipAddresses="", |
| 630 | tcp="", |
| 631 | sw1="", |
| 632 | sw2="", |
| 633 | expectedLink=0 ): |
| 634 | """ |
| 635 | Verify Single to Multi Point intents |
| 636 | NOTE:If main.hostsData is not defined, variables data should be passed in the |
| 637 | same order index wise. All devices in the list should have the same |
| 638 | format, either all the devices have its port or it doesn't. |
| 639 | eg. hostName = [ 'h1', 'h2' ,.. ] |
| 640 | devices = [ 'of:0000000000000001', 'of:0000000000000002', ...] |
| 641 | ports = [ '1', '1', ..] |
| 642 | ... |
| 643 | Description: |
| 644 | Verify add-multi-to-single-intent |
| 645 | Steps: |
| 646 | - Get device ids | ports |
kelvin-onlab | b2310a4 | 2015-05-21 14:17:29 -0700 | [diff] [blame] | 647 | - Add multi to single point intents |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 648 | - Check intents |
| 649 | - Verify flows |
| 650 | - Ping hosts |
| 651 | - Reroute |
| 652 | - Link down |
| 653 | - Verify flows |
| 654 | - Check topology |
| 655 | - Ping hosts |
| 656 | - Link up |
| 657 | - Verify flows |
| 658 | - Check topology |
| 659 | - Ping hosts |
| 660 | - Remove intents |
| 661 | Required: |
| 662 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
| 663 | hostNames - List of host names |
| 664 | Optional: |
| 665 | devices - List of device ids in the same order as the hosts |
| 666 | in hostNames |
| 667 | ports - List of port numbers in the same order as the device in |
| 668 | devices |
| 669 | ethType - Ethernet type eg. IPV4, IPV6 |
| 670 | macs - List of hosts mac address in the same order as the hosts in |
| 671 | hostNames |
| 672 | bandwidth - Bandwidth capacity |
| 673 | lambdaAlloc - Allocate lambda, defaults to False |
| 674 | ipProto - IP protocol |
| 675 | ipAddresses - IP addresses of host in the same order as the hosts in |
| 676 | hostNames |
| 677 | tcp - TCP ports in the same order as the hosts in hostNames |
| 678 | sw1 - First switch to bring down & up for rerouting purpose |
| 679 | sw2 - Second switch to bring down & up for rerouting purpose |
| 680 | expectedLink - Expected link when the switches are down, it should |
| 681 | be two links lower than the links before the two |
| 682 | switches are down |
| 683 | """ |
| 684 | |
| 685 | import time |
| 686 | import copy |
| 687 | assert main, "There is no main variable" |
| 688 | assert hostNames, "You must specify hosts" |
| 689 | assert devices or main.hostsData, "You must specify devices" |
| 690 | |
| 691 | global itemName |
| 692 | itemName = name |
| 693 | tempHostsData = {} |
| 694 | intentsId = [] |
| 695 | |
| 696 | macsDict = {} |
| 697 | ipDict = {} |
| 698 | if hostNames and devices: |
| 699 | if len( hostNames ) != len( devices ): |
| 700 | main.log.debug( "hosts and devices does not have the same length" ) |
| 701 | #print "len hostNames = ", len( hostNames ) |
| 702 | #print "len devices = ", len( devices ) |
| 703 | return main.FALSE |
| 704 | if ports: |
| 705 | if len( ports ) != len( devices ): |
| 706 | main.log.error( "Ports and devices does " + |
| 707 | "not have the same length" ) |
| 708 | #print "len devices = ", len( devices ) |
| 709 | #print "len ports = ", len( ports ) |
| 710 | return main.FALSE |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 711 | else: |
| 712 | main.log.info( "Device Ports are not specified" ) |
kelvin-onlab | f2ec6e0 | 2015-05-27 14:15:28 -0700 | [diff] [blame] | 713 | if macs: |
| 714 | for i in range( len( devices ) ): |
| 715 | macsDict[ devices[ i ] ] = macs[ i ] |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 716 | elif hostNames and not devices and main.hostsData: |
| 717 | devices = [] |
kelvin-onlab | b2310a4 | 2015-05-21 14:17:29 -0700 | [diff] [blame] | 718 | main.log.info( "multiToSingleIntent function is using main.hostsData" ) |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 719 | for host in hostNames: |
| 720 | devices.append( main.hostsData.get( host ).get( 'location' ) ) |
| 721 | macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \ |
| 722 | main.hostsData.get( host ).get( 'mac' ) |
| 723 | ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \ |
| 724 | main.hostsData.get( host ).get( 'ipAddresses' ) |
| 725 | #print main.hostsData |
| 726 | |
| 727 | #print 'host names = ', hostNames |
| 728 | #print 'devices = ', devices |
| 729 | #print "macsDict = ", macsDict |
| 730 | |
| 731 | pingResult = main.TRUE |
| 732 | intentResult = main.TRUE |
| 733 | removeIntentResult = main.TRUE |
| 734 | flowResult = main.TRUE |
| 735 | topoResult = main.TRUE |
| 736 | linkDownResult = main.TRUE |
| 737 | linkUpResult = main.TRUE |
| 738 | |
| 739 | devicesCopy = copy.copy( devices ) |
| 740 | if ports: |
| 741 | portsCopy = copy.copy( ports ) |
kelvin-onlab | b2310a4 | 2015-05-21 14:17:29 -0700 | [diff] [blame] | 742 | main.log.info( itemName + ": Adding multi point to single point intents" ) |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 743 | # Adding bidirectional point intents |
| 744 | for i in range( len( devices ) ): |
| 745 | egressDevice = devicesCopy[ i ] |
| 746 | ingressDeviceList = copy.copy( devicesCopy ) |
| 747 | ingressDeviceList.remove( egressDevice ) |
| 748 | if ports: |
| 749 | portEgress = portsCopy[ i ] |
| 750 | portIngressList = copy.copy( portsCopy ) |
| 751 | del portIngressList[ i ] |
| 752 | else: |
| 753 | portEgress = "" |
| 754 | portIngressList = None |
| 755 | if not macsDict: |
| 756 | dstMac = "" |
| 757 | else: |
| 758 | dstMac = macsDict[ egressDevice ] |
| 759 | if dstMac == None: |
| 760 | main.log.debug( "There is no MAC in device - " + egressDevice ) |
| 761 | dstMac = "" |
| 762 | |
| 763 | intentsId.append( main.CLIs[ 0 ].addMultipointToSinglepointIntent( |
| 764 | ingressDeviceList=ingressDeviceList, |
| 765 | egressDevice=egressDevice, |
| 766 | portIngressList=portIngressList, |
| 767 | portEgress=portEgress, |
| 768 | ethType=ethType, |
| 769 | ethDst=dstMac, |
| 770 | bandwidth=bandwidth, |
| 771 | lambdaAlloc=lambdaAlloc, |
| 772 | ipProto=ipProto, |
| 773 | ipSrc="", |
| 774 | ipDst="", |
| 775 | tcpSrc="", |
| 776 | tcpDst="" ) ) |
| 777 | |
| 778 | pingResult = pingallHosts( main, hostNames ) |
| 779 | |
| 780 | # Check intents state |
| 781 | time.sleep( 30 ) |
| 782 | intentResult = checkIntentState( main, intentsId ) |
| 783 | |
| 784 | # Check intents state again if first check fails... |
| 785 | if not intentResult: |
| 786 | intentResult = checkIntentState( main, intentsId ) |
| 787 | |
| 788 | # Verify flows |
| 789 | checkFlowsState( main ) |
| 790 | |
| 791 | # Ping hosts |
| 792 | pingResult = pingResult and pingallHosts( main, hostNames ) |
| 793 | # Ping hosts again... |
| 794 | pingResult = pingResult and pingallHosts( main, hostNames ) |
| 795 | time.sleep( 5 ) |
| 796 | |
| 797 | # Test rerouting if these variables exist |
| 798 | if sw1 and sw2 and expectedLink: |
| 799 | # link down |
| 800 | linkDownResult = link( main, sw1, sw2, "down" ) |
| 801 | intentResult = intentResult and checkIntentState( main, intentsId ) |
| 802 | |
| 803 | # Verify flows |
| 804 | checkFlowsState( main ) |
| 805 | |
| 806 | # Check OnosTopology |
| 807 | topoResult = checkTopology( main, expectedLink ) |
| 808 | |
| 809 | # Ping hosts |
| 810 | pingResult = pingResult and pingallHosts( main, hostNames ) |
| 811 | |
| 812 | intentResult = checkIntentState( main, intentsId ) |
| 813 | |
| 814 | # Checks ONOS state in link down |
| 815 | if linkDownResult and topoResult and pingResult and intentResult: |
| 816 | main.log.info( itemName + ": Successfully brought link down" ) |
| 817 | else: |
| 818 | main.log.error( itemName + ": Failed to bring link down" ) |
| 819 | |
| 820 | # link up |
| 821 | linkUpResult = link( main, sw1, sw2, "up" ) |
| 822 | time.sleep( 5 ) |
| 823 | |
| 824 | # Verify flows |
| 825 | checkFlowsState( main ) |
| 826 | |
| 827 | # Check OnosTopology |
| 828 | topoResult = checkTopology( main, main.numLinks ) |
| 829 | |
| 830 | # Ping hosts |
| 831 | pingResult = pingResult and pingallHosts( main, hostNames ) |
| 832 | |
| 833 | intentResult = checkIntentState( main, intentsId ) |
| 834 | |
| 835 | # Checks ONOS state in link up |
| 836 | if linkUpResult and topoResult and pingResult and intentResult: |
| 837 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 838 | else: |
| 839 | main.log.error( itemName + ": Failed to bring link back up" ) |
| 840 | |
| 841 | # Remove all intents |
| 842 | removeIntentResult = removeAllIntents( main, intentsId ) |
| 843 | |
| 844 | stepResult = pingResult and linkDownResult and linkUpResult \ |
| 845 | and intentResult and removeIntentResult |
| 846 | |
| 847 | return stepResult |
| 848 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 849 | def pingallHosts( main, hostList, pingType="ipv4" ): |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 850 | # Ping all host in the hosts list variable |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 851 | print "Pinging : ", hostList |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 852 | pingResult = main.TRUE |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 853 | pingResult = main.Mininet1.pingallHosts( hostList, pingType ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 854 | return pingResult |
| 855 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 856 | def getHostsData( main ): |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 857 | """ |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 858 | Use fwd app and pingall to discover all the hosts |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 859 | """ |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 860 | import json |
| 861 | activateResult = main.TRUE |
| 862 | appCheck = main.TRUE |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 863 | getDataResult = main.TRUE |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 864 | main.log.info( "Activating reactive forwarding app " ) |
| 865 | activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" ) |
| 866 | |
| 867 | for i in range( main.numCtrls ): |
| 868 | appCheck = appCheck and main.CLIs[ i ].appToIDCheck() |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 869 | if appCheck != main.TRUE: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 870 | main.log.warn( main.CLIs[ i ].apps() ) |
| 871 | main.log.warn( main.CLIs[ i ].appIDs() ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 872 | |
| 873 | pingResult = main.Mininet1.pingall() |
| 874 | hostsJson = json.loads( main.CLIs[ 0 ].hosts() ) |
| 875 | hosts = main.Mininet1.getHosts() |
| 876 | for host in hosts: |
| 877 | main.hostsData[ host ] = {} |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 878 | main.hostsData[ host ][ 'mac' ] = \ |
| 879 | main.Mininet1.getMacAddress( host ).upper() |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 880 | for hostj in hostsJson: |
| 881 | if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]: |
| 882 | main.hostsData[ host ][ 'id' ] = hostj[ 'id' ] |
| 883 | main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ] |
| 884 | main.hostsData[ host ][ 'location' ] = \ |
| 885 | hostj[ 'location' ][ 'elementId' ] + '/' + \ |
| 886 | hostj[ 'location' ][ 'port' ] |
| 887 | main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ] |
| 888 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 889 | main.log.info( "Deactivating reactive forwarding app " ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 890 | deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 891 | if activateResult and deactivateResult and main.hostsData: |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 892 | main.log.info( "Successfully used fwd app to discover hosts " ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 893 | getDataResult = main.TRUE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 894 | else: |
| 895 | main.log.info( "Failed to use fwd app to discover hosts " ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 896 | getDataResult = main.FALSE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 897 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 898 | print main.hostsData |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 899 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 900 | return getDataResult |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 901 | |
| 902 | def checkTopology( main, expectedLink ): |
| 903 | statusResult = main.TRUE |
| 904 | # Check onos topology |
| 905 | main.log.info( itemName + ": Checking ONOS topology " ) |
| 906 | |
| 907 | for i in range( main.numCtrls ): |
| 908 | topologyResult = main.CLIs[ i ].topology() |
| 909 | statusResult = main.ONOSbench.checkStatus( topologyResult, |
| 910 | main.numSwitch, |
| 911 | expectedLink )\ |
| 912 | and statusResult |
| 913 | if not statusResult: |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 914 | main.log.error( itemName + ": Topology mismatch" ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 915 | else: |
| 916 | main.log.info( itemName + ": Topology match" ) |
| 917 | return statusResult |
| 918 | |
| 919 | def checkIntentState( main, intentsId ): |
| 920 | |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 921 | intentResult = main.TRUE |
| 922 | |
| 923 | main.log.info( itemName + ": Checking intents state" ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 924 | for i in range( main.numCtrls ): |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 925 | intentResult = intentResult and \ |
| 926 | main.CLIs[ i ].checkIntentState( intentsId=intentsId ) |
| 927 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 928 | return intentResult |
| 929 | |
| 930 | def checkFlowsState( main ): |
| 931 | |
| 932 | main.log.info( itemName + ": Check flows state" ) |
| 933 | checkFlowsResult = main.CLIs[ 0 ].checkFlowsState() |
| 934 | return checkFlowsResult |
| 935 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 936 | def link( main, sw1, sw2, option): |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 937 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 938 | # link down |
| 939 | main.log.info( itemName + ": Bring link " + option + "between " + |
| 940 | sw1 + " and " + sw2 ) |
| 941 | linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option ) |
| 942 | return linkResult |
| 943 | |
| 944 | def removeAllIntents( main, intentsId ): |
| 945 | """ |
| 946 | Remove all intents in the intentsId |
| 947 | """ |
| 948 | import time |
| 949 | intentsRemaining = [] |
| 950 | removeIntentResult = main.TRUE |
| 951 | # Remove intents |
| 952 | for intent in intentsId: |
| 953 | main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True ) |
| 954 | |
| 955 | time.sleep( 5 ) |
| 956 | # Checks if there is remaining intents using intents() |
kelvin-onlab | 583fcb5 | 2015-05-21 13:10:46 -0700 | [diff] [blame] | 957 | intentsRemaining = main.CLIs[ 0 ].intents( jsonFormat=False ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 958 | # If there is remianing intents then remove intents should fail |
kelvin-onlab | 583fcb5 | 2015-05-21 13:10:46 -0700 | [diff] [blame] | 959 | |
| 960 | if intentsRemaining: |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 961 | main.log.info( itemName + ": There are " + |
| 962 | str( len( intentsRemaining ) ) + " intents remaining, " |
| 963 | + "failed to remove all the intents " ) |
| 964 | removeIntentResult = main.FALSE |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 965 | main.log.info( intentsRemaining ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 966 | else: |
| 967 | main.log.info( itemName + ": There are no intents remaining, " + |
| 968 | "successfully removed all the intents." ) |
| 969 | removeIntentResult = main.TRUE |
| 970 | return removeIntentResult |