com.h3c.of.lib.msg

## Class PortFactory

- java.lang.Object
- - com.h3c.of.lib.AbstractFactory
  - - com.h3c.of.lib.msg.PortFactory

-     public class PortFactory
      extends AbstractFactory

  Provides facilities for parsing, creating, and encoding `Port` instances.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `E_BAD_PORT_NUM` Exception message for invalid port number.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Port` | `copy(Port p)` Returns a copy (immutable) of the given port.
    `static MutablePort` | `createPort(ProtocolVersion pv)` Creates a mutable port.
    `static void` | `encodePort(Port port, OfPacketWriter pkt)` Encodes the specified port structure into the specified buffer.
    `static void` | `encodePortList(List<Port> ports, OfPacketWriter pkt)` Encodes a list of ports, writing them into the supplied buffer.
    `static void` | `encodePortNumber(BigPortNumber port, OfPacketWriter pkt, ProtocolVersion pv)` Encodes the given port number, writing it to the specified buffer, for the given protocol version.
    `static int` | `getPortLength(ProtocolVersion pv)` Returns the length of a port structure in bytes.
    `static MutablePort` | `mutableCopy(Port p)` Returns a mutable copy of the given port.
    `static Port` | `parsePort(OfPacketReader pkt, ProtocolVersion pv)` Parses the given packet buffer as a port structure.
    `static List<Port>` | `parsePortList(OfPacketReader pkt, ProtocolVersion pv)` Parses a list of port structures from the supplied buffer.
    `static BigPortNumber` | `parsePortNumber(OfPacketReader pkt, ProtocolVersion pv)` Parses a port number from the specified buffer, for the given protocol version.
    `protected String` | `tag()` Returns an identifying tag for the port factory.
    `static String` | `toDebugString(int indent, List<Port> ports)` Outputs a list of ports in debug string format.
    `static String` | `toDebugString(List<Port> ports)` Outputs a list of ports in debug string format.

    - ### Methods inherited from class com.h3c.of.lib.AbstractFactory

      `mpe, mpe, mpe, mpe`

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

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

- - ### Field Detail

    - #### E_BAD_PORT_NUM

          public static final String E_BAD_PORT_NUM

      Exception message for invalid port number.

  - ### Method Detail

    - #### tag

          protected String tag()

      Returns an identifying tag for the port factory.
      Specified by:
        `tag` in class `AbstractFactory`
      Returns:
        an identifying tag

    - #### parsePortList

          public static List<Port> parsePortList(OfPacketReader pkt,
                                 ProtocolVersion pv)
                                          throws MessageParseException

      Parses a list of port structures from the supplied buffer. It is assumed that buffer has been marked with the target index so we know when to stop.

      Note that this method causes the reader index of the underlying packet reader to be advanced by the length of the list, which should leave the reader index at the target index.

      This method delegates to `parsePort(com.h3c.of.lib.OfPacketReader, com.h3c.of.lib.ProtocolVersion)` for each individual port.

      Parameters:
        `pkt` - the data buffer
        `pv` - the protocol version
      Returns:
        a list of parsed ports
      Throws:
        `MessageParseException` - if unable to parse the structure

    - #### parsePort

          public static Port parsePort(OfPacketReader pkt,
                       ProtocolVersion pv)
                                throws MessageParseException

      Parses the given packet buffer as a port structure.
      Parameters:
        `pkt` - the packet buffer
        `pv` - the protocol version
      Returns:
        the parsed port instance
      Throws:
        `MessageParseException` - if a problem parsing the buffer

    - #### parsePortNumber

          public static BigPortNumber parsePortNumber(OfPacketReader pkt,
                                      ProtocolVersion pv)

      Parses a port number from the specified buffer, for the given protocol version. If the version is 1.0, two bytes (u16) are read; if the value is 1.1 or higher, four bytes (u32) are read. If the value parsed is greater than the maximum defined in the OpenFlow specification, an exception is thrown.

      Note that, for v1.0, "special" port numbers are translated into their u32 counterparts and returned.

      Parameters:
        `pkt` - the data buffer from which the port is to be read
        `pv` - the protocol version
      Returns:
        the parsed port number
      Throws:
        `IllegalArgumentException` - if the parsed port is not valid for the specified protocol version
      See Also:
        `Port`

    - #### createPort

          public static MutablePort createPort(ProtocolVersion pv)

      Creates a mutable port. Initially, no fields are set.
      Parameters:
        `pv` - the required protocol version
      Returns:
        the port structure
      Throws:
        `VersionNotSupportedException` - if the version is not supported

    - #### encodePort

          public static void encodePort(Port port,
                        OfPacketWriter pkt)
                                 throws IncompleteStructureException

      Encodes the specified port structure into the specified buffer. It is assumed that the writer index is in the correct place for the start of the structure. At the end of this method call, the writer index will have advanced by the length of the encoded port.

      Note that, for v1.0 ports, "special" port numbers are translated to their u16 counterparts.

      Parameters:
        `port` - the port to encode
        `pkt` - the buffer to write into
      Throws:
        `IllegalArgumentException` - if the port is mutable, or if the protocol version is 1.0 and the port number is not u16
        `IncompleteStructureException` - if the port is missing required fields

    - #### encodePortNumber

          public static void encodePortNumber(BigPortNumber port,
                              OfPacketWriter pkt,
                              ProtocolVersion pv)

      Encodes the given port number, writing it to the specified buffer, for the given protocol version. If the version is 1.0, two bytes (u16) are written; if the value is 1.1 or higher, four bytes (u32) are written. If the port number is greater than the maximum defined in the OpenFlow specification, an exception is thrown. If the `port` argument is null, the bytes are zero-filled.

      Note that, for v1.0, "special" port numbers are translated to their u16 counterparts.

      Parameters:
        `port` - the port number to encode
        `pkt` - the data buffer into which the port is to be written
        `pv` - the protocol version
      See Also:
        `Port`

    - #### encodePortList

          public static void encodePortList(List<Port> ports,
                            OfPacketWriter pkt)
                                     throws IncompleteStructureException

      Encodes a list of ports, writing them into the supplied buffer. Note that this method causes the writer index of the underlying `PacketBuffer` to be advanced by the length of the written ports.
      Parameters:
        `ports` - the list of ports
        `pkt` - the buffer into which the ports are to be written
      Throws:
        `IncompleteStructureException` - if any of the ports are missing required fields

    - #### copy

          public static Port copy(Port p)

      Returns a copy (immutable) of the given port.
      Parameters:
        `p` - the original port
      Returns:
        the copy

    - #### mutableCopy

          public static MutablePort mutableCopy(Port p)

      Returns a mutable copy of the given port.
      Parameters:
        `p` - the original port
      Returns:
        the mutable copy

    - #### getPortLength

          public static int getPortLength(ProtocolVersion pv)

      Returns the length of a port structure in bytes.
      Parameters:
        `pv` - the protocol version
      Returns:
        the length in bytes

    - #### toDebugString

          public static String toDebugString(List<Port> ports)

      Outputs a list of ports in debug string format.
      Parameters:
        `ports` - the list of ports
      Returns:
        a multi-line string representation of the list of ports

    - #### toDebugString

          public static String toDebugString(int indent,
                             List<Port> ports)

      Outputs a list of ports in debug string format.
      Parameters:
        `indent` - the additional indent (number of spaces)
        `ports` - the list of ports
      Returns:
        a multi-line string representation of the list of ports

Copyright © 2014. All Rights Reserved.