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
大多数人对这个东西不感兴趣,不过总会有人想尝试在做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.
我是潜水党,很少发贴,别喷我