A subclass of cMessage to represent packets, frames, datagrams, application messages, and similar data.
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;
int srcAddr = -1;
int ttl = 32;
}
- See also
- cSimpleModule, cDatarateChannel, cPacketQueue
|
|
| cPacket (const cPacket &packet) |
|
| cPacket (const char *name=nullptr, short kind=0, int64_t bitLength=0) |
|
virtual | ~cPacket () |
|
cPacket & | operator= (const cPacket &packet) |
|
|
virtual cPacket * | dup () const override |
|
virtual std::string | str () const override |
|
virtual void | forEachChild (cVisitor *v) override |
|
virtual void | parsimPack (cCommBuffer *buffer) const override |
|
virtual void | parsimUnpack (cCommBuffer *buffer) override |
|
virtual bool | isPacket () const override |
|
virtual const char * | getDisplayString () const override |
|
|
virtual void | setBitLength (int64_t l) |
|
void | setByteLength (int64_t l) |
|
virtual void | addBitLength (int64_t delta) |
|
void | addByteLength (int64_t delta) |
|
virtual int64_t | getBitLength () const |
|
int64_t | getByteLength () const |
|
virtual void | setBitError (bool e) |
|
virtual bool | hasBitError () const |
|
|
virtual void | encapsulate (cPacket *packet) |
|
virtual cPacket * | decapsulate () |
|
virtual cPacket * | getEncapsulatedPacket () const |
|
virtual bool | hasEncapsulatedPacket () const |
|
|
bool | isUpdate () const |
|
txid_t | getTransmissionId () const |
|
simtime_t_cref | getDuration () const |
|
simtime_t_cref | getRemainingDuration () const |
|
bool | isReceptionStart () const |
|
bool | isReceptionEnd () const |
|
| cMessage (const cMessage &msg) |
|
| cMessage (const char *name=nullptr, short kind=0) |
|
virtual | ~cMessage () |
|
cMessage & | operator= (const cMessage &msg) |
|
void | setKind (short k) |
|
void | setTimestamp () |
|
void | setTimestamp (simtime_t t) |
|
void | setContextPointer (void *p) |
|
virtual void | setControlInfo (cObject *p) |
|
cObject * | removeControlInfo () |
|
short | getKind () const |
|
simtime_t_cref | getTimestamp () const |
|
void * | getContextPointer () const |
|
cObject * | getControlInfo () const |
|
virtual cArray & | getParList () |
|
virtual cMsgPar & | addPar (const char *name) |
|
virtual cMsgPar & | addPar (cMsgPar *par) |
|
virtual cMsgPar & | par (int index) |
|
virtual cMsgPar & | par (const char *name) |
|
virtual int | findPar (const char *name) const |
|
virtual bool | hasPar (const char *name) const |
|
virtual cObject * | addObject (cObject *par) |
|
virtual cObject * | getObject (const char *name) |
|
virtual bool | hasObject (const char *name) |
|
virtual cObject * | removeObject (const char *name) |
|
virtual cObject * | removeObject (cObject *par) |
|
bool | isSelfMessage () const |
|
cModule * | getSenderModule () const |
|
cGate * | getSenderGate () const |
|
cModule * | getArrivalModule () const |
|
cGate * | getArrivalGate () const |
|
int | getSenderModuleId () const |
|
int | getSenderGateId () const |
|
int | getArrivalModuleId () const |
|
int | getArrivalGateId () const |
|
simtime_t_cref | getCreationTime () const |
|
simtime_t_cref | getSendingTime () const |
|
simtime_t_cref | getArrivalTime () const |
|
bool | arrivedOn (int gateId) const |
|
bool | arrivedOn (const char *gateName) const |
|
bool | arrivedOn (const char *gateName, int gateIndex) const |
|
msgid_t | getId () const |
|
msgid_t | getTreeId () const |
|
void | setArrival (int moduleId, int gateId) |
|
void | setArrival (int moduleId, int gateId, simtime_t_cref t) |
|
| cEvent (const cEvent &event) |
|
| cEvent (const char *name) |
|
virtual | ~cEvent () |
|
cEvent & | operator= (const cEvent &event) |
|
void | setSchedulingPriority (short p) |
|
short | getSchedulingPriority () const |
|
bool | isScheduled () const |
|
simtime_t_cref | getArrivalTime () const |
|
bool | shouldPrecede (const cEvent *event) const |
|
| cOwnedObject () |
|
| cOwnedObject (const char *name, bool namepooling=true) |
|
| cOwnedObject (const cOwnedObject &obj) |
|
virtual | ~cOwnedObject () |
|
cOwnedObject & | operator= (const cOwnedObject &o) |
|
virtual cObject * | getOwner () const override |
|
virtual bool | isOwnedObject () const override |
|
| cNamedObject () |
|
| cNamedObject (const char *name, bool namepooling=true) |
|
| cNamedObject (const cNamedObject &obj) |
|
virtual | ~cNamedObject () |
|
cNamedObject & | operator= (const cNamedObject &o) |
|
virtual void | setName (const char *s) |
|
virtual const char * | getName () const override |
|
virtual void | setNamePooling (bool b) |
|
virtual bool | getNamePooling () |
|
| cObject () |
|
| cObject (const cObject &other)=default |
|
virtual | ~cObject () |
|
virtual const char * | getClassName () const |
|
bool | isName (const char *s) const |
|
virtual const char * | getFullName () const |
|
virtual std::string | getFullPath () const |
|
virtual std::string | getClassAndFullName () const |
|
virtual std::string | getClassAndFullPath () const |
|
const cObject * | getThisPtr () const |
|
virtual std::ostream & | printOn (std::ostream &os) const |
|
virtual bool | isSoftOwner () const |
|
cObject * | findObject (const char *name, bool deep=true) |
|
virtual cClassDescriptor * | getDescriptor () const |
|
void | copyNotSupported () const |
|
virtual void 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.
simtime_t_cref getRemainingDuration |
( |
| ) |
const |
|
inline |
Returns the remaining transmission time for the packet after the packet was sent through a transmission channel such as cDatarateChannel.
For packets delivered to a gate with the default (at-end) delivery mode, the remaining transmission time is zero.
For packets delivered to a gate with the immediate delivery mode, the remaining duration is the full transmission duration if the packet is a normal (i.e. non-update) packet. If the packet is a transmission update (isUpdate() would return true), the remaining transmission time is determined by the send options passed the send call.
After a sending not involving a transmission channel, the remaining duration will be zero.
- See also
- isUpdate(), getDuration(), getArrivalTime(), cDatarateChannel, cGate::setDeliverImmediately(), cSimpleModule::send(), cSimpleModule::sendDirect(), SendOptions