Integrating NS-3 with SUMO using TraCI
ns3吧
全部回复
仅看楼主
level 12
lanfker86 楼主
linux下打汉字麻烦,我尽量用英文。 这些代码不是我写的,我只是综合了网上已有的代码,做了写少许改动。
大多数人对这个东西不感兴趣,不过总会有人想尝试在做Simulation的期间控制车辆,而不是SUMO先产生完整的Trace file, NS-3 只能用,而不能控制SUMO。 我也没时间把它修改得很完美, 抛砖引玉罢了。我用的Ubuntu 12.04 LTS, SUMO-0.18.0, NS-3.18.1
Part I: SUMO installation
Before we install SUMO, there are some libraries we need to install if our linux system does not have them. (Please check SUMO's wiki page).
SUMO installation uses typical GNU autotool chain. Users can use ./configure, make, make install to install SUMO on their linux machines. Since we want interations between NS-3 and SUMO, one solution is that we can use libraries from SUMO. To this end, we add CXXFLAGS='-fPIC' before ./configure command.
Then the command for configure looks likes this: CXXFLAGS ./configure. Then, execute 'make' and 'make install' (probably need root permission).
After the SUMO installation completes, we got an archive file called 'libtraci.a' (taking src/utils/traci/ as an example). We are going to copy needed archive files to ns-3 later.
Part II: NS-3
Since are going to use part of the SUMO's implementation, we need to let NS-3 know where to find SUMO's header files. Here, I am assuming we do not have a root permission. To do this, we need to add an extra INCLUDES directory to G++ flags. There is how: in the root folder of NS-3, there is a file called wscript. Find ' env = conf.env'. After that, add this:
conf.env.append_value ('INCLUDES', ['/home/user/sumo-0.18.0/src'])
The directory may change according to your own situation, but you can get an idea from this example.
After doing that, we create a new module in NS-3. I named it as 'traci-client'. In this module folder (src/traci-client), there is also a file called wscript. We can add needed libraries from SUMO in this wscript. For example, in my case, I added libraries for traci, tcpip, xerces-c. Here is how we can add these libraries for NS-3: At the end of this wscript file, we add these python statements
module.env.append_value ('LINKFLAGS', ['-L../src/traci-client/model/lib'])
module.env.append_value('LIB', ['tcpip'])
module.env.append_value('LIB', ['traci'])
module.env.append_value('LIB', ['xerces-c'])
With all these settings done, we can write our TraCI client interface. In my case, I heavily used an online open source project named OVNIS. Interested readers can refer to its website or github repository. OVNIS is based on older version of SUMO and NS-3, and it does not work for the latest version of SUMO and NS-3.
I have attached my traci-cient model in this post. One thing to notice is that I have copied all the library files I needed to ns-3.18.1/src/traci-client/model/lib. I guess you can infer from my wsript configuration :).
I also wrote an traci application in src/applications/ (see attached files traci-application.zip)
To test if it is working, there is a file named vanet.cc in scratch/. I also attach this file in this post.
In order to run simulation, we'd better install SUMO and NS-3 on the same machine. Then copy SUMO's configuration files in ns3.18.1/scratch/. The .sumocfg file is the most important one since NS-3 needs to use this file to find which port it is going to use for socket communciation.
我是潜水党,很少发贴,别喷我
2013年12月16日 17点12分 1
level 12
lanfker86 楼主
传上去就失效??
用这个链接吧 [无效] http://pan.baidu.com/s/1EKurI
2013年12月16日 17点12分 2
level 1
楼主,请问那个traci-client-module.h 是自动生成的吗?还是手动添加的,里面是一些什么内容,新学NS3,不太懂,希望楼主赐教!
[email protected]
如果可以的话,能否留下邮箱联系!
2015年06月03日 06点06分 4
这个traci-client-module.h其实是ns3 自动生成的,代表着src/traci-client/model/这个文件夹的所有头文件。 你有问题直接贴吧问就好了。 我懂的我会答复的。
2015年06月03日 12点06分
@lanfker86 可能我理解的不太对,将traci—client和traci-application 放到了NS3的 src目录下,然后将vanet.cc放到了scratch下面执行,其他是按照步骤来的,然后就报出了找不到traci-client-module.h 的错,哪里有问题,能详细讲讲吗?谢谢了
2015年06月03日 12点06分
@lanfker86 大概是第二行代码, 把‘traci-client’ 加进去,就是这样 module = bld.create_ns3_module('applications', ['network', 'internet','config-store', 'tools','traci-client'])
2015年06月03日 16点06分
@lanfker86 我在ns3.13下面试的。 这东西我写得比较早了,你试试,如果还不行,就联系我邮箱吧: [email protected] . 回头我有空重新整理一下,到windows下去写汉语。 方便些。[汗]
2015年06月03日 16点06分
level 1
楼主,我想问下,traci-client那个是自己手动创建的文件夹吗?然后这里的wscript在哪里啊
2016年05月05日 02点05分 5
src/文件夹下面有一个python脚本叫做 create-module.py 用它创建。 wscript在src/traci-client/下面,语法也是python的。
2016年05月05日 15点05分
@lanfker86 原来是这样啊!多谢楼主解答,实在太感谢了
2016年05月05日 16点05分
level 8
楼主是研究车载网络吗
2016年10月16日 05点10分 6
是,不过我退吧了。 吧里没人。 混着没意思
2016年10月17日 16点10分
@lanfker86 可否留个联系方式方便交流 刚接触ns3 车联网方向[哈哈]
2016年10月17日 16点10分
2016年10月27日 10点10分
@楼主º☜ 我也是菜鸟,一起一起。
2016年10月27日 12点10分
level 1
楼主,用汉语写一个教程吧 ,英语看的太混乱了,弄了好几天都不对。
2017年04月03日 09点04分 7
我另外有个帖子,里面有虚拟机镜像,你去下载就是了,不需要自己配
2017年04月03日 11点04分
level 1
楼主,现在写论文,发现有想法,但却不会使用SUMO和NS-3来做实验,这两个工具完全不了解,怎么破,感觉要跪了。。。
2017年10月12日 07点10分 9
level 12
lanfker86 楼主
主要是ns3需要多花时间学学
2017年10月12日 12点10分 10
level 2
楼主你好,我正在使用ns-3做无人机路由方向的毕业设计,遇到了许多问题,请问能否私信联系方式?感激不尽!
2018年04月02日 07点04分 15
Routing我没做过,你问我,我也不清楚。 我只是做过WIFI的MAC层。 而且我现在也已经不使用NS3了。 我所有的知识都是我之前积累的。 怕是帮不了你
2018年04月02日 14点04分
@lanfker86 好的,还是谢谢!
2018年04月02日 14点04分
@贝贝哈哈 还有啊, 你有问题直接提就是了,我若真知道答案,必然会答的。 不知道的那就没法了。 我人不在国内,你要联系方式也没用。 帖子里面回复即可
2018年04月02日 14点04分
level 1
这些东西是你写的么 有参考资料的地址么 我现在也在做这一块 看能不能一起合作一下
2018年07月17日 10点07分 16
我已经不玩ns3了。
2018年07月17日 14点07分
回复 lanfker86 :之前有其他的资料么 这一块做的人太少了 我有点想做出来 开源
2018年07月17日 14点07分
我参考了 https://guthub.com/pigne/ovnis 我另外的帖子里面有vm 镜像,里面有source code
2018年07月17日 15点07分
回复 lanfker86 :
2018年07月17日 17点07分
level 1
楼主,我现在在做水下无线传感器网络Mac层的协议仿真,请问你知道怎么做吗
2020年02月09日 13点02分 17
老哥,还在吗?我也是现在才接触ns3水下仿真这块的,可否一块交流一下啊
2021年04月15日 07点04分
兄弟 你会了没 我做路由的 水下节点怎么添加能量模块
2021年09月22日 03点09分
level 1
楼主,你这虚拟机跑了一天,还没结果,总共跑多久啊[疑问]
2020年02月23日 10点02分 18
将traci—client和traci-application 放到了NS3的 src目录下,然后将vanet.cc放到了scratch下面执行,其他是按照步骤来的,然后就build报出了AttributeError: 'BuildContext' object has no attribute 'new_task_gen'
2020年02月25日 08点02分
level 3
请问各位,怎么用NS3和SUMO实现互通呢?该怎么配置?
2021年10月12日 01点10分 19
1