Class Packet
java.lang.Object
org.opendaylight.openflowplugin.libraries.liblldp.Packet
Abstract class which represents the generic network packet object. It provides
the basic methods which are common for all the packets, like serialize and
deserialize.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondeserialize
(byte[] data, int bitOffset, int size) This method deserializes the data bits obtained from the wire into the respective header and payload which are of type Packet.boolean
int
getfieldnumBits
(String fieldName) This method fetches the number of bits for header field specified by 'fieldname'.int
getfieldOffset
(String fieldName) This method fetches the start bit offset for header field specified by 'fieldname'.int
Gets the header length in bits.byte[]
Returns the raw payload carried by this packet in case payload was not parsed.int
hashCode()
boolean
Return whether the deserialized packet is to be considered corrupted.protected void
postDeserializeCustomOperation
(byte[] data, int startBitOffset) This method re-computes the checksum of the bits received on the wire and validates it with the checksum in the bits received Since the computation of checksum varies based on the protocol, this method is overridden.protected void
postSerializeCustomOperation
(byte[] myBytes) This method gets called at the end of the serialization process It is intended for the child packets to insert some custom data into the output byte stream which cannot be done or cannot be done efficiently during the normal Packet.serialize() path.byte[]
This method serializes the header and payload from the respective packet class, into a single stream of bytes to be sent on the wire.void
setHeaderField
(String headerField, byte[] readValue) void
void
setPayload
(Packet payload) void
setRawPayload
(byte[] bytes) Set a raw payload in the packet class.toString()
-
Field Details
-
writeAccess
protected final boolean writeAccess -
corrupted
protected boolean corrupted -
parent
-
payload
-
rawPayload
protected byte[] rawPayload -
hdrFieldCoordMap
-
hdrFieldsMap
-
payloadFactory
-
-
Constructor Details
-
Packet
public Packet() -
Packet
public Packet(boolean writeAccess)
-
-
Method Details
-
getParent
-
getPayload
-
setParent
-
setPayload
-
setHeaderField
-
deserialize
This method deserializes the data bits obtained from the wire into the respective header and payload which are of type Packet.- Parameters:
data
- - data from wire to deserializebitOffset
- bit position where packet header starts in data arraysize
- size of packet in bits- Returns:
- Packet
- Throws:
PacketException
- if deserialization fails
-
serialize
This method serializes the header and payload from the respective packet class, into a single stream of bytes to be sent on the wire.- Returns:
- The byte array representing the serialized Packet
- Throws:
PacketException
- if serialization fails
-
postSerializeCustomOperation
This method gets called at the end of the serialization process It is intended for the child packets to insert some custom data into the output byte stream which cannot be done or cannot be done efficiently during the normal Packet.serialize() path. An example is the checksum computation for IPv4- Parameters:
myBytes
- serialized bytes- Throws:
PacketException
- on failure
-
postDeserializeCustomOperation
protected void postDeserializeCustomOperation(byte[] data, int startBitOffset) throws PacketException This method re-computes the checksum of the bits received on the wire and validates it with the checksum in the bits received Since the computation of checksum varies based on the protocol, this method is overridden. Currently only IPv4 and ICMP do checksum computation and validation. TCP and UDP need to implement these if required.- Parameters:
data
- The byte stream representing the Ethernet framestartBitOffset
- The bit offset from where the byte array corresponding to this Packet starts in the frame- Throws:
PacketException
- on failure
-
getHeaderSize
public int getHeaderSize()Gets the header length in bits.- Returns:
- int the header length in bits
-
getfieldOffset
This method fetches the start bit offset for header field specified by 'fieldname'. The offset is present in the hdrFieldCoordMap of the respective packet class- Returns:
- Integer - startOffset of the requested field
-
getfieldnumBits
This method fetches the number of bits for header field specified by 'fieldname'. The numBits are present in the hdrFieldCoordMap of the respective packet class- Returns:
- Integer - number of bits of the requested field
-
toString
-
getRawPayload
public byte[] getRawPayload()Returns the raw payload carried by this packet in case payload was not parsed. Caller can call this function in case the getPaylod() returns null.- Returns:
- The raw payload if not parsable as an array of bytes, null otherwise
-
setRawPayload
public void setRawPayload(byte[] bytes) Set a raw payload in the packet class.- Parameters:
bytes
- The raw payload as byte array
-
isCorrupted
public boolean isCorrupted()Return whether the deserialized packet is to be considered corrupted. This is the case when the checksum computed after reconstructing the packet received from wire is not equal to the checksum read from the stream. For the Packet class which do not have a checksum field, this function will always return false.- Returns:
- true if the deserialized packet's recomputed checksum is not equal to the packet carried checksum
-
hashCode
public int hashCode() -
equals
-