Search code examples
omnet++inet

How to get the duration of a packet


In omnet++, I created a packet using the following command and I need to see the duration (in second and in bits) of packet.

void XMac::sendPreamble(MacAddress preamble_address)
{
    //~ diff with XMAC, @ in preamble!
    auto preamble = makeShared<XMacControlFrame>();
    preamble->setSrcAddr(interfaceEntry->getMacAddress());
    preamble->setDestAddr(preamble_address);
    preamble->setChunkLength(ctrlFrameLength);
    preamble->setType(XMAC_PREAMBLE);
    auto packet = new Packet("Preamble", preamble);
    packet->addTag<PacketProtocolTag>()->setProtocol(&Protocol::xmac);
    attachSignal(packet, simTime());
    sendDown(packet);
    nbTxPreambles++;
}

Can anyone please suggest me the syntax of how to see the duration of packet?

Thank you


Solution

  • Every packet has a length (in bits or bytes). The duration (i.e. time of sending a packet via a channel) depends on at least two factors:

    • length of the packet
    • bitrate of a channel

    The length of the packet may be read for example this way:

    auto len = packet->getTotalLength(); 
    int lenBits = b(len).get();  // in bits
    

    After receiving the packet, the transmission duration may be obtained using:

    simtime_t duration = packet->getDuration()