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 byte
hardwareAddressLength
protected short
hardwareType
static short
HW_TYPE_ETHERNET
static short
INITIAL_HEADER_LENGTH
static short
OP_RARP_REPLY
static short
OP_RARP_REQUEST
static short
OP_REPLY
static short
OP_REQUEST
protected short
opCode
static short
PROTO_TYPE_IP
protected byte
protocolAddressLength
protected short
protocolType
protected byte[]
senderHardwareAddress
protected byte[]
senderProtocolAddress
protected byte[]
targetHardwareAddress
protected 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 Ethernet
buildArpReply(Ip4Address srcIp, MacAddress srcMac, Ethernet request)
Builds an ARP reply based on a request.static Ethernet
buildArpRequest(byte[] senderMacAddress, byte[] senderIpAddress, byte[] targetMacAddress, byte[] targetIpAddress, byte[] destinationMacAddress, short vlanId)
Builds an ARP request using the supplied parameters.static Ethernet
buildArpRequest(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.ARP
duplicate()
Make an exact copy of the ARP packet.boolean
equals(java.lang.Object obj)
byte
getHardwareAddressLength()
short
getHardwareType()
short
getOpCode()
byte
getProtocolAddressLength()
short
getProtocolType()
byte[]
getSenderHardwareAddress()
byte[]
getSenderProtocolAddress()
byte[]
getTargetHardwareAddress()
byte[]
getTargetProtocolAddress()
int
hashCode()
boolean
isGratuitous()
byte[]
serialize()
Sets all payloads parent packet if applicable, then serializes this packet and all payloads.ARP
setHardwareAddressLength(byte hwAddressLength)
ARP
setHardwareType(short hwType)
ARP
setOpCode(short op)
ARP
setProtocolAddressLength(byte protoAddressLength)
ARP
setProtocolType(short protoType)
ARP
setSenderHardwareAddress(byte[] senderHWAddress)
ARP
setSenderProtocolAddress(byte[] senderProtoAddress)
ARP
setSenderProtocolAddress(int address)
ARP
setTargetHardwareAddress(byte[] targetHWAddress)
ARP
setTargetProtocolAddress(byte[] targetProtoAddress)
ARP
setTargetProtocolAddress(int address)
java.lang.String
toString()
-
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:IPacket
Sets 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:
hashCode
in classBasePacket
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in 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:
toString
in classjava.lang.Object
-
-