com.h3c.of.common

## Class ProgrammableSink

- java.lang.Object
- - com.h3c.of.common.ProgrammableSink

- All Implemented Interfaces:
    MessageSink

      public class ProgrammableSink
      extends Object
      implements MessageSink

  A utility implementation of the `MessageSink` interface which can be used in unit tests of OpenFlow message interactions.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ProgrammableSink(DataPathId defaultDpid)` Constructs a programmable message sink.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addError(DataPathId dpid, List<String> context, String msg)` Adds an assertion error to the accumulation list for the given datapath.
    `void` | `addError(DataPathId dpid, List<String> context, String msg, Object exp, Object act)` Adds an assertion error to the accumulation list for the given datapath.
    `void` | `assocXid(DataPathId dpid, long xid)` Associates an expected transaction id with a datapath.
    `void` | `dataPathAdded(DataPathId dpid, ProtocolVersion negotiated, IpAddress ip)` Invoked by the controller when a new datapath has completed the handshake sequence and is ready to talk OpenFlow.
    `void` | `dataPathRemoved(DataPathId dpid, ProtocolVersion negotiated, IpAddress ip)` Invoked by the controller when a datapath connection is dropped.
    `void` | `dataPathRevoked(DataPathId dpid, ProtocolVersion negotiated, IpAddress ip)` Invoked by the controller when a datapath connection is refused because a datapath with the given ID is already connected.
    `void` | `endReplay()` Ends the replay.
    `void` | `expect(DataPathId dpid, MessageType type)` Adds the expectation that the next message is of the specified type.
    `void` | `expect(DataPathId dpid, MessageType type, AbstractMsgAssertor ma)` Adds the expectation that the next message is of the specified type, and that the assertions embodied in the message assertor, when run against the message, are all true.
    `void` | `expect(MessageType type)` Adds the expectation that the next message is of the specified type, (and expected from the default datapath).
    `void` | `expect(MessageType type, AbstractMsgAssertor ma)` Adds the expectation that the next message is of the specified type, and that the assertions embodied in the message assertor, when run against the message, are all true, (and expected from the default datapath).
    `void` | `msgRx(OpenflowMessage msg, DataPathId dpid, int auxId, ProtocolVersion negotiated)` Incoming OpenFlow messages are routed through this API method.
    `void` | `replay()` Switches the sink into replay mode.
    `ProgrammableSink` | `setNonStrict()` Setting the sink to non-strict mode means that the sink will ignore any message received that it is not expecting, rather than failing the test.

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

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

- - ### Constructor Detail

    - #### ProgrammableSink

          public ProgrammableSink(DataPathId defaultDpid)

      Constructs a programmable message sink. The datapath id given here is used in all method calls that do not explicitly specify a datapath id. This can be null, as long as each expectation is added with an `expect(...)` method that explicitly specifies the datapath from which the message is expected.
      Parameters:
        `defaultDpid` - the default dpid

  - ### Method Detail

    - #### expect

          public void expect(MessageType type)

      Adds the expectation that the next message is of the specified type, (and expected from the default datapath).
      Parameters:
        `type` - the expected message type

    - #### expect

          public void expect(DataPathId dpid,
                    MessageType type)

      Adds the expectation that the next message is of the specified type.
      Parameters:
        `dpid` - the datapath from which the message is expected
        `type` - the expected message type

    - #### expect

          public void expect(MessageType type,
                    AbstractMsgAssertor ma)

      Adds the expectation that the next message is of the specified type, and that the assertions embodied in the message assertor, when run against the message, are all true, (and expected from the default datapath).
      Parameters:
        `type` - the expected message type
        `ma` - the message assertor

    - #### expect

          public void expect(DataPathId dpid,
                    MessageType type,
                    AbstractMsgAssertor ma)

      Adds the expectation that the next message is of the specified type, and that the assertions embodied in the message assertor, when run against the message, are all true.
      Parameters:
        `dpid` - the datapath from which the message is expected
        `type` - the expected message type
        `ma` - the message assertor

    - #### replay

          public void replay()

      Switches the sink into replay mode.

    - #### endReplay

          public void endReplay()

      Ends the replay. Throws an AssertionError if there are unmet expectations remaining.

    - #### dataPathAdded

          public void dataPathAdded(DataPathId dpid,
                           ProtocolVersion negotiated,
                           IpAddress ip)

      Invoked by the controller when a new datapath has completed the handshake sequence and is ready to talk OpenFlow. The IP address is that of the remote end of the connection (i.e. the IP address of the switch).

      This default implementation does nothing.

      Specified by:
        `dataPathAdded` in interface `MessageSink`
      Parameters:
        `dpid` - the datapath id
        `negotiated` - the negotiated version
        `ip` - the IP address of the switch

    - #### dataPathRemoved

          public void dataPathRemoved(DataPathId dpid,
                             ProtocolVersion negotiated,
                             IpAddress ip)

      Invoked by the controller when a datapath connection is dropped. The IP address is that of the remote end of the connection (i.e. the IP address of the switch).

      This default implementation does nothing.

      Specified by:
        `dataPathRemoved` in interface `MessageSink`
      Parameters:
        `dpid` - the datapath id
        `negotiated` - the negotiated version
        `ip` - the IP address of the switch

    - #### dataPathRevoked

          public void dataPathRevoked(DataPathId dpid,
                             ProtocolVersion negotiated,
                             IpAddress ip)

      Invoked by the controller when a datapath connection is refused because a datapath with the given ID is already connected.

      This default implementation does nothing.

      Specified by:
        `dataPathRevoked` in interface `MessageSink`
      Parameters:
        `dpid` - the datapath id
        `negotiated` - the negotiated version
        `ip` - the IP address of the switch

    - #### msgRx

          public void msgRx(OpenflowMessage msg,
                   DataPathId dpid,
                   int auxId,
                   ProtocolVersion negotiated)

      Incoming OpenFlow messages are routed through this API method. Note that this is called from another thread (not the main test thread), so we need to just accumulate assertion failures, not throw them.
      Specified by:
        `msgRx` in interface `MessageSink`
      Parameters:
        `msg` - the OpenFlow message
        `dpid` - the source datapath ID
        `auxId` - the auxiliary connection ID
        `negotiated` - the negotiated version

    - #### addError

          public void addError(DataPathId dpid,
                      List<String> context,
                      String msg)

      Adds an assertion error to the accumulation list for the given datapath.
      Parameters:
        `dpid` - the datapath id
        `context` - list of error context messages
        `msg` - the error message

    - #### addError

          public void addError(DataPathId dpid,
                      List<String> context,
                      String msg,
                      Object exp,
                      Object act)

      Adds an assertion error to the accumulation list for the given datapath.
      Parameters:
        `dpid` - the datapath id
        `context` - list of error context messages
        `msg` - the error message
        `exp` - the expected value
        `act` - the actual value

    - #### assocXid

          public void assocXid(DataPathId dpid,
                      long xid)

      Associates an expected transaction id with a datapath. Adds the xid to the end of the list of expected xids for the datapath.
      Parameters:
        `dpid` - the datapath id
        `xid` - the expected transaction id

    - #### setNonStrict

          public ProgrammableSink setNonStrict()

      Setting the sink to non-strict mode means that the sink will ignore any message received that it is not expecting, rather than failing the test.

      Returns a reference to itself to allow for method chaining. For example:

               sink.setNonStrict().replay();

      Returns:
        self

Copyright © 2014. All Rights Reserved.