tictoc1的学习
ned文件
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28simple Txc1 //通过simple构建了一个节点 { gates: //节点有两个门 input in;//输入门 output out;//输出门 } // // Two instances (tic and toc) of Txc1 connected both ways. // Tic and toc will pass messages to one another. // network Tictoc1//构造一个网络,网络名称叫做Tictoc1 { @display("bgb=147,150");//display可以理解为显示 submodules: tic: Txc1 { @display("p=31,36"); } toc: Txc1 { @display("p=91,83"); } connections://两个节点如何连接 tic.out --> { delay = 100ms; } --> toc.in; tic.in <-- { delay = 100ms; } <-- toc.out; }
cc文件
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39#include <string.h> #include <omnetpp.h> using namespace omnetpp; /** * Derive the Txc1 class from cSimpleModule. In the Tictoc1 network, * both the `tic' and `toc' modules are Txc1 objects, created by OMNeT++ * at the beginning of the simulation. */ class Txc1 : public cSimpleModule { protected: // The following redefined virtual function holds the algorithm. virtual void initialize() override;//初始化功能 virtual void handleMessage(cMessage *msg) override;//处理信息 }; // The module class needs to be registered with OMNeT++ Define_Module(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) {//获取模块的名称,网络有两个子模块(tic、toc) // 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");//通过out门发出消息 } } void Txc1::handleMessage(cMessage *msg)//toc收到消息后 { // 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++基础知识一的全部内容,更多相关OMNET++基础知识一内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复