|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.neeve.util.UtlListElement
com.neeve.pkt.PktSerializable
com.neeve.pkt.PktHeader
public final class PktHeader
Represents the header portion of a packet.
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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.neeve.pkt.PktSerializable |
---|
PktSerializable.DeserializeContext, PktSerializable.SerializeContext |
Field Summary | |
---|---|
static int |
MAGIC
|
static int |
MAGIC_SIZE
|
static short |
MAX_HTL
|
static int |
STATIC_HEADER_LENGTH
|
Fields inherited from class com.neeve.util.UtlListElement |
---|
count, head, next, prev |
Method Summary | |
---|---|
PktSubheaderFMC |
activateFMCSubheader(boolean reset)
Activate the fabric multicast subheader. |
PktSubheaderFUC |
activateFUCSubheader(boolean reset)
Activate the fabric unicast subheader. |
PktSubheaderHSpace |
activateHSpaceSubheader(boolean reset)
Activate the hierarchical space subheader. |
PktSubheaderODS |
activateODSSubheader(boolean reset)
Activate the ODS subheader. |
PktSubheaderROGRL |
activateROGRLSubheader(boolean reset)
Activate the ROGRL subheader. |
PktSubheaderRR |
activateRRSubheader(boolean reset)
Activate the request-reply subheader. |
PktSubheaderSMA |
activateSMASubheader(boolean reset)
Activate the SMA subheader. |
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 |
deactivateHSpaceSubheader()
Deactivate the hierarchical space subheader. |
void |
deactivateODSSubheader()
Deactivate the ODS subheader. |
void |
deactivateROGRLSubheader()
Deactivate the ROGRL subheader. |
void |
deactivateRRSubheader()
Deactivate the request-reply subheader. |
void |
deactivateSMASubheader()
Deactivate the SMA subheader. |
void |
deserialize(PktSerializable.DeserializeContext context,
int headerSerializedLength,
Tracer tracer)
Implementation of PktSerializable.deserialize(com.neeve.pkt.PktSerializable.DeserializeContext, int, com.neeve.trace.Tracer) . |
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 This method returns the body type encoded in a serialized packet header. |
PktBuffer |
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. |
PktSubheaderHSpace |
getHSpaceSubheader()
Get the packet hierarchical space 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). |
PktSubheaderODS |
getODSSubheader()
Get the packet ODS subheader. |
boolean |
getReplyExpected()
Get the 'reply expected' flag (V1 Header Field). |
PktSubheaderROGRL |
getROGRLSubheader()
Get the packet ROGRL subheader. |
PktSubheaderRR |
getRRSubheader()
Get the request-reply subheader. |
int |
getSerializedLength()
Implementation of PktSerializable.getSerializedLength()
This method returns the serialized length of the static header plus
the serialized length of all attached subheaders. |
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. |
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 PktBuffer.Initializer.initializeBuffer() |
static boolean |
preDeserialize(PktSerializable.DeserializeContext context)
Perform pre-deserialization checks. |
void |
reset()
Reset the contents of a packet header. |
void |
serialize(PktSerializable.SerializeContext context,
Tracer tracer)
Implementation of PktSerializable.serialize(com.neeve.pkt.PktSerializable.SerializeContext, com.neeve.trace.Tracer) . |
void |
setClazz(short clazz)
Set the packet class (V1 Header Field). |
void |
setDeserializationPolicy(int policy)
Implementation of PktSerializable.setDeserializationPolicy(int) . |
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 |
setNoBuffering(boolean val)
Set the 'no buffering' flag (V1 Header Field). |
void |
setReplyExpected(boolean val)
Set the 'reply expected' flag (V1 Header Field). |
void |
setSerializationPolicy(int policy)
Implementation of PktSerializable.setSerializationPolicy(int) . |
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). |
String |
toString()
Return a string representation of the object. |
Methods inherited from class com.neeve.pkt.PktSerializable |
---|
deserialize, getDeserializationPolicy, getSerializationPolicy, isValidDeserializationPolicy, isValidSerializationPolicy, serialize |
Methods inherited from class com.neeve.util.UtlListElement |
---|
count, insertAfter, insertBefore, isLinked, next, previous, unlink, wipe |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int STATIC_HEADER_LENGTH
public static final int MAGIC_SIZE
public static final int MAGIC
public static final short MAX_HTL
Method Detail |
---|
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 boolean preDeserialize(PktSerializable.DeserializeContext context) throws EPktCorruptException, EPktVersionInvalidException
context
- The context to use for the predeserialization process.
See PktSerializable.DeserializeContext
for more information.
This method validates that the remaining data in the provided byte
buffer contains a valid and full serialized packet. If not valid, a
EPktCorruptException
is thrown. If valid but the header
format version is incorrect, a EPktVersionInvalidException
is
thrown. If valid but not complete, the method returns false and provides
information in the context parameter as to how much additional data is
needed to oomplete the packet. If the byte buffer contains a valid and
complete packet, the context parameter is unchanged.
This method does not actually initialize the header from the
provided buffer. It just serves as a deserialization prologue to
check the integrity of the header and whether enough data is present
to deserialize a complete packet. The markers of the provided buffer
are not modified by this method. The user should call this
method and, in case this method returns successfully, instantiate a
packet header and initialize it using the deserialize(com.neeve.pkt.PktSerializable.DeserializeContext, int, com.neeve.trace.Tracer)
method.
EPktCorruptException
- Thrown if the provided byte buffer does not
contain a valid serialized packet.
EPktVersionInvalidException
- Thrown in case the serialized buffer
contains an invalid header format versionpublic 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(com.neeve.pkt.PktSerializable.SerializeContext, com.neeve.trace.Tracer)
method and can be used by
the user after a call to serialize(com.neeve.pkt.PktSerializable.SerializeContext, com.neeve.trace.Tracer)
to check the length of the
serialized packet. Note that although this field contains the length
of the full packet, the serialize(com.neeve.pkt.PktSerializable.SerializeContext, com.neeve.trace.Tracer)
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 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 final short getNumSubheaders()
public final PktBuffer 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 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 PktSubheaderHSpace activateHSpaceSubheader(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 deactivateHSpaceSubheader()
It is safe to deactivate an already inactive sub-header.
public final PktSubheaderHSpace getHSpaceSubheader()
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 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 PktSubheaderROGRL activateROGRLSubheader(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 deactivateROGRLSubheader()
It is safe to deactivate an already inactive sub-header.
public final PktSubheaderROGRL getROGRLSubheader()
public final PktBody getBody()
public final void reset()
This method resets the contents of a header. Upon return from this method, the contents of the header are the same as a freshly created header of the latest header version.
This method retains its reference to it container packet (if any).
This method is intended for use with object pools through which packet header objects can be recycled rather than created fresh every time.
public final void setSerializationPolicy(int policy)
PktSerializable.setSerializationPolicy(int)
.
setSerializationPolicy
in class PktSerializable
policy
- The serialization policy to use for this entity. The
following are the permissible serialization policies:PktConstants.SERIALIZE_POLICY_HEADER_COPY_BODY_COPY
PktConstants.SERIALIZE_POLICY_HEADER_COPY_BODY_ATTACH
PktConstants.SERIALIZE_POLICY_HEADER_ATTACH_BODY_ATTACH
public final void serialize(PktSerializable.SerializeContext context, Tracer tracer) throws EPktSerializeException
PktSerializable.serialize(com.neeve.pkt.PktSerializable.SerializeContext, com.neeve.trace.Tracer)
.
This method serializes the packet header into the buffer list
in the specified serialization context. This method invokes
PktSerializable.resolveSerializationPolicy(int)
using the
policy in the specified context to resolve the serialization
policy to use. The default serialization policy set in this
entity is determined using the configuration information for
the type of the packet being serialized.
The user should note that this method only serializes the packet header. The user is responsible for serializing the packet body separately.
serialize
in class PktSerializable
context
- The context to be used by the serialization process. See
PktSerializable.SerializeContext
for more information.tracer
- Tracer used to output serialization related trace. Can be
null in which case no trace is output.
EPktSerializeException
- Thrown in case an error is encountered
during the serialization process.
This method serializes a serialiable entity into a byte array presented as a set of byte buffers. As input, this method accepts a serialization context that, among other fields, contains a list of buffers of type {link java.nio.ByteBuffer} into which the entity is to serialize itself. The serialization operation is policy driven and the policy determines whether the header is copied into space remaining in the provided buffers or whether the internal entity buffers are just appended to the provided buffer list. In case the decision is made to copy the serialized data into the provided buffers, the data is always copied into the last buffer in the list. In case the last buffer does not contain enough remaining space to accomodate all the serialized data, this method will allocate and append a new buffer that will be of the same type and capacity as the last buffer in the provided list. Read the documentation of the policy constants to understand which policies cause the header to be copied as opposed to appended (the policy constant names are also self descriptive)
public final void setDeserializationPolicy(int policy)
PktSerializable.setDeserializationPolicy(int)
.
setDeserializationPolicy
in class PktSerializable
policy
- The deserialization policy to use for this entity. The
following are the permissible serialization policies:PktConstants.DESERIALIZE_POLICY_HEADER_COPY_BODY_COPY
PktConstants.DESERIALIZE_POLICY_HEADER_COPY_BODY_SLICE
PktConstants.DESERIALIZE_POLICY_HEADER_SLICE_BODY_SLICE
public final void deserialize(PktSerializable.DeserializeContext context, int headerSerializedLength, Tracer tracer) throws EPktDeserializeException
PktSerializable.deserialize(com.neeve.pkt.PktSerializable.DeserializeContext, int, com.neeve.trace.Tracer)
.
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 preDeserialize(com.neeve.pkt.PktSerializable.DeserializeContext)
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 preDeserialize(com.neeve.pkt.PktSerializable.DeserializeContext)
method
returns successfully i.e. the serialized packet has correct integrity
and the full packet is contained in the buffer. Calling this method
using a corrupt or incomplete buffer has undefined results.
This method invokes PktSerializable.deserialize(com.neeve.pkt.PktSerializable.DeserializeContext, int, com.neeve.trace.Tracer)
using the
policy in the specified context to reolve the deserialization policy
to use. The default deserialization policy set in this entity is
determined using the configuration information for the type of the
packet being deserialized.
deserialize
in class PktSerializable
context
- The context to be used by the deserialization process.
See PktSerializable.DeserializeContext
for more information.headerSerializedLength
- This parameter is present for entities
whose serialized form does not contain the serialized length of the
entity. For such entities, the caller needs to pass in the serialized
length to the entity during deserialize time. For other entities, this
value will be ignored and should be set to -1 (some entities that
pull the length from the serialized form may indeed validate that
the passed in value is -1)tracer
- Tracer used to output deserialization related trace. Can be
null in which case no trace is output.
EPktDeserializeException
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 final int getSerializedLength()
PktSerializable.getSerializedLength()
This method returns the serialized length of the static header plus the serialized length of all attached subheaders.
getSerializedLength
in class PktSerializable
public final void initializeBuffer()
PktBuffer.Initializer.initializeBuffer()
initializeBuffer
in interface PktBuffer.Initializer
public final String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |