简体   繁体   English

等待模拟时间 Omnet++

[英]Wait simulation time Omnet++

I need to modify UdpEchoApp (from Inet package) so that before it sends back the packet it waits "x" seconds of simulation time.我需要修改 UdpEchoApp(来自 Inet 包),以便在它发回数据包之前等待“x”秒的模拟时间。 I tried doing something like:我尝试做类似的事情:

simtime_t before;
//something to calculate
simtime_t after;
if (after-before > x) {continue}
else {do something and then recalculate after}

but this crashes Qtenv.但这会使 Qtenv 崩溃。 Is there something i can do to resolve this problem ?我能做些什么来解决这个问题吗? I also post the function that sends back the received packet:我还发布了发回接收到的数据包的函数:

void UdpEchoApp::socketDataArrived(UdpSocket *socket, Packet *pk)
{
    // determine its source address/port
    L3Address remoteAddress = pk->getTag<L3AddressInd>()->getSrcAddress();
    int srcPort = pk->getTag<L4PortInd>()->getSrcPort();
    pk->clearTags();
    pk->trim();

    // statistics
    numEchoed++;
    emit(packetSentSignal, pk);
    // send back
    socket->sendTo(pk, remoteAddress, srcPort);
}

Thank you谢谢

Your code is wrong: simulation time is increased by simulation environment according to incoming events.您的代码是错误的:根据传入事件,模拟环境会增加模拟时间。 In other words, simulation time is modified outside the standard methods that defines a behavior of a module.换句话说,在定义模块行为的标准方法之外修改模拟时间。
To simulate a delay during the simulation one has to use a selfmessage.要在模拟过程中模拟延迟,必须使用自我消息。
In short:简而言之:

  1. In socketDataArrived() :socketDataArrived()
  • remember the packet to send and remoteAddress in a buffer,记住要发送的数据包和缓冲区中的remoteAddress
  • schedule a selfmessage x seconds later (using scheduleAt() ). x秒后安排一条自我消息(使用scheduleAt() )。
  1. In handleMessageWhenUp() when your selfmessage occurs take the packet from the buffer and send it.handleMessageWhenUp()当您的 selfmessage 发生时,从缓冲区中取出数据包并将其发送。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM