Class Packet
- java.lang.Object
-
- org.opendaylight.openflowplugin.libraries.liblldp.Packet
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
corrupted
protected Map<String,org.apache.commons.lang3.tuple.Pair<Integer,Integer>>
hdrFieldCoordMap
protected Map<String,byte[]>
hdrFieldsMap
protected Packet
parent
protected Packet
payload
protected Class<? extends Packet>
payloadClass
protected byte[]
rawPayload
protected boolean
writeAccess
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Packet
deserialize(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
equals(Object obj)
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
getHeaderSize()
Gets the header length in bits.Packet
getParent()
Packet
getPayload()
byte[]
getRawPayload()
Returns the raw payload carried by this packet in case payload was not parsed.int
hashCode()
boolean
isCorrupted()
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[]
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.void
setHeaderField(String headerField, byte[] readValue)
void
setParent(Packet parent)
void
setPayload(Packet payload)
void
setRawPayload(byte[] bytes)
Set a raw payload in the packet class.String
toString()
-
-
-
Field Detail
-
writeAccess
protected boolean writeAccess
-
corrupted
protected boolean corrupted
-
parent
protected Packet parent
-
payload
protected Packet payload
-
rawPayload
protected byte[] rawPayload
-
hdrFieldCoordMap
protected Map<String,org.apache.commons.lang3.tuple.Pair<Integer,Integer>> hdrFieldCoordMap
-
-
Method Detail
-
getParent
public Packet getParent()
-
getPayload
public Packet getPayload()
-
setParent
public void setParent(Packet parent)
-
setPayload
public void setPayload(Packet payload)
-
setHeaderField
public void setHeaderField(String headerField, byte[] readValue)
-
deserialize
public Packet deserialize(byte[] data, int bitOffset, int size) throws PacketException
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
public byte[] serialize() throws PacketException
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
protected void postSerializeCustomOperation(byte[] myBytes) throws PacketException
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
public int getfieldOffset(String fieldName)
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
public int getfieldnumBits(String fieldName)
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
-
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
-
-