cPacket Class Reference
[Simulation core classes]

A subclass of cMessage that can be used to represent packets (frames, datagrams, application messages, etc). More...

#include <cmessage.h>

Inheritance diagram for cPacket:
cMessage cOwnedObject cNamedObject cObject

List of all members.

Public Member Functions

Constructors, destructor, assignment

 cPacket (const cPacket &packet)
 cPacket (const char *name=NULL, short kind=0, int64 bitLength=0)
virtual ~cPacket ()
cPacketoperator= (const cPacket &packet)
Redefined cObject member functions.

virtual cPacketdup () const
virtual std::string info () const
virtual std::string detailedInfo () const
virtual void forEachChild (cVisitor *v)
virtual void parsimPack (cCommBuffer *buffer)
virtual void parsimUnpack (cCommBuffer *buffer)
virtual bool isPacket () const
Length and bit error flag

virtual void setBitLength (int64 l)
void setByteLength (int64 l)
virtual void addBitLength (int64 delta)
void addByteLength (int64 delta)
virtual int64 getBitLength () const
int64 getByteLength () const
virtual void setBitError (bool e)
virtual bool hasBitError () const
Message encapsulation.

virtual void encapsulate (cPacket *packet)
virtual cPacketdecapsulate ()
virtual cPacketgetEncapsulatedPacket () const
_OPPDEPRECATED cPacketgetEncapsulatedMsg () const
virtual bool hasEncapsulatedPacket () const
Transmission state

simtime_t_cref getDuration () const
bool isReceptionStart () const

Detailed Description

A subclass of cMessage that can be used to represent packets (frames, datagrams, application messages, etc).

cPacket adds length (measured in bits or bytes), bit error flag, and encapsulation capability to cMessage. Length and bit error flag are significant when the packet travels through a cDatarateChannel or another channel that supports data rate and/or error modelling.

cPacket is rarely used "as is". Typically the user wants to subclass it to create specific packet types for various protocols being modelled. The most convenient way to do that are via message declaration files (.msg), which are translated into C++ classes. An example message declaration:

 packet Datagram
 {
     int destAddr = -1; // destination address
     int srcAddr = -1;  // source address
     int ttl =  32;     // time to live
 }
See also:
cSimpleModule, cDatarateChannel, cPacketQueue

Constructor & Destructor Documentation

cPacket::cPacket ( const char *  name = NULL,
short  kind = 0,
int64  bitLength = 0 
) [explicit]

Constructor.

It takes the packet name, message kind value, and the packet length in bits; all optional.


Member Function Documentation

virtual void cPacket::addBitLength ( int64  delta  )  [virtual]

Changes packet length by the given value (bits).

This is useful for modeling encapsulation/decapsulation. (See also encapsulate() and decapsulate().) The caller must take care that the result does not overflow (i.e. fits into an int64).

The value may be negative (packet length may be decreased too). If the resulting length would be negative, the method throws a cRuntimeError.

void cPacket::addByteLength ( int64  delta  )  [inline]

Changes packet length by the given value (bytes).

This is just a convenience function which invokes addBitLength() with 8*l as argument. The caller must take care that the result does not overflow (i.e. fits into an int64).

virtual cPacket* cPacket::decapsulate (  )  [virtual]

Decapsulates a packet from the packet object.

The length of this packet will be decreased by the length of the encapsulated packet, except if it was zero. If the length would become negative, cRuntimeError is thrown. If there is no encapsulated packet, the method returns NULL.

virtual std::string cPacket::detailedInfo (  )  const [virtual]

Produces a multi-line description of the object's contents.

See cObject for more details.

Reimplemented from cMessage.

virtual cPacket* cPacket::dup (  )  const [inline, virtual]

Creates and returns an exact copy of this object.

See cObject for more details.

Reimplemented from cMessage.

virtual void cPacket::encapsulate ( cPacket packet  )  [virtual]

Encapsulates packet in the packet.

The packet length gets increased by the length of the encapsulated packet.

IMPORTANT NOTE: IT IS FORBIDDEN TO KEEP A POINTER TO A MESSAGE AFTER IT WAS ENCAPSULATED. For performance reasons, encapsulated packets are reference counted, meaning that the encapsulated packet is not duplicated when you duplicate a packet, but rather, both (all) copies share the same packet instance. Any change done to the encapsulated packet would affect other packets as well. Decapsulation (and even calling getEncapsulatedPacket()) will create an own (non-shared) copy of the packet.

virtual void cPacket::forEachChild ( cVisitor v  )  [virtual]

Calls v->visit(this) for each contained object.

See cObject for more details.

Reimplemented from cMessage.

int64 cPacket::getByteLength (  )  const [inline]

Returns the packet length in bytes, that is, bitlength/8.

If bitlength is not a multiple of 8, the result is rounded up.

simtime_t_cref cPacket::getDuration (  )  const [inline]

Returns the transmission duration after the packet was sent through a channel with data rate.

See also:
isReceptionStart(), getArrivalTime(), cDatarateChannel
_OPPDEPRECATED cPacket* cPacket::getEncapsulatedMsg (  )  const [inline]

DEPRECATED.

getEncapsulatedMsg() was renamed to getEncapsulatedPacket(), this method was left for backward compatibility.

virtual cPacket* cPacket::getEncapsulatedPacket (  )  const [virtual]

Returns a pointer to the encapsulated packet, or NULL if there is no encapsulated packet.

IMPORTANT: see notes at encapsulate() about reference counting of encapsulated packets.

virtual bool cPacket::hasEncapsulatedPacket (  )  const [virtual]

Returns true if the packet contains an encapsulated packet, and false otherwise.

This method is potentially more efficient than getEncapsulatedPacket()!=NULL, because it does not need to unshare a shared encapsulated packet (see note at encapsulate()).

virtual std::string cPacket::info (  )  const [virtual]

Produces a one-line description of the object's contents.

See cObject for more details.

Reimplemented from cMessage.

bool cPacket::isReceptionStart (  )  const [inline]

Tells whether this packet represents the start or the end of the reception, provided the packet has nonzero length and it travelled through a channel with nonzero data rate.

This can be configured on the receiving gate (see cGate::setDeliverOnReceptionStart()).

See also:
getArrivalTime(), getDuration(), cDatarateChannel
cPacket& cPacket::operator= ( const cPacket packet  ) 

Assignment operator.

Duplication and the assignment operator work all right with cPacket. The name member is not copied; see cNamedObject's operator=() for more details.

virtual void cPacket::parsimPack ( cCommBuffer buffer  )  [virtual]

Serializes the object into an MPI send buffer Used by the simulation kernel for parallel execution.

See cObject for more details.

Reimplemented from cMessage.

virtual void cPacket::parsimUnpack ( cCommBuffer buffer  )  [virtual]

Deserializes the object from an MPI receive buffer Used by the simulation kernel for parallel execution.

See cObject for more details.

Reimplemented from cMessage.

virtual void cPacket::setBitLength ( int64  l  )  [virtual]

Sets packet length (in bits).

When the packet is sent through a channel, packet length affects the transmission duration and the probability of setting the bit error flag.

void cPacket::setByteLength ( int64  l  )  [inline]

Sets packet length (bytes).

This is just a convenience function which invokes setBitLength() with 8*l as argument. The caller must take care that the result does not overflow (i.e. fits into an int64).


The documentation for this class was generated from the following file:
Generated on Tue Dec 2 11:16:29 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3