How to make a full copy of a cMessage or cPacket

670 views
Skip to first unread message

Alessandro Pischedda

unread,
Jul 4, 2012, 10:30:48 AM7/4/12
to omn...@googlegroups.com
Hi,
I need to have a full copy of a packet/message (cPacket/cMessage), with full copy I mean that I want a new copy of the packet and his inner packets (encapsulated packets). Omnetpp's manual say that the copy (dup() method ) use a reference counter mechanism thus the inner packets aren't a new copy but the method update a reference counter and doesn't create a new inner packet.

Looking at the source code (cmessage.cc) I've notice that in reality is possible to have a new copy for each packet, you can see the code below

//top of cmessage.cc
#define REFCOUNTER

.....code code code ....

void cPacket::copy(const cPacket& msg)
{

#ifdef REFCOUNTING
    if (sharecount!=0)
        throw cRuntimeError(this,"operator=(): this message is refcounted (shared between "
                                 "several messages), it is forbidden to change it");
#endif

    len = msg.len;
    duration = msg.duration;

#ifndef REFCOUNTING
    dropAndDelete(encapmsg);
    if (msg.encapmsg)
        take(encapmsg = (cPacket *)msg.encapmsg->dup());
    else
        encapmsg = NULL;
#else
    if (encapmsg)
        _deleteEncapMsg();
    encapmsg = msg.encapmsg;
    if (encapmsg && ++encapmsg->sharecount==0)   // sharecount overflow
    {
        --encapmsg->sharecount;
        take(encapmsg = (cPacket *)encapmsg->dup());
    }
#endif
}

You probably say : "ok, it's enough to not define the REFCOUNTER to have a full copy of a packet", the problems are that REFCOUNTER is defined at the top of the file and my boss doesn't want to change omnetpp's files. So, is there some way to make it possible?

P.S. sorry for some syntatic or semantic errors.

Alfonso Ariza Quintana

unread,
Jul 4, 2012, 10:59:33 AM7/4/12
to omn...@googlegroups.com
 
It doesn’t have sense, if you want access to the encapsulate packet you need to use the methods decapsulate() or getEncapsulatePacket() and both methods do a copy of the inner packet, the ref counter is, in reality, a defer copy, the copy is postposed to a future, in the moment that you need to access to the inner packet, the idea is optimize the simulation for example, in wireless simulation you need to make a copy of the packet for every node and, most of this copies will be delete in the receptor without consult the encapsulated packets, the ref count avoid to make a copy of this packets, the copy will be made only in the nodes that really need to access to the encapsulated packets
--
Sent from the OMNeT++ mailing list. To configure your membership,
visit http://groups.google.com/group/omnetpp

Alessandro Pischedda

unread,
Jul 4, 2012, 12:08:06 PM7/4/12
to omn...@googlegroups.com
You right and thank you for your answer, I should have looked to dencapsulate() and getEncapsulatePacket() method before make the question. Anyway I don't understand why the code can permit, teorically, to use a reference count mechanism or not . Should it be better change that code ?


Alfonso Ariza Quintana

unread,
Jul 4, 2012, 12:16:18 PM7/4/12
to omn...@googlegroups.com

Think in wifi, your application sends a packet that is encapsulate in TCP/Udp ->IP->Ieee80211 and you need to make a copy for every node because the network is broadcast, but only a node will process the 80211 frame. With the ref count you only need to make the copy of the Ieee frame, for every node but you don’t need initially, to make a copy of all the encapsulated packets, all the nodes, except the destination will delete the 802.11 frame, if you do the whole copy, you need to duplicate all the encapsulated packets that will be deleted immediately after the arrival, in this case you will have a waste of time. You waste time creating copy that are useless and waste time deleting these useless copies.

Shaikha Al-Khuder

unread,
Feb 9, 2016, 9:52:17 AM2/9/16
to OMNeT++ Users, aari...@hotmail.com
If I use this:

// Duplicate message and send the copy.
    cMessage *copy = (cMessage *) msg->dup();
    send(copy, "out");


What fields are kept the same?
And does this duplicate the TreeId as well?

I'm asking this because if I have a malicious node that captured he packet, duplicated it and retransmitted it, can it be detected that is duplicated through the TreeID? 
I read somewhere that each msg is given a msgId each time it's created...

I hope you understood what I'm trying to say.
Reply all
Reply to author
Forward
0 new messages