---
# System prepended metadata

title: III 5GC + UERANSIM 兩個要裝在不同台或docker
tags: [5G-SA]

---

# III 5GC + UERANSIM 兩個要裝在不同台或docker
###### tags: `5G-SA`
## Dependency
`sudo apt update`
`sudo apt upgrade`
`sudo apt install git build-essential vim strace net-tools iputils-ping iproute2 wget gcc g++ autoconf libtool pkg-config libmnl-dev libyaml-dev install make openjdk-11-jdk maven libsctp-dev lksctp-tools`

## III5GC
### Install
https://hackmd.io/@iii5gc/install
`git clone https://github.com/III-5GC/III-5GC-Free-Trial.git`
`cd III-5GC-Free-Trial`
`sudo ./run.sh -i`
內外網各需要一張網卡，內網可以用totolink接上然後設`192.168.1.X`，但我是直接用`docker0`當內網。

目前會偵測不到`docker0`這張網卡導致結束，我先把腳本裡的exit給註解掉。
`docker network connect bridge oam`
`./run.sh -nic1 docker0 -oamIp 192.168.1.10 -sbi 192.168.1.0/24 -sbiGw 192.168.1.254 -nic2 eno1 -natIp 10.118.126.179 -nat 10.118.126.0/24 -natGw 10.118.126.1`

這樣代表docker建好了:
![](https://i.imgur.com/HhcVLTS.jpg)

看docker network是否建立成功:
`docker exec -it oam ifconfig`
![](https://i.imgur.com/11KPmqk.jpg)

### docker-compose issue
#### Error: 
`ERROR: Couldn’t connect to Docker daemon at http+docker://localunixsocket - is it running?
If it’s at a non-standard location, specify the URL with the DOCKER_HOST environment variable.`

#### Solution

`sudo gpasswd -a ${USER} docker`
`sudo su`
`su ${USER}`
`docker-compose up -d`

### Start up container
`sudo docker exec -it natcontainer /bin/bash`
`sudo docker exec -it oam /bin/bash`

### oam (container)
`sudo ./runOAM.sh` 做完應該要如下圖能看到他開啟SMF等容器，才能在docker exec開啟他們and push the start button
![](https://i.imgur.com/jvpJNgZ.png)

然後就能在本機用網頁看http://172.17.0.2，進入管理頁面，看不到的話就是沒做bridge:
`docker network connect bridge oam`，做完能Ping到應該就能看到。
#### flask issue
若是在管理頁面按下start後，回傳`error500`的話就是python沒吃到`mountPath`，直接到`dockerCommand.py`裡面加入絕對路徑:
`os.environ["mountPath"] = "/home/labuser/III-5GC-Free-Trial/5gc_oam/conf"
`![](https://i.imgur.com/Q6QFwJC.jpg)
https://stackoverflow.com/questions/17309889/how-to-debug-a-flask-app

#### turn on debug mode 
![](https://i.imgur.com/Mmtjbn9.jpg)
到`__init__.py`裡面的`app.run()`改成`app.run(debug=True)`
#### oam的腳本跑完之後，會有這麼多個container:

![](https://i.imgur.com/JcjoVHq.jpg)

### natcontainer
開起來之後直接執行裡面的腳本，看起來只是對iptables和route做一些設定

### iiiAMF/AMF/PCF/UPF
各自開起來之後再做route設定，像AMF就要給它到`docker0`的route: `route add -net 172.17.0.0 gw 192.168.1.10 netmask 255.255.0.0 dev eth0`
local to AMF: `sudo route add -net 192.168.1.0 gw 172.17.0.2 netmask 255.255.255.0 dev docker0`
ex:本機的route設定:
![](https://i.imgur.com/joqz7F8.jpg)

---------------------------------

## UERANSIM 
### Install 
`git clone https://github.com/aligungr/UERANSIM.git`
注意版本，3.1.5有ue的bug，3.1.6則沒有，
要用gcc-9、g++9、cmake3.17.5來編譯:
#### cmake 三種方式:
第一:
`sudo snap install cmake --classic`

第二:
`apt remove cmake`
`pip install cmake`

第三:
`apt install cmake`
`wget https://cmake.org/files/v3.17/cmake-3.17.5-Linux-x86_64.tar.gz`
`tar zxvf cmake-3.17.5-Linux-x86_64.tar.gz`
`sudo mv cmake-3.17.5-Linux-x86_64     /opt/cmake-3.17.5`
`sudo ln -sf  /opt/cmake-3.17.5/bin/*    /usr/bin/`
`cmake --version`
#### gcc g++
可以先用gcc -v看版本是否是我們要的，有先update的話基本上就會是9版
`sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90`
`sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 90`

Config alternatives:
`sudo update-alternatives --config gcc` 
`sudo update-alternatives --config g++`

Check 都要是9.x版
`gcc -v` 
`g++ -v`
#### make
`cd UERANSIM`
`make -j4`

#### UE Release issue
因為CN那裡的加密演算法沒有IA3/EA3（從amflog.log檔觀察到），所以要改成false，其餘設定請看[custom-ue.yaml](https://drive.google.com/file/d/1R2tKBrT4Del2CJYtZCk0uCHimwHozM-q/view?usp=sharing).

#### gNB
slice底下的sd要記得改

## run
`cd ~/UERANSIM/build`
`sudo ./nr-gnb -c ~/UERANSIM/config/custom-gnb.yaml`
`sudo ./nr-ue -c ~/UERANSIM/config/custom-ue.yaml`