com.h3c.of.lib.msg

## Class Port

- java.lang.Object
- - com.h3c.of.lib.OpenflowStructure
  - - com.h3c.of.lib.msg.Port

- All Implemented Interfaces:
    Structure
  Direct Known Subclasses:
    MutablePort

      public class Port
      extends OpenflowStructure

  Represents physical ports, switch-defined logical ports, and OpenFlow specified reserved ports.

  Instances of this class are immutable.

  In OpenFlow, ports are numbered starting from 1. The maximum legal value for an individual port is `MAX` (but see below). Reserved OpenFlow Port numbers (fake output "ports") are also defined on this class:

  - `IN_PORT` - Send packet out the input port.
  - `TABLE` - Submit the packet to the first flow table.
  - `NORMAL` - Process with normal L2/L3 switching.
  - `FLOOD` - All physical ports in VLAN (with exceptions).
  - `ALL` - All physical ports except input port.
  - `CONTROLLER` - Send to the controller.
  - `LOCAL` - Local openflow "port".
  - `ANY` - Wildcard port used only for flow mod (delete) and flow stats requests.

  Note that in OpenFlow version 1.0, port numbers were defined as unsigned 16-bit (u16) values; Since version 1.1 port numbers have been defined as unsigned 32-bit (u32) values. Since this class represents ports spanning all versions of the protocol, the port number is expressed using the `BigPortNumber` class. When creating a version 1.0 port, the value of the port number is validated as u16. Additionally, when encoding the "special" values (listed above as `MAX`, and the Reserved values), their u16 counterparts are substituted at the time the port structure is encoded as bytes.

  Author:
    Simon Hunt, Liem Nguyen
  See Also:
    `PortFactory`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static BigPortNumber` | `ALL` All physical ports except input port; Since 1.0.
    `static BigPortNumber` | `ANY` Wildcard port used only for flow mod (delete) and flow stats requests; Since 1.1.
    `static BigPortNumber` | `CONTROLLER` Send to the Controller; Since 1.0.
    `static BigPortNumber` | `FLOOD` All physical ports in VLAN, except input port and those blocked or link down; Since 1.0.
    `static BigPortNumber` | `IN_PORT` Send the packet out the input port; Since 1.0.
    `static BigPortNumber` | `LOCAL` Local openflow "port"; Since 1.0.
    `static BigPortNumber` | `MAX` Maximum number of physical and logical switch ports; Since 1.0.
    `static BigPortNumber` | `NONE` Not associated with a physical port; Since 1.0.
    `static BigPortNumber` | `NORMAL` Process with normal L2/L3 switching; Since 1.0.
    `static BigPortNumber` | `TABLE` Submit the packet to the first flow table; Since 1.0.

    - ### Fields inherited from class com.h3c.of.lib.OpenflowStructure

      `version`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static PortNumber` | `equivalentSpecial(BigPortNumber bpn)` Returns the 1.0 "special" port number (u16) equivalent to the given 1.3 "special" big port number (u32).
    `static BigPortNumber` | `equivalentSpecial(PortNumber pn)` Returns the 1.3 "special" big port number (u32) equivalent to the given 1.0 "special" port number (u16).
    `Set<PortFeature>` | `getAdvertised()` Returns the set of features advertised by the port; Since 1.0.
    `static BigPortNumber` | `getBigPortNumber(String portNumber)` Returns the port, given its string representation, which can include a logical name or the numeric representation of the port.
    `Set<PortConfig>` | `getConfig()` Returns the port administrative settings.
    `Set<PortFeature>` | `getCurrent()` Returns the set of current features; Since 1.0.
    `long` | `getCurrentSpeed()` Returns the current port speed (bitrate) in kbps; Since 1.1.
    `MacAddress` | `getHwAddress()` Returns the MAC address for the port; Since 1.0.
    `long` | `getMaxSpeed()` Returns the maximum port speed (bitrate) in kbps; Since 1.1.
    `String` | `getName()` Returns the human readable name for the interface; Since 1.0.
    `Set<PortFeature>` | `getPeer()` Returns the set of features advertised by the peer; Since 1.0.
    `BigPortNumber` | `getPortNumber()` The port number uniquely identifies a port within a switch; Since 1.0.
    `static PortNumber` | `getPortNumber(String portNumber)` Returns the port, given its string representation, which can include a logical name or the numeric representation of the port.
    `Set<PortState>` | `getState()` Returns the state of the physical link or switch protocols outside of OpenFlow; Since 1.0.
    `Set<PortFeature>` | `getSupported()` Returns the set of features supported by the port; Since 1.0.
    `boolean` | `isBlocked()` Returns true if this port is prevented from being used for flooding.
    `boolean` | `isEnabled()` Returns true if the port is administratively enabled.
    `boolean` | `isLinkUp()` Returns true if this port's link is up.
    `static boolean` | `isStandardPort(BigPortNumber bpn, ProtocolVersion pv)` Returns true if the given port number is in the range 1 to MAX; false otherwise.
    `static String` | `logicalName(BigPortNumber port, ProtocolVersion pv)` Returns the logical name of the port, or null if the port number is not a special value (for the given protocol version).
    `static String` | `portNumberToString(BigPortNumber port)` Returns a string representation of the port number.
    `static String` | `portNumberToString(BigPortNumber port, ProtocolVersion pv)` Returns a string representation of the port number, for the given protocol version.
    `static String` | `portNumberToString(PortNumber port)` Returns a string representation of the port number.
    `void` | `setAbnormal(boolean isabnormal)` set port abnormal state
    `String` | `toDebugString()` Returns a multi-line representation of this port.
    `String` | `toDebugString(int indent)` Returns a multi-line representation of this port.
    `String` | `toString()`
    `void` | `validate()` Validates this structure for completeness and throws an exception if the structure is considered "not complete".
    `static void` | `validatePortValue(BigPortNumber bpn, ProtocolVersion pv)` Validates that the given port number is an acceptable value for encoding as a port number for the given protocol.

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

      `getVersion, hex, hex`

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

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

- - ### Field Detail

    - #### MAX

          public static final BigPortNumber MAX

      Maximum number of physical and logical switch ports; Since 1.0.

      Note: in 1.0, this value is `0xff00`.

    - #### IN_PORT

          public static final BigPortNumber IN_PORT

      Send the packet out the input port; Since 1.0. This reserved port must be explicitly used in order to send back out of the input port.

      Note: in 1.0, this value is `0xfff8`.

    - #### TABLE

          public static final BigPortNumber TABLE

      Submit the packet to the first flow table; Since 1.0. NB: This destination port can only be used in packet-out messages.

      Note: in 1.0, this value is `0xfff9`.

    - #### NORMAL

          public static final BigPortNumber NORMAL

      Process with normal L2/L3 switching; Since 1.0.

      Note: in 1.0, this value is `0xfffa`.

    - #### FLOOD

          public static final BigPortNumber FLOOD

      All physical ports in VLAN, except input port and those blocked or link down; Since 1.0.

      Note: in 1.0, this value is `0xfffb`.

    - #### ALL

          public static final BigPortNumber ALL

      All physical ports except input port; Since 1.0.

      Note: in 1.0, this value is `0xfffc`.

    - #### CONTROLLER

          public static final BigPortNumber CONTROLLER

      Send to the Controller; Since 1.0.

      Note: in 1.0, this value is `0xfffd`.

    - #### LOCAL

          public static final BigPortNumber LOCAL

      Local openflow "port"; Since 1.0.

      Note: in 1.0, this value is `0xfffe`.

    - #### ANY

          public static final BigPortNumber ANY

      Wildcard port used only for flow mod (delete) and flow stats requests; Since 1.1. Selects all flows regardless of output port (including flows with no output port).

      See `NONE` for 1.0.

    - #### NONE

          public static final BigPortNumber NONE

      Not associated with a physical port; Since 1.0.

      Note: in 1.0, this value is `0xffff`.

      See `ANY` for 1.1 and higher.

  - ### Method Detail

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `OpenflowStructure`

    - #### toDebugString

          public String toDebugString()

      Returns a multi-line representation of this port. Useful for debug output.
      Specified by:
        `toDebugString` in interface `Structure`
      Overrides:
        `toDebugString` in class `OpenflowStructure`
      Returns:
        a multi-line representation

    - #### toDebugString

          public String toDebugString(int indent)

      Returns a multi-line representation of this port. Useful for debug output.
      Parameters:
        `indent` - depth of indent
      Returns:
        a multi-line representation

    - #### validate

          public void validate()
                        throws IncompleteStructureException

      Description copied from class: `OpenflowStructure`
      Validates this structure for completeness and throws an exception if the structure is considered "not complete".

      This default implementation does nothing, i.e. default behavior is that structures are considered complete.

      Subclasses should override this method to check that mandatory fields or other internal state is present, throwing an exception if it is not.

      Overrides:
        `validate` in class `OpenflowStructure`
      Throws:
        `IncompleteStructureException` - if the structure is not complete

    - #### getPortNumber

          public BigPortNumber getPortNumber()

      The port number uniquely identifies a port within a switch; Since 1.0.
      Returns:
        the port number

    - #### getHwAddress

          public MacAddress getHwAddress()

      Returns the MAC address for the port; Since 1.0.
      Returns:
        the MAC address

    - #### getName

          public String getName()

      Returns the human readable name for the interface; Since 1.0. Limited to 15 characters.
      Returns:
        the port name

    - #### getConfig

          public Set<PortConfig> getConfig()

      Returns the port administrative settings.
      Returns:
        the current configuration settings

    - #### getState

          public Set<PortState> getState()

      Returns the state of the physical link or switch protocols outside of OpenFlow; Since 1.0.
      Returns:
        the port state

    - #### getCurrent

          public Set<PortFeature> getCurrent()

      Returns the set of current features; Since 1.0.
      Returns:
        the set of current features

    - #### getAdvertised

          public Set<PortFeature> getAdvertised()

      Returns the set of features advertised by the port; Since 1.0.
      Returns:
        the set of advertised features

    - #### getSupported

          public Set<PortFeature> getSupported()

      Returns the set of features supported by the port; Since 1.0.
      Returns:
        the set of supported features

    - #### getPeer

          public Set<PortFeature> getPeer()

      Returns the set of features advertised by the peer; Since 1.0.
      Returns:
        the peer advertised features

    - #### getCurrentSpeed

          public long getCurrentSpeed()

      Returns the current port speed (bitrate) in kbps; Since 1.1.
      Returns:
        current port speed (kbps)

    - #### getMaxSpeed

          public long getMaxSpeed()

      Returns the maximum port speed (bitrate) in kbps; Since 1.1.
      Returns:
        maximum port speed (kbps)

    - #### isEnabled

          public boolean isEnabled()

      Returns true if the port is administratively enabled. This is a convenience method that checks for the absence of the `PORT_DOWN` configuration flag.
      Returns:
        true if the port is enabled
      See Also:
        `getConfig()`

    - #### isLinkUp

          public boolean isLinkUp()

      Returns true if this port's link is up. This is a convenience method that checks for the absence of the `LINK_DOWN` state flag.
      Returns:
        true if the port's link is up
      See Also:
        `getState()`

    - #### isBlocked

          public boolean isBlocked()

      Returns true if this port is prevented from being used for flooding.

      The "blocked" flag indicates that a switch protocol outside of OpenFlow, such as 802.1D Spanning Tree, is preventing the use of the port with `FLOOD`.

      This convenience method checks for the presence of the `STP_BLOCK` or `BLOCKED` state flag, depending on the protocol version.

      Returns:
        true if the port is blocked

    - #### setAbnormal

          public void setAbnormal(boolean isabnormal)

      set port abnormal state
      Parameters:
        `isabnormal` - port state,false is normal, true is abnormal

    - #### portNumberToString

          public static String portNumberToString(BigPortNumber port,
                                  ProtocolVersion pv)

      Returns a string representation of the port number, for the given protocol version. Reserved values will include the logical name of the port.
      Parameters:
        `port` - the port number
        `pv` - the protocol version
      Returns:
        a string representation of the port number

    - #### portNumberToString

          public static String portNumberToString(BigPortNumber port)

      Returns a string representation of the port number. Reserved values will include the logical name of the port.
      Parameters:
        `port` - the port number
      Returns:
        a string representation of the port number

    - #### portNumberToString

          public static String portNumberToString(PortNumber port)

      Returns a string representation of the port number. Reserved values will include the logical name of the port.
      Parameters:
        `port` - the port number
      Returns:
        a string representation of the port number

    - #### equivalentSpecial

          public static BigPortNumber equivalentSpecial(PortNumber pn)

      Returns the 1.3 "special" big port number (u32) equivalent to the given 1.0 "special" port number (u16). This will be null if the given port number is not "special".

      For example:

               BigPortNumber max = Port.equivalentSpecial(Port.MAX_V10);
               assert(Port.MAX.equals(max));

      Parameters:
        `pn` - the 1.0 special port number
      Returns:
        the equivalent 1.3 special big port number; or null

    - #### equivalentSpecial

          public static PortNumber equivalentSpecial(BigPortNumber bpn)

      Returns the 1.0 "special" port number (u16) equivalent to the given 1.3 "special" big port number (u32). This will be null if the given port number is not "special".

      For example:

               PortNumber max = Port.equivalentSpecial(Port.MAX);
               assert(Port.MAX_V10.equals(max));

      Parameters:
        `bpn` - the 1.3 special big port number
      Returns:
        the equivalent 1.0 special port number; or null

    - #### validatePortValue

          public static void validatePortValue(BigPortNumber bpn,
                               ProtocolVersion pv)

      Validates that the given port number is an acceptable value for encoding as a port number for the given protocol. If all is good, returns silently; else throws an exception.

      Note that in 1.0, port numbers are u16.

      Parameters:
        `bpn` - the big port number to validate
        `pv` - the protocol version
      Throws:
        `IllegalArgumentException` - if the port number is invalid for the specified version

    - #### isStandardPort

          public static boolean isStandardPort(BigPortNumber bpn,
                               ProtocolVersion pv)

      Returns true if the given port number is in the range 1 to MAX; false otherwise.
      Parameters:
        `bpn` - the port number
        `pv` - the protocol version
      Returns:
        true if the port number is in the range 1 to MAX

    - #### logicalName

          public static String logicalName(BigPortNumber port,
                           ProtocolVersion pv)

      Returns the logical name of the port, or null if the port number is not a special value (for the given protocol version).
      Parameters:
        `port` - the port number
        `pv` - the protocol version
      Returns:
        the logical name of the port (or null)

    - #### getBigPortNumber

          public static BigPortNumber getBigPortNumber(String portNumber)

      Returns the port, given its string representation, which can include a logical name or the numeric representation of the port.
      Parameters:
        `portNumber` - string representation of the port
      Returns:
        port number, or null if portNumber is null or empty

    - #### getPortNumber

          public static PortNumber getPortNumber(String portNumber)

      Returns the port, given its string representation, which can include a logical name or the numeric representation of the port.
      Parameters:
        `portNumber` - string representation of the port
      Returns:
        port number, or null if portNumber is null or empty

Copyright © 2014. All Rights Reserved.