Package org.onlab.packet
Class MacAddress
- java.lang.Object
-
- org.onlab.packet.MacAddress
-
public class MacAddress extends Object
The class representing MAC address.
-
-
Field Summary
Fields Modifier and Type Field Description static MacAddress
BROADCAST
Broadcast MAC address.static MacAddress
EXACT_MASK
Mask that indicates exact match on the MacAddress.static MacAddress
IPV4_MULTICAST
IPv4 multicast MAC address.static MacAddress
IPV4_MULTICAST_MASK
IPv4 multicast MAC mask.static MacAddress
IPV6_MULTICAST
IPv6 multicast MAC address.static MacAddress
IPV6_MULTICAST_MASK
IPv6 multicast MAC mask.static MacAddress
LACP
LACP MAC address.static Set<MacAddress>
LLDP
A set of LLDP MAC addresses.static int
MAC_ADDRESS_LENGTH
static MacAddress
NONE
Dummy MAC address.static MacAddress
ONOS
First MAC address in ONOS OUI range.static MacAddress
ONOS_LLDP
ONOS LLDP MAC address with slow protocol destination address.static MacAddress
ZERO
All-zero MAC address.
-
Constructor Summary
Constructors Constructor Description MacAddress(byte[] address)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
int
hashCode()
boolean
inRange(MacAddress macAddr, MacAddress maskAddr)
Checks if the Mac Address is inside a range defined by macAddr and mask.boolean
isBroadcast()
Returnstrue
if the MAC address is the broadcast address.boolean
isLldp()
Returns true if this MAC address is used by link layer discovery protocol.boolean
isMulticast()
Returnstrue
if the MAC address is the multicast address.boolean
isOnos()
Returns true if the Organizationally Unique Identifier (OUI) of this MAC address matches ONOS OUI.int
length()
Returns the length of theMACAddress
.byte[]
oui()
Returns the Organizationally Unique Identifier (OUI) of this MAC address.byte[]
toBytes()
Returns the value of theMACAddress
as abyte
array.long
toLong()
Returns the value of theMACAddress
as along
.String
toString()
String
toStringNoColon()
static MacAddress
valueOf(byte[] address)
Returns a MAC address instance representing the specifiedbyte
array.static MacAddress
valueOf(long address)
Returns a MAC address instance representing the specifiedlong
value.static MacAddress
valueOf(String address)
Returns a MAC address instance representing the value of the specifiedString
.
-
-
-
Field Detail
-
ONOS
public static final MacAddress ONOS
First MAC address in ONOS OUI range.
-
NONE
public static final MacAddress NONE
Dummy MAC address. We use the first MAC address in ONOS OUI range as the dummy MAC address.
-
ONOS_LLDP
public static final MacAddress ONOS_LLDP
ONOS LLDP MAC address with slow protocol destination address.
-
ZERO
public static final MacAddress ZERO
All-zero MAC address.
-
BROADCAST
public static final MacAddress BROADCAST
Broadcast MAC address.
-
EXACT_MASK
public static final MacAddress EXACT_MASK
Mask that indicates exact match on the MacAddress.
-
IPV4_MULTICAST
public static final MacAddress IPV4_MULTICAST
IPv4 multicast MAC address.
-
IPV4_MULTICAST_MASK
public static final MacAddress IPV4_MULTICAST_MASK
IPv4 multicast MAC mask.
-
IPV6_MULTICAST
public static final MacAddress IPV6_MULTICAST
IPv6 multicast MAC address.
-
IPV6_MULTICAST_MASK
public static final MacAddress IPV6_MULTICAST_MASK
IPv6 multicast MAC mask.
-
LLDP
public static final Set<MacAddress> LLDP
A set of LLDP MAC addresses.
-
LACP
public static final MacAddress LACP
LACP MAC address.
-
MAC_ADDRESS_LENGTH
public static final int MAC_ADDRESS_LENGTH
- See Also:
- Constant Field Values
-
-
Method Detail
-
valueOf
public static MacAddress valueOf(String address)
Returns a MAC address instance representing the value of the specifiedString
.- Parameters:
address
- the String representation of the MAC Address to be parsed.- Returns:
- a MAC Address instance representing the value of the specified
String
. - Throws:
IllegalArgumentException
- if the string cannot be parsed as a MAC address.
-
valueOf
public static MacAddress valueOf(byte[] address)
Returns a MAC address instance representing the specifiedbyte
array.- Parameters:
address
- the byte array to be parsed.- Returns:
- a MAC address instance representing the specified
byte
array. - Throws:
IllegalArgumentException
- if the byte array cannot be parsed as a MAC address.
-
valueOf
public static MacAddress valueOf(long address)
Returns a MAC address instance representing the specifiedlong
value. The lower 48 bits of the long value are used to parse as a MAC address.- Parameters:
address
- the long value to be parsed. The lower 48 bits are used for a MAC address.- Returns:
- a MAC address instance representing the specified
long
value. - Throws:
IllegalArgumentException
- if the long value cannot be parsed as a MAC address.
-
length
public int length()
Returns the length of theMACAddress
.- Returns:
- the length of the
MACAddress
.
-
toBytes
public byte[] toBytes()
Returns the value of theMACAddress
as abyte
array.- Returns:
- the numeric value represented by this object after conversion to
type
byte
array.
-
toLong
public long toLong()
Returns the value of theMACAddress
as along
.- Returns:
- the numeric value represented by this object after conversion to
type
long
.
-
isBroadcast
public boolean isBroadcast()
Returnstrue
if the MAC address is the broadcast address.- Returns:
true
if the MAC address is the broadcast address.
-
isMulticast
public boolean isMulticast()
Returnstrue
if the MAC address is the multicast address.- Returns:
true
if the MAC address is the multicast address.
-
isLldp
public boolean isLldp()
Returns true if this MAC address is used by link layer discovery protocol.- Returns:
- true if this MAC is LLDP MAC.
-
isOnos
public boolean isOnos()
Returns true if the Organizationally Unique Identifier (OUI) of this MAC address matches ONOS OUI.- Returns:
- true if the OUI of this MAC address matches ONOS OUI.
-
oui
public byte[] oui()
Returns the Organizationally Unique Identifier (OUI) of this MAC address.- Returns:
- the OUI of this MAC address.
-
toStringNoColon
public String toStringNoColon()
- Returns:
- MAC address in string representation without colons (useful for radix tree storage)
-
inRange
public boolean inRange(MacAddress macAddr, MacAddress maskAddr)
Checks if the Mac Address is inside a range defined by macAddr and mask.- Parameters:
macAddr
- the mac addressmaskAddr
- the mask- Returns:
- true if in range, false otherwise.
-
-