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