DRCL J-Sim API

drcl.net
Class Packet

java.lang.Object
  extended bydrcl.net.Packet
All Implemented Interfaces:
java.lang.Cloneable, Countable, ObjectCloneable, PacketWrapper
Direct Known Subclasses:
AODV_Packet, ARPPacket, FooPacket, InetPacket, LLPacket, Mac_802_11_Packet, OSPF_Packet, SensorPacket, TCPPacket, UDPPacket

public abstract class Packet
extends java.lang.Object
implements PacketWrapper, Countable

This class defines the base class for implementing packets. A packet consists of a header and a body. The header structure should be further defined in subclasses. This class defines the interface a subclass should/would implement, and implements the setter/getter methods for the encapsulated body object, the packet size and the header size.


Field Summary
 java.lang.Object body
           
 int headerSize
           
 long id
          The packet ID that is used and maintained by instrument components, should be globally and uniquely recognized.
 int size
           
 
Constructor Summary
Packet()
           
Packet(int packetSize_)
           
Packet(int headerSize_, int bodySize_, java.lang.Object body_)
           
 
Method Summary
 java.lang.String _toString(java.lang.String separator_)
          Prints the packet header.
abstract  java.lang.Object clone()
          Returns a clone of this object.
 boolean equals(java.lang.Object that_)
          Returns true if that_ is a packet, and its packet size, header size and the encapsulated object are all equal to those of this packet.
 java.lang.Object getBody()
          Returns the encapsulated object of this packet.
 long getByteCount()
          Returns the byte count of this packet in the connection to which this packet belongs.
 int getHeaderSize()
          Returns the header size of this packet.
abstract  java.lang.String getName()
          Returns the name of this packet.
 int getNumberCount()
          Returns the "sequence" of the object.
 int getPacketCount()
          Returns the count of this packet in the connection to which this packet belongs.
 int getPacketSize()
          Returns the packet size of this packet.
 java.lang.String getPacketType()
          Returns the type of packet.
 int getSize()
          Returns the packet size of this packet.
 long getSizeCount()
          Returns the size "sequence" of the object.
 double getTimestamp()
           
 boolean isByteCountSupported()
           
 boolean isPacketCountSupported()
           
 boolean isTimestampSupported()
           
 void setBody(java.lang.Object b_, int bodySize_)
          Sets the encapsulated object of this packet.
 void setBody(Packet b_)
          Sets the encapsulated object of this packet with another packet.
 void setHeaderSize(int hsize_)
          Sets the header size of this packet.
 void setPacketSize(int packetSize_)
          Sets the packet size of this packet.
 void setSize(int packetSize_, int headerSize_)
          Sets the packet and header sizes of this packet.
 void setTimestamp(double time_)
           
 java.lang.String toString()
          Prints the content of this packet; subclasses should override _toString(String).
 java.lang.String toString(java.lang.String separator_)
          Prints the content of this packet; subclasses should override _toString(String).
 void wraps(Packet p_)
          Wraps the argument packet as the body of this packet.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

body

public java.lang.Object body

size

public int size

headerSize

public int headerSize

id

public long id
The packet ID that is used and maintained by instrument components, should be globally and uniquely recognized.

Constructor Detail

Packet

public Packet()

Packet

public Packet(int packetSize_)

Packet

public Packet(int headerSize_,
              int bodySize_,
              java.lang.Object body_)
Method Detail

clone

public abstract java.lang.Object clone()
Description copied from interface: ObjectCloneable
Returns a clone of this object.

Specified by:
clone in interface ObjectCloneable

getName

public abstract java.lang.String getName()
Returns the name of this packet.


getBody

public java.lang.Object getBody()
Returns the encapsulated object of this packet.


setBody

public void setBody(Packet b_)
Sets the encapsulated object of this packet with another packet.


wraps

public void wraps(Packet p_)
Wraps the argument packet as the body of this packet.

Specified by:
wraps in interface PacketWrapper

setBody

public void setBody(java.lang.Object b_,
                    int bodySize_)
Sets the encapsulated object of this packet.


getPacketSize

public int getPacketSize()
Returns the packet size of this packet.


getSize

public int getSize()
Returns the packet size of this packet.

Specified by:
getSize in interface Countable

setPacketSize

public void setPacketSize(int packetSize_)
Sets the packet size of this packet.


setHeaderSize

public void setHeaderSize(int hsize_)
Sets the header size of this packet.


getHeaderSize

public int getHeaderSize()
Returns the header size of this packet.


getPacketType

public java.lang.String getPacketType()
Returns the type of packet. By default, it delegates the call to the encapsulated packet, and returns getName() otherwise.


getPacketCount

public int getPacketCount()
Returns the count of this packet in the connection to which this packet belongs. By default, it delegates the call to the encapsulated packet, and throws a PacketException if the encapsulated object is not a packet.


getNumberCount

public int getNumberCount()
Description copied from interface: Countable
Returns the "sequence" of the object.

Specified by:
getNumberCount in interface Countable
See Also:
getPacketCount()

isPacketCountSupported

public boolean isPacketCountSupported()

getByteCount

public long getByteCount()
Returns the byte count of this packet in the connection to which this packet belongs. By default, it delegates the call to the encapsulated packet, and throws a PacketException if the encapsulated object is not a packet. This method approximates the byte count with the byte count obtained from the encapsulated packet plus the header size times the packet count.


getSizeCount

public long getSizeCount()
Description copied from interface: Countable
Returns the size "sequence" of the object.

Specified by:
getSizeCount in interface Countable
See Also:
getByteCount()

isByteCountSupported

public boolean isByteCountSupported()

getTimestamp

public double getTimestamp()

setTimestamp

public void setTimestamp(double time_)

isTimestampSupported

public boolean isTimestampSupported()

setSize

public void setSize(int packetSize_,
                    int headerSize_)
Sets the packet and header sizes of this packet.


toString

public java.lang.String toString()
Prints the content of this packet; subclasses should override _toString(String).


toString

public java.lang.String toString(java.lang.String separator_)
Prints the content of this packet; subclasses should override _toString(String).


_toString

public java.lang.String _toString(java.lang.String separator_)
Prints the packet header.


equals

public boolean equals(java.lang.Object that_)
Returns true if that_ is a packet, and its packet size, header size and the encapsulated object are all equal to those of this packet.


DRCL J-Sim API

Copyright © 1998-2003 Distributed Real-time Computing Lab (DRCL). All Rights Reserved.     ~ To J-Sim Home ~