I have some information I want to include in the packets, and I hope to achieve this by extending the UDPBasicApp application, sending out the packet, and updating it at every switch node in the network.
First, I made the following definitionsExtendedPacket.msg:
import inet.common.packet.chunk.Chunk; import inet.common.packet.Packet; namespace inet; class ExtendedPacket extends FieldsChunk { double delayDev; // Cumulative packet delay variance. } Subsequently, in udpBasicApp.cc:
void UdpBasicApp::sendPacket() { std::ostringstream str; str << packetName << "-" << numSent; Packet *packet = new Packet(str.str().c_str()); const auto& payload = makeShared<ExtendedPacket>(); payload->setChunkLength(B(par("messageLength"))); payload->setSequenceNumber(numSent); payload->addTag<CreationTimeTag>()->setCreationTime(simTime()); payload->setDelayDev(par("delayDev")); packet->insertAtBack(payload); L3Address destAddr = chooseDestAddr(); emit(packetSentSignal, packet); socket.sendTo(packet, destAddr, destPort); } And this is how I modified it:
const auto& oldPayload = packet->peekData<ExtendedPacket>(); auto newPayload = makeShared<ExtendedPacket>(); newPayload = oldPayload->dup(); newPayload->setDelayDev(delayDev); packet->removeAtBack<ExtendedPacket>(packet->getDataLength()); packet->insertAtBack(newPayload); Now, I’m facing the issue that my sending end seems unable to send out the packet.
How can this be resolved? Aside from this, are there any other issues with my code above?