com.h3c.of.lib.dt

## Class DataPathId

- java.lang.Object
- - com.h3c.util.cache.CacheableDataType
  - - com.h3c.of.lib.dt.DataPathId

- All Implemented Interfaces:
    Serializable, Comparable<DataPathId>

      public final class DataPathId
      extends CacheableDataType
      implements Comparable<DataPathId>

  Represents a Data Path Identifier; an aggregation of a `virtual identifier` and a `MAC address`.

  All constructors for this class are private. Creating instances of `DataPathId` is done via the static methods on the class.

  Instances of this class are immutable, making them inherently thread-safe.

  This class overrides `equals(java.lang.Object)` and `hashCode()` so that it plays nicely with the Collection classes.

  This class implements the `Comparable` interface to ensure that a sorted list is presented in an intuitive order.

  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `LENGTH_IN_BYTES` The length of a datapath id in bytes.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `compareTo(DataPathId o)`
    `boolean` | `equals(Object o)`
    `MacAddress` | `getMacAddress()` Returns the MAC address.
    `VId` | `getVid()` Returns the virtual identifier.
    `int` | `hashBucket(int nBuckets)` Returns a bucket index, based on the hash code of this dpid instance and the specified number of buckets.
    `int` | `hashCode()`
    `String` | `toAltString()` Returns an alternative string representation for this datapath ID.
    `byte[]` | `toByteArray()` Returns a byte array representation of this datapath ID.
    `long` | `toLong()` Returns a long value representation of this datapath ID.
    `String` | `toString()`
    `static DataPathId` | `valueOf(byte[] bytes)` Returns a datapath ID instance from the given byte array.
    `static DataPathId` | `valueOf(long value)` Returns a datapath ID instance from the given long value.
    `static DataPathId` | `valueOf(String spec)` Returns a datpath ID instance that encapsulates the virtual identifier and MAC address expressed in the given string specification.
    `static DataPathId` | `valueOf(VId vid, MacAddress mac)` Returns a datapath ID instance that encapsulates the given virtual identifier and MAC address.

    - ### Methods inherited from class com.h3c.util.cache.CacheableDataType

      `getRefQ, keyFromBytes`

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

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

- - ### Field Detail

    - #### LENGTH_IN_BYTES

          public static final int LENGTH_IN_BYTES

      The length of a datapath id in bytes.
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### toAltString

          public String toAltString()

      Returns an alternative string representation for this datapath ID.
      Returns:
        an alternative string representation

    - #### getVid

          public VId getVid()

      Returns the virtual identifier.
      Returns:
        the virtual identifier

    - #### getMacAddress

          public MacAddress getMacAddress()

      Returns the MAC address.
      Returns:
        the MAC address

    - #### toLong

          public long toLong()

      Returns a long value representation of this datapath ID. Note that this representation is simply treated as an opaque 64-bit value.
      Returns:
        a long value representation of this datapath ID

    - #### toByteArray

          public byte[] toByteArray()

      Returns a byte array representation of this datapath ID. The array is 8 bytes long, where the first two bytes correspond to the virtual identifier, and the last six bytes correspond to the MAC address.
      Returns:
        a byte array representation of this datapath ID

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### hashBucket

          public int hashBucket(int nBuckets)

      Returns a bucket index, based on the hash code of this dpid instance and the specified number of buckets.

      For N buckets, the value returned will be in the range 0 .. N-1; the value is deterministic, meaning that the same value is always returned for a specific value of N.

      Parameters:
        `nBuckets` - the number of buckets
      Returns:
        the hashed bucket index

    - #### compareTo

          public int compareTo(DataPathId o)

      Specified by:
        `compareTo` in interface `Comparable<DataPathId>`

    - #### valueOf

          public static DataPathId valueOf(VId vid,
                           MacAddress mac)

      Returns a datapath ID instance that encapsulates the given virtual identifier and MAC address.
      Parameters:
        `vid` - the virtual identifier
        `mac` - the MAC address
      Returns:
        the datapath ID
      Throws:
        `NullPointerException` - if either parameter is null

    - #### valueOf

          public static DataPathId valueOf(String spec)

      Returns a datpath ID instance that encapsulates the virtual identifier and MAC address expressed in the given string specification.

      The string spec can take three basic forms:

      - `"<virtual-id>/<mac-address>"`
      - `"<16-char-hex>"`
      - `"<colon-delim-hex>"`
      where `virtual-id` is an integer in the range `0..65535` (or `0x0..0xffff`), `mac-address` is a MAC address format accepted by `MacAddress.valueOf(String)`, `16-char-hex` is a 16-digit hex number, and `colon-delim-hex` is a 16-digit hex number with colons between each byte.

      For example, the following statements all yield the same value:

           DataPathId dpid = DataPathId.valueOf("123/00:05:53:AF:AA:C0");
           DataPathId same = DataPathId.valueOf("0x7b/000553:afaac0");
           DataPathId also = DataPathId.valueOf("007b000553AFAAC0");
           DataPathId copy = DataPathId.valueOf("00:7B:00:05:53:AF:AA:C0");

      Parameters:
        `spec` - the string specification
      Returns:
        the datapath ID instance
      Throws:
        `NullPointerException` - if spec is null
        `IllegalArgumentException` - if spec is malformed

    - #### valueOf

          public static DataPathId valueOf(byte[] bytes)

      Returns a datapath ID instance from the given byte array. The array is expected to be 8 bytes long.

      The first two bytes are interpreted as a `VId`, and the remaining six bytes are interpreted as a `MacAddress`.

      For example:

           int B = 256;
           byte[] bytes = new byte[] {
               0, 123,                                    // VID
               0x00, 0x05, 0x53, 0xaf-B, 0xaa-B, 0xc0-B   // MAC
           };

           DataPathId dpid = DataPathId.valueOf(bytes);

      Parameters:
        `bytes` - the byte array
      Returns:
        the datapath ID
      Throws:
        `NullPointerException` - if the byte array is null
        `IllegalArgumentException` - if the byte array is not 8 bytes long

    - #### valueOf

          public static DataPathId valueOf(long value)

      Returns a datapath ID instance from the given long value. Note that the long is treated as an opaque value of 64 bits.
      Parameters:
        `value` - the value
      Returns:
        the datapath ID

Copyright © 2014. All Rights Reserved.