OMNET++——Tictoc1的教程说明

概述

通过阅读Txc1.cc的文件,.cc文件是用来描述ned中模块的行为,在该代码中重新定义了来自cSimpleModule中的两个方法initialize()和handleMessage()

Txc1::initialize()初始化是仿真的起点,为了启动从tic-toc-tic-toc的仿真过程,选择tic创建一个消息,并通过它的门将消息传输出去,“tictocMsg”是一个任意字符串,它将是消息对象的名称。

Txc1::handleMessage():每当与消息到来时处理的操作。在这里只通过门的out端去做出响应。因为tictoc 都做了同样的事情,所以消息会在两者之间跳变。

注意这个行为过程将会在Txc1类中的对象持续进行,因此这种方式是针对同一类型的操作。

代码

void Txc1::initialize()
{
    // Initialize is called at the beginning of the simulation.
    // To bootstrap the tic-toc-tic-toc process, one of the modules needs
    // to send the first message. Let this be `tic'.

    // Am I Tic or Toc?
    if (strcmp("tic", getName()) == 0) {
        // create and send first message on gate "out". "tictocMsg" is an
        // arbitrary string which will be the name of the message object.
        cMessage *msg = new cMessage("tictocMsg");
        send(msg, "out");
    }
}

void Txc1::handleMessage(cMessage *msg)
{
    // The handleMessage() method is called whenever a message arrives
    // at the module. Here, we just send it to the other module, through
    // gate `out'. Because both `tic' and `toc' does the same, the message
    // will bounce between the two.
    send(msg, "out"); // send out the message
}
总结

omnet中的消息(入包、帧、作业等)和事件(定时器、超时)都有cMessage对象或其子类表示。在你发送或调度它们之后,它们将被模拟内核保存在“计划事件”或“未来事件”列表中,直到它们的时间到来,并通过handleMessage()传递给模块。

请注意,这个模拟中没有设置停止条件:它会永远继续下去。您将能够从GUI停止它。(您也可以在配置文件中指定模拟时间限制或CPU时间限制,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值