---
tags: ns3, ubuntu
image: https://i.imgur.com/U7Vfw3K.png
title: Ubuntu雙系統+NS3.25+VLC
description: 本篇教學包括安裝Ubuntu 18.04 + win10雙系統,安裝NS-3.25與Eclipse IDE整合,安裝NS-3.25 VLC套件(非官方)
GA: UA-167433668-1
---
# NS-3.25 + Ubuntu 18.04
**Asus ROG GL552VW 電競筆電**
硬碟:1TB HDD
RAM:12GB
處理器:Intel i7-7700HQ 2.80GHz 八核
:::spoiler (以下是寫給我自己看的,怕忘記ww)
顯卡:NVIDIA GeForce GTX 950M
MAC: 60-45-CB-2D-42-8E
IPv4 addr: 192.168.1.34 (preferred)
DHCP server: 192.168.1.1
DNS: 8.8.8.8, 8.8.4.4
:::
## Ubuntu + Win10 Dual boot 安裝方法
:::warning
:warning: 記得先備份windows系統!! :warning:
:::
### 1. 分割出ubuntu磁區
原本的配置只有一個 **C:** (900GB\+), 所以先用disk management把 **C:** 縮小到500GB\+,騰出空間給之後安裝ubuntu用
![](https://i.imgur.com/eSZToXS.png)
### 2. 製作開機碟
1. 去抓ubuntu的iso,我是用torrent (超快)
![](https://i.imgur.com/7ajSijP.png)
2. 做成開機碟,我是用rufus
### 3. 使用開機碟開機
這台筆電進BIOS的方法是:
1. 關機
2. 按著F2不放
3. 按一下電源鍵開機 (此時F2還是一直按著!)
4. 進到BIOS啦\~
選擇boot from剛才做的開機碟!
### 4. Ubuntu 安裝&設定
參考: [How To Install Ubuntu Alongside Windows 10](https://itsfoss.com/install-ubuntu-1404-dual-boot-mode-windows-8-81-uefi/)
不用選try了,可以直接install. 最重要的地方就是partition規劃了!
可以選擇Install alongside windows讓小精靈自動幫你切,也可以選擇Something else自己切。
如果選擇自己切,最重要的就是 **/** 和 **/home**. 前者大概20GB多,後者可以直接吃完剩下的。至於swap, 應該是SSD或RAM很小才需要,所以我就沒規劃了。
> 我原本只是好奇就選了Install alongside Windows, 想說看看預設的partition會怎麼分…沒想到就一去不回頭了RRR!!! 好歹給我看一下確認一下吧喂! :scream:
總之最後結果分出來是 **/** 直接吃滿剛才windows騰出來的400GB\+, 然後 **/home** 看起來是動態調整…? :thinking_face: :question:
![](https://i.imgur.com/GqDUqvM.png)
![](https://i.imgur.com/g3JYIxR.png)
進入Ubuntu之後可以直接開始裝NS3! :confetti_ball:
~~或者也可以先安裝一些有的沒的 (中文輸入法、顯卡驅動、spotify, discord... :rolling_on_the_floor_laughing: )~~
:::warning
:warning: **一些注意事項:**
- ASUS筆電控制電池充電上限的功能要Ubuntu 20.04開始才支援!參考:[link](https://askubuntu.com/questions/1056198/how-can-i-stop-charging-my-battery-at-60/1211506#1211506)
- 有線網絡無法連線:[link](https://hackmd.io/@rgbkoi/ByNBYaBjU)
:::
## NS 3 安裝方法 :minidisc:
### Prerequisites
官方參考:[Installation - Nsnam](https://www.nsnam.org/wiki/Installation#Ubuntu.2FDebian.2FMint)
> 1. 後面一大堆指令都要sudo很麻煩
> 可以先提升到root身份:`sudo -i` 或 `sudo su`
> 做完之後記得`exit`就好!
> 2. 以下`apt-get`都可以用`apt`取代 (最主要的差別是`apt`有進度條…w)
> 3. 每個指令最後可以加上`-y`跳過確認
- [x] **C++**
`$ sudo apt-get install gcc g++ python python3`
- [x] **Python**
`$ sudo apt-get install gcc g++ python python3 python3-dev`
- [x] **~~minimal requirements for Python (development)~~ (?)**
`$ sudo apt-get install python3-setuptools git mercurial`
:::info
官方沒說,但我額外安裝了`python-setuptools`以排除之後在download出現的警告..不知道有沒有差?
還有額外裝了python-config `python3 -m pip install python-config`
:::
- [x] **Netanim animator**
`$ sudo apt-get install qt5-default mercurial`
- [x] **Support for ns\-3\-pyviz visualizer**
`$ sudo apt-get install python-pygraphviz python-kiwi python-pygoocanvas libgoocanvas-dev ipython`
:::warning
ubunt 20.04: unable to locate `python-pygraphviz` `python-kiwi` `libgoocanvas-dev`
ubuntu 20.04: `ipython` has no installation candidate
**ubuntu 18.04: unable to locate `libgoocanvas-dev`**
:::
- For Ubuntu 18.04, python-pygoocanvas is no longer provided. The ns-3.29 release and later upgrades the support to GTK+ version 3, and requires these packages:
`apt-get install gir1.2-goocanvas-2.0 python-gi python-gi-cairo python-pygraphviz python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0 ipython ipython3`
:::warning
ubuntu 20.04: unable to locate `python-pygraphviz`
ubuntu 20.04: `ipython` has no installation candidate
:::
- [x] **Support for MPI-based distributed emulation**
`$ sudo apt-get install openmpi-bin openmpi-common openmpi-doc libopenmpi-dev`
- [x] **Support for bake build tool:**
`$ sudo apt-get install autoconf cvs bzr unrar`
- [x] **Debugging:**
`$ sudo apt-get install gdb valgrind`
- [x] **Support for utils/check-style.py code style check program**
`$ sudo apt-get install uncrustify`
- [x] **Doxygen and related inline documentation:**
`$ sudo apt-get install doxygen graphviz imagemagick`
`$ sudo apt-get install texlive texlive-extra-utils texlive-latex-extra texlive-font-utils dvipng latexmk`
- [ ] **~~ns-3 manual and tutorial~~ (可以跳過嗎?)**
`$ sudo apt-get install python3-sphinx dia`
- [x] **To read pcap packet traces**
`$ sudo apt-get install tcpdump`
- [x] **Database support for statistics framework**
`$ sudo apt-get install sqlite sqlite3 libsqlite3-dev`
- [x] **Xml-based version of the config store (requires libxml2 >= version 2.7)**
`$ sudo apt-get install libxml2 libxml2-dev`
- [x] **Support for generating modified python bindings**
`$ sudo apt-get install cmake libc6-dev libc6-dev-i386 libclang-6.0-dev llvm-6.0-dev automake` (官方tutorial這一部後面有接一個`pip`, 不過`pip`的真正安裝指令是下面藍框裡的)
:::info
安裝pip的方法:`$ sudo apt install python-pip`
:::
~~`$ python3 -m pip install --user cxxfilt`~~
`$ python -m pip install --user cxxfilt`
:::warning
ubuntu 20.04: unable to locate `pip`
(沒裝到pip, 第2行也沒辦法裝`cxxfilt`)
:::
- [ ] **可能要再裝`castxml`或`pygccxml` :thinking_face:**
- [x] **A GTK-based configuration system**
`apt-get install libgtk2.0-0 libgtk2.0-dev`
- [ ] **~~To experiment with virtual machines and ns-3~~**
`apt-get install vtun lxc uml-utilities`
- [x] **Support for openflow module (requires some boost libraries)**
`apt-get install libboost-signals-dev libboost-filesystem-dev`
:::warning
ubuntu 20.04: unable to locate `libboost-signals-dev`
:::
### Install NS3
using mercurial, in `~`:
```bash
$ mkdir repos
$ cd repos
$ hg clone http://code.nsnam.org/ns-3-allinone
$ cd ns-3-allinone
$ ./download.py -n ns-3.xx
$ ./build.py
```
~~download時會跳一些警告,多數是因為上面的prerequisite沒抓好。官方有些指令沒給對...改變方法已經在上面指令用藍色/紅色框框說明。~~
ubuntu 20.04才會,降級到ubuntu 18.04穩穩der ~目前為止…~
**Build時遇到的Error:**
1. =="Distutils not installed? Broken python installation? Get python-config now!"==
~~我猜這是因為python2沒裝到`python-config`, 要裝`python-config`需要`pip`, 但是ubuntu 20.04已經把python2的`pip`移除了!!!~~
- ~~目前我是想改成裝ns-3.29(比較新版本的ns貌似比較依賴python3)但是還沒裝完隨身碟就先爆了~~:skull:
- ~~說不定裝ubuntu 18.04可以? 因為python2-pip是20.04才被拔掉的吧...~~ :thinking_face:
- 用ubuntu18.04雖然還是顯示沒抓到python-config (明明有安裝到),但好像沒有再因為這個噴error
2. build的時候有個wimax model爆掉了
- 不知道為什麼,去設定pybindgen它就好了
- 方法1:
1. build的時候他會說它需要的pybindgen版本號,記下來
2. 把`ns-3-allinone/pybindgen/pybindgen/version.py`裡的版本號改成一樣的
- 方法2:*~(我沒試過!只是覺得或許這個方法也可以)~*
1. 把`ns-3-allinone/pybindgen/pybindgen/version.py`裡的版本號記下來
2. 把`ns-3-allinone/.config`裡的版本號改成一樣的
3. 另一個wimax model爆掉了…
- 乾脆直接把warning as error關掉...?
- `$ cd ns3.xx`
- `$ CXXFLAGS=\"-Wno-error\" ./waf configure`
- `$ ./waf`
:::success
成功了!!目前為止`./waf`成功我就謝天謝地了QQQQQ
:::
### Validating
:information_source: 以下都是在`ns-3.xx/`中進行的!
剛才`./waf configure`只有設定C的flag, 但是測試用的那些程式預設是不編譯的
所以這裡要再次做configure:
```
$ CXXFLAGS="-Wno-error" ./waf configure --enable-tests --enable-examples
$ ./waf
```
這時候就可以開始測試惹!會跑很久… :tea:
```
$ ./test.py
```
全部**PASS**就OK了!:confetti_ball::confetti_ball::clap:
## VLC套件
1. 先切換到ns-3.25路徑 (如果按照上面的步驟,那應該會是`~/repos/ns-3-allinone/ns-3.25`)
2. 用精靈(?)建立module
```
$ cd ./src
$ ./create-module.py vlc
```
2. 把剛才產生的`vlc`資料夾預設內容先清空
```
$ rm -rf ./vlc/*
```
3. 抓套件!
**選項1:** 抓我修改過的版本 ([changelog](https://hackmd.io/@rgbkoi/r1F7BVGNS))
```
$ cd ~/repos/ns-3-allinone/ns-3.25
$ git init
$ git remote add origin https://github.com/alexxss/vlc
$ git pull origin master
```
**選項2:** 抓原作者的原味套件 (請確保目前位於`ns-3.25/src/`)
```
$ git clone https://github.com/Aldalbahias/VLC-ns3-v3.25 ./vlc
$ cd ../
$ cp ./src/vlc/examples/vlc_example.cc ./scratch/
```
4. 編譯
```
$ CXXFLAGS="-Wno-error" ./waf configure
$ ./waf build
```
5. 執行
:::warning
:warning: 檔案路徑前面不能加上`./`,後面不能加上`.cc`
:::
```
$ ./waf --run scratch/vlc_example
```
## Eclipse Integration
參考: [Eclipse Integration](https://hackmd.io/@rgbkoi/rJ8nyCG6V), [Centos7下的NS-3安裝與配置總結](https://blog.csdn.net/ll_xh/article/details/84287071#3%20Eclipse%E9%85%8D%E7%BD%AE)
[Code::Blocks 版本](#Codeblocks-Integration)
### 安裝eclipse
#### 先裝java
`$ sudo apt install openjdk-8-jdk`
檢查有沒有裝好:`$ java -version`
輸出是`openjdk version "1.8.0_xxx"` 就OK!
#### 然後裝eclipse luna
(額外參考:[Installing Eclipse Luna IDE on Ubuntu Linux](https://www.pcquest.com/installing-eclipse-luna-ide-ubuntu-linux/), [How to install Eclipse IDE on Ubuntu 18.04 LTS](https://www.itzgeek.com/how-tos/linux/ubuntu-how-tos/how-to-install-eclipse-ide-on-ubuntu-18-04-lts.html))
1. 把eclipse luna壓縮檔抓到 **/opt**
```
$ cd /opt
$ sudo wget https://archive.eclipse.org/technology/epp/downloads/release/luna/SR2/eclipse-jee-luna-SR2-linux-gtk-x86_64.tar.gz
```
2. 解壓縮去 **/usr/** (弄完記得把tar ball砍掉)
```
$ sudo tar -zxvf eclipse-*-x86_64.tar.gz -C /usr/
```
3. 建立symlink ~~(雖然沒什麼用,應該可以說是good practice?)~~
```
$ sudo ln -s /usr/eclipse/eclipse /usr/bin/eclipse
```
4. 建立桌面啟動圖標 ~(沒裝vim所以用nano)~
```
$ sudo nano /usr/share/applications/eclipse.desktop
```
新增以下內容:
```
[Desktop Entry]
Encoding=UTF-8
Name=Eclipse 4.4.1
Comment=Eclipse Luna
Exec=/usr/bin/eclipse
Icon=/usr/eclipse/icon.xpm
Terminal=false
Type=Application
StartupNotify=false
Categories=Application;Development;Java;IDE
```
**Eclipse安裝好啦\~\~\~\~** :confetti_ball: :dancers:
![](https://i.imgur.com/EhYs1LK.jpg)
### Eclipse設定
:warning: 後來我都用c::b開發,這個設定不保證現在的可行性
1. 啟動eclipse, 一開始會要你設定workspace, 選擇ns-3.25路徑
![](https://i.imgur.com/3vnO5eD.png)
![](https://i.imgur.com/RZM7nPH.png)
2. 選擇Help→"Install New Software..."→"Add..."
![](https://i.imgur.com/t5LhdLn.png)
Name: `cdt`
Location: `http://download.eclipse.org/tools/cdt/releases/kepler`
輸入完畢點 "OK"
![](https://i.imgur.com/pnWeM9o.png)
3. 選 "Select All"
![](https://i.imgur.com/m91Uz1U.png)
然後就一直Next, 中途同意一下T&C, certificates之類的
等它下載完就會重啟
4. File→New→Project→C++ Project ...?
File→New→Project→C/C++→Makefile Project with Existing Code ...?
(toolchain選`none` ok嗎...?)
5. 左側Project Manager右鍵`ns-3.25`選Properties→C/C++ Build
- 取消勾選`Use default build command`
- 編輯`Build command`和`Build directory`
![](https://i.imgur.com/8Q55azP.png)
- 進入Behaviour分頁
- 編輯`Build (Incremental build): build`
![](https://i.imgur.com/naG2na3.png)
**Apply → OK**
6. 左側Project Manager右鍵`ns-3.25`選Debug as→Debug configurations...
7. 雙擊左側欄`C/C++ Application`
編輯Main的C/C++ Application:`build/scratch/vlc_example`
:warning: 後綴不能加`.cc`!
![](https://i.imgur.com/U7Vfw3K.png)
8. 選擇Environment分頁→New...
Variable: `LD_LIBRARY_PATH`
Value: `${workspace_loc:/ns-3.25/build}`
![](https://i.imgur.com/XaTPIpI.png)
**OK→Apply→Close**
9. 執行!
![](https://i.imgur.com/bgd6oFF.png)
![](https://i.imgur.com/D8slGfn.png)
:::success
**以上就算是成功啦\~\~\~可喜可賀** :dancers: :confetti_ball: :clap: :pray:
~~後面還有漫漫長路……………………~~
:::
## Code::blocks Integration
這裡的前提是自己的code是放在`ns-3.xx/scratch/thesis/`這個資料夾裡,main是`thesis.cc`
1. ~~安裝c::b\: 就正常安裝就好~~ :shrug:
Ubuntu app center的c::b版本太舊了OOXX毛病一堆,安裝新版本步驟:
```bash
sudo add-apt-repository ppa:codeblocks-devs/release
sudo apt-get update
sudo apt-get install codeblocks codeblocks-contrib
```
以上指令會安裝新版codeblocks (codeblocks-contrib是輔助套件)
:::info
移除PPA:`sudo add-apt-repository --remove ppa:codeblocks-devs/release`
移除c::b\: `sudo apt remove --autoremove codeblocks codeblocks-contrib`
:::
2. File→New→Project→Empty project
![](https://i.imgur.com/mSc73Z0.png)
3. 設定專案標題&路徑。c::b認定的專案路徑是`your/chosen/path/project-title`.
**重點是**看最後的resulting filename要是`path/to/ns-3.25/project-title`
![](https://i.imgur.com/TfZ2Rjy.png)
4. 截圖沒勾,但是請勾Release
![](https://i.imgur.com/PBUBwfM.png)
5. 把現有檔案加入專案:Project→Add files recursively, 選擇`ns-3.25/src`資料夾
![](https://i.imgur.com/5wNE3ds.png)
c::b會自動幫你勾`.cc`和`.h`檔案,直接按**OK**就好
![](https://i.imgur.com/YK71Q11.png)
同樣方法,加入`ns-3.25/scratch/thesis`.
![](https://i.imgur.com/59StsMZ.png)
6. 修改專案的各種設定:Project→Properties
- **Build targets**
左邊垂直欄位有兩個build target: 'Debug' 'Release'可以選,**兩個build target都要分別做以下步驟**。`<build target>`請代入build target的名字,`/path/to/ns-3.xx`請代入`ns-3.xx`的絕對路徑。
1. Output filename設 `build/<build target>/scratch/thesis/thesis` (如果沒有的話自己打)
2. Execution working dir設`/path/to/ns-3.xx/build`
3. 左側 "Build options..."→"Pre/post build steps"
- 'Debug'的Pre-build steps: `CXXFLAGS="-Wno-error -g -DDEBUG" ./waf configure --build-profile=debug --out=build/<build target>`
:::info
`-Wno-error` 表示compile的時候error判定會很鬆,意思是可能有些錯誤在compile的時候沒抓到,變成runtime error
`-g -DDEBUG` 表示compile的時候會產生debugging symbols, 這樣才可以用step into之類的debug工具
`--build-profile=debug` 同上
`--out=build/<build target>` 表示compile產生出來的檔案會在`build/<build target>`這個路徑
:::
- 'Release'的Pre-build steps: `CXXFLAGS="-Wno-error -O2" ./waf configure --build-profile=release --out=build/<build target>`
:::info
`-O2`是optimization level, 可以讓程式跑得比較快,但有可能會導致有些地方出錯。先確定debug跑過ok再開這個。
:::
4. "Build options..."→"Custom variables" 新增 `LD_LIBRARY_PATH=path/to/ns-3.25/build/<build target>`
- **Project Settings**: 使用ns-3.25自帶的makefile
勾 "This is a custom makefile", 然後確保execution directory是ns-3.25資料夾
![](https://i.imgur.com/BVpIb6n.png)
7. 儲存設定,然後打開Project→Build options→"Make" commands
修改Build project/target, Clean project/target, Ask if rebuild is needed:
![](https://i.imgur.com/nDF88vJ.png)
**左邊欄位的每個選項都要重複一次這一步。**
8. 儲存設定,build & run!
![](https://i.imgur.com/pGmV2AP.png)
:::info
如果跳error, 可嘗試開小黑窗cd至ns-3.xx然後執行waf configure
configure指令參考 :point_right: [**這**](#VLC套件) :point_left:
c::b的build log輸出看一下是什麼錯誤
:::