向NS-3添加新模块_ns3.37添加新模块_ns3.37不同版本模块移植
创始人
2024-02-19 06:46:07
0

 使用ns3的时候,我们需要调用很多模块,比如对wifi的简单功能进行仿真时:

ns-3.35_third.cc_ns-3网络仿真工具wifi脚本解析_wifi脚本网络拓扑_ns-3third脚本全注释_基础ns-3_ns-3入门_ns-3third脚本解析_Part1_Mr_liu_666的博客-CSDN博客IntroBG:ns-3网络仿真工具是一个用于搭建网络拓扑,测试网络算法、模拟不同环境的网络性能的一套软件,这套软件由多个小模块构成(wifi ipv4之类的模块),运行时调用哪个就编译链接哪个。(这一段是我的理解)NS2(Network Simulator, version 2)是一种面向对象的网络仿真器,本质上是一个离散事件模拟器。由UC Berkeley开发而成。它本身有一个虚拟时钟,所有的仿真都由离散事件驱动...https://blog.csdn.net/Mr_liu_666/article/details/121625416?spm=1001.2014.3001.5501
ns-3.35_third.cc_ns-3网络仿真工具wifi脚本解析_wifi脚本网络拓扑_ns-3third脚本全注释_基础ns-3_ns-3入门_ns-3third脚本解析_Part2_Mr_liu_666的博客-CSDN博客ns-3全注释系列,上篇见:https://blog.csdn.net/Mr_liu_666/article/details/121625416?spm=1001.2014.3001.5501https://blog.csdn.net/Mr_liu_666/article/details/122203797?spm=1001.2014.3001.5501

我们就用到了mobility、PointToPoint、csma、wifimac、wifiphty等等这些模块,那么当我需要仿真使用一个常用但ns3里面没有的模块的时候,我就需要新生成一个模块,或者把其他人写好的模块移植到当前环境——那么如果ns3版本不同的话,我们还是需要一些类似于新生成ns3模块的操作。

第一步 模块 layout

module layout,模块布局,也就是新建一个module你的装module的文件夹应该是啥格式的,首先,module都在src目录下,以spectrum模块为例,基本的目录结构如下:

src/module-name/bindings/doc/examples/CMakeLists.txthelper/model/test/examples-to-run.pyCMakeLists.txt

第二步 创建模块skeleton

 以上的目录可以手动创建,也可以自动创建,假设您新建模块的名字为new-module,在ns3.37目录下的utils目录下有自动化脚本可用

./utils/create-module.py new-module

默认情况下,新模块建立在Contrib中(原文档说会建立在src中,但是实际上建立在Contrib中):

两个Cmakelist.txt里面放的是源文件目录,同时指定需要调用哪些其他模块(类似于在Makefile 里面指定需要链接哪些库)。调用模块在new-module/Cmakelist.txt里定义,不在example下定义。

 创建初始状态如上图所示,可以看到两个源文件、两个头文件、一个要链接的libcore库和一个测试源文件,如果加一些别的库就在LIBRARIES_TO_LINK里面加:

build_lib(LIBNAME new-moduleSOURCE_FILES helper/new-module-helper.ccmodel/new-module.ccHEADER_FILES helper/new-module-helper.hmodel/new-module.hLIBRARIES_TO_LINK${libinternet}${libmobility}${libaodv}TEST_SOURCES test/new-module-test-suite.cc
)

 由于internet model依赖于core库,所以不用重复引用。

第三步 添加源文件列表

在new-module/Cmakelist.txt里面指定了new-module.cc new-module.h 等5个文件,运行ns configure之后就会进一步调用cmake,然后检查这些文件,再运行ns3 build,就编译Cmakelist.txt里面的源文件,再链接上指明的库,以spectrum模块为例子:

set(source_fileshelper/adhoc-aloha-noack-ideal-phy-helper.cchelper/spectrum-analyzer-helper.cchelper/spectrum-helper.cchelper/tv-spectrum-transmitter-helper.cchelper/waveform-generator-helper.ccmodel/aloha-noack-mac-header.ccmodel/aloha-noack-net-device.ccmodel/constant-spectrum-propagation-loss.ccmodel/friis-spectrum-propagation-loss.ccmodel/half-duplex-ideal-phy-signal-parameters.ccmodel/half-duplex-ideal-phy.ccmodel/matrix-based-channel-model.ccmodel/microwave-oven-spectrum-value-helper.ccmodel/multi-model-spectrum-channel.ccmodel/non-communicating-net-device.ccmodel/single-model-spectrum-channel.ccmodel/spectrum-analyzer.ccmodel/spectrum-channel.ccmodel/spectrum-converter.ccmodel/spectrum-error-model.ccmodel/spectrum-interference.ccmodel/spectrum-model-300kHz-300GHz-log.ccmodel/spectrum-model-ism2400MHz-res1MHz.ccmodel/spectrum-model.ccmodel/spectrum-phy.ccmodel/spectrum-propagation-loss-model.ccmodel/phased-array-spectrum-propagation-loss-model.ccmodel/spectrum-signal-parameters.ccmodel/spectrum-value.ccmodel/three-gpp-channel-model.ccmodel/three-gpp-spectrum-propagation-loss-model.ccmodel/trace-fading-loss-model.ccmodel/tv-spectrum-transmitter.ccmodel/waveform-generator.ccmodel/wifi-spectrum-value-helper.cc
)set(header_fileshelper/adhoc-aloha-noack-ideal-phy-helper.hhelper/spectrum-analyzer-helper.hhelper/spectrum-helper.hhelper/tv-spectrum-transmitter-helper.hhelper/waveform-generator-helper.hmodel/aloha-noack-mac-header.hmodel/aloha-noack-net-device.hmodel/constant-spectrum-propagation-loss.hmodel/friis-spectrum-propagation-loss.hmodel/half-duplex-ideal-phy-signal-parameters.hmodel/half-duplex-ideal-phy.hmodel/matrix-based-channel-model.hmodel/microwave-oven-spectrum-value-helper.hmodel/multi-model-spectrum-channel.hmodel/non-communicating-net-device.hmodel/single-model-spectrum-channel.hmodel/spectrum-analyzer.hmodel/spectrum-channel.hmodel/spectrum-converter.hmodel/spectrum-error-model.hmodel/spectrum-interference.hmodel/spectrum-model-300kHz-300GHz-log.hmodel/spectrum-model-ism2400MHz-res1MHz.hmodel/spectrum-model.hmodel/spectrum-phy.hmodel/spectrum-propagation-loss-model.hmodel/phased-array-spectrum-propagation-loss-model.hmodel/spectrum-signal-parameters.hmodel/spectrum-value.hmodel/three-gpp-channel-model.hmodel/three-gpp-spectrum-propagation-loss-model.hmodel/trace-fading-loss-model.hmodel/tv-spectrum-transmitter.hmodel/waveform-generator.hmodel/wifi-spectrum-value-helper.htest/spectrum-test.h
)build_lib(LIBNAME spectrumSOURCE_FILES ${source_files}HEADER_FILES ${header_files}LIBRARIES_TO_LINK ${libpropagation}${libantenna}TEST_SOURCEStest/spectrum-ideal-phy-test.cctest/spectrum-interference-test.cctest/spectrum-value-test.cctest/spectrum-waveform-generator-test.cctest/three-gpp-channel-test-suite.cctest/tv-helper-distribution-test.cctest/tv-spectrum-transmitter-test.cc
)

 可见spectrum模块也是一样。可以看到第二步和第三步的Cmakelist.txt格式不一样,两种都是可以的,比较长久像spectrum一样,短一点就像new-module一样就行

另外,source_files和header_files可以空着,也能编译,但是别的模块就调用不了newmodule的API了。

第四步 声明公共header文件

 如果在Cmakelist.txt里面指出了header文件,那么就会在build/include/ns3给你复制一个副本,其他模块include的时候就include "ns3/xxx.h"就行了。如果不想被外部调用,那就不放在列表里就好,这样就不会被复制了。

第五步 声明测试文件

如果module中含test,也需要在Cmakelist.txt里面指出,依旧以spectrum为例子(在上面代码里面已经粘贴过一次了,这里再粘贴一次):

build_lib(LIBNAME spectrumSOURCE_FILES ${source_files}HEADER_FILES ${header_files}LIBRARIES_TO_LINK ${libpropagation}${libantenna}TEST_SOURCEStest/spectrum-ideal-phy-test.cctest/spectrum-interference-test.cctest/spectrum-value-test.cctest/spectrum-waveform-generator-test.cctest/three-gpp-channel-test-suite.cctest/tv-helper-distribution-test.cctest/tv-spectrum-transmitter-test.cc
)

加了test之后可以用test.py --list查找到,

 也可以用test.py执行测试:

 第六步 声明example

 比如third first这类的都属于example,声明example需要源文件并且把它在examples /cmakelists.t xt 里面声明一下。examples下的cmakelists.txt会被上层的cmakelists.txt递归调用

 如果example需要链接外部module,也需要在example/cmakelists.txt里面指出:

第七步 将example 作为 test执行

需要在test的examples-to-run.py里面添加需要测试的example的源码文件名,依然以spectrum为例:

 example_name是要运行的可执行文件

do_run是运行示例的条件

do_valgrind_run是在valgrind下运行示例的条件。

第八步 configure 和 build

新生成的cmakelist.txt需要经过ns3 configure之后才能被读取、生成相应Makefile。有了Makefile之后运行ns3 biuld就可以把心添加的模块编译了。如果configure 的时候使能了test,那么test.py --list就可以看到新模块了,如果configure使能了example,那么ns3 run 就能直接运行声明的example了。

第九步 添加Python Bindings

如果想用python的方式调用,就需要这个了,由于我使用c++,以上内容就够了。

相关内容

热门资讯

喜欢穿一身黑的男生性格(喜欢穿... 今天百科达人给各位分享喜欢穿一身黑的男生性格的知识,其中也会对喜欢穿一身黑衣服的男人人好相处吗进行解...
发春是什么意思(思春和发春是什... 本篇文章极速百科给大家谈谈发春是什么意思,以及思春和发春是什么意思对应的知识点,希望对各位有所帮助,...
网络用语zl是什么意思(zl是... 今天给各位分享网络用语zl是什么意思的知识,其中也会对zl是啥意思是什么网络用语进行解释,如果能碰巧...
为什么酷狗音乐自己唱的歌不能下... 本篇文章极速百科小编给大家谈谈为什么酷狗音乐自己唱的歌不能下载到本地?,以及为什么酷狗下载的歌曲不是...
家里可以做假山养金鱼吗(假山能... 今天百科达人给各位分享家里可以做假山养金鱼吗的知识,其中也会对假山能放鱼缸里吗进行解释,如果能碰巧解...
华为下载未安装的文件去哪找(华... 今天百科达人给各位分享华为下载未安装的文件去哪找的知识,其中也会对华为下载未安装的文件去哪找到进行解...
四分五裂是什么生肖什么动物(四... 本篇文章极速百科小编给大家谈谈四分五裂是什么生肖什么动物,以及四分五裂打一生肖是什么对应的知识点,希...
怎么往应用助手里添加应用(应用... 今天百科达人给各位分享怎么往应用助手里添加应用的知识,其中也会对应用助手怎么添加微信进行解释,如果能...
苏州离哪个飞机场近(苏州离哪个... 本篇文章极速百科小编给大家谈谈苏州离哪个飞机场近,以及苏州离哪个飞机场近点对应的知识点,希望对各位有...
客厅放八骏马摆件可以吗(家里摆... 今天给各位分享客厅放八骏马摆件可以吗的知识,其中也会对家里摆八骏马摆件好吗进行解释,如果能碰巧解决你...