发现网上大部分是讲INET安装,少有几篇讲的是INET的示例,但是怎么实现自己的定制化节点,网络设计,并没有得到很好的解决。本文,自己将把定制化的学习过程分享给大家。
ps.某学院有个499的课,不知道会不会讲自定制节点等知识(看它课程目录,感觉拿着开源赚钱,有点…反正我也没钱买),现在就自己琢磨下。
1.学习分析inet4.3/tutorials/wireless文件夹里的文件,因为它包含了单纯的点对点无线传输。
(1)WirelessA.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
28
29
30
31
32
33
34
35package inet.tutorials.wireless;//表明本文件的位置 import inet.networklayer.configurator.ipv4.Ipv4NetworkConfigurator;//调用的子模块 import inet.node.inet.INetworkNode;//调用的子模块 import inet.physicallayer.wireless.common.contract.packetlevel.IRadioMedium;//调用的子模块 import inet.visualizer.contract.IIntegratedVisualizer;//调用的子模块 network WirelessA { parameters: @display("bgb=650,500;bgg=100,1,grey95");//显示有关不重要 @figure[title](type=label; pos=0,-1; anchor=sw; color=darkblue);//显示有关不重要 @figure[rcvdPkText](type=indicatorText; pos=380,20; anchor=w; font=,18; textFormat="packets received: %g"; initialValue=0);//显示接收到的数据 @statistic[packetReceived](source=hostB.app[0].packetReceived; record=figure(count); targetFigure=rcvdPkText); submodules://以下全部就是节点的定义 visualizer: <default(firstAvailableOrEmpty("IntegratedCanvasVisualizer"))> like IIntegratedVisualizer if typename != "" //调用的子模块:显示界面相关 { @display("p=580,125");//显示在界面上 } configurator: Ipv4NetworkConfigurator //调用的子模块:IPV4协议相关 { @display("p=580,200");//显示在界面上 } radioMedium: <default("UnitDiskRadioMedium")> like IRadioMedium //调用的子模块:信道 { @display("p=580,275");//显示在界面上 } hostA: <default("WirelessHost")> like INetworkNode //调用的子模块:无线节点 { @display("p=50,325");//显示在界面上 } hostB: <default("WirelessHost")> like INetworkNode //调用的子模块:无线节点 { @display("p=450,325");//显示在界面上 } }
(2)omnetpp.ini文件
作用:进一步配置网络:节点+拓扑
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[Config Wireless01] description = Two hosts communicating wirelessly network = WirelessA//进一步配置网络 sim-time-limit = 20s//仿真时间 //进一步配置节点 *.host*.ipv4.arp.typename = "GlobalArp" //进一步配置节点A *.hostA.numApps = 1 *.hostA.app[0].typename = "UdpBasicApp" *.hostA.app[0].destAddresses = "hostB" *.hostA.app[0].destPort = 5000 *.hostA.app[0].messageLength = 1000B *.hostA.app[0].sendInterval = exponential(12ms) *.hostA.app[0].packetName = "UDPData" //进一步配置节点B *.hostB.numApps = 1 *.hostB.app[0].typename = "UdpSink" *.hostB.app[0].localPort = 5000 //进一步配置节点 *.host*.wlan[0].typename = "AckingWirelessInterface" *.host*.wlan[0].mac.useAck = false *.host*.wlan[0].mac.fullDuplex = false *.host*.wlan[0].radio.transmitter.communicationRange = 500m//通信距离 *.host*.wlan[0].radio.receiver.ignoreInterference = true *.host*.wlan[0].mac.headerLength = 23B //进一步配置节点 *.host*.**.bitrate = 1Mbps
(3)如上,借鉴INET的框架,网络的节点和拓扑都简单就写得明明白白。但是!但是节点怎么执行代码呢?毕竟我们是要定制化协议的,我们在tictoc工程中学到的.cc+.h文件在哪里呢?这才是难到很多人的点---------继续上述分析:inet4.3/tutorials中还有一个文件package.ned文件
作用:不详,但是没它不行,后续搞懂了再补充它吧
1
2package inet.tutorials;
(4)点开inet/networklayer/configurator/ipv4/Ipv4NetworkConfigurator查看源码(是.cc和.h文件),因为此文件在WirelessA.ned中调用了
作用:定义了Ipv4NetworkConfigurator模块的具体内容,一堆包含文件,说明它也依赖于别的文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include "inet/networklayer/configurator/ipv4/Ipv4NetworkConfigurator.h" #include <set> #include "inet/common/INETUtils.h" #include "inet/common/ModuleAccess.h" #include "inet/common/XMLUtils.h" #include "inet/common/stlutils.h" #include "inet/networklayer/common/L3AddressResolver.h" #include "inet/networklayer/common/NetworkInterface.h" #include "inet/networklayer/contract/IInterfaceTable.h" #include "inet/networklayer/ipv4/IIpv4RoutingTable.h" namespace inet { Define_Module(Ipv4NetworkConfigurator);//这就是我们在WirelessA.ned调用的模块 ***** //一堆巨人的肩膀 ***** }
(5)点开inet/node/inet/INetworkNode查看源码(是个.ned文件),因为此文件在WirelessA.ned中调用了
1
2
3
4
5
6
7
8
9package inet.node.inet;//表示自己这个文件的位置 moduleinterface INetworkNode { parameters: @display("bgb=,448"); @networkNode; @labels(node,ethernet-node,wireless-node); }
(6)按照5和6的步骤,完成了所有直接调用文件的查看,分为.cc.h文件和.ned文件。文件中各自还有大量的引用依赖
总结:根据以上的分析,自定制的过程是:(名字随意)
1.写自己的test_self.ned文件。定义节点NODE_SELF1:调用相应子模块,但是由于需要自定值功能,因此应该还需要在子模块的基础上增加新的代码
2.写自己的test_self.ini文件。进一步配置网络
3.运行仿真
(7)验证
验证放在下一文章,还在验证中。。。。。。
最后
以上就是机智白猫最近收集整理的关于INET的定制使用OMNET++发现网上大部分是讲INET安装,少有几篇讲的是INET的示例,但是怎么实现自己的定制化节点,网络设计,并没有得到很好的解决。本文,自己将把定制化的学习过程分享给大家。的全部内容,更多相关INET内容请搜索靠谱客的其他文章。
发表评论 取消回复