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