Class Ethernet

  • All Implemented Interfaces:
    IPacket

    public class Ethernet
    extends BasePacket
    Ethernet Packet.
    • 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
      • MPLS_UNICAST

        public static final short MPLS_UNICAST
      • MPLS_MULTICAST

        public static final short MPLS_MULTICAST
      • ETHERNET_HEADER_LENGTH

        public static final short ETHERNET_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
    • Constructor Detail

      • Ethernet

        public Ethernet()
        By default, set Ethernet to untagged.
    • 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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class BasePacket
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • bytesToHex

        public static java.lang.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