Package org.onlab.packet
Class ARP
- java.lang.Object
-
- org.onlab.packet.BasePacket
-
- org.onlab.packet.ARP
-
- All Implemented Interfaces:
IPacket
public class ARP extends BasePacket
Representation of an ARP Packet.
-
-
Field Summary
Fields Modifier and Type Field Description protected bytehardwareAddressLengthprotected shorthardwareTypestatic shortHW_TYPE_ETHERNETstatic shortINITIAL_HEADER_LENGTHstatic shortOP_RARP_REPLYstatic shortOP_RARP_REQUESTstatic shortOP_REPLYstatic shortOP_REQUESTprotected shortopCodestatic shortPROTO_TYPE_IPprotected byteprotocolAddressLengthprotected shortprotocolTypeprotected byte[]senderHardwareAddressprotected byte[]senderProtocolAddressprotected byte[]targetHardwareAddressprotected byte[]targetProtocolAddress-
Fields inherited from class org.onlab.packet.BasePacket
parent, payload
-
-
Constructor Summary
Constructors Constructor Description ARP()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static EthernetbuildArpReply(Ip4Address srcIp, MacAddress srcMac, Ethernet request)Builds an ARP reply based on a request.static EthernetbuildArpRequest(byte[] senderMacAddress, byte[] senderIpAddress, byte[] targetMacAddress, byte[] targetIpAddress, byte[] destinationMacAddress, short vlanId)Builds an ARP request using the supplied parameters.static EthernetbuildArpRequest(byte[] senderMacAddress, byte[] senderIpAddress, byte[] targetIpAddress, short vlanId)Builds an ARP request using the supplied parameters.static Deserializer<ARP>deserializer()Deserializer function for ARP packets.ARPduplicate()Make an exact copy of the ARP packet.booleanequals(java.lang.Object obj)bytegetHardwareAddressLength()shortgetHardwareType()shortgetOpCode()bytegetProtocolAddressLength()shortgetProtocolType()byte[]getSenderHardwareAddress()byte[]getSenderProtocolAddress()byte[]getTargetHardwareAddress()byte[]getTargetProtocolAddress()inthashCode()booleanisGratuitous()byte[]serialize()Sets all payloads parent packet if applicable, then serializes this packet and all payloads.ARPsetHardwareAddressLength(byte hwAddressLength)ARPsetHardwareType(short hwType)ARPsetOpCode(short op)ARPsetProtocolAddressLength(byte protoAddressLength)ARPsetProtocolType(short protoType)ARPsetSenderHardwareAddress(byte[] senderHWAddress)ARPsetSenderProtocolAddress(byte[] senderProtoAddress)ARPsetSenderProtocolAddress(int address)ARPsetTargetHardwareAddress(byte[] targetHWAddress)ARPsetTargetProtocolAddress(byte[] targetProtoAddress)ARPsetTargetProtocolAddress(int address)java.lang.StringtoString()-
Methods inherited from class org.onlab.packet.BasePacket
clone, getParent, getPayload, resetChecksum, setParent, setPayload
-
-
-
-
Field Detail
-
HW_TYPE_ETHERNET
public static final short HW_TYPE_ETHERNET
- See Also:
- Constant Field Values
-
PROTO_TYPE_IP
public static final short PROTO_TYPE_IP
- See Also:
- Constant Field Values
-
OP_REQUEST
public static final short OP_REQUEST
- See Also:
- Constant Field Values
-
OP_REPLY
public static final short OP_REPLY
- See Also:
- Constant Field Values
-
OP_RARP_REQUEST
public static final short OP_RARP_REQUEST
- See Also:
- Constant Field Values
-
OP_RARP_REPLY
public static final short OP_RARP_REPLY
- See Also:
- Constant Field Values
-
INITIAL_HEADER_LENGTH
public static final short INITIAL_HEADER_LENGTH
- See Also:
- Constant Field Values
-
hardwareType
protected short hardwareType
-
protocolType
protected short protocolType
-
hardwareAddressLength
protected byte hardwareAddressLength
-
protocolAddressLength
protected byte protocolAddressLength
-
opCode
protected short opCode
-
senderHardwareAddress
protected byte[] senderHardwareAddress
-
senderProtocolAddress
protected byte[] senderProtocolAddress
-
targetHardwareAddress
protected byte[] targetHardwareAddress
-
targetProtocolAddress
protected byte[] targetProtocolAddress
-
-
Method Detail
-
getHardwareType
public short getHardwareType()
- Returns:
- the hardwareType
-
setHardwareType
public ARP setHardwareType(short hwType)
- Parameters:
hwType- the hardwareType to set- Returns:
- this
-
getProtocolType
public short getProtocolType()
- Returns:
- the protocolType
-
setProtocolType
public ARP setProtocolType(short protoType)
- Parameters:
protoType- the protocolType to set- Returns:
- this
-
getHardwareAddressLength
public byte getHardwareAddressLength()
- Returns:
- the hardwareAddressLength
-
setHardwareAddressLength
public ARP setHardwareAddressLength(byte hwAddressLength)
- Parameters:
hwAddressLength- the hardwareAddressLength to set- Returns:
- this
-
getProtocolAddressLength
public byte getProtocolAddressLength()
- Returns:
- the protocolAddressLength
-
setProtocolAddressLength
public ARP setProtocolAddressLength(byte protoAddressLength)
- Parameters:
protoAddressLength- the protocolAddressLength to set- Returns:
- this
-
getOpCode
public short getOpCode()
- Returns:
- the opCode
-
setOpCode
public ARP setOpCode(short op)
- Parameters:
op- the opCode to set- Returns:
- this
-
getSenderHardwareAddress
public byte[] getSenderHardwareAddress()
- Returns:
- the senderHardwareAddress
-
setSenderHardwareAddress
public ARP setSenderHardwareAddress(byte[] senderHWAddress)
- Parameters:
senderHWAddress- the senderHardwareAddress to set- Returns:
- this
-
getSenderProtocolAddress
public byte[] getSenderProtocolAddress()
- Returns:
- the senderProtocolAddress
-
setSenderProtocolAddress
public ARP setSenderProtocolAddress(byte[] senderProtoAddress)
- Parameters:
senderProtoAddress- the senderProtocolAddress to set- Returns:
- this
-
setSenderProtocolAddress
public ARP setSenderProtocolAddress(int address)
-
getTargetHardwareAddress
public byte[] getTargetHardwareAddress()
- Returns:
- the targetHardwareAddress
-
setTargetHardwareAddress
public ARP setTargetHardwareAddress(byte[] targetHWAddress)
- Parameters:
targetHWAddress- the targetHardwareAddress to set- Returns:
- this
-
getTargetProtocolAddress
public byte[] getTargetProtocolAddress()
- Returns:
- the targetProtocolAddress
-
isGratuitous
public boolean isGratuitous()
- Returns:
- True if gratuitous ARP (SPA = TPA), false otherwise
-
setTargetProtocolAddress
public ARP setTargetProtocolAddress(byte[] targetProtoAddress)
- Parameters:
targetProtoAddress- the targetProtocolAddress to set- Returns:
- this
-
setTargetProtocolAddress
public ARP setTargetProtocolAddress(int address)
-
serialize
public byte[] serialize()
Description copied from interface:IPacketSets all payloads parent packet if applicable, then serializes this packet and all payloads.- Returns:
- a byte[] containing this packet and payloads
-
hashCode
public int hashCode()
- Overrides:
hashCodein classBasePacket
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classBasePacket
-
buildArpRequest
public static Ethernet buildArpRequest(byte[] senderMacAddress, byte[] senderIpAddress, byte[] targetMacAddress, byte[] targetIpAddress, byte[] destinationMacAddress, short vlanId)
Builds an ARP request using the supplied parameters.- Parameters:
senderMacAddress- the mac address of the sendersenderIpAddress- the ip address of the sendertargetMacAddress- the mac address of the targettargetIpAddress- the ip address to resolvedestinationMacAddress- the mac address put in Ethernet headervlanId- the vlan id- Returns:
- the Ethernet frame containing the ARP request
-
buildArpRequest
public static Ethernet buildArpRequest(byte[] senderMacAddress, byte[] senderIpAddress, byte[] targetIpAddress, short vlanId)
Builds an ARP request using the supplied parameters.- Parameters:
senderMacAddress- the mac address of the sendersenderIpAddress- the ip address of the sendertargetIpAddress- the ip address to resolvevlanId- the vlan id- Returns:
- the Ethernet frame containing the ARP request
-
buildArpReply
public static Ethernet buildArpReply(Ip4Address srcIp, MacAddress srcMac, Ethernet request)
Builds an ARP reply based on a request.- Parameters:
srcIp- the IP address to use as the reply sourcesrcMac- the MAC address to use as the reply sourcerequest- the ARP request we got- Returns:
- an Ethernet frame containing the ARP reply
-
deserializer
public static Deserializer<ARP> deserializer()
Deserializer function for ARP packets.- Returns:
- deserializer function
-
duplicate
public ARP duplicate()
Make an exact copy of the ARP packet.- Returns:
- copy of the packet
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-