How to add a custom container in a packet

175 views
Skip to first unread message

bruno vieira

unread,
Jul 24, 2019, 6:24:39 AM7/24/19
to OMNeT++ Users
Dear All,

I currently have this code, in order to provide packet sending on my simulation:

    auto packet = new inet::Packet(msgName);
    const auto& payload = inet::makeShared<inet::ByteCountChunk>(inet::B(*packetLengthPar));
    auto now = omnetpp::simTime();
    bool dummy = now < startTime+warmUpDuration || (numPackets != -1 && numSent >= numPackets);
    packet->addPar("dummy") = dummy;
    packet->insertAtBack(payload);

    auto destAddr = chooseDestAddr();


    auto addressType = destAddr.getAddressType();
    packet->addTagIfAbsent<inet::PacketProtocolTag>()->setProtocol(protocol);//protocol
    packet->addTagIfAbsent<inet::DispatchProtocolReq>()->setProtocol(addressType->getNetworkProtocol());
    packet->addTagIfAbsent<inet::L3AddressReq>()->setDestAddress(destAddr);

    EV_WARN << "Sending packet: ";
    printPacket(packet);
    addRecorderAndEmit(sentPkTo,sentPkToSignals,destAddr,packet);
    emit(inet::packetSentSignal, packet);
    send(packet, "ipOut");

The "dummy" parameter, i have no interest in keeping for my application. How can I add a "container" in my packet that represents a real value? i.e I have a variable updated locally that I want to send within this packet.

Best regards,

Marcel Marek

unread,
Jul 26, 2019, 6:49:01 AM7/26/19
to OMNeT++ Users
I believe you need to create your own 'chunk'.
Create .msg file 


class MyHeader extends FieldsChunk
{

bool dummy;
};

in your c++

const auto& payload = makeShared<MyHeader>();


payload->setDummy(false);
packet
->insertAtBack(payload);
send
(packet,"ipOut");


Now you have a packet that looks like this: [MyHeader][IP][...]

m&M.
Reply all
Reply to author
Forward
0 new messages