public final class PktHeader extends UtlListElement implements IOElasticBuffer.Initializer
A packet consists of a header, body and tags. This class represents the header portion of the packet. The header consists of a fixed portion and a variable portion. The variable portion is in the form of subheaders.
The packet header is a versioned entity. The header version defines the format of the header i.e. what fields comprise the header and their relative locations when serialized. A crucial aspect of header versioning is that a version N header will always be a subset of a version M header where N < M i.e. all fields in version N of a header will be present and in the same position as fields in version M of the header. i.e. a header never shrinks or moves fields around. With time, the header can only grow. See the setter/getter method documentation for information on which header version the fields that they affect belong to.
| Modifier and Type | Field and Description |
|---|---|
static int |
MAGIC |
static int |
MAGIC_BE |
static int |
MAGIC_LE |
static int |
MAGIC_SIZE |
static short |
MAX_HTL |
static int |
STATIC_HEADER_LENGTH |
count, head, next, prev| Modifier and Type | Method and Description |
|---|---|
PktSubheaderFMC |
activateFMCSubheader(boolean reset)
Activate the fabric multicast subheader.
|
PktSubheaderFUC |
activateFUCSubheader(boolean reset)
Activate the fabric unicast subheader.
|
PktSubheaderODS |
activateODSSubheader(boolean reset)
Activate the ODS subheader.
|
PktSubheaderRR |
activateRRSubheader(boolean reset)
Activate the request-reply subheader.
|
PktSubheaderSMA |
activateSMASubheader(boolean reset)
Activate the SMA subheader.
|
static void |
clearMagic(ByteBuffer buffer,
int offset)
Clear the magic number from a serialized header
|
static void |
clearMagic(IOBuffer buffer,
int offset)
Clear the magic number from a serialized header
|
static void |
clearMagic(IOElasticBuffer buffer,
int offset)
Clear the magic number from a serialized header
|
static void |
clearMagic(long addr,
int offset)
Clear the magic number from a serialized header
|
static EPktException |
convertGetSerializedPacketLengthErrorCodeToException(ByteBuffer buf,
int bufOffset,
int code)
Convert an error code returned by
getSerializedPacketLengthNoException
to an exception |
static EPktException |
convertGetSerializedPacketLengthErrorCodeToException(IOBuffer iobuf,
int iobufOffset,
int code)
Convert an error code returned by
getSerializedPacketLengthNoException
to an exception |
static EPktException |
convertGetSerializedPacketLengthErrorCodeToException(long addr,
int offset,
int code)
Convert an error code returned by
getSerializedPacketLengthNoException
to an exception |
static PktHeader |
create(PktBody body,
Properties props)
Create a packet header
|
void |
deactivateFMCSubheader()
Deactivate the fabric multicast subheader.
|
void |
deactivateFUCSubheader()
Deactivate the fabric unicast subheader.
|
void |
deactivateODSSubheader()
Deactivate the ODS subheader.
|
void |
deactivateRRSubheader()
Deactivate the request-reply subheader.
|
void |
deactivateSMASubheader()
Deactivate the SMA subheader.
|
int |
deserialize(ByteBuffer buf,
int bufOffset)
Deserialize a packet header from a byte buffer
This method invokes
return putFrom(buf, bufOffset) followed by desync()
|
void |
deserialize(IOBuffer iobuf,
int iobufOffset)
Deserialize a packet header from an IO buffer
This method invokes
deserialize(iobuf, iobufOffset, length, false) followed by desync()
|
int |
deserialize(IOBuffer iobuf,
int iobufOffset,
boolean wrap)
Deserialize a packet header from an IO buffer
This method invokes
return putFrom(iobuf, iobufOffset, wrap) followed by desync()
|
int |
deserialize(long addr,
int addrOffset)
Deserialize a packet header from a native memory region
This method invokes
return putFrom(addr, addrOffset) followed by desync()
|
void |
desync()
Desync a packets header and subheader contents from the header and
subheader's backing buffers
Invoking this method ensures that a packet header and subheader
accessor methods can safely be used
|
String |
dump(String prefix)
Dump the contents of a packet body
|
PktBody |
getBody()
Get the body associated with this header
|
int |
getBodyType()
Get the packet body type (V1 Header Field).
|
static int |
getBodyType(ByteBuffer buffer,
int offset)
Get the body type from a serialized header.
|
static int |
getBodyType(IOBuffer buffer,
int offset)
Get the body type from a serialized header.
|
static int |
getBodyType(IOElasticBuffer buffer,
int offset)
Get the body type from a serialized header.
|
static int |
getBodyType(long addr,
int offset)
Get the body type from a serialized header.
|
IOElasticBuffer |
getBuffer()
Get the internal header buffer.
|
short |
getClazz()
Get the packet class (V1 Header Field).
|
int |
getDest()
Get the packet destination fabric address (V1 Header Field).
|
short |
getDestPort()
Get the packet destination port (V1 Header Field).
|
int |
getFlow()
Get the packet flow (V1 Header Field).
|
PktSubheaderFMC |
getFMCSubheader()
Get the packet fabric multicast subheader.
|
PktSubheaderFUC |
getFUCSubheader()
Get the packet fabric unicast subheader.
|
short |
getHtl()
Get the packet 'hops to live' (V1 Header Field).
|
static short |
getLatestVersion()
Get the latest header version.
|
int |
getLength()
Get the packet length (V1 Header Field).
|
boolean |
getNoBuffering()
Get the 'no buffering' flag (V1 Header Field).
|
short |
getNumSubheaders()
Get the number of attached subheaders (V1 Header Field).
|
static short |
getNumSubheaders(long addr,
int offset)
Get the number of attached subheaders (V1 Header Field) from a serialized header.
|
PktSubheaderODS |
getODSSubheader()
Get the packet ODS subheader.
|
long |
getPreWireTs()
Get the pre-wire timestamp
|
boolean |
getReplyExpected()
Get the 'reply expected' flag (V1 Header Field).
|
PktSubheaderRR |
getRRSubheader()
Get the request-reply subheader.
|
int |
getSerializedLength()
Get the serialized length of a packet header
This method returns the serialized length of the static header plus
the serialized length of all attached subheaders.
|
static int |
getSerializedLength(long addr,
int offset)
Get the serialized length of a packet header from the serialized form of a packet
|
static int |
getSerializedPacketLength(ByteBuffer buf,
int bufOffset,
int length)
Parse and return length of a serialized packet in a byte buffer
|
static int |
getSerializedPacketLength(IOBuffer iobuf,
int iobufOffset,
int length)
Parse and return length of a serialized packet in an IO buffer
|
static int |
getSerializedPacketLength(long addr,
int offset,
int length)
Parse and return length of a serialized packet in a native memory region
|
static int |
getSerializedPacketLengthNoException(ByteBuffer buf,
int bufOffset,
int length)
Parse and return length of a serialized packet in a byte buffer
|
static int |
getSerializedPacketLengthNoException(IOBuffer iobuf,
int iobufOffset,
int length)
Parse and return length of a serialized packet in an IO buffer
|
static int |
getSerializedPacketLengthNoException(long addr,
int offset,
int length)
Parse and return length of a serialized packet in a memory region
|
PktSubheaderSMA |
getSMASubheader()
Get the packet SMA subheader.
|
int |
getSrc()
Get the packet source fabric address (V1 Header Field).
|
short |
getSrcPort()
Get the packet source port (V1 Header Field).
|
int |
getStaticSerializedLength()
Get the serialized length of the only the static portion of the header.
|
PktSubheader |
getSubheader(int type,
boolean ignoreInactive)
Core method to get a subheader.
|
static int |
getSubheaderOffset(long addr,
int offset,
int subheaderType)
Get the offset of the a subheader
|
int |
getTo(byte[] array)
Copy the contents of a packet header's backing buffer to a byte array
This method invokes
return getTo(array, 0)
|
int |
getTo(byte[] array,
int arrayOffset)
Copy the contents of a packet header's backing buffer to a byte array
This method invokes
return getTo(array, arrayOffset, true)
|
int |
getTo(byte[] array,
int arrayOffset,
boolean withMagic)
Copy the contents of a packet header's backing buffer to a byte array
|
int |
getTo(ByteBuffer buf)
Copy the contents of a packet header's backing buffer to a byte buffer
This method invokes
return getTo(buf, true)
|
int |
getTo(ByteBuffer buf,
boolean withMagic)
Copy the contents of a packet header's backing buffer to a byte buffer
This method invokes
return getTo(buf, buf.position(), withMagic)
|
int |
getTo(ByteBuffer buf,
int bufOffset)
Copy the contents of a packet header's backing buffer to a byte buffer
This method invokes
return getTo(buf, bufOffset, true)
|
int |
getTo(ByteBuffer buf,
int bufOffset,
boolean withMagic)
Copy the contents of a packet header's backing buffer to a byte buffer
|
int |
getTo(IOBuffer iobuf,
int iobufOffset)
Copy the contents of a packet header's backing buffer to an
IOBuffer
This method invokes return getTo(iobuf, iobufOffset, true)
|
int |
getTo(IOBuffer iobuf,
int iobufOffset,
boolean withMagic)
Copy the contents of a packet header's backing buffer to an
IOBuffer |
int |
getTo(IOElasticBuffer iobuf,
int iobufOffset)
Copy the contents of a packet header's backing buffer to an
IOElasticBuffer
This method invokes return getto(iobuf, iobufOffset, true)
|
int |
getTo(IOElasticBuffer iobuf,
int iobufOffset,
boolean withMagic)
Copy the contents of a packet header's backing buffer to an
IOElasticBuffer |
int |
getTo(long addr,
int addrOffset)
Copy the contents of a packet header's backing buffer to a native memory region
This method invokes
return getTo(addr, addrOffset, true)
|
int |
getTo(long addr,
int addrOffset,
boolean withMagic)
Copy the contents of a packet header's backing buffer to a native memory region
|
short |
getVersion()
Get the header format version (V1 Header Field).
|
static boolean |
hasMagic(ByteBuffer buffer,
int offset)
Check if a serialized buffer is start of a packet
|
void |
initializeBuffer()
Implementation of
IOElasticBuffer.Initializer.initializeBuffer() |
int |
putFrom(ByteBuffer buf,
int bufOffset)
Copy the contents of a packet header's backing buffer from a byte buffer
|
int |
putFrom(IOBuffer iobuf,
int iobufOffset)
Copy the contents of a packet header's backing buffer from an
IOBuffer
This method invokes return putFrom(iobuf, iobufOffset, length, false)
|
int |
putFrom(IOBuffer iobuf,
int iobufOffset,
boolean wrap)
Copy the contents of a packet header's backing buffer from an
IOBuffer |
int |
putFrom(long addr,
int addrOffset)
Copy the contents of a packet header's backing buffer from a native memory region
|
int |
putFrom(PktHeader src)
Copy the contents of a packet header's backing buffer from another header
|
void |
reset()
Reset the contents of a packet header.
|
void |
reset(boolean initBackingBuffer)
Reset the contents of a packet header.
|
static void |
restoreClearedMagic(ByteBuffer buffer,
int offset)
Restore the magic number in a serialized header serialized without magic
|
static void |
restoreClearedMagic(IOBuffer buffer,
int offset)
Restore the magic number in a serialized header serialized without magic
|
static void |
restoreClearedMagic(IOElasticBuffer buffer,
int offset)
Restore the magic number in a serialized header serialized without magic
|
static void |
restoreClearedMagic(long addr,
int offset)
Restore the magic number in a serialized header serialized without magic
|
int |
serialize(byte[] array,
int arrayOffset)
Serialize a packet header to a byte array
This method invokes
serialize(array, arrayOffset, true)
|
int |
serialize(byte[] array,
int arrayOffset,
boolean withMagic)
Serialize a packet header to a byte array
This method invokes syncf().getTo(array, arrayOffset, withMagic)
|
int |
serialize(ByteBuffer buf)
Serialize a packet header to a byte buffer
This method invokes
serialize(buf, true)
|
int |
serialize(ByteBuffer buf,
boolean withMagic)
Serialize a packet header to a byte buffer
This method invokes
serialize(buf, buf.position(), withMagic)
|
int |
serialize(ByteBuffer buf,
int bufOffset)
Serialize a packet header to a byte buffer
This method invokes
serialize(buf, bufOffset, true)
|
int |
serialize(ByteBuffer buf,
int bufOffset,
boolean withMagic)
Serialize a packet header to a byte buffer
This method invokes syncf().getTo(buf, bufOffset, withMagic)
|
int |
serialize(IOBuffer iobuf,
int iobufOffset)
Serialize a packet header to an IO buffer
This method invokes
serialize(iobuf, iobufOffset, true)
|
int |
serialize(IOBuffer iobuf,
int iobufOffset,
boolean withMagic)
Serialize a packet header to an IO buffer
This method invokes syncf().getTo(iobuf, iobufOffset, withMagic)
|
int |
serialize(IOElasticBuffer iobuf,
int iobufOffset)
Serialize a packet header to an elastic IO buffer
This method invokes
serialize(iobuf, iobufOffset, true)
|
int |
serialize(IOElasticBuffer iobuf,
int iobufOffset,
boolean withMagic)
Serialize a packet header to an elastic IO buffer
This method invokes syncf().getTo(iobuf, iobufOffset, withMagic)
|
int |
serialize(long address,
int addressOffset)
Serialize a packet header to a native memory region
This method invokes
serialize(address, addressOffset, true)
|
int |
serialize(long address,
int addressOffset,
boolean withMagic)
Serialize a packet header to a native memory region
This method invokes syncf().getTo(address, addressOffset, withMagic)
|
void |
setClazz(short clazz)
Set the packet class (V1 Header Field).
|
void |
setDest(int addr)
Set the packet destination fabric address (V1 Header Field).
|
void |
setDestPort(short port)
Set the packet destination port (V1 Header Field).
|
void |
setFlow(int flow)
Set the packet flow (V1 Header Field).
|
void |
setHtl(short htl)
Set the packet 'hops to live' (V1 Header Field).
|
void |
setLength(int length)
Set the packet length (V1 Header Field).
|
void |
setNoBuffering(boolean val)
Set the 'no buffering' flag (V1 Header Field).
|
static void |
setPreWireTs(ByteBuffer buffer,
int pos,
long ts)
Set the send pre-wire timestamp(V1 Header Field) in the supplied buffer.
|
static void |
setPreWireTs(IOBuffer buffer,
int pos,
long ts)
Set the send pre-wire timestamp(V1 Header Field) in the supplied buffer.
|
static void |
setPreWireTs(IOElasticBuffer buffer,
int pos,
long ts)
Set the send pre-wire timestamp(V1 Header Field) in the supplied buffer.
|
void |
setPreWireTs(long ts)
Set the send pre-wire timestamp(V1 Header Field).
|
void |
setReplyExpected(boolean val)
Set the 'reply expected' flag (V1 Header Field).
|
void |
setSrc(int addr)
Set the packet source fabric address (V1 Header Field).
|
void |
setSrcPort(short port)
Set the packet source port(V1 Header Field).
|
int |
sync()
Sync a packets header and subheader contents to the header and subheaders'
backing buffers
|
PktHeader |
syncf()
Sync method for use with fluent programming
|
String |
toString()
Return a string representation of the object.
|
count, insertAfter, insertBefore, isLinked, next, previous, unlink, wipepublic static final int STATIC_HEADER_LENGTH
public static final int MAGIC_SIZE
public static final int MAGIC_LE
public static final int MAGIC_BE
public static final int MAGIC
public static final short MAX_HTL
public static PktHeader create(PktBody body, Properties props)
body - The associated bodyprops - Property set to use in the creation of the packet header.
Currently, the header does not support any creation or operational
properties. This is present for future compatibility.This method creates a packet header. The created header has all header elements initialized to their default values. The type and length elements are initialized as 0 upon return from this method. The type element is initialized when a packet body is associated with the header. The length field is initialized when the header is serialized. or initialized through deserialization.
Note that this method creates a standalone header that is not associated
with a packet body. A public user should only use this method in case
that is what is desired i.e. a standalone header with no associated
body. To create a packet header asociated with a body, the user should
not use this method directly. The PktFactory packet creation
methods should be used which create and associate packet headers and
bodies.
public static final EPktException convertGetSerializedPacketLengthErrorCodeToException(ByteBuffer buf, int bufOffset, int code)
getSerializedPacketLengthNoException
to an exceptionbuf - The buffer that was supplied to getSerializedPacketLengthNoException(java.nio.ByteBuffer, int, int)bufOffset - The buffer offset that was supplied to getSerializedPacketLengthNoException(java.nio.ByteBuffer, int, int)code - The error code returned by getSerializedPacketLengthNoException(java.nio.ByteBuffer, int, int)IllegalArgumentException - Thrown if the supplied value does
not represent an error returned by getSerializedPacketLengthNoExceptionpublic static final int getSerializedPacketLength(ByteBuffer buf, int bufOffset, int length)
buf - The buffer containing the packetbufOffset - The offset into the buffer where the packet startslength - The number of valid bytes starting from the offsetThis method parses the supplied buffer and attempts to return the length of the serialized packet starting at the supplied offset. It only considers the supplied length. If the supplied length is not enough to determine the serialized length, then this method returns 0. Otherwise, it checks the integrity of the packet by validating the magic and version and then returns the length of the packet. Note that the returned length may be more than the supplied length in which case the full packet is not present in the buffer.
EPktCorruptException - Thrown if a valid packet does not start at
the specified offset in he bufferEPktVersionInvalidException - Thrown in case the buffer contains
a serialized packet with an invalid header format versionpublic static final int getSerializedPacketLengthNoException(ByteBuffer buf, int bufOffset, int length)
buf - The buffer containing the packetbufOffset - The offset into the buffer where the packet startslength - The number of valid bytes starting from the offset
This method performs the same function as #getSerializedPacketLength(buf, int, int)
except that it does not throw any exception if it encounters an error. Instead,
it return a nagative code in case it encounters an error. The caller can then
invoke convertGetSerializedPacketLengthErrorCodeToException(java.nio.ByteBuffer, int, int)
public static final EPktException convertGetSerializedPacketLengthErrorCodeToException(IOBuffer iobuf, int iobufOffset, int code)
getSerializedPacketLengthNoException
to an exceptionbuf - The buffer that was supplied to getSerializedPacketLengthNoException(java.nio.ByteBuffer, int, int)bufOffset - The buffer offset that was supplied to getSerializedPacketLengthNoException(java.nio.ByteBuffer, int, int)code - The error code returned by getSerializedPacketLengthNoException(java.nio.ByteBuffer, int, int)IllegalArgumentException - Thrown if the supplied value does
not represent an error returned by getSerializedPacketLengthNoExceptionpublic static final int getSerializedPacketLength(IOBuffer iobuf, int iobufOffset, int length)
iobuf - The buffer containing the packetiobufOffset - The offset into the buffer where the packet startslength - The number of valid bytes starting from the offsetThis method parses the supplied buffer and attempts to return the length of the serialized packet starting at the supplied offset. It only considers the supplied length. If the supplied length is not enough to determine the serialized length, then this method returns 0. Otherwise, it checks the integrity of the packet by validating the magic and version and then returns the length of the packet. Note that the returned length may be more than the supplied length in which case the full packet is not present in the buffer.
EPktCorruptException - Thrown if a valid packet does not start at
the specified offset in he bufferEPktVersionInvalidException - Thrown in case the buffer contains
a serialized packet with an invalid header format versionpublic static final int getSerializedPacketLengthNoException(IOBuffer iobuf, int iobufOffset, int length)
buf - The buffer containing the packetbufOffset - The offset into the buffer where the packet startslength - The number of valid bytes starting from the offset
This method performs the same function as #getSerializedPacketLength(buf, int, int)
except that it does not throw any exception if it encounters an error. Instead,
it return a nagative code in case it encounters an error. The caller can then
invoke convertGetSerializedPacketLengthErrorCodeToException(java.nio.ByteBuffer, int, int)
public static final EPktException convertGetSerializedPacketLengthErrorCodeToException(long addr, int offset, int code)
getSerializedPacketLengthNoException
to an exceptionaddr - The address that was supplied to getSerializedPacketLengthNoException(java.nio.ByteBuffer, int, int)offset - The address offset that was supplied to getSerializedPacketLengthNoException(java.nio.ByteBuffer, int, int)code - The error code returned by getSerializedPacketLengthNoException(java.nio.ByteBuffer, int, int)IllegalArgumentException - Thrown if the supplied value does
not represent an error returned by getSerializedPacketLengthNoExceptionpublic static final int getSerializedPacketLength(long addr,
int offset,
int length)
addr - The address of the region containing the packetoffset - The offset into the memory region where the packet startslength - The number of valid bytes starting from the offsetThis method parses the supplied memory region and attempts to return the length of the serialized packet starting at the supplied offset. It only considers the supplied length. If the supplied length is not enough to determine the serialized length, then this method returns 0. Otherwise, it checks the integrity of the packet by validating the magic and version and then returns the length of the packet. Note that the returned length may be more than the supplied length in which case the full packet is not present in the buffer.
EPktCorruptException - Thrown if a valid packet does not start at
the specified offset in he bufferEPktVersionInvalidException - Thrown in case the buffer contains
a serialized packet with an invalid header format versionpublic static final int getSerializedPacketLengthNoException(long addr,
int offset,
int length)
addr - The address of the memory region containing the packetoffset - The offset into the region where the packet startslength - The number of valid bytes starting from the offset
This method performs the same function as #getSerializedPacketLength(addr, int, int)
except that it does not throw any exception if it encounters an error. Instead,
it return a nagative code in case it encounters an error. The caller can then
invoke convertGetSerializedPacketLengthErrorCodeToException(java.nio.ByteBuffer, int, int)
public static final void clearMagic(ByteBuffer buffer, int offset)
public static final void clearMagic(IOBuffer buffer, int offset)
public static final void clearMagic(IOElasticBuffer buffer, int offset)
public static final void clearMagic(long addr,
int offset)
public static final void restoreClearedMagic(ByteBuffer buffer, int offset)
public static final void restoreClearedMagic(IOBuffer buffer, int offset)
public static final void restoreClearedMagic(IOElasticBuffer buffer, int offset)
public static final void restoreClearedMagic(long addr,
int offset)
public static final boolean hasMagic(ByteBuffer buffer, int offset)
public static final short getLatestVersion()
This method returns the latest header version i.e. the version used when headers are created explicitly i.e. not through deserialization
public final short getVersion()
public final int getLength()
This method returns the packet length set in the packet header. This
field is set by the serialize(java.nio.ByteBuffer, int, boolean) method and can be used by
the user after a call to serialize(java.nio.ByteBuffer, int, boolean) to check the length of the
serialized packet. Note that although this field contains the length
of the full packet, the serialize(java.nio.ByteBuffer, int, boolean) method does not serialize
the attached body (if present). That is the responsibility of the user.
public final void setSrc(int addr)
addr - The fabric address to setpublic final int getSrc()
public final void setDest(int addr)
addr - The fabric address to setpublic final int getDest()
public static final void setPreWireTs(ByteBuffer buffer, int pos, long ts)
The pre-wire timestamp field uses the same position in the backing buffer as the source and dest fields. So, either the src + dest fields can be used or the pre-wire timestamp but not both.
buffer - The buffer to set it in.pos - The offset into the buffer where the serialized packet starts.ts - The timestamp to setpublic static final void setPreWireTs(IOBuffer buffer, int pos, long ts)
The pre-wire timestamp field uses the same position in the backing buffer as the source and dest fields. So, either the src + dest fields can be used or the pre-wire timestamp but not both.
buffer - The buffer to set it in.pos - The offset into the buffer where the serialized packet starts.ts - The timestamp to setpublic static final void setPreWireTs(IOElasticBuffer buffer, int pos, long ts)
The pre-wire timestamp field uses the same position in the backing buffer as the source and dest fields. So, either the src + dest fields can be used or the pre-wire timestamp but not both.
buffer - The buffer to set it in.pos - The offset into the buffer where the serialized packet starts.ts - The timestamp to setpublic final void setPreWireTs(long ts)
The pre-wire timestamp field uses the same position in the backing buffer as the source and dest fields. So, either the src + dest fields can be used or the pre-wire timestamp but not both.
ts - The timestamp to setpublic final long getPreWireTs()
public final void setSrcPort(short port)
port - The port to setpublic final short getSrcPort()
public final void setDestPort(short port)
port - The port to setpublic final short getDestPort()
public final void setFlow(int flow)
flow - The packet flow to setpublic final int getFlow()
public final void setNoBuffering(boolean val)
This method is used to specify that the packet should be delivered to the intended destination with as little latency as possible. This flag is used by intermediate network links as a directive to not buffer the packet but to flush it through the network ASAP.
public final boolean getNoBuffering()
public final void setReplyExpected(boolean val)
This method is used to specify that the packet is the request in a request-reply exchange.
public final boolean getReplyExpected()
public final void setHtl(short htl)
htl - The htl to set. Although the type of this parameter
is short, it is encoded on the wire as a single byte. Thus, only the
lower byte is used from this parameter. The reason for this is that we
want to treat htl as an 'unsigned byte'public final short getHtl()
public final void setClazz(short clazz)
clazz - The packet class to set. Although the type of this
parameter is short, it is encoded on the wire as a single byte.
Thus, only the lower byte is used from this parameter. The reason
for this is that we want to treat clazz as an 'unsigned byte'public final short getClazz()
public final int getBodyType()
public static final int getBodyType(ByteBuffer buffer, int offset)
This method returns the body type encoded in a serialized packet header. If the header was serialized without an attached body, then the type field will be zero in the serialized header.
The body type field is only guaranteed to be set during header serialization time into the serialization buffer which may be different from the header buffer depending on the serialization policy used. Thus, even if the body is set in a header, it is not guaranteed that the header buffer will contain the serialized body type prior to serialization or even after serialization in case the header was copied into a separate buffer during serialization. Therefore, this method is only reliable for use to get the body type from a serialized header.
public static final int getBodyType(IOBuffer buffer, int offset)
getBodyType(ByteBuffer, int)public static final int getBodyType(IOElasticBuffer buffer, int offset)
getBodyType(ByteBuffer, int)public static final int getBodyType(long addr,
int offset)
getBodyType(ByteBuffer, int)public static final short getNumSubheaders(long addr,
int offset)
addr - The address of the memory region where the header is serializedoffset - The offset into the native memory region where the header is serializedpublic final short getNumSubheaders()
public final IOElasticBuffer getBuffer()
This method returns the internal buffer used to store elements of the static portion of the header. Each subheader maintains its own buffer. The user must not modify the contents of this buffer. Use the header element setter/getter methods to modify the contents of the buffer.
public final PktSubheaderRR activateRRSubheader(boolean reset)
reset - Indicates whether the subheader should be reset after
activation. This flag is only present for those situations where
the user deactivates a subheader and then reactivates for use but
only partially re-populates the header after re-activation.It is safe to activate an already active sub-header.
public final void deactivateRRSubheader()
It is safe to deactivate an already inactive sub-header.
public final PktSubheader getSubheader(int type, boolean ignoreInactive)
type - The subheader type.ignoreInactive - Return subheader even if inactivepublic final PktSubheaderRR getRRSubheader()
public final PktSubheaderFMC activateFMCSubheader(boolean reset)
reset - Indicates whether the subheader should be reset after
activation. This flag is only present for those situations where
the user deactivates a subheader and then reactivates for use but
only partially re-populates the header after re-activation.It is safe to activate an already active sub-header.
public final void deactivateFMCSubheader()
It is safe to deactivate an already inactive sub-header.
public final PktSubheaderFMC getFMCSubheader()
public final PktSubheaderFUC activateFUCSubheader(boolean reset)
reset - Indicates whether the subheader should be reset after
activation. This flag is only present for those situations where
the user deactivates a subheader and then reactivates for use but
only partially re-populates the header after re-activation.It is safe to activate an already active sub-header.
public final void deactivateFUCSubheader()
It is safe to deactivate an already inactive sub-header.
public final PktSubheaderFUC getFUCSubheader()
public final PktSubheaderSMA activateSMASubheader(boolean reset)
reset - Indicates whether the subheader should be reset after
activation. This flag is only present for those situations where
the user deactivates a subheader and then reactivates for use but
only partially re-populates the header after re-activation.It is safe to activate an already active sub-header.
public final void deactivateSMASubheader()
It is safe to deactivate an already inactive sub-header.
public final PktSubheaderSMA getSMASubheader()
public static final int getSubheaderOffset(long addr,
int offset,
int subheaderType)
public final PktSubheaderODS activateODSSubheader(boolean reset)
reset - Indicates whether the subheader should be reset after
activation. This flag is only present for those situations where
the user deactivates a subheader and then reactivates for use but
only partially re-populates the header after re-activation.It is safe to activate an already active sub-header.
public final void deactivateODSSubheader()
It is safe to deactivate an already inactive sub-header.
public final PktSubheaderODS getODSSubheader()
public final PktBody getBody()
public final void reset(boolean initBackingBuffer)
initializeBuffer - Whether to wipe and initialize the backing bufferpublic final void reset()
This method invokes reset(true)
public final void setLength(int length)
NOTE: THIS METHOD IS RESERVED FOR USE BY THE PLATFORM
public final int getStaticSerializedLength()
This method returns the serialized length of only the static portion of the header. This length is governed by the header version. /P>
public static final int getSerializedLength(long addr,
int offset)
public final int getSerializedLength()
This method returns the serialized length of the static header plus the serialized length of all attached subheaders.
public final int sync()
Invoking this method ensures that a packet header and its subheaders are fully serialized to their backing buffers and can be copied out
Note: This method use PktBody#getBuffer().getLength() to get the
serialized length of the body. It uses this to compute the total
length of the packet that is part of the serialized header. Therefore,
PktBody.sync() needs to be invoked prior to this method to
ensure that the serialized length of the body is reflected correctly
in the body's backing buffer. Generally speaking what this means is
that when sync'inc a packet, the body should be sync'd first and then
the header.
public final PktHeader syncf()
This method is the same as sync() except it return this
object instead of length for fluent invocation chaining
public final void desync()
Invoking this method ensures that a packet header and subheader accessor methods can safely be used
public final int getTo(ByteBuffer buf, int bufOffset, boolean withMagic)
buf - The byte buffer to copy tobufOffset - The offset into the buffer where the serialized contents
of the packet header needs to be copiedwithMagic - Whether to copy the magic number or notThis method copies the serialized contents of a packet header to a byte buffer. It copies the contents to the target buffer starting at the supplied buffer offset. This method does not change any of the markers of the target buffer.
Note:Since this method does not change any markers of the target buffer, the caller needs to ensure the buffer has enough capacity to accommodate the header's contents. The caller can invokegetSerializedLength() to get
the length of the header's contents and use that to set the target buffer's
capacity before invoking this method.
Note:This method does not invoke sync() before doing the
copy. The caller needs to ensure that sync() is invoked prior to invoking
this method.
public final int getTo(ByteBuffer buf, int bufOffset)
This method invokes return getTo(buf, bufOffset, true)
public final int getTo(ByteBuffer buf, boolean withMagic)
This method invokes return getTo(buf, buf.position(), withMagic)
public final int getTo(ByteBuffer buf)
This method invokes return getTo(buf, true)
public final int getTo(byte[] array,
int arrayOffset,
boolean withMagic)
array - The byte array to copy toarrayOffset - The offset into the array where the serialized contents
of the packet header needs to be copiedwithMagic - Whether to copy the magic number or notThis method copies the serialized contents of a packet header to a byte array.
Note:The caller needs to ensure the target array has enough capacity to accommodate the header's serialized contents. The caller can invoke thegetSerializedLength() method to get the length of the header's contents
to ensure the target array is sized correctly
Note:This method does not invoke sync() before doing the
copy. The caller needs to ensure that sync() is invoked prior to invoking
this method.
public final int getTo(byte[] array,
int arrayOffset)
This method invokes return getTo(array, arrayOffset, true)
public final int getTo(byte[] array)
This method invokes return getTo(array, 0)
public final int getTo(IOBuffer iobuf, int iobufOffset, boolean withMagic)
IOBufferiobuf - The IO buffer to copy toiobufOffset - The offset into the IO buffer where the serialized contents
of the packet header needs to be copiedwithMagic - Whether to copy the magic number or not
This method copies the serialized contents of a packet header to an IOBuffer.
getSerializedLength() method to get the length of the header's contents
to ensure the target buffer is sized correctly
Note:This method does not invoke sync() before doing the
copy. The caller needs to ensure that sync() is invoked prior to invoking
this method.
public final int getTo(IOBuffer iobuf, int iobufOffset)
IOBuffer
This method invokes return getTo(iobuf, iobufOffset, true)
public final int getTo(IOElasticBuffer iobuf, int iobufOffset, boolean withMagic)
IOElasticBufferiobuf - The IO buffer to copy toiobufOffset - The offset into the target buffer where the serialized contents
of the packet header needs to be copiedwithMagic - Whether to copy the magic number or not
This method copies the serialized contents of a packet header to an IOElasticBuffer.
sync() before doing the
copy. The caller needs to ensure that sync() is invoked prior to invoking
this method.
public final int getTo(IOElasticBuffer iobuf, int iobufOffset)
IOElasticBuffer
This method invokes return getto(iobuf, iobufOffset, true)
public final int getTo(long addr,
int addrOffset,
boolean withMagic)
addr - The address of the native memory region to copy toaddrOffset - The offset into the memory region where the serialized
contents of the packet header should be copies to.withMagic - Whether to copy the magic number or notThis method copies the serialized contents of a packet header to a native memory region
Note:The caller needs to ensure the target memory region has enough capacity to accommodate the header's serialized contents. The caller can invoke thegetSerializedLength() method to get the length of the header's contents
to ensure the target region is sized correctly
Note:This method does not invoke sync() before doing the
copy. The caller needs to ensure that sync() is invoked prior to invoking
this method.
public final int getTo(long addr,
int addrOffset)
This method invokes return getTo(addr, addrOffset, true)
public final int putFrom(ByteBuffer buf, int bufOffset)
buf - The byte buffer to copy frombufOffset - The offset into the buffer where the serialized contents
of the packet header begins.This method copies the contents of a packet header from a byte buffer. This method copies the content starting from the supplied buffer offset. It does not change any of the markers of the source byte buffer during the course of the copy
This method does not does not check for packet integrity or whether the buffer
contains a full packet header or not. The user should call getSerializedPacketLength(java.nio.ByteBuffer, int, int)
before invoking this method to check for packet integrity and whether the buffer contains
a full packet before calling this method. This method should only be subsequently called
in case the getSerializedPacketLength(java.nio.ByteBuffer, int, int) method returns successfully i.e. the serialized
packet has correct integrity and the full serialized packet is contained in the buffer.
Calling this method using a corrupt or incomplete buffer has undefined results.
public final int putFrom(IOBuffer iobuf, int iobufOffset, boolean wrap)
IOBufferiobuf - The IO buffer to copy fromiobufOffset - The offset into the IO buffer where the serialized contents
of the packet header begins.wrap - Indicates whether this method should copy the contents of the IO buffer
to the packet header or wrap the packet header and subheader's buffers around the
supplied IO bufferThis method copies the contents of a packet header by wrapping or copying contents from a byte buffer to the packet header's buffer.
This method does not does not check for packet integrity or whether the buffer
contains a full packet header or not. The user should call getSerializedPacketLength(java.nio.ByteBuffer, int, int)
before invoking this method to check for packet integrity and whether the buffer contains
a full packet before calling this method. This method should only be subsequently called
in case the getSerializedPacketLength(java.nio.ByteBuffer, int, int) method returns successfully i.e. the serialized
packet has correct integrity and the full serialized packet is contained in the buffer.
Calling this method using a corrupt or incomplete buffer has undefined results.
public final int putFrom(IOBuffer iobuf, int iobufOffset) throws EPktDeserializeException
IOBuffer
This method invokes return putFrom(iobuf, iobufOffset, length, false)
EPktDeserializeExceptionpublic final int putFrom(long addr,
int addrOffset)
addr - The memory region to copy fromaddrOffset - The offset into the memory region where the serialized contents
of the packet header begins.This method copies the contents of a packet header from a native memory region.
This method does not does not check for packet integrity or whether the buffer
contains a full packet header or not. The user should call getSerializedPacketLength(java.nio.ByteBuffer, int, int)
before invoking this method to check for packet integrity and whether the buffer contains
a full packet before calling this method. This method should only be subsequently called
in case the getSerializedPacketLength(java.nio.ByteBuffer, int, int) method returns successfully i.e. the serialized
packet has correct integrity and the full serialized packet is contained in the buffer.
Calling this method using a corrupt or incomplete buffer has undefined results.
public final int putFrom(PktHeader src)
src - The source header to copy fromNote: This method assumes that the source header is already sync'd
public final int serialize(ByteBuffer buf, int bufOffset, boolean withMagic)
This method invokes syncf().getTo(buf, bufOffset, withMagic)
public final int serialize(ByteBuffer buf, int bufOffset)
This method invokes serialize(buf, bufOffset, true)
public final int serialize(ByteBuffer buf, boolean withMagic)
This method invokes serialize(buf, buf.position(), withMagic)
public final int serialize(ByteBuffer buf)
This method invokes serialize(buf, true)
public final int serialize(byte[] array,
int arrayOffset,
boolean withMagic)
This method invokes syncf().getTo(array, arrayOffset, withMagic)
public final int serialize(byte[] array,
int arrayOffset)
This method invokes serialize(array, arrayOffset, true)
public final int serialize(IOBuffer iobuf, int iobufOffset, boolean withMagic)
This method invokes syncf().getTo(iobuf, iobufOffset, withMagic)
public final int serialize(IOBuffer iobuf, int iobufOffset)
This method invokes serialize(iobuf, iobufOffset, true)
public final int serialize(IOElasticBuffer iobuf, int iobufOffset, boolean withMagic)
This method invokes syncf().getTo(iobuf, iobufOffset, withMagic)
public final int serialize(IOElasticBuffer iobuf, int iobufOffset)
This method invokes serialize(iobuf, iobufOffset, true)
public final int serialize(long address,
int addressOffset,
boolean withMagic)
This method invokes syncf().getTo(address, addressOffset, withMagic)
public final int serialize(long address,
int addressOffset)
This method invokes serialize(address, addressOffset, true)
public final int deserialize(ByteBuffer buf, int bufOffset)
This method invokes return putFrom(buf, bufOffset) followed by desync()
public final int deserialize(IOBuffer iobuf, int iobufOffset, boolean wrap)
This method invokes return putFrom(iobuf, iobufOffset, wrap) followed by desync()
public final void deserialize(IOBuffer iobuf, int iobufOffset) throws EPktDeserializeException
This method invokes deserialize(iobuf, iobufOffset, length, false) followed by desync()
EPktDeserializeExceptionpublic final int deserialize(long addr,
int addrOffset)
This method invokes return putFrom(addr, addrOffset) followed by desync()
public final void initializeBuffer()
IOElasticBuffer.Initializer.initializeBuffer()initializeBuffer in interface IOElasticBuffer.InitializerCopyright © 2019 N5 Technologies, Inc. All Rights Reserved.