com.h3c.of.sw

## Class MockSwitchBank

- java.lang.Object
- - com.h3c.of.sw.MockSwitchBank

-     public class MockSwitchBank
      extends Object

  Represents a bank of mock openflow switches; useful for OpenFlow Controller and Application unit testing.

  The mock switch bank is configured via a text-based definition file. This file contains a number of sections:

  - [switches] - defines the mock switches contained within the bank and possibly used in the scenario
  - [packets] - defines packet payloads that may be used in the scenario
  - [scenario] - defines a programmed set of actions that the bank will execute when it is activated.

  Notes: The `[packets]` functionality has not yet been implemented. The `[scenario]` functionality is incomplete; a base set of action keywords will parse correctly, but the scenario engine has not yet been implemented. As a provisional workaround, when the bank is activated, the mock switches are activated one after the other with a short (50ms) delay between each activation.

  An example definition file is shown below. Note that blank lines and lines beginning with "#" are considered comments and thus ignored by the parser.

        ## Switch bank definition file
        [switches]
        SW10 = simple10sw4port.def
        SW13 = simple13sw32port.def

  The records in the [switches] section take the form `LNAME = filename.def` where LNAME is the logical name that will be used to refer to the switch in the scenario, and filename.def is the name of the definition file describing the mock switch. The file is assumed to be in the same directory as the bank definition file.

  This example will be expanded once the [packets] and [scenario] functionality have been fully implemented.

  See Also:
    `MockOpenflowSwitch`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MockSwitchBank(String path, boolean showOutput)` Constructs the switch bank from a bank definition object.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `activate()` Activates the switch bank, by starting the scenario script.
    `void` | `activate(DataPathId dpid)` Activates the mock switch with the specified datapath ID.
    `void` | `deactivate(DataPathId dpid)` Deactivates the mock switch with the specified datapath ID.
    `void` | `endScenario()` Ends the scenario by checking each mock switch for failed assertions.
    `int` | `expectedToCompleteHandshake()` Returns the number of mock switches that are expected to complete the handshake process.
    `DataPathId[]` | `getDpids()` Returns the datapath IDs of the configured switches in an array.
    `void` | `resume()` Resumes the scenario processing after a scripted SUSPEND.
    `void` | `setInternalMsgLatch(DataPathId dpid, CountDownLatch latch)` Install a count down latch on the specified mock switch's message handler.
    `void` | `shutdown()` Immediately shuts down all activated switches.
    `int` | `size()` Returns the number of configured mock switches.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### MockSwitchBank

          public MockSwitchBank(String path,
                        boolean showOutput)

      Constructs the switch bank from a bank definition object.
      Parameters:
        `path` - the bank definition file path
        `showOutput` - if true, output to STDOUT is permissible

  - ### Method Detail

    - #### activate

          public void activate()

      Activates the switch bank, by starting the scenario script.

    - #### resume

          public void resume()

      Resumes the scenario processing after a scripted SUSPEND.

    - #### shutdown

          public void shutdown()

      Immediately shuts down all activated switches.

    - #### size

          public int size()

      Returns the number of configured mock switches.
      Returns:
        the number of switches in the bank

    - #### expectedToCompleteHandshake

          public int expectedToCompleteHandshake()

      Returns the number of mock switches that are expected to complete the handshake process. The default implementation is the same as the number of switches in the bank.

      Implementors should override this to account for switches with unsupported protocol versions.

      Returns:
        number of switches expected to handshake

    - #### getDpids

          public DataPathId[] getDpids()

      Returns the datapath IDs of the configured switches in an array.
      Returns:
        the datapath IDs

    - #### activate

          public void activate(DataPathId dpid)

      Activates the mock switch with the specified datapath ID. If the switch is already active (connected to the controller) an exception is thrown.
      Parameters:
        `dpid` - the switch's datapath ID
      Throws:
        `NullPointerException` - if dpid is null
        `IllegalArgumentException` - if there is no datapath with the specified ID
        `IllegalStateException` - if the switch is already active

    - #### deactivate

          public void deactivate(DataPathId dpid)

      Deactivates the mock switch with the specified datapath ID. If the switch is already inactive (not connected to the contoller) an exception is thrown.
      Parameters:
        `dpid` - the switch's datapath ID
      Throws:
        `NullPointerException` - if dpid is null
        `IllegalArgumentException` - if there is no datapath with the specified ID
        `IllegalStateException` - if the switch is already inactive

    - #### setInternalMsgLatch

          public void setInternalMsgLatch(DataPathId dpid,
                                 CountDownLatch latch)

      Install a count down latch on the specified mock switch's message handler.
      Parameters:
        `dpid` - the id of the switch
        `latch` - the latch to install

    - #### endScenario

          public void endScenario()

      Ends the scenario by checking each mock switch for failed assertions. Throws an AssertionError if there were issues.

Copyright © 2014. All Rights Reserved.