public abstract class Packet extends Object implements Cloneable
Packet
is an 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.
This class is provided only for VTN internal use. This class may be changed without any notice.
Modifier and Type | Class and Description |
---|---|
protected static class |
Packet.HeaderField
HeaderField describes the location of the header field in the
packet header. |
Modifier and Type | Method and Description |
---|---|
Packet |
clone()
Return a deep copy of this packet.
|
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 o)
Determine whether the given object is identical to this object.
|
protected boolean |
equalsField(String name,
byte[] value1,
byte[] value2)
Compare the given header field values.
|
protected byte |
getByte(String name)
Return the value of the specified field as a byte.
|
protected byte[] |
getBytes(String name)
Return the value of the specified field as a byte array.
|
int |
getFieldNumBits(String name)
This method fetches the number of bits for header field specified by
name . |
protected int |
getFieldNumBits(String name,
Packet.HeaderField entry)
Return the number of bits in the header field configured in the given
instance.
|
int |
getFieldOffset(String name)
This method fetches the start bit offset for header field specified by
name . |
protected int |
getFieldOffset(String name,
Packet.HeaderField entry)
Return the offset of the header field configured in the given instance.
|
protected Map<String,byte[]> |
getHeaderFieldMap()
Return a map that keeps packet header fields.
|
protected abstract Map<String,Packet.HeaderField> |
getHeaderFormat()
Return a map that determines the format of the packet.
|
int |
getHeaderSize()
Gets the header length in bits.
|
protected int |
getInt(String name)
Return the value of the specified field as an integer.
|
protected Ip4Network |
getIp4Network(String name)
Return the value of the specified field as an IPv4 address.
|
Packet |
getPayload()
Return the packet encapsulated by this packet.
|
byte[] |
getRawPayload()
Returns the raw payload carried by this packet in case payload was not
parsed.
|
protected int |
getRawPayloadSize()
Return the size of the raw payload in this packet.
|
protected short |
getShort(String name)
Return the value of the specified field as a short integer.
|
int |
hashCode()
Return the hash code of this object.
|
boolean |
isCorrupted()
Return whether the deserialized packet is to be considered corrupted.
|
protected boolean |
isZeroShort(byte[] value)
Determine whether the given value represents a zero short value or not.
|
protected void |
postDeserializeCustomOperation(byte[] data,
int offset)
This method re-computes the checksum of the bits received on the wire
and validates it with the checksum in the bits received.
|
protected void |
postSerializeCustomOperation(byte[] myBytes)
This method gets called at the end of the serialization process.
|
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.
|
protected void |
setCorrupted(boolean c)
Set a boolean value which determines whether this packet is corrupted
or not.
|
protected void |
setHeaderField(String name,
byte[] value)
Associate the specified value with the specified header field.
|
void |
setPayload(Packet p)
Set the packet encapsulated by this packet.
|
protected void |
setPayloadClass(Class<? extends Packet> cls)
Set a class that specifies the type of packets encapsulated by this
packet.
|
void |
setRawPayload(byte[] bytes)
Set a raw payload in the packet class.
|
String |
toString()
Return a string representation of this object.
|
public final Packet getPayload()
null
if not present.public void setPayload(Packet p)
p
- The packet encapsulated by this packet.public Packet deserialize(byte[] data, int bitOffset, int size) throws PacketException
data
- Data from wire to deserialize.bitOffset
- Bit position where packet header starts in data array.size
- Size of packet in bits.PacketException
- An error occurred.public byte[] serialize() throws PacketException
PacketException
- An error occurred.protected void postSerializeCustomOperation(byte[] myBytes) throws PacketException
myBytes
- Serialized bytes.PacketException
- An error occurred.protected void postDeserializeCustomOperation(byte[] data, int offset) throws PacketException
data
- The byte stream representing the Ethernet frame.offset
- The bit offset from where the byte array corresponding to
this Packet starts in the framePacketException
- An error occurred.protected final void setPayloadClass(Class<? extends Packet> cls)
cls
- A class that specifies the type of the payload packet.protected void setHeaderField(String name, byte[] value)
name
- The name of the header field.value
- The value to be associated with the specified header
field. null
cannot be specified.protected final Map<String,byte[]> getHeaderFieldMap()
public int getHeaderSize()
public final int getFieldOffset(String name)
name
.name
- The name of the header field.public final int getFieldNumBits(String name)
name
.name
- The name of the header field.public byte[] getRawPayload()
null
.null
otherwisepublic void setRawPayload(byte[] bytes)
bytes
- The raw payload as byte array.public final boolean isCorrupted()
protected final void setCorrupted(boolean c)
c
- true
indicates that this packet is corrupted.protected final int getRawPayloadSize()
protected int getFieldOffset(String name, Packet.HeaderField entry)
name
- The name of the header field.entry
- The header field entry associated with name
.protected int getFieldNumBits(String name, Packet.HeaderField entry)
name
- The name of the header field.entry
- The header field entry associated with name
.protected boolean equalsField(String name, byte[] value1, byte[] value2)
name
- The name of the header field.value1
- The first header field value to be compared.value2
- The second header field value to be compared.true
only if the given two header field values are
identical.protected final byte[] getBytes(String name)
name
- The name of the field.protected final byte getByte(String name)
name
- The name of the field.protected final int getInt(String name)
name
- The name of the field.protected final short getShort(String name)
name
- The name of the field.protected final Ip4Network getIp4Network(String name)
name
- The name of the field.Ip4Network
instance.protected final boolean isZeroShort(byte[] value)
value
- A byte array that contains a short integer.true
only if the given value represents a zero.protected abstract Map<String,Packet.HeaderField> getHeaderFormat()
public final int hashCode()
Note that this method never uses the payload to compute the hash code.
public final boolean equals(Object o)
Note that this method never compares the payload encapsulated by the packet.
public final String toString()
Copyright © 2018 OpenDaylight. All rights reserved.