我有一个给定的网络,其节点具有以下两种方法:
void Txc13::initialize()
{
// Module 0 sends the first message
if (getIndex() == 0) {
// Boot the process scheduling the initial message as a self-message.
TicTocMsg13 *msg = generateMessage();
simtime_t delay = par("delayTime");
scheduleAt(simTime()+delay, msg);
}
}
void Txc13::handleMessage(cMessage *msg)
{
// we do some casting to access the fields inside the message
TicTocMsg13 *ttmsg = check_and_cast<TicTocMsg13 *>(msg);
if (ttmsg->getDestination() == getIndex()) {
// Message arrived.
bubble("ARRIVED!");
delete ttmsg;
}
else {
// We need to forward the message.
forwardMessage(ttmsg);
}
}
这很好。一旦离开节点0(getIndex()==0
)的消息到达其预期的目的地,模拟就会结束。
现在,我愿意触发一些node0
之后离开delay
的消息。
延迟按指数分布network.tic[*].delayTime = exponential(10s)
。
如何触发来自同一节点的多条消息?
谢谢!
答案 0 :(得分:0)
好的,我想我明白了。这是这两种方法的代码。在initialize
方法中,我创建了一条event
消息,该消息最初是在t=0
处触发的。
void Txc13::initialize()
{
// Create the event object we'll use for timing -- just any ordinary message.
event = new cMessage("event");
// Module 0 sends the first message
if (getIndex() == 0) {
scheduleAt(0.0, event);
}
}
在handleMessage
方法中,我检查传入消息是否为event
。如果是这样,我确实会等待simtime_t delay = par("delayTime")
的访问,该getIndex() == 0
会按指数分配,并发出另一个自消息并转发该消息本身。
由于我希望所有消息都从node0开始,因此我也用void Txc13::handleMessage(cMessage *msg)
{
if (msg == event and getIndex() == 0){
TicTocMsg13 *msg = generateMessage();
simtime_t delay = par("delayTime");
scheduleAt(simTime()+delay, event);
forwardMessage(msg);
}
else {
// we do some casting to access the fields inside the message
TicTocMsg13 *ttmsg = check_and_cast<TicTocMsg13 *>(msg);
if (ttmsg->getDestination() == getIndex()) {
// Message arrived.
//EV << "Message " << ttmsg << " arrived after " << ttmsg->getHopCount() << " hops.\n";
bubble("ARRIVED!");
delete ttmsg;
// Generate another one.
//EV << "Generating another message: ";
//TicTocMsg13 *newmsg = generateMessage();
//EV << newmsg << endl;
//forwardMessage(newmsg);
}
else {
// We need to forward the message.
forwardMessage(ttmsg);
}
}
}
进行了检查。
Order
通过此操作,我获得了以下elog,您可以欣赏到每个事件之后都会转发一条消息。