Package org.onlab.packet
Class Ethernet
- java.lang.Object
-
- org.onlab.packet.BasePacket
-
- org.onlab.packet.Ethernet
-
- All Implemented Interfaces:
IPacket
public class Ethernet extends BasePacket
Ethernet Packet.
-
-
Field Summary
Fields Modifier and Type Field Description static short
DATALAYER_ADDRESS_LENGTH
protected MacAddress
destinationMACAddress
static short
ETHERNET_HEADER_LENGTH
protected short
etherType
static short
MPLS_MULTICAST
static short
MPLS_UNICAST
protected boolean
pad
protected byte
priorityCode
protected byte
qInQPriorityCode
protected short
qinqTPID
protected short
qinqVID
protected MacAddress
sourceMACAddress
static short
TYPE_ARP
static short
TYPE_BSN
static short
TYPE_IPV4
static short
TYPE_IPV6
static short
TYPE_LLDP
static short
TYPE_PPPOED
static short
TYPE_QINQ
static short
TYPE_RARP
static short
TYPE_VLAN
static short
VLAN_HEADER_LENGTH
static short
VLAN_UNTAGGED
protected short
vlanID
-
Fields inherited from class org.onlab.packet.BasePacket
parent, payload
-
-
Constructor Summary
Constructors Constructor Description Ethernet()
By default, set Ethernet to untagged.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static String
bytesToHex(byte[] in)
static Deserializer<Ethernet>
deserializer()
Deserializer function for Ethernet packets.Ethernet
duplicate()
Make an exact copy of the ethernet packet.boolean
equals(Object obj)
MacAddress
getDestinationMAC()
Gets the destination MAC address.byte[]
getDestinationMACAddress()
Gets the destination MAC address.short
getEtherType()
Gets the Ethernet type.byte
getPriorityCode()
Gets the priority code.byte
getQinQPriorityCode()
Gets the QinQ priority code.short
getQinQTPID()
Gets the QinQ TPID.short
getQinQVID()
Gets the QinQ VLAN ID.MacAddress
getSourceMAC()
Gets the source MAC address.byte[]
getSourceMACAddress()
Gets the source MAC address.short
getVlanID()
Gets the VLAN ID.int
hashCode()
boolean
isBroadcast()
static boolean
isMACAddress(String macAddress)
Checks to see if a string is a valid MAC address.boolean
isMulticast()
boolean
isPad()
Pad this packet to 60 bytes minimum, filling with zeros?byte[]
serialize()
Sets all payloads parent packet if applicable, then serializes this packet and all payloads.Ethernet
setDestinationMACAddress(byte[] destMac)
Sets the destination MAC address.Ethernet
setDestinationMACAddress(String destMac)
Sets the destination MAC address.Ethernet
setDestinationMACAddress(MacAddress destMac)
Sets the destination MAC address.Ethernet
setEtherType(short ethType)
Sets the Ethernet type.Ethernet
setPad(boolean pd)
Pad this packet to 60 bytes minimum, filling with zeros?Ethernet
setPriorityCode(byte priority)
Sets the priority code.Ethernet
setQinQPriorityCode(byte priority)
Sets the QinQ priority code.Ethernet
setQinQTPID(short tpId)
Sets the QinQ TPID.Ethernet
setQinQVID(short vlan)
Sets the QinQ VLAN ID.Ethernet
setSourceMACAddress(byte[] sourceMac)
Sets the source MAC address.Ethernet
setSourceMACAddress(String sourceMac)
Sets the source MAC address.Ethernet
setSourceMACAddress(MacAddress sourceMac)
Sets the source MAC address.Ethernet
setVlanID(short vlan)
Sets the VLAN ID.static byte[]
toByteArray(long macAddress)
Converts a long MAC address to a byte array.static long
toLong(byte[] macAddress)
Accepts a MAC address and returns the corresponding long, where the MAC bytes are set on the lower order bytes of the long.static byte[]
toMACAddress(String macAddress)
Accepts a MAC address of the form 00:aa:11:bb:22:cc, case does not matter, and returns a corresponding byte[].String
toString()
-
Methods inherited from class org.onlab.packet.BasePacket
clone, getParent, getPayload, resetChecksum, setParent, setPayload
-
-
-
-
Field Detail
-
TYPE_ARP
public static final short TYPE_ARP
-
TYPE_RARP
public static final short TYPE_RARP
-
TYPE_IPV4
public static final short TYPE_IPV4
-
TYPE_IPV6
public static final short TYPE_IPV6
-
TYPE_LLDP
public static final short TYPE_LLDP
-
TYPE_VLAN
public static final short TYPE_VLAN
-
TYPE_QINQ
public static final short TYPE_QINQ
-
TYPE_BSN
public static final short TYPE_BSN
-
TYPE_PPPOED
public static final short TYPE_PPPOED
-
MPLS_UNICAST
public static final short MPLS_UNICAST
-
MPLS_MULTICAST
public static final short MPLS_MULTICAST
-
VLAN_UNTAGGED
public static final short VLAN_UNTAGGED
- See Also:
- Constant Field Values
-
ETHERNET_HEADER_LENGTH
public static final short ETHERNET_HEADER_LENGTH
- See Also:
- Constant Field Values
-
VLAN_HEADER_LENGTH
public static final short VLAN_HEADER_LENGTH
- See Also:
- Constant Field Values
-
DATALAYER_ADDRESS_LENGTH
public static final short DATALAYER_ADDRESS_LENGTH
- See Also:
- Constant Field Values
-
destinationMACAddress
protected MacAddress destinationMACAddress
-
sourceMACAddress
protected MacAddress sourceMACAddress
-
priorityCode
protected byte priorityCode
-
qInQPriorityCode
protected byte qInQPriorityCode
-
vlanID
protected short vlanID
-
qinqVID
protected short qinqVID
-
qinqTPID
protected short qinqTPID
-
etherType
protected short etherType
-
pad
protected boolean pad
-
-
Method Detail
-
getDestinationMACAddress
public byte[] getDestinationMACAddress()
Gets the destination MAC address.- Returns:
- the destination MAC as a byte array
-
getDestinationMAC
public MacAddress getDestinationMAC()
Gets the destination MAC address.- Returns:
- the destination MAC
-
setDestinationMACAddress
public Ethernet setDestinationMACAddress(MacAddress destMac)
Sets the destination MAC address.- Parameters:
destMac
- the destination MAC to set- Returns:
- the Ethernet frame
-
setDestinationMACAddress
public Ethernet setDestinationMACAddress(byte[] destMac)
Sets the destination MAC address.- Parameters:
destMac
- the destination MAC to set- Returns:
- the Ethernet frame
-
setDestinationMACAddress
public Ethernet setDestinationMACAddress(String destMac)
Sets the destination MAC address.- Parameters:
destMac
- the destination MAC to set- Returns:
- the Ethernet frame
-
getSourceMACAddress
public byte[] getSourceMACAddress()
Gets the source MAC address.- Returns:
- the source MACAddress as a byte array
-
getSourceMAC
public MacAddress getSourceMAC()
Gets the source MAC address.- Returns:
- the source MACAddress
-
setSourceMACAddress
public Ethernet setSourceMACAddress(MacAddress sourceMac)
Sets the source MAC address.- Parameters:
sourceMac
- the source MAC to set- Returns:
- the Ethernet frame
-
setSourceMACAddress
public Ethernet setSourceMACAddress(byte[] sourceMac)
Sets the source MAC address.- Parameters:
sourceMac
- the source MAC to set- Returns:
- the Ethernet frame
-
setSourceMACAddress
public Ethernet setSourceMACAddress(String sourceMac)
Sets the source MAC address.- Parameters:
sourceMac
- the source MAC to set- Returns:
- the Ethernet frame
-
getPriorityCode
public byte getPriorityCode()
Gets the priority code.- Returns:
- the priorityCode
-
setPriorityCode
public Ethernet setPriorityCode(byte priority)
Sets the priority code.- Parameters:
priority
- the priorityCode to set- Returns:
- the Ethernet frame
-
getQinQPriorityCode
public byte getQinQPriorityCode()
Gets the QinQ priority code.- Returns:
- the qInQPriorityCode
-
setQinQPriorityCode
public Ethernet setQinQPriorityCode(byte priority)
Sets the QinQ priority code.- Parameters:
priority
- the priorityCode to set- Returns:
- the Ethernet frame
-
getVlanID
public short getVlanID()
Gets the VLAN ID.- Returns:
- the vlanID
-
setVlanID
public Ethernet setVlanID(short vlan)
Sets the VLAN ID.- Parameters:
vlan
- the vlanID to set- Returns:
- the Ethernet frame
-
getQinQVID
public short getQinQVID()
Gets the QinQ VLAN ID.- Returns:
- the QinQ vlanID
-
setQinQVID
public Ethernet setQinQVID(short vlan)
Sets the QinQ VLAN ID.- Parameters:
vlan
- the vlanID to set- Returns:
- the Ethernet frame
-
getQinQTPID
public short getQinQTPID()
Gets the QinQ TPID.- Returns:
- the QinQ TPID
-
setQinQTPID
public Ethernet setQinQTPID(short tpId)
Sets the QinQ TPID.- Parameters:
tpId
- the TPID to set- Returns:
- the Ethernet frame
-
getEtherType
public short getEtherType()
Gets the Ethernet type.- Returns:
- the etherType
-
setEtherType
public Ethernet setEtherType(short ethType)
Sets the Ethernet type.- Parameters:
ethType
- the etherType to set- Returns:
- the Ethernet frame
-
isBroadcast
public boolean isBroadcast()
- Returns:
- True if the Ethernet frame is broadcast, false otherwise
-
isMulticast
public boolean isMulticast()
- Returns:
- True is the Ethernet frame is multicast, False otherwise
-
isPad
public boolean isPad()
Pad this packet to 60 bytes minimum, filling with zeros?- Returns:
- the pad
-
setPad
public Ethernet setPad(boolean pd)
Pad this packet to 60 bytes minimum, filling with zeros?- Parameters:
pd
- the pad to set- Returns:
- this
-
serialize
public byte[] serialize()
Description copied from interface:IPacket
Sets all payloads parent packet if applicable, then serializes this packet and all payloads.- Returns:
- a byte[] containing this packet and payloads
-
isMACAddress
public static boolean isMACAddress(String macAddress)
Checks to see if a string is a valid MAC address.- Parameters:
macAddress
- string to test if it is a valid MAC- Returns:
- True if macAddress is a valid MAC, False otherwise
-
toMACAddress
public static byte[] toMACAddress(String macAddress)
Accepts a MAC address of the form 00:aa:11:bb:22:cc, case does not matter, and returns a corresponding byte[].- Parameters:
macAddress
- The MAC address to convert into a byte array- Returns:
- The macAddress as a byte array
-
toLong
public static long toLong(byte[] macAddress)
Accepts a MAC address and returns the corresponding long, where the MAC bytes are set on the lower order bytes of the long.- Parameters:
macAddress
- MAC address as a byte array- Returns:
- a long containing the mac address bytes
-
toByteArray
public static byte[] toByteArray(long macAddress)
Converts a long MAC address to a byte array.- Parameters:
macAddress
- MAC address set on the lower order bytes of the long- Returns:
- the bytes of the mac address
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classBasePacket
-
equals
public boolean equals(Object obj)
- Overrides:
equals
in classBasePacket
-
bytesToHex
public static String bytesToHex(byte[] in)
-
deserializer
public static Deserializer<Ethernet> deserializer()
Deserializer function for Ethernet packets.- Returns:
- deserializer function
-
duplicate
public Ethernet duplicate()
Make an exact copy of the ethernet packet.- Returns:
- copy of the packet
-
-