ndnSIM仿真平台使用之安装

 

由于参照ndnSIM官网http://ndnsim.net/current/index.html会出现可视化模块安装不上、切换老版本时编译出错等问题,本文在官网安装教程的基础上,重新整理了两个版本的ndnSIM(2.1与2.7)的详细安装流程。

版本信息如下:

  1. ndnSIM2.1
    操作系统:Ubuntu 16.04
    ndnSIM:ndnSIM-2.1
    ns-3-dev:ns-3.23-dev-ndnSIM-2.1
    pybindgen:0.17.0.post45+ng4806e4f

  2. ndnSIM2.7
    操作系统:Ubuntu 18.10
    ndnSIM:ndnSIM-2.7
    ns-3-dev:ndnSIM-ns-3.29
    pybindgen:0.19.0

更新记录:

  • 20200326:按照原先ndnSIM2.1安装步骤仍有可能无法正常运行可视化程序,现已修改。

git的使用

由于在安装不同版本时需要用git来切换,所以首先简单介绍一下安装过程中需要用到的几个git命令。

  • git tag

列出现有标签,效果如下:

image

  • git checkout

切换版本,根据git tag列出来的标签,切换至需要的标签。

例如:

git checkout ns-3.23-dev-ndnSIM-2.1
  • git submodule update –init

下载子模块内容,安装ndnSIM时需要用到,需要下载ndn-cxx和NFD两个子模块。

ndnSIM2.1

对应的操作系统为Ubuntu 16.04。

安装前准备工作

ndnSIM2.1的安装前准备工作可完全按照官网http://ndnsim.net/2.1/getting-started.html所述进行,具体如下:

sudo apt-get install build-essential libsqlite3-dev libcrypto++-dev
sudo apt-get install libboost-all-dev
sudo apt-get install python-dev python-pygraphviz python-kiwi
sudo apt-get install python-pygoocanvas python-gnome2
sudo apt-get install python-rsvg ipython

(20200326修改)此外,为了安装可视化程序还需要安装额外的两个包python-setuptools和python-gnome2-desktop-dev(官网中无此步骤):

sudo apt-get install python-setuptools
sudo apt-get install python-gnome2-desktop-dev

下载源码

mkdir ndnSIM2.1
cd ndnSIM2.1
git clone https://github.com/named-data-ndnSIM/ns-3-dev.git ns-3
git clone https://github.com/named-data-ndnSIM/pybindgen.git pybindgen
git clone https://github.com/named-data-ndnSIM/ndnSIM.git ns-3/src/ndnSIM

注意此处第三处clone与官网略有差别,少了一个--recursive

切换版本

ndnSIM

进入ndnSIM的目录:ndnSIM2.1/ns-3/src/ndnSIM,打开终端,输入git tag查看所有标签,发现有ndnSIM-2.1,然后输入一下命令可切换至2.1版本:

git checkout ndnSIM-2.1

输入以下命令下载子模块ndn-cxx和NFD:

git submodule update --init

ns-3-dev

进入ns-3目录:ndnSIM2.1/ns-3,打开终端,输入git tag查看所有标签,发现有ns-3.23-dev-ndnSIM-2.1,然后输入以下命令可切换至3.23版本:

git checkout ns-3.23-dev-ndnSIM-2.1

pybindgen

进入pybindgen目录:ndnSIM2.1/pybindgen,打开终端,输入输入git tag查看所有标签,发现有0.17.0.post45+ng4806e4f,然后输入以下命令可切换至该版本:

git checkout 0.17.0.post45+ng4806e4f

(20200326修改)然后在此目录下安装重新安装该python模块:

sudo python setup.py install

重新设置ns-3要求的pybindgen版本

这里应该是pybindgen的一个bug,我们虽然在上步把pybindgen的版本切换到了0.17.0.post45+ng4806e4f,但ns-3在编译前检测时只能检测到0.17.0.post45,但需要0.17.0.post45+ng4806e4f,运行./waf configure发现错误如下:

image

我们进入目录ndnSIM2.1/ns-3/bindings/python,打开wcript文件,作如下修改:

image

保存后回到ns-3目录,再次运行./waf configure,发现错误消失:

image

运行ndnSIM

经过以上配置,ndnSIM2.1可正常运行,可视化程序也可正常运行,可通过以下命令验证。

cd ~/ndnSIM2.1/ns-3
./waf configure --enable-examples
./waf
./waf --run ndn-simple --vis

ndnSIM2.7

对应的操作系统为Ubuntu 18.10。由于当前没有准备Ubuntu 18.04的虚拟机,故此部分没有截图说明,但文字部分已足够指导安装。

安装前准备工作

ndnSIM2.7的安装前准备工作可完全按照官网http://ndnsim.net/2.7/getting-started.html有细微出入,主要是可视化程序的依赖上:

sudo apt install build-essential libsqlite3-dev libboost-all-dev libssl-dev git python-setuptools castxml
sudo apt install python-dev python-pygraphviz python-kiwi python-gnome2 ipython libcairo2-dev python3-gi libgirepository1.0-dev python-gi python-gi-cairo gir1.2-gtk-3.0 gir1.2-goocanvas-2.0 python-pip
pip install pygraphviz pycairo PyGObject pygccxml

以上是官网的安装命令,全部安装完毕后发现可视化程序依然不能使用,需要再输入以下命令(参考https://github.com/pygraphviz/pygraphviz/issues/54):

sudo apt-get install graphviz libgraphviz-dev graphviz-dev pkg-config
pip install pygraphviz

安装完毕后可视化程序可以正常使用。

下载源码

mkdir ndnSIM2.7
cd ndnSIM2.7
git clone https://github.com/named-data-ndnSIM/ns-3-dev.git ns-3
git clone https://github.com/named-data-ndnSIM/pybindgen.git pybindgen
git clone --recursive https://github.com/named-data-ndnSIM/ndnSIM.git ns-3/src/ndnSIM

切换版本

ndnSIM2.7是目前最新的版本(2019.04.24),git下载下来的源码都是最新源码,因此不需要做切换。

运行ndnSIM

cd ~/ndnSIM2.7/ns-3
./waf configure --enable-examples
./waf
./waf --run ndn-simple --vis