ns3安装教程-A guide to learn the network discrete event simulator ns3

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010643777/article/details/88563286

  I think it may be helpful to write a guide for newbie on the network simulator ns3 for chinese. But this guide will be in English. To develop the ability to google the possible solution to problems in English is a must for programmers, which needs some endeavor to overcome such obstacle.

1 Install

1.1 Upgrade gcc to gcc6

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-6 g++-6
cd /usr/bin
sudo rm gcc
sudo ln -s gcc-6 gcc
sudo rm g++
sudo ln -s g++-6 g++

reference: Ubuntu升级GCC版本 https://blog.csdn.net/gatieme/article/details/52871438

1.2 Download ns3

1.2.1 Method1:

Downlaod ns3 in github(https://github.com/nsnam/ns-3-dev-git)
  And you can download a specific version:
在这里插入图片描述
 For example download ns3.26(https://github.com/nsnam/ns-3-dev-git/tree/ns-3.26).

1.2.2 Method2:

 Of course, you can download the code with the git method, which may be a bit slower since all the versions will be downloaded.

git  clone https://github.com/nsnam/ns-3-dev-git.git
cd ns-3-dev-git/
git tag
git checkout ns-3.26

 Cope the content under the folder ns-3-dev to a new created folder ns3.26

1.3 Change some warning flags

Change the warning flags in the fille (waf-tools/cflags.py) which may lead compiling failure.
 Original:

self.warnings_flags = [['-Wall'], ['-Werror'], ['-Wextra']]

 Changed version:

self.warnings_flags = [['-Wall'], ['-Wno-unused-parameter'], ['-Wextra']]

1.4 Build

cd ns-3.26/
sudo su
./waf configure
./waf

2 create you own model

 In this part, I will the codes (https://github.com/SoonyangZhang/possion-traffic) as an example to show how to add you own module to ns3. This module is a Possion traffic generator. The one way transmission delay of each received packet will be traced (at receiver side). Each successfully received packet will be acknowledged by the receiver, and the round trip delay will be traced also.

2.1 traced data folder

  Create a new folder named ‘traces’ under ns-3.26 to collect data. The reason in in the possiontrace.cc.

void PossionTrace::OpenTraceOwdFile(std::string name){
	char buf[FILENAME_MAX];
	memset(buf,0,FILENAME_MAX);
	std::string path = std::string (getcwd(buf, FILENAME_MAX)) + "/traces/"
			+name+"_owd.txt";
	m_owd.open(path.c_str(), std::fstream::out);
}
void PossionTrace::OpenTraceRttFile(std::string name){
	char buf[FILENAME_MAX];
	memset(buf,0,FILENAME_MAX);
	std::string path = std::string (getcwd(buf, FILENAME_MAX)) + "/traces/"
			+name+"_rtt.txt";
	m_rtt.open(path.c_str(), std::fstream::out);
}

2.2 module install

 Put the folder possion folder (download from github)to src in ns-3.26.
在这里插入图片描述
 put the possion-traffic.cc (in scratch file on github) under scratch file in ns-3.26. Of course, the wscript should be included.

2.3 Rebuild and run

cd ns-3.26
sudo su
./waf configure
./waf
./waf --run scratch/possion-traffic

 And the traced data can be got under traces file.

2.4 Download the ns3 with possion module configured

 I upload the ns3 with the possion traffic generator in BaiduWangpan (url: https://pan.baidu.com/s/1o6R7y6I_T0VoeJOl0Mo4uQ extraction code: jbav ).

And this version include a trace module (mytrace) and a congestion control module for real time video transmission (nada, https://github.com/cisco/ns3-rmcat).

3 Others

3.1 Introduce third party dynamic library

https://blog.csdn.net/u010643777/article/details/80171171

3.2 Introduce third party static library

https://blog.csdn.net/u010643777/article/details/85017577

3.3 The third party library applys c++ 14 or above

  Change the environment configuration (Ln 499) in wscript under ns3.26
Original:

    env.append_value('CXXFLAGS', '-std=c++11')

Modified:

    env.append_value('CXXFLAGS', '-std=c++11')

3.4 Run

With introduced third party libraries, when you first run simulation, do the command as the following:

sudo su
source /etc/profile
./waf --run scratch/your-project

猜你喜欢

转载自blog.csdn.net/u010643777/article/details/88563286
今日推荐