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 | 2ff5702 | 2015-05-29 10:48:51 -0700 | [diff] [blame] | 13 | onosNode=0, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 14 | host1Id="", |
| 15 | host2Id="", |
| 16 | mac1="", |
| 17 | mac2="", |
| 18 | vlan1="-1", |
| 19 | vlan2="-1", |
| 20 | sw1="", |
| 21 | sw2="", |
| 22 | expectedLink=0 ): |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 23 | """ |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 24 | Description: |
| 25 | Verify add-host-intent |
| 26 | Steps: |
| 27 | - Discover hosts |
| 28 | - Add host intents |
| 29 | - Check intents |
| 30 | - Verify flows |
| 31 | - Ping hosts |
| 32 | - Reroute |
| 33 | - Link down |
| 34 | - Verify flows |
| 35 | - Check topology |
| 36 | - Ping hosts |
| 37 | - Link up |
| 38 | - Verify flows |
| 39 | - Check topology |
| 40 | - Ping hosts |
| 41 | - Remove intents |
| 42 | Required: |
| 43 | name - Type of host intent to add eg. IPV4 | VLAN | Dualstack |
| 44 | host1 - Name of first host |
| 45 | host2 - Name of second host |
| 46 | Optional: |
| 47 | host1Id - ONOS id of the first host eg. 00:00:00:00:00:01/-1 |
| 48 | host2Id - ONOS id of the second host |
| 49 | mac1 - Mac address of first host |
| 50 | mac2 - Mac address of the second host |
| 51 | vlan1 - Vlan tag of first host, defaults to -1 |
| 52 | vlan2 - Vlan tag of second host, defaults to -1 |
| 53 | sw1 - First switch to bring down & up for rerouting purpose |
| 54 | sw2 - Second switch to bring down & up for rerouting purpose |
| 55 | expectedLink - Expected link when the switches are down, it should |
| 56 | be two links lower than the links before the two |
| 57 | switches are down |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 58 | """ |
| 59 | import time |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 60 | |
| 61 | # Assert variables |
| 62 | assert main, "There is no main variable" |
| 63 | assert name, "variable name is empty" |
| 64 | assert host1 and host2, "You must specify hosts" |
| 65 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 66 | global itemName |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 67 | itemName = name |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 68 | h1Id = host1Id |
| 69 | h2Id = host2Id |
| 70 | h1Mac = mac1 |
| 71 | h2Mac = mac2 |
| 72 | vlan1 = vlan1 |
| 73 | vlan2 = vlan2 |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 74 | hostNames = [ host1 , host2 ] |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 75 | intentsId = [] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 76 | stepResult = main.TRUE |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 77 | pingResult = main.TRUE |
| 78 | intentResult = main.TRUE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 79 | removeIntentResult = main.TRUE |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 80 | flowResult = main.TRUE |
| 81 | topoResult = main.TRUE |
| 82 | linkDownResult = main.TRUE |
| 83 | linkUpResult = main.TRUE |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 84 | onosNode = int( onosNode ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 85 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 86 | if main.hostsData: |
| 87 | if not h1Mac: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 88 | h1Mac = main.hostsData[ host1 ][ 'mac' ] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 89 | if not h2Mac: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 90 | h2Mac = main.hostsData[ host2 ][ 'mac' ] |
| 91 | if main.hostsData[ host1 ][ 'vlan' ] != '-1': |
| 92 | vlan1 = main.hostsData[ host1 ][ 'vlan' ] |
| 93 | if main.hostsData[ host2 ][ 'vlan' ] != '-1': |
| 94 | vlan2 = main.hostsData[ host2 ][ 'vlan' ] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 95 | if not h1Id: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 96 | h1Id = main.hostsData[ host1 ][ 'id' ] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 97 | if not h2Id: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 98 | h2Id = main.hostsData[ host2 ][ 'id' ] |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 99 | |
| 100 | assert h1Id and h2Id, "You must specify host IDs" |
| 101 | if not ( h1Id and h2Id ): |
| 102 | main.log.info( "There are no host IDs" ) |
| 103 | return main.FALSE |
| 104 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 105 | # Discover hosts using arping |
kelvin-onlab | 2ff5702 | 2015-05-29 10:48:51 -0700 | [diff] [blame] | 106 | if not main.hostsData: |
| 107 | main.log.info( itemName + ": Discover host using arping" ) |
| 108 | main.Mininet1.arping( host=host1 ) |
| 109 | main.Mininet1.arping( host=host2 ) |
| 110 | host1 = main.CLIs[ 0 ].getHost( mac=h1Mac ) |
| 111 | host2 = main.CLIs[ 0 ].getHost( mac=h2Mac ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 112 | |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 113 | # Check flows count in each node |
| 114 | checkFlowsCount( main ) |
| 115 | |
| 116 | # Checking connectivity before installing intents |
| 117 | main.log.info( itemName + ": Check hosts connection before adding intents" ) |
| 118 | checkPing = pingallHosts( main, hostNames ) |
| 119 | if not checkPing: |
| 120 | main.log.info( itemName + ": Ping did not go through " + |
| 121 | "before adding intents" ) |
| 122 | else: |
| 123 | main.log.debug( itemName + ": Pinged successful before adding " + |
| 124 | "intents,please check fwd app if it is activated" ) |
| 125 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 126 | # Adding host intents |
| 127 | main.log.info( itemName + ": Adding host intents" ) |
kelvin-onlab | 2ff5702 | 2015-05-29 10:48:51 -0700 | [diff] [blame] | 128 | intent1 = main.CLIs[ onosNode ].addHostIntent( hostIdOne=h1Id, |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 129 | hostIdTwo=h2Id ) |
| 130 | intentsId.append( intent1 ) |
| 131 | time.sleep( 5 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 132 | |
| 133 | # Check intents state |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 134 | time.sleep( 30 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 135 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 136 | checkFlowsCount( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 137 | |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 138 | # Check intents state again if first check fails... |
| 139 | if not intentResult: |
| 140 | intentResult = checkIntentState( main, intentsId ) |
| 141 | |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 142 | # Check flows count in each node |
| 143 | checkFlowsCount( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 144 | # Verify flows |
| 145 | checkFlowsState( main ) |
| 146 | |
| 147 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 148 | firstPingResult = pingallHosts( main, hostNames ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 149 | if not firstPingResult: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 150 | main.log.debug( "First ping failed, there must be" + |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 151 | " something wrong with ONOS performance" ) |
| 152 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 153 | # Ping hosts again... |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 154 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 155 | time.sleep( 5 ) |
| 156 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 157 | # Test rerouting if these variables exist |
| 158 | if sw1 and sw2 and expectedLink: |
| 159 | # link down |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 160 | linkDownResult = link( main, sw1, sw2, "down" ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 161 | intentResult = intentResult and checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 162 | |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 163 | # Check flows count in each node |
| 164 | checkFlowsCount( main ) |
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 |
| 169 | topoResult = checkTopology( main, expectedLink ) |
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 | 2ccad6e | 2015-05-18 10:36:54 -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 down |
| 177 | if linkDownResult and topoResult and pingResult and intentResult: |
| 178 | main.log.info( itemName + ": Successfully brought link down" ) |
| 179 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 180 | main.log.error( itemName + ": Failed to bring link down" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 181 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 182 | # link up |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 183 | linkUpResult = link( main, sw1, sw2, "up" ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 184 | time.sleep( 5 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 185 | |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 186 | # Check flows count in each node |
| 187 | checkFlowsCount( main ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 188 | # Verify flows |
| 189 | checkFlowsState( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 190 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 191 | # Check OnosTopology |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 192 | topoResult = checkTopology( main, main.numLinks ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 193 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 194 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 195 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 196 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 197 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 198 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 199 | # Checks ONOS state in link up |
| 200 | if linkUpResult and topoResult and pingResult and intentResult: |
| 201 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 202 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 203 | main.log.error( itemName + ": Failed to bring link back up" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 204 | |
| 205 | # Remove all intents |
| 206 | removeIntentResult = removeAllIntents( main, intentsId ) |
| 207 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 208 | stepResult = pingResult and linkDownResult and linkUpResult \ |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 209 | and intentResult and removeIntentResult |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 210 | |
| 211 | return stepResult |
| 212 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 213 | def pointIntent( main, |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 214 | name, |
| 215 | host1, |
| 216 | host2, |
kelvin-onlab | 2ff5702 | 2015-05-29 10:48:51 -0700 | [diff] [blame] | 217 | onosNode=0, |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 218 | deviceId1="", |
| 219 | deviceId2="", |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 220 | port1="", |
| 221 | port2="", |
| 222 | ethType="", |
| 223 | mac1="", |
| 224 | mac2="", |
| 225 | bandwidth="", |
| 226 | lambdaAlloc=False, |
| 227 | ipProto="", |
| 228 | ip1="", |
| 229 | ip2="", |
| 230 | tcp1="", |
| 231 | tcp2="", |
| 232 | sw1="", |
| 233 | sw2="", |
| 234 | expectedLink=0 ): |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 235 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 236 | """ |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 237 | Description: |
| 238 | Verify add-point-intent |
| 239 | Steps: |
| 240 | - Get device ids | ports |
| 241 | - Add point intents |
| 242 | - Check intents |
| 243 | - Verify flows |
| 244 | - Ping hosts |
| 245 | - Reroute |
| 246 | - Link down |
| 247 | - Verify flows |
| 248 | - Check topology |
| 249 | - Ping hosts |
| 250 | - Link up |
| 251 | - Verify flows |
| 252 | - Check topology |
| 253 | - Ping hosts |
| 254 | - Remove intents |
| 255 | Required: |
| 256 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
| 257 | host1 - Name of first host |
| 258 | host2 - Name of second host |
| 259 | Optional: |
| 260 | deviceId1 - ONOS device id of the first switch, the same as the |
| 261 | location of the first host eg. of:0000000000000001/1, |
| 262 | located at device 1 port 1 |
| 263 | deviceId2 - ONOS device id of the second switch |
| 264 | port1 - The port number where the first host is attached |
| 265 | port2 - The port number where the second host is attached |
| 266 | ethType - Ethernet type eg. IPV4, IPV6 |
| 267 | mac1 - Mac address of first host |
| 268 | mac2 - Mac address of the second host |
| 269 | bandwidth - Bandwidth capacity |
| 270 | lambdaAlloc - Allocate lambda, defaults to False |
| 271 | ipProto - IP protocol |
| 272 | ip1 - IP address of first host |
| 273 | ip2 - IP address of second host |
| 274 | tcp1 - TCP port of first host |
| 275 | tcp2 - TCP port of second host |
| 276 | sw1 - First switch to bring down & up for rerouting purpose |
| 277 | sw2 - Second switch to bring down & up for rerouting purpose |
| 278 | expectedLink - Expected link when the switches are down, it should |
| 279 | be two links lower than the links before the two |
| 280 | switches are down |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 281 | """ |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 282 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 283 | import time |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 284 | assert main, "There is no main variable" |
| 285 | assert name, "variable name is empty" |
| 286 | assert host1 and host2, "You must specify hosts" |
| 287 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 288 | global itemName |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 289 | itemName = name |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 290 | host1 = host1 |
| 291 | host2 = host2 |
| 292 | hostNames = [ host1, host2 ] |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 293 | intentsId = [] |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 294 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 295 | pingResult = main.TRUE |
| 296 | intentResult = main.TRUE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 297 | removeIntentResult = main.TRUE |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 298 | flowResult = main.TRUE |
| 299 | topoResult = main.TRUE |
| 300 | linkDownResult = main.TRUE |
| 301 | linkUpResult = main.TRUE |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 302 | onosNode = int( onosNode ) |
| 303 | |
| 304 | # Checking connectivity before installing intents |
| 305 | main.log.info( itemName + ": Check hosts connection before adding intents" ) |
| 306 | checkPing = pingallHosts( main, hostNames ) |
| 307 | if not checkPing: |
| 308 | main.log.info( itemName + ": Ping did not go through " + |
| 309 | "before adding intents" ) |
| 310 | else: |
| 311 | main.log.debug( itemName + ": Pinged successful before adding " + |
| 312 | "intents,please check fwd app if it is activated" ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 313 | |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 314 | # Adding bidirectional point intents |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 315 | main.log.info( itemName + ": Adding point intents" ) |
kelvin-onlab | 2ff5702 | 2015-05-29 10:48:51 -0700 | [diff] [blame] | 316 | intent1 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId1, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 317 | egressDevice=deviceId2, |
| 318 | portIngress=port1, |
| 319 | portEgress=port2, |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 320 | ethType=ethType, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 321 | ethSrc=mac1, |
| 322 | ethDst=mac2, |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 323 | bandwidth=bandwidth, |
| 324 | lambdaAlloc=lambdaAlloc, |
| 325 | ipProto=ipProto, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 326 | ipSrc=ip1, |
| 327 | ipDst=ip2, |
| 328 | tcpSrc=tcp1, |
| 329 | tcpDst=tcp2 ) |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 330 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 331 | intentsId.append( intent1 ) |
| 332 | time.sleep( 5 ) |
kelvin-onlab | 2ff5702 | 2015-05-29 10:48:51 -0700 | [diff] [blame] | 333 | intent2 = main.CLIs[ onosNode ].addPointIntent( ingressDevice=deviceId2, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 334 | egressDevice=deviceId1, |
| 335 | portIngress=port2, |
| 336 | portEgress=port1, |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 337 | ethType=ethType, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 338 | ethSrc=mac2, |
| 339 | ethDst=mac1, |
kelvin-onlab | b223560 | 2015-05-13 17:51:06 -0700 | [diff] [blame] | 340 | bandwidth=bandwidth, |
| 341 | lambdaAlloc=lambdaAlloc, |
| 342 | ipProto=ipProto, |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 343 | ipSrc=ip2, |
| 344 | ipDst=ip1, |
| 345 | tcpSrc=tcp2, |
| 346 | tcpDst=tcp1 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 347 | intentsId.append( intent2 ) |
| 348 | |
| 349 | # Check intents state |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 350 | time.sleep( 30 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 351 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 352 | # Check flows count in each node |
| 353 | checkFlowsCount( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 354 | |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 355 | # Check intents state again if first check fails... |
| 356 | if not intentResult: |
| 357 | intentResult = checkIntentState( main, intentsId ) |
| 358 | |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 359 | # Check flows count in each node |
| 360 | checkFlowsCount( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 361 | # Verify flows |
| 362 | checkFlowsState( main ) |
| 363 | |
| 364 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 365 | firstPingResult = pingallHosts( main, hostNames ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 366 | if not firstPingResult: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 367 | main.log.debug( "First ping failed, there must be" + |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 368 | " something wrong with ONOS performance" ) |
| 369 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 370 | # Ping hosts again... |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 371 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 372 | time.sleep( 5 ) |
| 373 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 374 | # Test rerouting if these variables exist |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 375 | if sw1 and sw2 and expectedLink: |
| 376 | # link down |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 377 | linkDownResult = link( main, sw1, sw2, "down" ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 378 | intentResult = intentResult and checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 379 | |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 380 | # Check flows count in each node |
| 381 | checkFlowsCount( main ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 382 | # Verify flows |
| 383 | checkFlowsState( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 384 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 385 | # Check OnosTopology |
| 386 | topoResult = checkTopology( main, expectedLink ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 387 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 388 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 389 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 390 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 391 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 392 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 393 | # Checks ONOS state in link down |
| 394 | if linkDownResult and topoResult and pingResult and intentResult: |
| 395 | main.log.info( itemName + ": Successfully brought link down" ) |
| 396 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 397 | main.log.error( itemName + ": Failed to bring link down" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 398 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 399 | # link up |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 400 | linkUpResult = link( main, sw1, sw2, "up" ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 401 | time.sleep( 5 ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 402 | |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 403 | # Check flows count in each node |
| 404 | checkFlowsCount( main ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 405 | # Verify flows |
| 406 | checkFlowsState( main ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 407 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 408 | # Check OnosTopology |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 409 | topoResult = checkTopology( main, main.numLinks ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 410 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 411 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 412 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 413 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 414 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 415 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 416 | # Checks ONOS state in link up |
| 417 | if linkUpResult and topoResult and pingResult and intentResult: |
| 418 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 419 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 420 | main.log.error( itemName + ": Failed to bring link back up" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 421 | |
| 422 | # Remove all intents |
| 423 | removeIntentResult = removeAllIntents( main, intentsId ) |
| 424 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 425 | stepResult = pingResult and linkDownResult and linkUpResult \ |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 426 | and intentResult and removeIntentResult |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 427 | |
| 428 | return stepResult |
| 429 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 430 | def singleToMultiIntent( main, |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 431 | name, |
| 432 | hostNames, |
kelvin-onlab | 2ff5702 | 2015-05-29 10:48:51 -0700 | [diff] [blame] | 433 | onosNode=0, |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 434 | devices="", |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 435 | ports=None, |
| 436 | ethType="", |
| 437 | macs=None, |
| 438 | bandwidth="", |
| 439 | lambdaAlloc=False, |
| 440 | ipProto="", |
| 441 | ipAddresses="", |
| 442 | tcp="", |
| 443 | sw1="", |
| 444 | sw2="", |
| 445 | expectedLink=0 ): |
| 446 | """ |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 447 | Verify Single to Multi Point intents |
| 448 | 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] | 449 | same order index wise. All devices in the list should have the same |
| 450 | format, either all the devices have its port or it doesn't. |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 451 | eg. hostName = [ 'h1', 'h2' ,.. ] |
| 452 | devices = [ 'of:0000000000000001', 'of:0000000000000002', ...] |
| 453 | ports = [ '1', '1', ..] |
| 454 | ... |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 455 | Description: |
kelvin-onlab | 583fcb5 | 2015-05-21 13:10:46 -0700 | [diff] [blame] | 456 | Verify add-single-to-multi-intent iterates through the list of given |
| 457 | host | devices and add intents |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 458 | Steps: |
| 459 | - Get device ids | ports |
| 460 | - Add single to multi point intents |
| 461 | - Check intents |
| 462 | - Verify flows |
| 463 | - Ping hosts |
| 464 | - Reroute |
| 465 | - Link down |
| 466 | - Verify flows |
| 467 | - Check topology |
| 468 | - Ping hosts |
| 469 | - Link up |
| 470 | - Verify flows |
| 471 | - Check topology |
| 472 | - Ping hosts |
| 473 | - Remove intents |
| 474 | Required: |
| 475 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
| 476 | hostNames - List of host names |
| 477 | Optional: |
| 478 | devices - List of device ids in the same order as the hosts |
| 479 | in hostNames |
| 480 | ports - List of port numbers in the same order as the device in |
| 481 | devices |
| 482 | ethType - Ethernet type eg. IPV4, IPV6 |
| 483 | macs - List of hosts mac address in the same order as the hosts in |
| 484 | hostNames |
| 485 | bandwidth - Bandwidth capacity |
| 486 | lambdaAlloc - Allocate lambda, defaults to False |
| 487 | ipProto - IP protocol |
| 488 | ipAddresses - IP addresses of host in the same order as the hosts in |
| 489 | hostNames |
| 490 | tcp - TCP ports in the same order as the hosts in hostNames |
| 491 | sw1 - First switch to bring down & up for rerouting purpose |
| 492 | sw2 - Second switch to bring down & up for rerouting purpose |
| 493 | expectedLink - Expected link when the switches are down, it should |
| 494 | be two links lower than the links before the two |
| 495 | switches are down |
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 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 498 | import time |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 499 | import copy |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 500 | assert main, "There is no main variable" |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 501 | assert hostNames, "You must specify hosts" |
| 502 | assert devices or main.hostsData, "You must specify devices" |
| 503 | |
| 504 | global itemName |
| 505 | itemName = name |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 506 | tempHostsData = {} |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 507 | intentsId = [] |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 508 | onosNode = int( onosNode ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 509 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 510 | macsDict = {} |
| 511 | ipDict = {} |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 512 | if hostNames and devices: |
| 513 | if len( hostNames ) != len( devices ): |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 514 | main.log.debug( "hosts and devices does not have the same length" ) |
| 515 | #print "len hostNames = ", len( hostNames ) |
| 516 | #print "len devices = ", len( devices ) |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 517 | return main.FALSE |
| 518 | if ports: |
| 519 | if len( ports ) != len( devices ): |
| 520 | main.log.error( "Ports and devices does " + |
| 521 | "not have the same length" ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 522 | #print "len devices = ", len( devices ) |
| 523 | #print "len ports = ", len( ports ) |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 524 | return main.FALSE |
| 525 | else: |
| 526 | main.log.info( "Device Ports are not specified" ) |
kelvin-onlab | f2ec6e0 | 2015-05-27 14:15:28 -0700 | [diff] [blame] | 527 | if macs: |
| 528 | for i in range( len( devices ) ): |
| 529 | macsDict[ devices[ i ] ] = macs[ i ] |
| 530 | |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 531 | elif hostNames and not devices and main.hostsData: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 532 | devices = [] |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 533 | main.log.info( "singleToMultiIntent function is using main.hostsData" ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 534 | for host in hostNames: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 535 | devices.append( main.hostsData.get( host ).get( 'location' ) ) |
| 536 | macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \ |
| 537 | main.hostsData.get( host ).get( 'mac' ) |
| 538 | ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \ |
| 539 | main.hostsData.get( host ).get( 'ipAddresses' ) |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 540 | #print main.hostsData |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 541 | |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 542 | #print 'host names = ', hostNames |
| 543 | #print 'devices = ', devices |
| 544 | #print "macsDict = ", macsDict |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 545 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 546 | pingResult = main.TRUE |
| 547 | intentResult = main.TRUE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 548 | removeIntentResult = main.TRUE |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 549 | flowResult = main.TRUE |
| 550 | topoResult = main.TRUE |
| 551 | linkDownResult = main.TRUE |
| 552 | linkUpResult = main.TRUE |
| 553 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 554 | devicesCopy = copy.copy( devices ) |
| 555 | if ports: |
| 556 | portsCopy = copy.copy( ports ) |
| 557 | main.log.info( itemName + ": Adding single point to multi point intents" ) |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 558 | |
| 559 | # Check flows count in each node |
| 560 | checkFlowsCount( main ) |
| 561 | |
| 562 | # Checking connectivity before installing intents |
| 563 | main.log.info( itemName + ": Check hosts connection before adding intents" ) |
| 564 | checkPing = pingallHosts( main, hostNames ) |
| 565 | if not checkPing: |
| 566 | main.log.info( itemName + ": Ping did not go through " + |
| 567 | "before adding intents" ) |
| 568 | else: |
| 569 | main.log.debug( itemName + ": Pinged successful before adding " + |
| 570 | "intents,please check fwd app if it is activated" ) |
| 571 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 572 | # Adding bidirectional point intents |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 573 | for i in range( len( devices ) ): |
| 574 | ingressDevice = devicesCopy[ i ] |
| 575 | egressDeviceList = copy.copy( devicesCopy ) |
| 576 | egressDeviceList.remove( ingressDevice ) |
| 577 | if ports: |
| 578 | portIngress = portsCopy[ i ] |
| 579 | portEgressList = copy.copy( portsCopy ) |
| 580 | del portEgressList[ i ] |
| 581 | else: |
| 582 | portIngress = "" |
| 583 | portEgressList = None |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 584 | if not macsDict: |
| 585 | srcMac = "" |
| 586 | else: |
| 587 | srcMac = macsDict[ ingressDevice ] |
| 588 | if srcMac == None: |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 589 | main.log.debug( "There is no MAC in device - " + ingressDevice ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 590 | srcMac = "" |
| 591 | |
kelvin-onlab | 2ff5702 | 2015-05-29 10:48:51 -0700 | [diff] [blame] | 592 | intentsId.append( |
| 593 | main.CLIs[ onosNode ].addSinglepointToMultipointIntent( |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 594 | ingressDevice=ingressDevice, |
| 595 | egressDeviceList=egressDeviceList, |
| 596 | portIngress=portIngress, |
| 597 | portEgressList=portEgressList, |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 598 | ethType=ethType, |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 599 | ethSrc=srcMac, |
kelvin-onlab | 90b6b04 | 2015-05-18 20:57:13 -0700 | [diff] [blame] | 600 | bandwidth=bandwidth, |
| 601 | lambdaAlloc=lambdaAlloc, |
| 602 | ipProto=ipProto, |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 603 | ipSrc="", |
| 604 | ipDst="", |
| 605 | tcpSrc="", |
| 606 | tcpDst="" ) ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 607 | |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 608 | # Wait some time for the flow to go through when using multi instance |
kelvin-onlab | 2ff5702 | 2015-05-29 10:48:51 -0700 | [diff] [blame] | 609 | time.sleep( 10 ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 610 | pingResult = pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 611 | |
| 612 | # Check intents state |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 613 | time.sleep( 30 ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 614 | intentResult = checkIntentState( main, intentsId ) |
| 615 | |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 616 | # Check intents state again if first check fails... |
| 617 | if not intentResult: |
| 618 | intentResult = checkIntentState( main, intentsId ) |
| 619 | |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 620 | # Check flows count in each node |
| 621 | checkFlowsCount( main ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 622 | # Verify flows |
| 623 | checkFlowsState( main ) |
| 624 | |
| 625 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 626 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 627 | # Ping hosts again... |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 628 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 629 | time.sleep( 5 ) |
| 630 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 631 | # Test rerouting if these variables exist |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 632 | if sw1 and sw2 and expectedLink: |
| 633 | # link down |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 634 | linkDownResult = link( main, sw1, sw2, "down" ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 635 | intentResult = intentResult and checkIntentState( main, intentsId ) |
| 636 | |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 637 | # Check flows count in each node |
| 638 | checkFlowsCount( main ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 639 | # Verify flows |
| 640 | checkFlowsState( main ) |
| 641 | |
| 642 | # Check OnosTopology |
| 643 | topoResult = checkTopology( main, expectedLink ) |
| 644 | |
| 645 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 646 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 647 | |
| 648 | intentResult = checkIntentState( main, intentsId ) |
| 649 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 650 | # Checks ONOS state in link down |
| 651 | if linkDownResult and topoResult and pingResult and intentResult: |
| 652 | main.log.info( itemName + ": Successfully brought link down" ) |
| 653 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 654 | main.log.error( itemName + ": Failed to bring link down" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 655 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 656 | # link up |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 657 | linkUpResult = link( main, sw1, sw2, "up" ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 658 | time.sleep( 5 ) |
| 659 | |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 660 | # Check flows count in each node |
| 661 | checkFlowsCount( main ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 662 | # Verify flows |
| 663 | checkFlowsState( main ) |
| 664 | |
| 665 | # Check OnosTopology |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 666 | topoResult = checkTopology( main, main.numLinks ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 667 | |
| 668 | # Ping hosts |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 669 | pingResult = pingResult and pingallHosts( main, hostNames ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 670 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 671 | intentResult = checkIntentState( main, intentsId ) |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 672 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 673 | # Checks ONOS state in link up |
| 674 | if linkUpResult and topoResult and pingResult and intentResult: |
| 675 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 676 | else: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 677 | main.log.error( itemName + ": Failed to bring link back up" ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 678 | |
| 679 | # Remove all intents |
| 680 | removeIntentResult = removeAllIntents( main, intentsId ) |
| 681 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 682 | stepResult = pingResult and linkDownResult and linkUpResult \ |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 683 | and intentResult and removeIntentResult |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 684 | |
| 685 | return stepResult |
| 686 | |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 687 | def multiToSingleIntent( main, |
| 688 | name, |
| 689 | hostNames, |
kelvin-onlab | 2ff5702 | 2015-05-29 10:48:51 -0700 | [diff] [blame] | 690 | onosNode=0, |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 691 | devices="", |
| 692 | ports=None, |
| 693 | ethType="", |
| 694 | macs=None, |
| 695 | bandwidth="", |
| 696 | lambdaAlloc=False, |
| 697 | ipProto="", |
| 698 | ipAddresses="", |
| 699 | tcp="", |
| 700 | sw1="", |
| 701 | sw2="", |
| 702 | expectedLink=0 ): |
| 703 | """ |
| 704 | Verify Single to Multi Point intents |
| 705 | NOTE:If main.hostsData is not defined, variables data should be passed in the |
| 706 | same order index wise. All devices in the list should have the same |
| 707 | format, either all the devices have its port or it doesn't. |
| 708 | eg. hostName = [ 'h1', 'h2' ,.. ] |
| 709 | devices = [ 'of:0000000000000001', 'of:0000000000000002', ...] |
| 710 | ports = [ '1', '1', ..] |
| 711 | ... |
| 712 | Description: |
| 713 | Verify add-multi-to-single-intent |
| 714 | Steps: |
| 715 | - Get device ids | ports |
kelvin-onlab | b2310a4 | 2015-05-21 14:17:29 -0700 | [diff] [blame] | 716 | - Add multi to single point intents |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 717 | - Check intents |
| 718 | - Verify flows |
| 719 | - Ping hosts |
| 720 | - Reroute |
| 721 | - Link down |
| 722 | - Verify flows |
| 723 | - Check topology |
| 724 | - Ping hosts |
| 725 | - Link up |
| 726 | - Verify flows |
| 727 | - Check topology |
| 728 | - Ping hosts |
| 729 | - Remove intents |
| 730 | Required: |
| 731 | name - Type of point intent to add eg. IPV4 | VLAN | Dualstack |
| 732 | hostNames - List of host names |
| 733 | Optional: |
| 734 | devices - List of device ids in the same order as the hosts |
| 735 | in hostNames |
| 736 | ports - List of port numbers in the same order as the device in |
| 737 | devices |
| 738 | ethType - Ethernet type eg. IPV4, IPV6 |
| 739 | macs - List of hosts mac address in the same order as the hosts in |
| 740 | hostNames |
| 741 | bandwidth - Bandwidth capacity |
| 742 | lambdaAlloc - Allocate lambda, defaults to False |
| 743 | ipProto - IP protocol |
| 744 | ipAddresses - IP addresses of host in the same order as the hosts in |
| 745 | hostNames |
| 746 | tcp - TCP ports in the same order as the hosts in hostNames |
| 747 | sw1 - First switch to bring down & up for rerouting purpose |
| 748 | sw2 - Second switch to bring down & up for rerouting purpose |
| 749 | expectedLink - Expected link when the switches are down, it should |
| 750 | be two links lower than the links before the two |
| 751 | switches are down |
| 752 | """ |
| 753 | |
| 754 | import time |
| 755 | import copy |
| 756 | assert main, "There is no main variable" |
| 757 | assert hostNames, "You must specify hosts" |
| 758 | assert devices or main.hostsData, "You must specify devices" |
| 759 | |
| 760 | global itemName |
| 761 | itemName = name |
| 762 | tempHostsData = {} |
| 763 | intentsId = [] |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 764 | onosNode = int( onosNode ) |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 765 | |
| 766 | macsDict = {} |
| 767 | ipDict = {} |
| 768 | if hostNames and devices: |
| 769 | if len( hostNames ) != len( devices ): |
| 770 | main.log.debug( "hosts and devices does not have the same length" ) |
| 771 | #print "len hostNames = ", len( hostNames ) |
| 772 | #print "len devices = ", len( devices ) |
| 773 | return main.FALSE |
| 774 | if ports: |
| 775 | if len( ports ) != len( devices ): |
| 776 | main.log.error( "Ports and devices does " + |
| 777 | "not have the same length" ) |
| 778 | #print "len devices = ", len( devices ) |
| 779 | #print "len ports = ", len( ports ) |
| 780 | return main.FALSE |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 781 | else: |
| 782 | main.log.info( "Device Ports are not specified" ) |
kelvin-onlab | f2ec6e0 | 2015-05-27 14:15:28 -0700 | [diff] [blame] | 783 | if macs: |
| 784 | for i in range( len( devices ) ): |
| 785 | macsDict[ devices[ i ] ] = macs[ i ] |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 786 | elif hostNames and not devices and main.hostsData: |
| 787 | devices = [] |
kelvin-onlab | b2310a4 | 2015-05-21 14:17:29 -0700 | [diff] [blame] | 788 | main.log.info( "multiToSingleIntent function is using main.hostsData" ) |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 789 | for host in hostNames: |
| 790 | devices.append( main.hostsData.get( host ).get( 'location' ) ) |
| 791 | macsDict[ main.hostsData.get( host ).get( 'location' ) ] = \ |
| 792 | main.hostsData.get( host ).get( 'mac' ) |
| 793 | ipDict[ main.hostsData.get( host ).get( 'location' ) ] = \ |
| 794 | main.hostsData.get( host ).get( 'ipAddresses' ) |
| 795 | #print main.hostsData |
| 796 | |
| 797 | #print 'host names = ', hostNames |
| 798 | #print 'devices = ', devices |
| 799 | #print "macsDict = ", macsDict |
| 800 | |
| 801 | pingResult = main.TRUE |
| 802 | intentResult = main.TRUE |
| 803 | removeIntentResult = main.TRUE |
| 804 | flowResult = main.TRUE |
| 805 | topoResult = main.TRUE |
| 806 | linkDownResult = main.TRUE |
| 807 | linkUpResult = main.TRUE |
| 808 | |
| 809 | devicesCopy = copy.copy( devices ) |
| 810 | if ports: |
| 811 | portsCopy = copy.copy( ports ) |
kelvin-onlab | b2310a4 | 2015-05-21 14:17:29 -0700 | [diff] [blame] | 812 | main.log.info( itemName + ": Adding multi point to single point intents" ) |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 813 | |
| 814 | # Check flows count in each node |
| 815 | checkFlowsCount( main ) |
| 816 | |
| 817 | # Checking connectivity before installing intents |
| 818 | main.log.info( itemName + ": Check hosts connection before adding intents" ) |
| 819 | checkPing = pingallHosts( main, hostNames ) |
| 820 | if not checkPing: |
| 821 | main.log.info( itemName + ": Ping did not go through " + |
| 822 | "before adding intents" ) |
| 823 | else: |
| 824 | main.log.debug( itemName + ": Pinged successful before adding " + |
| 825 | "intents,please check fwd app if it is activated" ) |
| 826 | |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 827 | # Adding bidirectional point intents |
| 828 | for i in range( len( devices ) ): |
| 829 | egressDevice = devicesCopy[ i ] |
| 830 | ingressDeviceList = copy.copy( devicesCopy ) |
| 831 | ingressDeviceList.remove( egressDevice ) |
| 832 | if ports: |
| 833 | portEgress = portsCopy[ i ] |
| 834 | portIngressList = copy.copy( portsCopy ) |
| 835 | del portIngressList[ i ] |
| 836 | else: |
| 837 | portEgress = "" |
| 838 | portIngressList = None |
| 839 | if not macsDict: |
| 840 | dstMac = "" |
| 841 | else: |
| 842 | dstMac = macsDict[ egressDevice ] |
| 843 | if dstMac == None: |
| 844 | main.log.debug( "There is no MAC in device - " + egressDevice ) |
| 845 | dstMac = "" |
| 846 | |
kelvin-onlab | 2ff5702 | 2015-05-29 10:48:51 -0700 | [diff] [blame] | 847 | intentsId.append( |
| 848 | main.CLIs[ onosNode ].addMultipointToSinglepointIntent( |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 849 | ingressDeviceList=ingressDeviceList, |
| 850 | egressDevice=egressDevice, |
| 851 | portIngressList=portIngressList, |
| 852 | portEgress=portEgress, |
| 853 | ethType=ethType, |
| 854 | ethDst=dstMac, |
| 855 | bandwidth=bandwidth, |
| 856 | lambdaAlloc=lambdaAlloc, |
| 857 | ipProto=ipProto, |
| 858 | ipSrc="", |
| 859 | ipDst="", |
| 860 | tcpSrc="", |
| 861 | tcpDst="" ) ) |
| 862 | |
| 863 | pingResult = pingallHosts( main, hostNames ) |
| 864 | |
| 865 | # Check intents state |
| 866 | time.sleep( 30 ) |
| 867 | intentResult = checkIntentState( main, intentsId ) |
| 868 | |
| 869 | # Check intents state again if first check fails... |
| 870 | if not intentResult: |
| 871 | intentResult = checkIntentState( main, intentsId ) |
| 872 | |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 873 | # Check flows count in each node |
| 874 | checkFlowsCount( main ) |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 875 | # Verify flows |
| 876 | checkFlowsState( main ) |
| 877 | |
| 878 | # Ping hosts |
| 879 | pingResult = pingResult and pingallHosts( main, hostNames ) |
| 880 | # Ping hosts again... |
| 881 | pingResult = pingResult and pingallHosts( main, hostNames ) |
| 882 | time.sleep( 5 ) |
| 883 | |
| 884 | # Test rerouting if these variables exist |
| 885 | if sw1 and sw2 and expectedLink: |
| 886 | # link down |
| 887 | linkDownResult = link( main, sw1, sw2, "down" ) |
| 888 | intentResult = intentResult and checkIntentState( main, intentsId ) |
| 889 | |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 890 | # Check flows count in each node |
| 891 | checkFlowsCount( main ) |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 892 | # Verify flows |
| 893 | checkFlowsState( main ) |
| 894 | |
| 895 | # Check OnosTopology |
| 896 | topoResult = checkTopology( main, expectedLink ) |
| 897 | |
| 898 | # Ping hosts |
| 899 | pingResult = pingResult and pingallHosts( main, hostNames ) |
| 900 | |
| 901 | intentResult = checkIntentState( main, intentsId ) |
| 902 | |
| 903 | # Checks ONOS state in link down |
| 904 | if linkDownResult and topoResult and pingResult and intentResult: |
| 905 | main.log.info( itemName + ": Successfully brought link down" ) |
| 906 | else: |
| 907 | main.log.error( itemName + ": Failed to bring link down" ) |
| 908 | |
| 909 | # link up |
| 910 | linkUpResult = link( main, sw1, sw2, "up" ) |
| 911 | time.sleep( 5 ) |
| 912 | |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 913 | # Check flows count in each node |
| 914 | checkFlowsCount( main ) |
kelvin-onlab | c751ab4 | 2015-05-21 14:09:39 -0700 | [diff] [blame] | 915 | # Verify flows |
| 916 | checkFlowsState( main ) |
| 917 | |
| 918 | # Check OnosTopology |
| 919 | topoResult = checkTopology( main, main.numLinks ) |
| 920 | |
| 921 | # Ping hosts |
| 922 | pingResult = pingResult and pingallHosts( main, hostNames ) |
| 923 | |
| 924 | intentResult = checkIntentState( main, intentsId ) |
| 925 | |
| 926 | # Checks ONOS state in link up |
| 927 | if linkUpResult and topoResult and pingResult and intentResult: |
| 928 | main.log.info( itemName + ": Successfully brought link back up" ) |
| 929 | else: |
| 930 | main.log.error( itemName + ": Failed to bring link back up" ) |
| 931 | |
| 932 | # Remove all intents |
| 933 | removeIntentResult = removeAllIntents( main, intentsId ) |
| 934 | |
| 935 | stepResult = pingResult and linkDownResult and linkUpResult \ |
| 936 | and intentResult and removeIntentResult |
| 937 | |
| 938 | return stepResult |
| 939 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 940 | def pingallHosts( main, hostList, pingType="ipv4" ): |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 941 | # Ping all host in the hosts list variable |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 942 | print "Pinging : ", hostList |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 943 | pingResult = main.TRUE |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 944 | pingResult = main.Mininet1.pingallHosts( hostList, pingType ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 945 | return pingResult |
| 946 | |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 947 | def getHostsData( main ): |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 948 | """ |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 949 | Use fwd app and pingall to discover all the hosts |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 950 | """ |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 951 | import json |
| 952 | activateResult = main.TRUE |
| 953 | appCheck = main.TRUE |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 954 | getDataResult = main.TRUE |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 955 | main.log.info( "Activating reactive forwarding app " ) |
| 956 | activateResult = main.CLIs[ 0 ].activateApp( "org.onosproject.fwd" ) |
| 957 | |
| 958 | for i in range( main.numCtrls ): |
| 959 | appCheck = appCheck and main.CLIs[ i ].appToIDCheck() |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 960 | if appCheck != main.TRUE: |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 961 | main.log.warn( main.CLIs[ i ].apps() ) |
| 962 | main.log.warn( main.CLIs[ i ].appIDs() ) |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 963 | |
| 964 | pingResult = main.Mininet1.pingall() |
| 965 | hostsJson = json.loads( main.CLIs[ 0 ].hosts() ) |
| 966 | hosts = main.Mininet1.getHosts() |
| 967 | for host in hosts: |
| 968 | main.hostsData[ host ] = {} |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 969 | main.hostsData[ host ][ 'mac' ] = \ |
| 970 | main.Mininet1.getMacAddress( host ).upper() |
kelvin-onlab | 2ccad6e | 2015-05-18 10:36:54 -0700 | [diff] [blame] | 971 | for hostj in hostsJson: |
| 972 | if main.hostsData[ host ][ 'mac' ] == hostj[ 'mac' ]: |
| 973 | main.hostsData[ host ][ 'id' ] = hostj[ 'id' ] |
| 974 | main.hostsData[ host ][ 'vlan' ] = hostj[ 'vlan' ] |
| 975 | main.hostsData[ host ][ 'location' ] = \ |
| 976 | hostj[ 'location' ][ 'elementId' ] + '/' + \ |
| 977 | hostj[ 'location' ][ 'port' ] |
| 978 | main.hostsData[ host ][ 'ipAddresses' ] = hostj[ 'ipAddresses' ] |
| 979 | |
kelvin-onlab | e7270fa | 2015-05-18 14:35:03 -0700 | [diff] [blame] | 980 | main.log.info( "Deactivating reactive forwarding app " ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 981 | deactivateResult = main.CLIs[ 0 ].deactivateApp( "org.onosproject.fwd" ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 982 | if activateResult and deactivateResult and main.hostsData: |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 983 | main.log.info( "Successfully used fwd app to discover hosts " ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 984 | getDataResult = main.TRUE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 985 | else: |
| 986 | main.log.info( "Failed to use fwd app to discover hosts " ) |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 987 | getDataResult = main.FALSE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 988 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 989 | print main.hostsData |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 990 | |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 991 | return getDataResult |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 992 | |
| 993 | def checkTopology( main, expectedLink ): |
| 994 | statusResult = main.TRUE |
| 995 | # Check onos topology |
| 996 | main.log.info( itemName + ": Checking ONOS topology " ) |
| 997 | |
| 998 | for i in range( main.numCtrls ): |
| 999 | topologyResult = main.CLIs[ i ].topology() |
| 1000 | statusResult = main.ONOSbench.checkStatus( topologyResult, |
| 1001 | main.numSwitch, |
| 1002 | expectedLink )\ |
| 1003 | and statusResult |
| 1004 | if not statusResult: |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 1005 | main.log.error( itemName + ": Topology mismatch" ) |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 1006 | else: |
| 1007 | main.log.info( itemName + ": Topology match" ) |
| 1008 | return statusResult |
| 1009 | |
| 1010 | def checkIntentState( main, intentsId ): |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 1011 | """ |
| 1012 | This function will check intent state to make sure all the intents |
| 1013 | are in INSTALLED state |
| 1014 | """ |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 1015 | |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 1016 | intentResult = main.TRUE |
kelvin-onlab | 2ff5702 | 2015-05-29 10:48:51 -0700 | [diff] [blame] | 1017 | results = [] |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 1018 | |
| 1019 | main.log.info( itemName + ": Checking intents state" ) |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 1020 | # First check of intents |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 1021 | for i in range( main.numCtrls ): |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 1022 | tempResult = main.CLIs[ i ].checkIntentState( intentsId=intentsId ) |
| 1023 | results.append( tempResult ) |
| 1024 | |
| 1025 | expectedState = [ 'INSTALLED', 'INSTALLING' ] |
kelvin-onlab | 2ff5702 | 2015-05-29 10:48:51 -0700 | [diff] [blame] | 1026 | |
| 1027 | if all( result == main.TRUE for result in results ): |
| 1028 | main.log.info( itemName + ": Intents are installed correctly" ) |
| 1029 | else: |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 1030 | # Wait for at least 5 second before checking the intents again |
| 1031 | time.sleep( 5 ) |
| 1032 | results = [] |
| 1033 | # Second check of intents since some of the intents may be in |
| 1034 | # INSTALLING state, they should be in INSTALLED at this time |
| 1035 | for i in range( main.numCtrls ): |
| 1036 | tempResult = main.CLIs[ i ].checkIntentState( |
| 1037 | intentsId=intentsId ) |
| 1038 | results.append( tempResult ) |
| 1039 | if all( result == main.TRUE for result in results ): |
| 1040 | main.log.info( itemName + ": Intents are installed correctly" ) |
| 1041 | else: |
| 1042 | main.log.error( itemName + ": Intents are NOT installed correctly" ) |
| 1043 | intentResult = main.FALSE |
kelvin-onlab | 381b34c | 2015-05-21 09:21:06 -0700 | [diff] [blame] | 1044 | |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 1045 | return intentResult |
| 1046 | |
| 1047 | def checkFlowsState( main ): |
| 1048 | |
| 1049 | main.log.info( itemName + ": Check flows state" ) |
| 1050 | checkFlowsResult = main.CLIs[ 0 ].checkFlowsState() |
| 1051 | return checkFlowsResult |
| 1052 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 1053 | def link( main, sw1, sw2, option): |
kelvin-onlab | e5239e5 | 2015-05-13 14:46:45 -0700 | [diff] [blame] | 1054 | |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 1055 | # link down |
| 1056 | main.log.info( itemName + ": Bring link " + option + "between " + |
| 1057 | sw1 + " and " + sw2 ) |
| 1058 | linkResult = main.Mininet1.link( end1=sw1, end2=sw2, option=option ) |
| 1059 | return linkResult |
| 1060 | |
| 1061 | def removeAllIntents( main, intentsId ): |
| 1062 | """ |
| 1063 | Remove all intents in the intentsId |
| 1064 | """ |
| 1065 | import time |
| 1066 | intentsRemaining = [] |
| 1067 | removeIntentResult = main.TRUE |
| 1068 | # Remove intents |
| 1069 | for intent in intentsId: |
| 1070 | main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True ) |
| 1071 | |
| 1072 | time.sleep( 5 ) |
| 1073 | # Checks if there is remaining intents using intents() |
kelvin-onlab | 583fcb5 | 2015-05-21 13:10:46 -0700 | [diff] [blame] | 1074 | intentsRemaining = main.CLIs[ 0 ].intents( jsonFormat=False ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 1075 | # If there is remianing intents then remove intents should fail |
kelvin-onlab | 583fcb5 | 2015-05-21 13:10:46 -0700 | [diff] [blame] | 1076 | |
| 1077 | if intentsRemaining: |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 1078 | main.log.info( itemName + ": There are " + |
| 1079 | str( len( intentsRemaining ) ) + " intents remaining, " |
| 1080 | + "failed to remove all the intents " ) |
| 1081 | removeIntentResult = main.FALSE |
kelvin-onlab | 0890001 | 2015-05-20 14:30:44 -0700 | [diff] [blame] | 1082 | main.log.info( intentsRemaining ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 1083 | else: |
| 1084 | main.log.info( itemName + ": There are no intents remaining, " + |
| 1085 | "successfully removed all the intents." ) |
| 1086 | removeIntentResult = main.TRUE |
| 1087 | return removeIntentResult |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 1088 | |
| 1089 | def checkFlowsCount( main ): |
| 1090 | """ |
| 1091 | Check flows count in each node |
| 1092 | """ |
| 1093 | import json |
| 1094 | |
| 1095 | flowsCount = [] |
| 1096 | main.log.info( itemName + ": Checking flows count in each ONOS node" ) |
| 1097 | for i in range( main.numCtrls ): |
| 1098 | summaryResult = main.CLIs[ i ].summary() |
| 1099 | if not summaryResult: |
| 1100 | main.log.error( itemName + ": There is something wrong with " + |
| 1101 | "summary command" ) |
| 1102 | return main.FALSE |
| 1103 | else: |
| 1104 | summaryJson = json.loads( summaryResult ) |
| 1105 | flowsCount.append( summaryJson.get( 'flows' ) ) |
| 1106 | |
| 1107 | if flowsCount: |
| 1108 | if all( flows==flowsCount[ 0 ] for flows in flowsCount ): |
| 1109 | main.log.info( itemName + ": There are " + str( flowsCount[ 0 ] ) + |
| 1110 | " flows in all ONOS node" ) |
| 1111 | else: |
| 1112 | for i in range( main.numCtrls ): |
| 1113 | main.log.debug( itemName + ": ONOS node " + str( i ) + " has " + |
| 1114 | flowsCount[ i ] + " flows" ) |
| 1115 | else: |
| 1116 | main.log.error( "Checking flows count failed, check summary command" ) |
| 1117 | return main.FALSE |
| 1118 | |
| 1119 | return main.TRUE |
| 1120 | |