Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 1 | /** |
| 2 | * Copyright 2013, Big Switch Networks, Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | * not use this file except in compliance with the License. You may obtain |
| 6 | * a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | * License for the specific language governing permissions and limitations |
| 14 | * under the License. |
| 15 | **/ |
| 16 | |
| 17 | package net.floodlightcontroller.core.internal; |
| 18 | |
| 19 | import static org.easymock.EasyMock.*; |
| 20 | import static org.junit.Assert.*; |
| 21 | |
| 22 | import java.io.IOException; |
| 23 | import java.util.ArrayList; |
| 24 | import java.util.Collection; |
| 25 | import java.util.Collections; |
| 26 | import java.util.HashSet; |
| 27 | import java.util.List; |
| 28 | import java.util.Map; |
| 29 | import java.util.Set; |
| 30 | import java.util.concurrent.ConcurrentHashMap; |
| 31 | |
| 32 | import net.floodlightcontroller.core.FloodlightContext; |
| 33 | import net.floodlightcontroller.core.IFloodlightProviderService; |
| 34 | import net.floodlightcontroller.core.IOFSwitch; |
| 35 | import net.floodlightcontroller.core.SwitchDriverSubHandshakeAlreadyStarted; |
| 36 | import net.floodlightcontroller.core.SwitchDriverSubHandshakeCompleted; |
| 37 | import net.floodlightcontroller.core.SwitchDriverSubHandshakeNotStarted; |
| 38 | import net.floodlightcontroller.core.IOFSwitch.PortChangeEvent; |
| 39 | import net.floodlightcontroller.core.IOFSwitch.PortChangeType; |
| 40 | import net.floodlightcontroller.debugcounter.DebugCounter; |
| 41 | import net.floodlightcontroller.debugcounter.IDebugCounterService; |
| 42 | |
| 43 | import org.junit.Before; |
| 44 | import org.junit.Test; |
| 45 | import org.projectfloodlight.openflow.protocol.OFFactories; |
| 46 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 47 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 48 | import org.projectfloodlight.openflow.protocol.OFNiciraControllerRole; |
| 49 | import org.projectfloodlight.openflow.protocol.OFPortConfig; |
| 50 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 51 | import org.projectfloodlight.openflow.protocol.OFPortFeatures; |
| 52 | import org.projectfloodlight.openflow.protocol.OFPortReason; |
| 53 | import org.projectfloodlight.openflow.protocol.OFPortState; |
| 54 | import org.projectfloodlight.openflow.protocol.OFPortStatus; |
| 55 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 56 | import org.projectfloodlight.openflow.types.DatapathId; |
| 57 | import org.projectfloodlight.openflow.types.OFPort; |
| 58 | |
| 59 | public class OFSwitchImplBaseTest { |
| 60 | |
| 61 | IFloodlightProviderService floodlightProvider; |
| 62 | Map<Long, IOFSwitch> switches; |
| 63 | |
| 64 | private class OFSwitchTest extends OFSwitchImplBase { |
| 65 | public OFSwitchTest(IFloodlightProviderService fp) { |
| 66 | super(); |
| 67 | stringId = "whatever"; |
| 68 | datapathId = DatapathId.of(1L); |
| 69 | floodlightProvider = fp; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public void write(OFMessage msg, FloodlightContext cntx) {} |
| 74 | |
| 75 | |
| 76 | @Override |
| 77 | public String toString() { |
| 78 | return "OFSwitchTest"; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | private OFSwitchTest sw; |
| 83 | |
| 84 | /* |
| 85 | * AAS: Setting the factory to default value of OF1.0 wire protocol. |
| 86 | * TODO: revisit this when we do 1.2 unit testing. |
| 87 | */ |
| 88 | private OFFactory factory10 = OFFactories.getFactory(OFVersion.OF_10); |
| 89 | |
| 90 | private OFPortDesc p1a; |
| 91 | private OFPortDesc p1b; |
| 92 | private OFPortDesc p2a; |
| 93 | private OFPortDesc p2b; |
| 94 | private OFPortDesc p3; |
| 95 | private final OFPortDesc portFoo1 = factory10.buildPortDesc() |
| 96 | .setName("foo") |
| 97 | .setPortNo(OFPort.of(11)) |
| 98 | .build(); |
| 99 | private final OFPortDesc portFoo2 = factory10.buildPortDesc() |
| 100 | .setName("foo") |
| 101 | .setPortNo(OFPort.of(12)) |
| 102 | .build(); |
| 103 | private final OFPortDesc portBar1 = factory10.buildPortDesc() |
| 104 | .setName("bar") |
| 105 | .setPortNo(OFPort.of(11)) |
| 106 | .build(); |
| 107 | private final OFPortDesc portBar2 = factory10.buildPortDesc() |
| 108 | .setName("bar") |
| 109 | .setPortNo(OFPort.of(12)) |
| 110 | .build(); |
| 111 | private final PortChangeEvent portFoo1Add = |
| 112 | new PortChangeEvent(portFoo1, PortChangeType.ADD); |
| 113 | private final PortChangeEvent portFoo2Add = |
| 114 | new PortChangeEvent(portFoo2, PortChangeType.ADD); |
| 115 | private final PortChangeEvent portBar1Add = |
| 116 | new PortChangeEvent(portBar1, PortChangeType.ADD); |
| 117 | private final PortChangeEvent portBar2Add = |
| 118 | new PortChangeEvent(portBar2, PortChangeType.ADD); |
| 119 | private final PortChangeEvent portFoo1Del = |
| 120 | new PortChangeEvent(portFoo1, PortChangeType.DELETE); |
| 121 | private final PortChangeEvent portFoo2Del = |
| 122 | new PortChangeEvent(portFoo2, PortChangeType.DELETE); |
| 123 | private final PortChangeEvent portBar1Del = |
| 124 | new PortChangeEvent(portBar1, PortChangeType.DELETE); |
| 125 | private final PortChangeEvent portBar2Del = |
| 126 | new PortChangeEvent(portBar2, PortChangeType.DELETE); |
| 127 | |
| 128 | @Before |
| 129 | public void setUp() throws Exception { |
| 130 | |
| 131 | floodlightProvider = createMock(IFloodlightProviderService.class); |
| 132 | sw = new OFSwitchTest(floodlightProvider); |
| 133 | IDebugCounterService debugCounter = new DebugCounter(); |
| 134 | sw.setDebugCounterService(debugCounter); |
| 135 | switches = new ConcurrentHashMap<Long, IOFSwitch>(); |
| 136 | switches.put(sw.getId(), sw); |
| 137 | expect(floodlightProvider.getSwitch(sw.getId())).andReturn(sw).anyTimes(); |
| 138 | |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Takes a state and adds it to the passed state set |
| 143 | * |
| 144 | * @param state the set to add to or remove from |
| 145 | * @param aState the state to be added or removed. |
| 146 | * @param op add or remove operation |
| 147 | * @return |
| 148 | */ |
| 149 | private <T> Set<T> modState(Set<T> state, T aState, boolean op) { |
| 150 | if (state == null) |
| 151 | state = new HashSet<T>(); |
| 152 | if (op) { |
| 153 | state.add(aState); |
| 154 | } else { |
| 155 | state.remove(aState); |
| 156 | } |
| 157 | return state; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Check if a port is enabled |
| 162 | * @param p the port |
| 163 | * @return true id port is enabled and false otherwise. |
| 164 | */ |
| 165 | private boolean isEnabled(OFPortDesc p) { |
| 166 | return (p != null && |
| 167 | !p.getState().contains(OFPortState.LINK_DOWN) && |
| 168 | !p.getState().contains(OFPortState.BLOCKED) && |
| 169 | !p.getConfig().contains(OFPortConfig.PORT_DOWN)); |
| 170 | } |
| 171 | |
| 172 | @Before |
| 173 | public void setUpPorts() { |
| 174 | /* |
| 175 | * Convenience variables to enhance readability. |
| 176 | */ |
| 177 | final boolean ADD = true; |
| 178 | final boolean REM = !ADD; |
| 179 | |
| 180 | OFPortDesc.Builder bld = factory10.buildPortDesc(); |
| 181 | // p1a is disabled |
| 182 | |
| 183 | p1a = bld.setName("port1") |
| 184 | .setPortNo(OFPort.of(1)) |
| 185 | .setState(modState(bld.getState(), OFPortState.LINK_DOWN, ADD)) |
| 186 | .build(); |
| 187 | |
| 188 | assertFalse("Sanity check portEnabled", isEnabled(p1a)); |
| 189 | |
| 190 | bld = factory10.buildPortDesc(); |
| 191 | // p1b is enabled |
| 192 | // p1b has different feature from p1a |
| 193 | p1b = bld.setName("port1") |
| 194 | .setPortNo(OFPort.of(1)) |
| 195 | .setAdvertised(modState(bld.getAdvertised(), |
| 196 | OFPortFeatures.PF_1GB_FD, ADD)) |
| 197 | .setState(modState(bld.getState(), |
| 198 | OFPortState.LINK_DOWN, REM)) |
| 199 | .setConfig(modState(bld.getConfig(), OFPortConfig.PORT_DOWN, REM)) |
| 200 | .build(); |
| 201 | assertTrue("Sanity check portEnabled", isEnabled(p1b)); |
| 202 | |
| 203 | // p2 is disabled |
| 204 | // p2 has mixed case |
| 205 | bld = factory10.buildPortDesc(); |
| 206 | p2a = bld.setName("Port2") |
| 207 | .setState(modState(bld.getState(), |
| 208 | OFPortState.LINK_DOWN, REM)) |
| 209 | .setConfig(modState(bld.getConfig(), |
| 210 | OFPortConfig.PORT_DOWN, ADD)) |
| 211 | .setPortNo(OFPort.of(2)) |
| 212 | .build(); |
| 213 | |
| 214 | // p2b only differs in PortFeatures |
| 215 | bld = factory10.buildPortDesc(); |
| 216 | |
| 217 | p2b = bld.setName("Port2") |
| 218 | .setState(modState(bld.getState(), |
| 219 | OFPortState.LINK_DOWN, REM)) |
| 220 | .setConfig(modState(bld.getConfig(), |
| 221 | OFPortConfig.PORT_DOWN, ADD)) |
| 222 | .setPortNo(OFPort.of(2)) |
| 223 | .setAdvertised(modState(bld.getAdvertised(), |
| 224 | OFPortFeatures.PF_100MB_HD, ADD)) |
| 225 | .build(); |
| 226 | assertFalse("Sanity check portEnabled", isEnabled(p2a)); |
| 227 | |
| 228 | // p3 is enabled |
| 229 | // p3 has mixed case |
| 230 | bld = factory10.buildPortDesc(); |
| 231 | p3 = bld.setName("porT3") |
| 232 | .setState(modState(bld.getState(), |
| 233 | OFPortState.LINK_DOWN, REM)) |
| 234 | .setPortNo(OFPort.of(3)) |
| 235 | .build(); |
| 236 | assertTrue("Sanity check portEnabled", isEnabled(p3)); |
| 237 | |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Test whether two collections contains the same elements, regardless |
| 242 | * of the order in which the elements appear in the collections |
| 243 | * @param expected |
| 244 | * @param actual |
| 245 | */ |
| 246 | private static <T> void assertCollectionEqualsNoOrder(Collection<T> expected, |
| 247 | Collection<T> actual) { |
| 248 | String msg = String.format("expected=%s, actual=%s", |
| 249 | expected, actual); |
| 250 | assertEquals(msg, expected.size(), actual.size()); |
| 251 | for(T e: expected) { |
| 252 | if (!actual.contains(e)) { |
| 253 | msg = String.format("Expected element %s not found in " + |
| 254 | "actual. expected=%s, actual=%s", |
| 255 | e, expected, actual); |
| 256 | fail(msg); |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | |
| 262 | /** |
| 263 | * Test "normal" setPorts() and comparePorts() methods. No name<->number |
| 264 | * conflicts or exception testing. |
| 265 | */ |
| 266 | @Test |
| 267 | public void testBasicSetPortOperations() { |
| 268 | Collection<OFPortDesc> oldPorts = Collections.emptyList(); |
| 269 | Collection<OFPortDesc> oldEnabledPorts = Collections.emptyList(); |
| 270 | Collection<Integer> oldEnabledPortNumbers = Collections.emptyList(); |
| 271 | List<OFPortDesc> ports = new ArrayList<OFPortDesc>(); |
| 272 | |
| 273 | |
| 274 | Collection<PortChangeEvent> expectedChanges = |
| 275 | new ArrayList<IOFSwitch.PortChangeEvent>(); |
| 276 | |
| 277 | Collection<PortChangeEvent> actualChanges = sw.comparePorts(ports); |
| 278 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 279 | assertEquals(0, sw.getPorts().size()); |
| 280 | assertEquals(0, sw.getEnabledPorts().size()); |
| 281 | assertEquals(0, sw.getEnabledPortNumbers().size()); |
| 282 | |
| 283 | actualChanges = sw.setPorts(ports); |
| 284 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 285 | assertEquals(0, sw.getPorts().size()); |
| 286 | assertEquals(0, sw.getEnabledPorts().size()); |
| 287 | assertEquals(0, sw.getEnabledPortNumbers().size()); |
| 288 | |
| 289 | //--------------------------------------------- |
| 290 | // Add port p1a and p2a |
| 291 | ports.add(p1a); |
| 292 | ports.add(p2a); |
| 293 | |
| 294 | PortChangeEvent evP1aAdded = |
| 295 | new PortChangeEvent(p1a, PortChangeType.ADD); |
| 296 | PortChangeEvent evP2aAdded = |
| 297 | new PortChangeEvent(p2a, PortChangeType.ADD); |
| 298 | |
| 299 | expectedChanges.clear(); |
| 300 | expectedChanges.add(evP1aAdded); |
| 301 | expectedChanges.add(evP2aAdded); |
| 302 | |
| 303 | actualChanges = sw.comparePorts(ports); |
| 304 | assertEquals(0, sw.getPorts().size()); |
| 305 | assertEquals(0, sw.getEnabledPorts().size()); |
| 306 | assertEquals(0, sw.getEnabledPortNumbers().size()); |
| 307 | assertEquals(2, actualChanges.size()); |
| 308 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 309 | |
| 310 | actualChanges = sw.setPorts(ports); |
| 311 | assertEquals(2, actualChanges.size()); |
| 312 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 313 | |
| 314 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 315 | assertTrue("enabled ports should be empty", |
| 316 | sw.getEnabledPortNumbers().isEmpty()); |
| 317 | assertTrue("enabled ports should be empty", |
| 318 | sw.getEnabledPorts().isEmpty()); |
| 319 | assertEquals(p1a, sw.getPort((short)1)); |
| 320 | assertEquals(p1a, sw.getPort("port1")); |
| 321 | assertEquals(p1a, sw.getPort("PoRt1")); // case insensitive get |
| 322 | |
| 323 | assertEquals(p2a, sw.getPort((short)2)); |
| 324 | assertEquals(p2a, sw.getPort("port2")); |
| 325 | assertEquals(p2a, sw.getPort("PoRt2")); // case insensitive get |
| 326 | |
| 327 | assertEquals(null, sw.getPort((short)3)); |
| 328 | assertEquals(null, sw.getPort("port3")); |
| 329 | assertEquals(null, sw.getPort("PoRt3")); // case insensitive get |
| 330 | |
| 331 | |
| 332 | //---------------------------------------------------- |
| 333 | // Set the same ports again. No changes |
| 334 | oldPorts = sw.getPorts(); |
| 335 | oldEnabledPorts = sw.getEnabledPorts(); |
| 336 | oldEnabledPortNumbers = sw.getEnabledPortNumbers(); |
| 337 | |
| 338 | expectedChanges.clear(); |
| 339 | |
| 340 | actualChanges = sw.comparePorts(ports); |
| 341 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 342 | assertEquals(oldPorts, sw.getPorts()); |
| 343 | assertEquals(oldEnabledPorts, sw.getEnabledPorts()); |
| 344 | assertEquals(oldEnabledPortNumbers, sw.getEnabledPortNumbers()); |
| 345 | |
| 346 | actualChanges = sw.setPorts(ports); |
| 347 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 348 | assertEquals(oldPorts, sw.getPorts()); |
| 349 | assertEquals(oldEnabledPorts, sw.getEnabledPorts()); |
| 350 | assertEquals(oldEnabledPortNumbers, sw.getEnabledPortNumbers()); |
| 351 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 352 | |
| 353 | assertTrue("enabled ports should be empty", |
| 354 | sw.getEnabledPortNumbers().isEmpty()); |
| 355 | assertTrue("enabled ports should be empty", |
| 356 | sw.getEnabledPorts().isEmpty()); |
| 357 | assertEquals(p1a, sw.getPort((short)1)); |
| 358 | assertEquals(p1a, sw.getPort("port1")); |
| 359 | assertEquals(p1a, sw.getPort("PoRt1")); // case insensitive get |
| 360 | |
| 361 | assertEquals(p2a, sw.getPort((short)2)); |
| 362 | assertEquals(p2a, sw.getPort("port2")); |
| 363 | assertEquals(p2a, sw.getPort("PoRt2")); // case insensitive get |
| 364 | |
| 365 | assertEquals(null, sw.getPort((short)3)); |
| 366 | assertEquals(null, sw.getPort("port3")); |
| 367 | assertEquals(null, sw.getPort("PoRt3")); // case insensitive get |
| 368 | |
| 369 | //---------------------------------------------------- |
| 370 | // Remove p1a, add p1b. Should receive a port up |
| 371 | oldPorts = sw.getPorts(); |
| 372 | oldEnabledPorts = sw.getEnabledPorts(); |
| 373 | oldEnabledPortNumbers = sw.getEnabledPortNumbers(); |
| 374 | ports.clear(); |
| 375 | ports.add(p2a); |
| 376 | ports.add(p1b); |
| 377 | |
| 378 | // comparePorts |
| 379 | PortChangeEvent evP1bUp = new PortChangeEvent(p1b, PortChangeType.UP); |
| 380 | actualChanges = sw.comparePorts(ports); |
| 381 | assertEquals(oldPorts, sw.getPorts()); |
| 382 | assertEquals(oldEnabledPorts, sw.getEnabledPorts()); |
| 383 | assertEquals(oldEnabledPortNumbers, sw.getEnabledPortNumbers()); |
| 384 | assertEquals(1, actualChanges.size()); |
| 385 | assertTrue("No UP event for port1", actualChanges.contains(evP1bUp)); |
| 386 | |
| 387 | // setPorts |
| 388 | actualChanges = sw.setPorts(ports); |
| 389 | assertEquals(1, actualChanges.size()); |
| 390 | assertTrue("No UP event for port1", actualChanges.contains(evP1bUp)); |
| 391 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 392 | List<OFPortDesc> enabledPorts = new ArrayList<OFPortDesc>(); |
| 393 | enabledPorts.add(p1b); |
| 394 | List<Integer> enabledPortNumbers = new ArrayList<Integer>(); |
| 395 | enabledPortNumbers.add(1); |
| 396 | assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts()); |
| 397 | assertCollectionEqualsNoOrder(enabledPortNumbers, |
| 398 | sw.getEnabledPortNumbers()); |
| 399 | assertEquals(p1b, sw.getPort((short)1)); |
| 400 | assertEquals(p1b, sw.getPort("port1")); |
| 401 | assertEquals(p1b, sw.getPort("PoRt1")); // case insensitive get |
| 402 | |
| 403 | assertEquals(p2a, sw.getPort((short)2)); |
| 404 | assertEquals(p2a, sw.getPort("port2")); |
| 405 | assertEquals(p2a, sw.getPort("PoRt2")); // case insensitive get |
| 406 | |
| 407 | assertEquals(null, sw.getPort((short)3)); |
| 408 | assertEquals(null, sw.getPort("port3")); |
| 409 | assertEquals(null, sw.getPort("PoRt3")); // case insensitive get |
| 410 | |
| 411 | //---------------------------------------------------- |
| 412 | // Remove p2a, add p2b. Should receive a port modify |
| 413 | oldPorts = sw.getPorts(); |
| 414 | oldEnabledPorts = sw.getEnabledPorts(); |
| 415 | oldEnabledPortNumbers = sw.getEnabledPortNumbers(); |
| 416 | ports.clear(); |
| 417 | ports.add(p2b); |
| 418 | ports.add(p1b); |
| 419 | |
| 420 | PortChangeEvent evP2bModified = |
| 421 | new PortChangeEvent(p2b, PortChangeType.OTHER_UPDATE); |
| 422 | |
| 423 | // comparePorts |
| 424 | actualChanges = sw.comparePorts(ports); |
| 425 | assertEquals(oldPorts, sw.getPorts()); |
| 426 | assertEquals(oldEnabledPorts, sw.getEnabledPorts()); |
| 427 | assertEquals(oldEnabledPortNumbers, sw.getEnabledPortNumbers()); |
| 428 | assertEquals(1, actualChanges.size()); |
| 429 | assertTrue("No OTHER_CHANGE event for port2", |
| 430 | actualChanges.contains(evP2bModified)); |
| 431 | |
| 432 | // setPorts |
| 433 | actualChanges = sw.setPorts(ports); |
| 434 | assertEquals(1, actualChanges.size()); |
| 435 | assertTrue("No OTHER_CHANGE event for port2", |
| 436 | actualChanges.contains(evP2bModified)); |
| 437 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 438 | enabledPorts = new ArrayList<OFPortDesc>(); |
| 439 | enabledPorts.add(p1b); |
| 440 | enabledPortNumbers = new ArrayList<Integer>(); |
| 441 | enabledPortNumbers.add(1); |
| 442 | assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts()); |
| 443 | assertCollectionEqualsNoOrder(enabledPortNumbers, |
| 444 | sw.getEnabledPortNumbers()); |
| 445 | assertEquals(p1b, sw.getPort((short)1)); |
| 446 | assertEquals(p1b, sw.getPort("port1")); |
| 447 | assertEquals(p1b, sw.getPort("PoRt1")); // case insensitive get |
| 448 | |
| 449 | assertEquals(p2b, sw.getPort((short)2)); |
| 450 | assertEquals(p2b, sw.getPort("port2")); |
| 451 | assertEquals(p2b, sw.getPort("PoRt2")); // case insensitive get |
| 452 | |
| 453 | assertEquals(null, sw.getPort((short)3)); |
| 454 | assertEquals(null, sw.getPort("port3")); |
| 455 | assertEquals(null, sw.getPort("PoRt3")); // case insensitive get |
| 456 | |
| 457 | |
| 458 | //---------------------------------------------------- |
| 459 | // Remove p1b, add p1a. Should receive a port DOWN |
| 460 | // Remove p2b, add p2a. Should receive a port modify |
| 461 | // Add p3, should receive an add |
| 462 | oldPorts = sw.getPorts(); |
| 463 | oldEnabledPorts = sw.getEnabledPorts(); |
| 464 | oldEnabledPortNumbers = sw.getEnabledPortNumbers(); |
| 465 | ports.clear(); |
| 466 | ports.add(p2a); |
| 467 | ports.add(p1a); |
| 468 | ports.add(p3); |
| 469 | |
| 470 | PortChangeEvent evP1aDown = |
| 471 | new PortChangeEvent(p1a, PortChangeType.DOWN); |
| 472 | PortChangeEvent evP2aModified = |
| 473 | new PortChangeEvent(p2a, PortChangeType.OTHER_UPDATE); |
| 474 | PortChangeEvent evP3Add = |
| 475 | new PortChangeEvent(p3, PortChangeType.ADD); |
| 476 | expectedChanges.clear(); |
| 477 | expectedChanges.add(evP1aDown); |
| 478 | expectedChanges.add(evP2aModified); |
| 479 | expectedChanges.add(evP3Add); |
| 480 | |
| 481 | // comparePorts |
| 482 | actualChanges = sw.comparePorts(ports); |
| 483 | assertEquals(oldPorts, sw.getPorts()); |
| 484 | assertEquals(oldEnabledPorts, sw.getEnabledPorts()); |
| 485 | assertEquals(oldEnabledPortNumbers, sw.getEnabledPortNumbers()); |
| 486 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 487 | |
| 488 | // setPorts |
| 489 | actualChanges = sw.setPorts(ports); |
| 490 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 491 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 492 | enabledPorts.clear(); |
| 493 | enabledPorts.add(p3); |
| 494 | enabledPortNumbers.clear(); |
| 495 | enabledPortNumbers.add(3); |
| 496 | assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts()); |
| 497 | assertCollectionEqualsNoOrder(enabledPortNumbers, |
| 498 | sw.getEnabledPortNumbers()); |
| 499 | assertEquals(p1a, sw.getPort((short)1)); |
| 500 | assertEquals(p1a, sw.getPort("port1")); |
| 501 | assertEquals(p1a, sw.getPort("PoRt1")); // case insensitive get |
| 502 | |
| 503 | assertEquals(p2a, sw.getPort((short)2)); |
| 504 | assertEquals(p2a, sw.getPort("port2")); |
| 505 | assertEquals(p2a, sw.getPort("PoRt2")); // case insensitive get |
| 506 | |
| 507 | assertEquals(p3, sw.getPort((short)3)); |
| 508 | assertEquals(p3, sw.getPort("port3")); |
| 509 | assertEquals(p3, sw.getPort("PoRt3")); // case insensitive get |
| 510 | |
| 511 | |
| 512 | //---------------------------------------------------- |
| 513 | // Remove p1b Should receive a port DELETE |
| 514 | // Remove p2b Should receive a port DELETE |
| 515 | oldPorts = sw.getPorts(); |
| 516 | oldEnabledPorts = sw.getEnabledPorts(); |
| 517 | oldEnabledPortNumbers = sw.getEnabledPortNumbers(); |
| 518 | ports.clear(); |
| 519 | ports.add(p3); |
| 520 | |
| 521 | PortChangeEvent evP1aDel = |
| 522 | new PortChangeEvent(p1a, PortChangeType.DELETE); |
| 523 | PortChangeEvent evP2aDel = |
| 524 | new PortChangeEvent(p2a, PortChangeType.DELETE); |
| 525 | expectedChanges.clear(); |
| 526 | expectedChanges.add(evP1aDel); |
| 527 | expectedChanges.add(evP2aDel); |
| 528 | |
| 529 | // comparePorts |
| 530 | actualChanges = sw.comparePorts(ports); |
| 531 | assertEquals(oldPorts, sw.getPorts()); |
| 532 | assertEquals(oldEnabledPorts, sw.getEnabledPorts()); |
| 533 | assertEquals(oldEnabledPortNumbers, sw.getEnabledPortNumbers()); |
| 534 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 535 | |
| 536 | // setPorts |
| 537 | actualChanges = sw.setPorts(ports); |
| 538 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 539 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 540 | enabledPorts.clear(); |
| 541 | enabledPorts.add(p3); |
| 542 | enabledPortNumbers.clear(); |
| 543 | enabledPortNumbers.add(3); |
| 544 | assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts()); |
| 545 | assertCollectionEqualsNoOrder(enabledPortNumbers, |
| 546 | sw.getEnabledPortNumbers()); |
| 547 | |
| 548 | assertEquals(p3, sw.getPort((short)3)); |
| 549 | assertEquals(p3, sw.getPort("port3")); |
| 550 | assertEquals(p3, sw.getPort("PoRt3")); // case insensitive get |
| 551 | } |
| 552 | |
| 553 | |
| 554 | /** |
| 555 | * Test "normal" OFPortStatus handling. No name<->number |
| 556 | * conflicts or exception testing. |
| 557 | */ |
| 558 | @Test |
| 559 | public void testBasicPortStatusOperation() { |
| 560 | OFPortStatus ps = null; |
| 561 | List<OFPortDesc> ports = new ArrayList<OFPortDesc>(); |
| 562 | ports.add(p1a); |
| 563 | ports.add(p2a); |
| 564 | |
| 565 | |
| 566 | // Set p1a and p2a as baseline |
| 567 | PortChangeEvent evP1aAdded = |
| 568 | new PortChangeEvent(p1a, PortChangeType.ADD); |
| 569 | PortChangeEvent evP2aAdded = |
| 570 | new PortChangeEvent(p2a, PortChangeType.ADD); |
| 571 | |
| 572 | Collection<PortChangeEvent> expectedChanges = |
| 573 | new ArrayList<IOFSwitch.PortChangeEvent>(); |
| 574 | expectedChanges.add(evP1aAdded); |
| 575 | expectedChanges.add(evP2aAdded); |
| 576 | |
| 577 | Collection<PortChangeEvent> actualChanges = sw.comparePorts(ports); |
| 578 | assertEquals(0, sw.getPorts().size()); |
| 579 | assertEquals(0, sw.getEnabledPorts().size()); |
| 580 | assertEquals(0, sw.getEnabledPortNumbers().size()); |
| 581 | assertEquals(2, actualChanges.size()); |
| 582 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 583 | |
| 584 | actualChanges = sw.setPorts(ports); |
| 585 | assertEquals(2, actualChanges.size()); |
| 586 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 587 | |
| 588 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 589 | assertTrue("enabled ports should be empty", |
| 590 | sw.getEnabledPortNumbers().isEmpty()); |
| 591 | assertTrue("enabled ports should be empty", |
| 592 | sw.getEnabledPorts().isEmpty()); |
| 593 | assertEquals(p1a, sw.getPort((short)1)); |
| 594 | assertEquals(p1a, sw.getPort("port1")); |
| 595 | assertEquals(p1a, sw.getPort("PoRt1")); // case insensitive get |
| 596 | |
| 597 | assertEquals(p2a, sw.getPort((short)2)); |
| 598 | assertEquals(p2a, sw.getPort("port2")); |
| 599 | assertEquals(p2a, sw.getPort("PoRt2")); // case insensitive get |
| 600 | |
| 601 | //---------------------------------------------------- |
| 602 | // P1a -> p1b. Should receive a port up |
| 603 | ports.clear(); |
| 604 | ports.add(p2a); |
| 605 | ports.add(p1b); |
| 606 | |
| 607 | ps = factory10.buildPortStatus().setReason(OFPortReason.MODIFY).setDesc(p1b).build(); |
| 608 | |
| 609 | PortChangeEvent evP1bUp = new PortChangeEvent(p1b, PortChangeType.UP); |
| 610 | actualChanges = sw.processOFPortStatus(ps); |
| 611 | expectedChanges.clear(); |
| 612 | expectedChanges.add(evP1bUp); |
| 613 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 614 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 615 | List<OFPortDesc> enabledPorts = new ArrayList<OFPortDesc>(); |
| 616 | enabledPorts.add(p1b); |
| 617 | List<Integer> enabledPortNumbers = new ArrayList<Integer>(); |
| 618 | enabledPortNumbers.add(1); |
| 619 | assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts()); |
| 620 | assertCollectionEqualsNoOrder(enabledPortNumbers, |
| 621 | sw.getEnabledPortNumbers()); |
| 622 | assertEquals(p1b, sw.getPort((short)1)); |
| 623 | assertEquals(p1b, sw.getPort("port1")); |
| 624 | assertEquals(p1b, sw.getPort("PoRt1")); // case insensitive get |
| 625 | |
| 626 | assertEquals(p2a, sw.getPort((short)2)); |
| 627 | assertEquals(p2a, sw.getPort("port2")); |
| 628 | assertEquals(p2a, sw.getPort("PoRt2")); // case insensitive get |
| 629 | |
| 630 | //---------------------------------------------------- |
| 631 | // p2a -> p2b. Should receive a port modify |
| 632 | ports.clear(); |
| 633 | ports.add(p2b); |
| 634 | ports.add(p1b); |
| 635 | |
| 636 | PortChangeEvent evP2bModified = |
| 637 | new PortChangeEvent(p2b, PortChangeType.OTHER_UPDATE); |
| 638 | |
| 639 | ps = ps.createBuilder().setReason(OFPortReason.MODIFY).setDesc(p2b).build(); |
| 640 | |
| 641 | |
| 642 | |
| 643 | actualChanges = sw.processOFPortStatus(ps); |
| 644 | expectedChanges.clear(); |
| 645 | expectedChanges.add(evP2bModified); |
| 646 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 647 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 648 | enabledPorts = new ArrayList<OFPortDesc>(); |
| 649 | enabledPorts.add(p1b); |
| 650 | enabledPortNumbers = new ArrayList<Integer>(); |
| 651 | enabledPortNumbers.add(1); |
| 652 | assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts()); |
| 653 | assertCollectionEqualsNoOrder(enabledPortNumbers, |
| 654 | sw.getEnabledPortNumbers()); |
| 655 | assertEquals(p1b, sw.getPort((short)1)); |
| 656 | assertEquals(p1b, sw.getPort("port1")); |
| 657 | assertEquals(p1b, sw.getPort("PoRt1")); // case insensitive get |
| 658 | |
| 659 | assertEquals(p2b, sw.getPort((short)2)); |
| 660 | assertEquals(p2b, sw.getPort("port2")); |
| 661 | assertEquals(p2b, sw.getPort("PoRt2")); // case insensitive get |
| 662 | |
| 663 | assertEquals(null, sw.getPort((short)3)); |
| 664 | assertEquals(null, sw.getPort("port3")); |
| 665 | assertEquals(null, sw.getPort("PoRt3")); // case insensitive get |
| 666 | |
| 667 | |
| 668 | //---------------------------------------------------- |
| 669 | // p1b -> p1a. Via an OFPPR_ADD, Should receive a port DOWN |
| 670 | ports.clear(); |
| 671 | ports.add(p2b); |
| 672 | ports.add(p1a); |
| 673 | |
| 674 | // we use an ADD here. We treat ADD and MODIFY the same way |
| 675 | ps = ps.createBuilder().setReason(OFPortReason.ADD).setDesc(p1a).build(); |
| 676 | |
| 677 | |
| 678 | PortChangeEvent evP1aDown = |
| 679 | new PortChangeEvent(p1a, PortChangeType.DOWN); |
| 680 | actualChanges = sw.processOFPortStatus(ps); |
| 681 | expectedChanges.clear(); |
| 682 | expectedChanges.add(evP1aDown); |
| 683 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 684 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 685 | enabledPorts.clear(); |
| 686 | enabledPortNumbers.clear(); |
| 687 | assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts()); |
| 688 | assertCollectionEqualsNoOrder(enabledPortNumbers, |
| 689 | sw.getEnabledPortNumbers()); |
| 690 | assertEquals(p1a, sw.getPort((short)1)); |
| 691 | assertEquals(p1a, sw.getPort("port1")); |
| 692 | assertEquals(p1a, sw.getPort("PoRt1")); // case insensitive get |
| 693 | |
| 694 | assertEquals(p2b, sw.getPort((short)2)); |
| 695 | assertEquals(p2b, sw.getPort("port2")); |
| 696 | assertEquals(p2b, sw.getPort("PoRt2")); // case insensitive get |
| 697 | |
| 698 | |
| 699 | //---------------------------------------------------- |
| 700 | // p2b -> p2a. Via an OFPPR_ADD, Should receive a port MODIFY |
| 701 | ports.clear(); |
| 702 | ports.add(p2a); |
| 703 | ports.add(p1a); |
| 704 | |
| 705 | // we use an ADD here. We treat ADD and MODIFY the same way |
| 706 | ps = ps.createBuilder().setReason(OFPortReason.ADD).setDesc(p2a).build(); |
| 707 | |
| 708 | PortChangeEvent evP2aModify = |
| 709 | new PortChangeEvent(p2a, PortChangeType.OTHER_UPDATE); |
| 710 | actualChanges = sw.processOFPortStatus(ps); |
| 711 | expectedChanges.clear(); |
| 712 | expectedChanges.add(evP2aModify); |
| 713 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 714 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 715 | enabledPorts.clear(); |
| 716 | enabledPortNumbers.clear(); |
| 717 | assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts()); |
| 718 | assertCollectionEqualsNoOrder(enabledPortNumbers, |
| 719 | sw.getEnabledPortNumbers()); |
| 720 | assertEquals(p1a, sw.getPort((short)1)); |
| 721 | assertEquals(p1a, sw.getPort("port1")); |
| 722 | assertEquals(p1a, sw.getPort("PoRt1")); // case insensitive get |
| 723 | |
| 724 | assertEquals(p2a, sw.getPort((short)2)); |
| 725 | assertEquals(p2a, sw.getPort("port2")); |
| 726 | assertEquals(p2a, sw.getPort("PoRt2")); // case insensitive get |
| 727 | |
| 728 | |
| 729 | //---------------------------------------------------- |
| 730 | // Remove p2a |
| 731 | ports.clear(); |
| 732 | ports.add(p1a); |
| 733 | |
| 734 | ps = ps.createBuilder().setReason(OFPortReason.DELETE).setDesc(p2a).build(); |
| 735 | |
| 736 | PortChangeEvent evP2aDel = |
| 737 | new PortChangeEvent(p2a, PortChangeType.DELETE); |
| 738 | actualChanges = sw.processOFPortStatus(ps); |
| 739 | expectedChanges.clear(); |
| 740 | expectedChanges.add(evP2aDel); |
| 741 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 742 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 743 | enabledPorts.clear(); |
| 744 | enabledPortNumbers.clear(); |
| 745 | assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts()); |
| 746 | assertCollectionEqualsNoOrder(enabledPortNumbers, |
| 747 | sw.getEnabledPortNumbers()); |
| 748 | assertEquals(p1a, sw.getPort((short)1)); |
| 749 | assertEquals(p1a, sw.getPort("port1")); |
| 750 | assertEquals(p1a, sw.getPort("PoRt1")); // case insensitive get |
| 751 | |
| 752 | assertEquals(null, sw.getPort((short)2)); |
| 753 | assertEquals(null, sw.getPort("port2")); |
| 754 | assertEquals(null, sw.getPort("PoRt2")); // case insensitive get |
| 755 | |
| 756 | //---------------------------------------------------- |
| 757 | // Remove p2a again. Nothing should happen. |
| 758 | ports.clear(); |
| 759 | ports.add(p1a); |
| 760 | |
| 761 | ps = ps.createBuilder().setReason(OFPortReason.DELETE).setDesc(p2a).build(); |
| 762 | |
| 763 | actualChanges = sw.processOFPortStatus(ps); |
| 764 | expectedChanges.clear(); |
| 765 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 766 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 767 | enabledPorts.clear(); |
| 768 | enabledPortNumbers.clear(); |
| 769 | assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts()); |
| 770 | assertCollectionEqualsNoOrder(enabledPortNumbers, |
| 771 | sw.getEnabledPortNumbers()); |
| 772 | assertEquals(p1a, sw.getPort((short)1)); |
| 773 | assertEquals(p1a, sw.getPort("port1")); |
| 774 | assertEquals(p1a, sw.getPort("PoRt1")); // case insensitive get |
| 775 | |
| 776 | assertEquals(null, sw.getPort((short)2)); |
| 777 | assertEquals(null, sw.getPort("port2")); |
| 778 | assertEquals(null, sw.getPort("PoRt2")); // case insensitive get |
| 779 | |
| 780 | |
| 781 | //---------------------------------------------------- |
| 782 | // Remove p1a |
| 783 | ports.clear(); |
| 784 | |
| 785 | ps = ps.createBuilder().setReason(OFPortReason.DELETE).setDesc(p1a).build(); |
| 786 | |
| 787 | PortChangeEvent evP1aDel = |
| 788 | new PortChangeEvent(p1a, PortChangeType.DELETE); |
| 789 | actualChanges = sw.processOFPortStatus(ps); |
| 790 | expectedChanges.clear(); |
| 791 | expectedChanges.add(evP1aDel); |
| 792 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 793 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 794 | enabledPorts.clear(); |
| 795 | enabledPortNumbers.clear(); |
| 796 | assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts()); |
| 797 | assertCollectionEqualsNoOrder(enabledPortNumbers, |
| 798 | sw.getEnabledPortNumbers()); |
| 799 | assertEquals(null, sw.getPort((short)1)); |
| 800 | assertEquals(null, sw.getPort("port1")); |
| 801 | assertEquals(null, sw.getPort("PoRt1")); // case insensitive get |
| 802 | |
| 803 | assertEquals(null, sw.getPort((short)2)); |
| 804 | assertEquals(null, sw.getPort("port2")); |
| 805 | assertEquals(null, sw.getPort("PoRt2")); // case insensitive get |
| 806 | |
| 807 | |
| 808 | //---------------------------------------------------- |
| 809 | // Add p3, should receive an add |
| 810 | ports.clear(); |
| 811 | ports.add(p3); |
| 812 | |
| 813 | PortChangeEvent evP3Add = |
| 814 | new PortChangeEvent(p3, PortChangeType.ADD); |
| 815 | expectedChanges.clear(); |
| 816 | expectedChanges.add(evP3Add); |
| 817 | |
| 818 | ps = ps.createBuilder().setReason(OFPortReason.ADD).setDesc(p3).build(); |
| 819 | |
| 820 | actualChanges = sw.processOFPortStatus(ps); |
| 821 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 822 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 823 | enabledPorts.clear(); |
| 824 | enabledPorts.add(p3); |
| 825 | enabledPortNumbers.clear(); |
| 826 | enabledPortNumbers.add(3); |
| 827 | assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts()); |
| 828 | assertCollectionEqualsNoOrder(enabledPortNumbers, |
| 829 | sw.getEnabledPortNumbers()); |
| 830 | assertEquals(null, sw.getPort((short)1)); |
| 831 | assertEquals(null, sw.getPort("port1")); |
| 832 | assertEquals(null, sw.getPort("PoRt1")); // case insensitive get |
| 833 | |
| 834 | assertEquals(null, sw.getPort((short)2)); |
| 835 | assertEquals(null, sw.getPort("port2")); |
| 836 | assertEquals(null, sw.getPort("PoRt2")); // case insensitive get |
| 837 | |
| 838 | assertEquals(p3, sw.getPort((short)3)); |
| 839 | assertEquals(p3, sw.getPort("port3")); |
| 840 | assertEquals(p3, sw.getPort("PoRt3")); // case insensitive get |
| 841 | |
| 842 | //---------------------------------------------------- |
| 843 | // Add p1b, back should receive an add |
| 844 | ports.clear(); |
| 845 | ports.add(p1b); |
| 846 | ports.add(p3); |
| 847 | |
| 848 | PortChangeEvent evP1bAdd = |
| 849 | new PortChangeEvent(p1b, PortChangeType.ADD); |
| 850 | expectedChanges.clear(); |
| 851 | expectedChanges.add(evP1bAdd); |
| 852 | |
| 853 | // use a modify to add the port |
| 854 | ps = ps.createBuilder().setReason(OFPortReason.MODIFY).setDesc(p1b).build(); |
| 855 | |
| 856 | actualChanges = sw.processOFPortStatus(ps); |
| 857 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 858 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 859 | enabledPorts.clear(); |
| 860 | enabledPorts.add(p3); |
| 861 | enabledPorts.add(p1b); |
| 862 | enabledPortNumbers.clear(); |
| 863 | enabledPortNumbers.add(3); |
| 864 | enabledPortNumbers.add(1); |
| 865 | assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts()); |
| 866 | assertCollectionEqualsNoOrder(enabledPortNumbers, |
| 867 | sw.getEnabledPortNumbers()); |
| 868 | assertEquals(p1b, sw.getPort((short)1)); |
| 869 | assertEquals(p1b, sw.getPort("port1")); |
| 870 | assertEquals(p1b, sw.getPort("PoRt1")); // case insensitive get |
| 871 | |
| 872 | assertEquals(null, sw.getPort((short)2)); |
| 873 | assertEquals(null, sw.getPort("port2")); |
| 874 | assertEquals(null, sw.getPort("PoRt2")); // case insensitive get |
| 875 | |
| 876 | assertEquals(p3, sw.getPort((short)3)); |
| 877 | assertEquals(p3, sw.getPort("port3")); |
| 878 | assertEquals(p3, sw.getPort("PoRt3")); // case insensitive get |
| 879 | |
| 880 | //---------------------------------------------------- |
| 881 | // Modify, but nothing really changed |
| 882 | ports.clear(); |
| 883 | ports.add(p1b); |
| 884 | ports.add(p3); |
| 885 | |
| 886 | expectedChanges.clear(); |
| 887 | |
| 888 | // use a modify to add the port |
| 889 | ps = ps.createBuilder().setReason(OFPortReason.MODIFY).setDesc(p1b).build(); |
| 890 | |
| 891 | actualChanges = sw.processOFPortStatus(ps); |
| 892 | assertCollectionEqualsNoOrder(expectedChanges, actualChanges); |
| 893 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 894 | enabledPorts.clear(); |
| 895 | enabledPorts.add(p3); |
| 896 | enabledPorts.add(p1b); |
| 897 | enabledPortNumbers.clear(); |
| 898 | enabledPortNumbers.add(3); |
| 899 | enabledPortNumbers.add(1); |
| 900 | assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts()); |
| 901 | assertCollectionEqualsNoOrder(enabledPortNumbers, |
| 902 | sw.getEnabledPortNumbers()); |
| 903 | assertEquals(p1b, sw.getPort((short)1)); |
| 904 | assertEquals(p1b, sw.getPort("port1")); |
| 905 | assertEquals(p1b, sw.getPort("PoRt1")); // case insensitive get |
| 906 | |
| 907 | assertEquals(null, sw.getPort((short)2)); |
| 908 | assertEquals(null, sw.getPort("port2")); |
| 909 | assertEquals(null, sw.getPort("PoRt2")); // case insensitive get |
| 910 | |
| 911 | assertEquals(p3, sw.getPort((short)3)); |
| 912 | assertEquals(p3, sw.getPort("port3")); |
| 913 | assertEquals(p3, sw.getPort("PoRt3")); // case insensitive get |
| 914 | } |
| 915 | |
| 916 | |
| 917 | /** |
| 918 | * Test exception handling for setPorts() and comparePorts() |
| 919 | */ |
| 920 | @Test |
| 921 | @SuppressWarnings("EmptyStatement") |
| 922 | public void testSetPortExceptions() { |
| 923 | try { |
| 924 | sw.setPorts(null); |
| 925 | fail("Expected exception not thrown"); |
| 926 | } catch (NullPointerException e) { }; |
| 927 | |
| 928 | // two ports with same name |
| 929 | List<OFPortDesc> ports = new ArrayList<OFPortDesc>(); |
| 930 | ports.add(factory10.buildPortDesc().setName("port1") |
| 931 | .setPortNo(OFPort.of(1)) |
| 932 | .build()); |
| 933 | ports.add(factory10.buildPortDesc().setName("port1") |
| 934 | .setPortNo(OFPort.of(2)) |
| 935 | .build()); |
| 936 | |
| 937 | try { |
| 938 | sw.setPorts(ports); |
| 939 | fail("Expected exception not thrown"); |
| 940 | } catch (IllegalArgumentException e) { }; |
| 941 | |
| 942 | // two ports with same number |
| 943 | ports.clear(); |
| 944 | ports.add(factory10.buildPortDesc().setName("port1") |
| 945 | .setPortNo(OFPort.of(1)) |
| 946 | .build()); |
| 947 | ports.add(factory10.buildPortDesc().setName("port2") |
| 948 | .setPortNo(OFPort.of(1)) |
| 949 | .build()); |
| 950 | |
| 951 | try { |
| 952 | sw.setPorts(ports); |
| 953 | fail("Expected exception not thrown"); |
| 954 | } catch (IllegalArgumentException e) { }; |
| 955 | |
| 956 | // null port in list |
| 957 | ports.clear(); |
| 958 | ports.add(factory10.buildPortDesc().setName("port1") |
| 959 | .setPortNo(OFPort.of(1)) |
| 960 | .build()); |
| 961 | |
| 962 | ports.add(null); |
| 963 | try { |
| 964 | sw.setPorts(ports); |
| 965 | fail("Excpeted exception not thrown"); |
| 966 | } catch (NullPointerException e) { }; |
| 967 | |
| 968 | // try getPort(null) |
| 969 | try { |
| 970 | sw.getPort(null); |
| 971 | fail("Excpeted exception not thrown"); |
| 972 | } catch (NullPointerException e) { }; |
| 973 | |
| 974 | //-------------------------- |
| 975 | // comparePorts() |
| 976 | try { |
| 977 | sw.comparePorts(null); |
| 978 | fail("Excpeted exception not thrown"); |
| 979 | } catch (NullPointerException e) { }; |
| 980 | |
| 981 | // two ports with same name |
| 982 | ports = new ArrayList<OFPortDesc>(); |
| 983 | |
| 984 | ports.add(factory10.buildPortDesc().setName("port1") |
| 985 | .setPortNo(OFPort.of(1)) |
| 986 | .build()); |
| 987 | ports.add(factory10.buildPortDesc().setName("port1") |
| 988 | .setPortNo(OFPort.of(2)) |
| 989 | .build()); |
| 990 | |
| 991 | try { |
| 992 | sw.comparePorts(ports); |
| 993 | fail("Excpeted exception not thrown"); |
| 994 | } catch (IllegalArgumentException e) { }; |
| 995 | |
| 996 | // two ports with same number |
| 997 | ports.clear(); |
| 998 | ports.add(factory10.buildPortDesc().setName("port1") |
| 999 | .setPortNo(OFPort.of(1)) |
| 1000 | .build()); |
| 1001 | ports.add(factory10.buildPortDesc().setName("port2") |
| 1002 | .setPortNo(OFPort.of(1)) |
| 1003 | .build()); |
| 1004 | |
| 1005 | try { |
| 1006 | sw.comparePorts(ports); |
| 1007 | fail("Excpeted exception not thrown"); |
| 1008 | } catch (IllegalArgumentException e) { }; |
| 1009 | |
| 1010 | // null port in list |
| 1011 | ports.clear(); |
| 1012 | ports.add(factory10.buildPortDesc().setName("port1") |
| 1013 | .setPortNo(OFPort.of(1)) |
| 1014 | .build()); |
| 1015 | ports.add(null); |
| 1016 | try { |
| 1017 | sw.comparePorts(ports); |
| 1018 | fail("Excpeted exception not thrown"); |
| 1019 | } catch (NullPointerException e) { }; |
| 1020 | |
| 1021 | // try getPort(null) |
| 1022 | try { |
| 1023 | sw.getPort(null); |
| 1024 | fail("Excpeted exception not thrown"); |
| 1025 | } catch (NullPointerException e) { }; |
| 1026 | |
| 1027 | } |
| 1028 | |
| 1029 | @Test |
| 1030 | public void testPortStatusExceptions() { |
| 1031 | |
| 1032 | try { |
| 1033 | sw.processOFPortStatus(null); |
| 1034 | fail("Expected exception not thrown"); |
| 1035 | } catch (NullPointerException e) { } |
| 1036 | |
| 1037 | // illegal reason code |
| 1038 | |
| 1039 | /* |
| 1040 | * |
| 1041 | * AAS: Can't do this test because LOXI doesn't give you the ability to |
| 1042 | * set your own reason as a byte. |
| 1043 | * |
| 1044 | * ps = ps.createBuilder().setReason(OFPortReason.).build(); |
| 1045 | * ps.setDesc(OFPortDesc.create("p1", (short)1).toOFPhysicalPort()); |
| 1046 | * try { |
| 1047 | * sw.processOFPortStatus(ps); |
| 1048 | * fail("Expected exception not thrown"); |
| 1049 | * } catch (IllegalArgumentException e) { } |
| 1050 | */ |
| 1051 | |
| 1052 | /* |
| 1053 | * AAS: Loxi does not allow you to define a PortStatus message |
| 1054 | * with no port so skipping this test. |
| 1055 | * |
| 1056 | * // null port |
| 1057 | * ps = factory10.buildPortStatus().setReason(OFPortReason.ADD) |
| 1058 | * .setDesc(null) |
| 1059 | * .build(); |
| 1060 | * |
| 1061 | * try { |
| 1062 | * sw.processOFPortStatus(ps); |
| 1063 | * fail("Expected exception not thrown"); |
| 1064 | * } catch (NullPointerException e) { } |
| 1065 | */ |
| 1066 | } |
| 1067 | |
| 1068 | /** |
| 1069 | * Assert that the expected PortChangeEvents have been recevied, asserting |
| 1070 | * the expected ordering. |
| 1071 | * |
| 1072 | * All events in earlyEvents have to appear in actualEvents before any |
| 1073 | * event in lateEvent appears. Events in anytimeEvents can appear at any |
| 1074 | * given time. earlyEvents, lateEvents, and anytimeEvents must be mutually |
| 1075 | * exclusive (their intersection must be none) and their union must |
| 1076 | * contain all elements from actualEvents |
| 1077 | * @param earlyEvents |
| 1078 | * @param lateEvents |
| 1079 | * @param anytimeEvents |
| 1080 | * @param actualEvents |
| 1081 | */ |
| 1082 | private static void assertChangeEvents(Collection<PortChangeEvent> earlyEvents, |
| 1083 | Collection<PortChangeEvent> lateEvents, |
| 1084 | Collection<PortChangeEvent> anytimeEvents, |
| 1085 | Collection<PortChangeEvent> actualEvents) { |
| 1086 | String inputDesc = String.format("earlyEvents=%s, lateEvents=%s, " + |
| 1087 | "anytimeEvents=%s, actualEvents=%s", |
| 1088 | earlyEvents, lateEvents, anytimeEvents, actualEvents); |
| 1089 | // Make copies of expected lists, so we can modify them |
| 1090 | Collection<PortChangeEvent> early = |
| 1091 | new ArrayList<PortChangeEvent>(earlyEvents); |
| 1092 | Collection<PortChangeEvent> late = |
| 1093 | new ArrayList<PortChangeEvent>(lateEvents); |
| 1094 | Collection<PortChangeEvent> any = |
| 1095 | new ArrayList<PortChangeEvent>(anytimeEvents); |
| 1096 | |
| 1097 | // Sanity check: no overlap between early, late, and anytime events |
| 1098 | for (PortChangeEvent ev: early) { |
| 1099 | assertFalse("Test setup error. Early and late overlap", |
| 1100 | late.contains(ev)); |
| 1101 | assertFalse("Test setup error. Early and anytime overlap", |
| 1102 | any.contains(ev)); |
| 1103 | } |
| 1104 | for (PortChangeEvent ev: late) { |
| 1105 | assertFalse("Test setup error. Late and early overlap", |
| 1106 | early.contains(ev)); |
| 1107 | assertFalse("Test setup error. Late and any overlap", |
| 1108 | any.contains(ev)); |
| 1109 | } |
| 1110 | for (PortChangeEvent ev: any) { |
| 1111 | assertFalse("Test setup error. Anytime and early overlap", |
| 1112 | early.contains(ev)); |
| 1113 | assertFalse("Test setup error. Anytime and late overlap", |
| 1114 | late.contains(ev)); |
| 1115 | } |
| 1116 | |
| 1117 | for (PortChangeEvent a: actualEvents) { |
| 1118 | if (early.remove(a)) { |
| 1119 | continue; |
| 1120 | } |
| 1121 | if (any.remove(a)) { |
| 1122 | continue; |
| 1123 | } |
| 1124 | if (late.remove(a)) { |
| 1125 | if (!early.isEmpty()) { |
| 1126 | fail(a + " is in late list, but haven't seen all required " + |
| 1127 | "early events. " + inputDesc); |
| 1128 | } else { |
| 1129 | continue; |
| 1130 | } |
| 1131 | } |
| 1132 | fail(a + " was not expected. " + inputDesc); |
| 1133 | } |
| 1134 | if (!early.isEmpty()) |
| 1135 | fail("Elements left in early: " + early + ". " + inputDesc); |
| 1136 | if (!late.isEmpty()) |
| 1137 | fail("Elements left in late: " + late + ". " + inputDesc); |
| 1138 | if (!any.isEmpty()) |
| 1139 | fail("Elements left in any: " + any + ". " + inputDesc); |
| 1140 | } |
| 1141 | |
| 1142 | /** |
| 1143 | * Test setPort() with changing name / number mappings |
| 1144 | * We don't test comparePorts() here. We assume setPorts() and |
| 1145 | * comparePorts() use the same underlying implementation |
| 1146 | */ |
| 1147 | @Test |
| 1148 | public void testSetPortNameNumberMappingChange() { |
| 1149 | |
| 1150 | List<OFPortDesc> ports = new ArrayList<OFPortDesc>(); |
| 1151 | Collection<PortChangeEvent> early = new ArrayList<PortChangeEvent>(); |
| 1152 | Collection<PortChangeEvent> late = new ArrayList<PortChangeEvent>(); |
| 1153 | Collection<PortChangeEvent> anytime = new ArrayList<PortChangeEvent>(); |
| 1154 | Collection<PortChangeEvent> actualChanges = null; |
| 1155 | |
| 1156 | ports.add(portFoo1); |
| 1157 | ports.add(p1a); |
| 1158 | sw.setPorts(ports); |
| 1159 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 1160 | |
| 1161 | // Add portFoo2: name collision |
| 1162 | ports.clear(); |
| 1163 | ports.add(portFoo2); |
| 1164 | ports.add(p1a); |
| 1165 | early.clear(); |
| 1166 | late.clear(); |
| 1167 | anytime.clear(); |
| 1168 | actualChanges = sw.setPorts(ports); |
| 1169 | early.add(portFoo1Del); |
| 1170 | late.add(portFoo2Add); |
| 1171 | assertChangeEvents(early, late, anytime, actualChanges); |
| 1172 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 1173 | |
| 1174 | // Add portBar2: number collision |
| 1175 | ports.clear(); |
| 1176 | ports.add(portBar2); |
| 1177 | ports.add(p1a); |
| 1178 | early.clear(); |
| 1179 | late.clear(); |
| 1180 | anytime.clear(); |
| 1181 | actualChanges = sw.setPorts(ports); |
| 1182 | early.add(portFoo2Del); |
| 1183 | late.add(portBar2Add); |
| 1184 | assertChangeEvents(early, late, anytime, actualChanges); |
| 1185 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 1186 | |
| 1187 | // Set to portFoo1, portBar2. No collisions in this step |
| 1188 | ports.clear(); |
| 1189 | ports.add(portFoo1); |
| 1190 | ports.add(portBar2); |
| 1191 | ports.add(p1a); |
| 1192 | early.clear(); |
| 1193 | late.clear(); |
| 1194 | anytime.clear(); |
| 1195 | actualChanges = sw.setPorts(ports); |
| 1196 | anytime.add(portFoo1Add); |
| 1197 | assertChangeEvents(early, late, anytime, actualChanges); |
| 1198 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 1199 | |
| 1200 | // Add portFoo2: name and number collision |
| 1201 | ports.clear(); |
| 1202 | ports.add(portFoo2); |
| 1203 | ports.add(p1a); |
| 1204 | early.clear(); |
| 1205 | late.clear(); |
| 1206 | anytime.clear(); |
| 1207 | actualChanges = sw.setPorts(ports); |
| 1208 | early.add(portFoo1Del); |
| 1209 | early.add(portBar2Del); |
| 1210 | late.add(portFoo2Add); |
| 1211 | assertChangeEvents(early, late, anytime, actualChanges); |
| 1212 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 1213 | |
| 1214 | // Set to portFoo2, portBar1. No collisions in this step |
| 1215 | ports.clear(); |
| 1216 | ports.add(portFoo2); |
| 1217 | ports.add(portBar1); |
| 1218 | ports.add(p1a); |
| 1219 | early.clear(); |
| 1220 | late.clear(); |
| 1221 | anytime.clear(); |
| 1222 | actualChanges = sw.setPorts(ports); |
| 1223 | anytime.add(portBar1Add); |
| 1224 | assertChangeEvents(early, late, anytime, actualChanges); |
| 1225 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 1226 | |
| 1227 | // Add portFoo1, portBar2 name and number collision |
| 1228 | // Also change p1a -> p1b: expect modify for it |
| 1229 | // Also add p3: expect add for it |
| 1230 | PortChangeEvent p1bUp = new PortChangeEvent(p1b, PortChangeType.UP); |
| 1231 | PortChangeEvent p3Add = new PortChangeEvent(p3, PortChangeType.ADD); |
| 1232 | ports.clear(); |
| 1233 | ports.add(portFoo1); |
| 1234 | ports.add(portBar2); |
| 1235 | ports.add(p1b); |
| 1236 | ports.add(p3); |
| 1237 | early.clear(); |
| 1238 | late.clear(); |
| 1239 | anytime.clear(); |
| 1240 | actualChanges = sw.setPorts(ports); |
| 1241 | early.add(portFoo2Del); |
| 1242 | early.add(portBar1Del); |
| 1243 | late.add(portFoo1Add); |
| 1244 | late.add(portBar2Add); |
| 1245 | anytime.add(p1bUp); |
| 1246 | anytime.add(p3Add); |
| 1247 | assertChangeEvents(early, late, anytime, actualChanges); |
| 1248 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 1249 | } |
| 1250 | |
| 1251 | |
| 1252 | @Test |
| 1253 | public void testPortStatusNameNumberMappingChange() { |
| 1254 | List<OFPortDesc> ports = new ArrayList<OFPortDesc>(); |
| 1255 | Collection<PortChangeEvent> early = new ArrayList<PortChangeEvent>(); |
| 1256 | Collection<PortChangeEvent> late = new ArrayList<PortChangeEvent>(); |
| 1257 | Collection<PortChangeEvent> anytime = new ArrayList<PortChangeEvent>(); |
| 1258 | Collection<PortChangeEvent> actualChanges = null; |
| 1259 | |
| 1260 | // init: add portFoo1, p1a |
| 1261 | ports.add(portFoo1); |
| 1262 | ports.add(p1a); |
| 1263 | sw.setPorts(ports); |
| 1264 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 1265 | |
| 1266 | OFPortStatus ps = factory10.buildPortStatus() |
| 1267 | .setReason(OFPortReason.MODIFY) |
| 1268 | .setDesc(portFoo2) |
| 1269 | .build(); |
| 1270 | |
| 1271 | // portFoo1 -> portFoo2 via MODIFY : name collision |
| 1272 | ports.clear(); |
| 1273 | ports.add(portFoo2); |
| 1274 | ports.add(p1a); |
| 1275 | early.clear(); |
| 1276 | late.clear(); |
| 1277 | anytime.clear(); |
| 1278 | actualChanges = sw.processOFPortStatus(ps); |
| 1279 | early.add(portFoo1Del); |
| 1280 | late.add(portFoo2Add); |
| 1281 | assertChangeEvents(early, late, anytime, actualChanges); |
| 1282 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 1283 | |
| 1284 | // portFoo2 -> portBar2 via ADD number collision |
| 1285 | ps = ps.createBuilder().setReason(OFPortReason.ADD) |
| 1286 | .setDesc(portBar2) |
| 1287 | .build(); |
| 1288 | |
| 1289 | ports.clear(); |
| 1290 | ports.add(portBar2); |
| 1291 | ports.add(p1a); |
| 1292 | early.clear(); |
| 1293 | late.clear(); |
| 1294 | anytime.clear(); |
| 1295 | actualChanges = sw.processOFPortStatus(ps); |
| 1296 | early.add(portFoo2Del); |
| 1297 | late.add(portBar2Add); |
| 1298 | assertChangeEvents(early, late, anytime, actualChanges); |
| 1299 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 1300 | |
| 1301 | // Set to portFoo1, portBar2 |
| 1302 | ports.clear(); |
| 1303 | ports.add(portFoo1); |
| 1304 | ports.add(portBar2); |
| 1305 | sw.setPorts(ports); |
| 1306 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 1307 | |
| 1308 | // portFoo1 + portBar2 -> portFoo2: name and number collision |
| 1309 | ps = ps.createBuilder().setReason(OFPortReason.MODIFY) |
| 1310 | .setDesc(portFoo2) |
| 1311 | .build(); |
| 1312 | |
| 1313 | ports.clear(); |
| 1314 | ports.add(portFoo2); |
| 1315 | early.clear(); |
| 1316 | late.clear(); |
| 1317 | anytime.clear(); |
| 1318 | actualChanges = sw.processOFPortStatus(ps); |
| 1319 | early.add(portFoo1Del); |
| 1320 | early.add(portBar2Del); |
| 1321 | late.add(portFoo2Add); |
| 1322 | assertChangeEvents(early, late, anytime, actualChanges); |
| 1323 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 1324 | |
| 1325 | //---------------------- |
| 1326 | // Test DELETEs |
| 1327 | |
| 1328 | // del portFoo1: name exists (portFoo2), but number doesn't. |
| 1329 | ps = ps.createBuilder().setReason(OFPortReason.DELETE) |
| 1330 | .setDesc(portFoo1) |
| 1331 | .build(); |
| 1332 | |
| 1333 | ports.clear(); |
| 1334 | early.clear(); |
| 1335 | late.clear(); |
| 1336 | anytime.clear(); |
| 1337 | actualChanges = sw.processOFPortStatus(ps); |
| 1338 | anytime.add(portFoo2Del); |
| 1339 | assertChangeEvents(early, late, anytime, actualChanges); |
| 1340 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 1341 | |
| 1342 | // Set to portFoo1 |
| 1343 | ports.clear(); |
| 1344 | ports.add(portFoo1); |
| 1345 | sw.setPorts(ports); |
| 1346 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 1347 | |
| 1348 | // del portBar1: number exists (portFoo1), but name doesn't. |
| 1349 | ps = ps.createBuilder().setReason(OFPortReason.DELETE) |
| 1350 | .setDesc(portBar1) |
| 1351 | .build(); |
| 1352 | |
| 1353 | ports.clear(); |
| 1354 | early.clear(); |
| 1355 | late.clear(); |
| 1356 | anytime.clear(); |
| 1357 | actualChanges = sw.processOFPortStatus(ps); |
| 1358 | anytime.add(portFoo1Del); |
| 1359 | assertChangeEvents(early, late, anytime, actualChanges); |
| 1360 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 1361 | |
| 1362 | |
| 1363 | // Set to portFoo1, portBar2 |
| 1364 | ports.clear(); |
| 1365 | ports.add(portFoo1); |
| 1366 | ports.add(portBar2); |
| 1367 | sw.setPorts(ports); |
| 1368 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 1369 | |
| 1370 | // del portFoo2: name and number exists |
| 1371 | ps = ps.createBuilder().setReason(OFPortReason.DELETE) |
| 1372 | .setDesc(portFoo2) |
| 1373 | .build(); |
| 1374 | |
| 1375 | ports.clear(); |
| 1376 | early.clear(); |
| 1377 | late.clear(); |
| 1378 | anytime.clear(); |
| 1379 | actualChanges = sw.processOFPortStatus(ps); |
| 1380 | anytime.add(portFoo1Del); |
| 1381 | anytime.add(portBar2Del); |
| 1382 | assertChangeEvents(early, late, anytime, actualChanges); |
| 1383 | assertCollectionEqualsNoOrder(ports, sw.getPorts()); |
| 1384 | } |
| 1385 | |
| 1386 | @Test |
| 1387 | public void testSubHandshake() { |
| 1388 | //Nicira role messages are vendor extentions should do the job. |
| 1389 | OFMessage m = factory10.niciraControllerRoleRequest(OFNiciraControllerRole.ROLE_MASTER); |
| 1390 | // BasicFactory.getInstance().getMessage(OFType.VENDOR); |
| 1391 | // test execptions before handshake is started |
| 1392 | try { |
| 1393 | sw.processDriverHandshakeMessage(m); |
| 1394 | fail("expected exception not thrown"); |
| 1395 | } catch (SwitchDriverSubHandshakeNotStarted e) { /* expected */ } |
| 1396 | try { |
| 1397 | sw.isDriverHandshakeComplete(); |
| 1398 | fail("expected exception not thrown"); |
| 1399 | } catch (SwitchDriverSubHandshakeNotStarted e) { /* expected */ } |
| 1400 | |
| 1401 | // start the handshake -- it should immediately complete |
| 1402 | try { |
| 1403 | sw.startDriverHandshake(); |
| 1404 | } catch (IOException e1) { |
| 1405 | fail("Unexpected IOException thrown."); |
| 1406 | } |
| 1407 | assertTrue("Handshake should be complete", |
| 1408 | sw.isDriverHandshakeComplete()); |
| 1409 | |
| 1410 | // test exceptions after handshake is completed |
| 1411 | try { |
| 1412 | sw.processDriverHandshakeMessage(m); |
| 1413 | fail("expected exception not thrown"); |
| 1414 | } catch (SwitchDriverSubHandshakeCompleted e) { /* expected */ } |
| 1415 | try { |
| 1416 | sw.startDriverHandshake(); |
| 1417 | fail("Expected exception not thrown"); |
| 1418 | } catch (SwitchDriverSubHandshakeAlreadyStarted e) { |
| 1419 | /* expected */ |
| 1420 | } catch (IOException e) { |
| 1421 | fail("Unexpected IOException thrown."); |
| 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | } |