安裝 UE/RAN 模擬器
此示範我們將練習:
- 安裝 UERANSIM
- 簡單測試 free5GC + UERANSIM
1. 建立 ueramsim VM
重複 free5gc VM 的建立步驟,產生一個新的 VM
- VM 名稱為 ueransim, 記得所有網卡 MAC 都產生新的
- 成功後確定可以連網及使用 SSH 登入
- 更改 hostname 為
ueransim
- 設定 Host-only 網路介面卡靜態 IP 位址為
192.168.56.102
- 重新開機,並啟動 free5gc
- 在 ueransim
ping 192.168.56.101
測試與 free5gc 的連線, 同樣在 free5gcping 192.168.56.102
測試與 ueransim 的連線
2. 安裝 UERANSIM
瀏覽器搜尋 ueransim, 得到網址:
瀏覽閱讀 UERANSIM 開源專案的基本資訊及用途。進入安裝頁面:
下載 UERANSIM
cd ~
git clone https://github.com/aligungr/UERANSIM
cd UERANSIM
git checkout v3.1.0
更新系統
sudo apt update
sudo apt upgrade
安裝工具
sudo apt install make
sudo apt install g++
sudo apt install libsctp-dev lksctp-tools
sudo apt install iproute2
sudo snap install cmake --classic
編譯 UERANSIM
cd ~/UERANSIM
make
3. 安裝 free5GC WebConsole
free5GC 提供一個簡單網頁介面 WebConsole 來管理 UE 註冊資料,供各 NF 使用。 WebConsole 需要 Node.js 及 Yarn 工具來編譯。
首先 SSH 登入 free5gc (192.168.56.101
),先把可能存在的舊工具移除:
sudo apt remove cmdtest
sudo apt remove yarn
安裝 Node.js 及 Yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get update
sudo apt-get install -y nodejs yarn
開始建立 WebConsole
cd ~/free5gc
make webconsole
4. 使用 WebConsole 新增註冊資料
先啟動 WebConsole 伺服器:
cd ~/free5gc/webconsole
go run server.go
終端機印出使用網址 :5000。請在本機打開瀏覽器,輸入網址 http://192.168.56.101:5000
- 打開網頁後,輸入 帳號
admin
,密碼free5gc
- 進入後拉寬瀏覽器,直到看到左側
Subscribers
- 選取
Subscribers
並新增一筆資料- 注意除了 Operator Code Type 選擇 OP 外,其他欄位先保留預設資料,供後續模擬器使用
- 新增完成後,終端機按 Ctrl-C 就可停止 WebConsole
5. 設定 free5GC 核網參數及 UERANSIM 參數
在 free5gc, 我們需要編輯三個設定檔:
~/free5gc/config/amfcfg.yaml
~/free5gc/config/smfcfg.yaml
~/free5gc/config/upfcfg.yaml
SSH 登入 free5gc 後,更改 ~/free5gc/config/amfcfg.yaml
cd ~/free5gc
nano config/amfcfg.yaml
將 ngapIpList 裡的 IP 從 127.0.0.1
改成 192.168.56.101
,亦即
...
ngapIpList: # the IP list of N2 interfaces on this AMF
- 127.0.0.1
改成
...
ngapIpList: # the IP list of N2 interfaces on this AMF
- 192.168.56.101 # 127.0.0.1
接著更改 ~/free5gc/config/smfcfg.yaml
nano config/smfcfg.yaml
將 userplane_information / up_nodes / UPF / interfaces / endpoints 裡的
IP 從 127.0.0.8
改成 192.168.56.101
,亦即
...
interfaces: # Interface list for this UPF
- interfaceType: N3 # the type of the interface (N3 or N9)
endpoints: # the IP address of this N3/N9 interface on this UPF
- 127.0.0.8
改成
...
interfaces: # Interface list for this UPF
- interfaceType: N3 # the type of the interface (N3 or N9)
endpoints: # the IP address of this N3/N9 interface on this UPF
- 192.168.56.101 # 127.0.0.8
最後更改 ~/free5gc/config/upfcfg.yaml
,將 gtpu 裡的 IP
從 127.0.0.8
改為 192.168.56.101
,亦即
...
gtpu:
forwarder: gtp5g
# The IP list of the N3/N9 interfaces on this UPF
# If there are multiple connection, set addr to 0.0.0.0 or list all the addresses
ifList:
- addr: 127.0.0.8
type: N3
改成
...
gtpu:
forwarder: gtp5g
# The IP list of the N3/N9 interfaces on this UPF
# If there are multiple connection, set addr to 0.0.0.0 or list all the addresses
ifList:
- addr: 192.168.56.101 # 127.0.0.8
type: N3
6. 設定 UERANSIM
在 ueransim, 有兩個設定檔跟 free5GC 有關:
~/UERANSIM/config/free5gc-gnb.yaml
~/UERANSIM/config/free5gc-ue.yaml
其中第二個檔案為 UE 設定,內容應與 free5gc 的 WebConsole 產生的預設註冊資料一致, 不需更改。
首先 SSH 登入 ueransim 後,更改 ~/UERANSIM/config/free5gc-gnb.yaml
,
將 ngapIp 及 gtpIp 的 IP 從 127.0.0.1
改成 192.168.56.102
,並將 amfConfigs 裡的
位址改成 192.168.56.101
,亦即
...
ngapIp: 127.0.0.1 # gNB's local IP address for N2 Interface (Usually same with local IP)
gtpIp: 127.0.0.1 # gNB's local IP address for N3 Interface (Usually same with local IP)
# List of AMF address information
amfConfigs:
- address: 127.0.0.1
改成
...
ngapIp: 192.168.56.102 # 127.0.0.1 # gNB's local IP address for N2 Interface (Usually same with local IP)
gtpIp: 192.168.56.102 # 127.0.0.1 # gNB's local IP address for N3 Interface (Usually same with local IP)
# List of AMF address information
amfConfigs:
- address: 192.168.56.101 # 127.0.0.1
接著可以檢視 ~/UERANSIM/config/free5gc-ue.yaml
,看設定資料是否和 WebConsole 裡的資料一致,例如
# IMSI number of the UE. IMSI = [MCC|MNC|MSISDN] (In total 15 or 16 digits)
supi: 'imsi-208930000000003'
# Mobile Country Code value
mcc: '208'
# Mobile Network Code value (2 or 3 digits)
mnc: '93'
# Permanent subscription key
key: '8baf473f2f8fd09487cccbd7097c6862'
# Operator code (OP or OPC) of the UE
op: '8e27b6af0e692e750f32667a3b14605d'
# This value specifies the OP type and it can be either 'OP' or 'OPC'
opType: 'OP'
...
# Initial PDU sessions to be established
sessions:
- type: 'IPv4'
apn: 'internet'
slice:
sst: 0x01
sd: 0x010203
# List of requested S-NSSAIs by this UE
slices:
- sst: 0x01
sd: 0x010203
...
與之前新增的註冊資料一致。
7. 測試 free5GC + UERANSIM
SSH 登入 free5gc, 若曾重新開啟 free5gc,記得先做:
sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -o enp0s3 -j MASQUERADE
sudo systemctl stop ufw
並執行下列指令:
sudo iptables -I FORWARD 1 -j ACCEPT
確定網路環境及設定檔已更改後,到 free5gc 執行 ./run.sh
cd ~/free5gc
./run.sh
此時 free5GC 核網啟動。
另外需準備三個終端機視窗執行 UERANSIM 模擬器 (或你會使用 tmux 也可只用一個):
視窗 1,登入 ueransim,確定模擬器已編譯好,且設定檔也以改好,執行 nr-gnb
cd ~/UERANSIM
build/nr-gnb -c config/free5gc-gnb.yaml
視窗 2,登入 ueransim,用管理員身分執行 nr-gnb
cd ~/UERANSIM
sudo build/nr-ue -c config/free5gc-ue.yaml
視窗 3,登入 ueransim,用 ping
測試模擬器,free5GC 核網,及網際網路是否連通。
首先,用 ifconfig
檢視是否有建立通道 uesimtun0:
$ ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::a00:27ff:fe65:1472 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:65:14:72 txqueuelen 1000 (Ethernet)
RX packets 80 bytes 32423 (32.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 90 bytes 12860 (12.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.56.102 netmask 255.255.255.0 broadcast 192.168.56.255
inet6 fe80::a00:27ff:fe5e:be64 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:5e:be:64 txqueuelen 1000 (Ethernet)
RX packets 1515 bytes 130490 (130.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1010 bytes 206670 (206.6 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 3445 bytes 174416 (174.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3445 bytes 174416 (174.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
uesimtun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500
inet 60.60.0.1 netmask 255.255.255.255 destination 60.60.0.1
inet6 fe80::2034:d00:a76:84b7 prefixlen 64 scopeid 0x20<link>
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 500 (UNSPEC)
RX packets 3 bytes 252 (252.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 13 bytes 732 (732.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
接著使用 ping
:
ping -I uesimtun0 google.com
若有回應代表系統及網路成功運作,恭喜。
常見問題
若安裝與執行 free5GC 及 UERANSIM 過程中發生問題, 先記得有無執行下面幾點,完成再開始測試:
free5gc VM 若重新啟動,有無先執行設定:
sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -o enp0s3 -j MASQUERADE
sudo systemctl stop ufw
sudo iptables -I FORWARD 1 -j ACCEPT
free5gc VM 若想執行測試 ./test.sh TestXXX
,檢查設定檔有先恢復原狀
~/free5gc/config/amfcfg.yaml
~/free5gc/config/smfcfg.yaml
~/free5gc/config/upfcfg.yaml
可用 git diff
檢查。若測試仍有問題,可先清除 MongoDB 資料庫再試:
$ mongo free5gc
...
> db.dropDatabase()
{ "dropped" : "free5gc", "ok" : 1 }
> exit
bye
VM 的介面卡名稱及 IP 是否正確,且和相關的設定檔或指令相符。可從
你的主機 ping 192.168.56.101
及 ping 192.168.56.102
,並在
你的 VM ifconfig
及測試對外連線 ping
。
若已成功安裝測試 free5GC 及 UERANSIM,想知道接下來做什麼,可以完成
之後的簡單應用。要理解及修改 free5GC 的程式內容,除了 5G 標準文件需要研讀外,
可從 test.sh
及 run.sh
著手看網路及程式如何設定。基本網路原理有一些參考: