Open5gs and Openairinterface CU/DU split
===
###### tags: `open5gs` `openairinterface`
:::info
- **Location:** RT LAB
- **Agenda**
1. Open5gs v2.7.2
- VM OS : Ubuntu 22.04.4 LTS
- IP : 192.168.60.2
1. Openairinterface (main branch)
- VM OS : Ubuntu 22.04.4 LTS
- IP : 192.168.60.8
- **Author:** Saffana Zyan DINI
- **Contact:** Zyzy <M11102815@gapps.ntust.edu.tw>
- **Reference:**
- [Building Open5GS from Sources](https://open5gs.org/open5gs/docs/guide/02-building-open5gs-from-sources/)
- [How to build Openairinterface](https://gitlab.eurecom.fr/oai/openairinterface5g/-/blob/develop/doc/BUILD.md)
- [Open5gs ueransim sample config](https://github.com/s5uishida/open5gs_5gc_ueransim_sample_config?tab=readme-ov-file)
:::
### The Architecture

### The Call Flow

:dart: Build Open5gs(VM1)
---
#### Getting MongoDB
Import the public key used by the package management system.
```yaml
sudo apt update
sudo apt install gnupg
curl -fsSL https://pgp.mongodb.com/server-6.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg --dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
```
Install the MongoDB packages.
```
sudo apt update
sudo apt install -y mongodb-org
sudo systemctl start mongod
sudo systemctl enable mongod
```
Check Mongod status
```
sudo systemctl status mongod
```

#### Setting up TUN device (not persistent after rebooting)
Create the TUN device with the interface name ogstun.
```
sudo ip tuntap add name ogstun mode tun
sudo ip addr add 10.45.0.1/16 dev ogstun
sudo ip addr add 2001:db8:cafe::1/48 dev ogstun
sudo ip link set ogstun up
```

check ogstun interface:
```
ifconfig ogstun
```

#### Building Open5GS
Install the dependencies for building the source code.
```bash
sudo apt install python3-pip python3-setuptools python3-wheel ninja-build build-essential flex bison git cmake libsctp-dev libgnutls28-dev libgcrypt-dev libssl-dev libidn11-dev libmongoc-dev libbson-dev libyaml-dev libnghttp2-dev libmicrohttpd-dev libcurl4-gnutls-dev libnghttp2-dev libtins-dev libtalloc-dev meson
```
Git clone.
```
git clone https://github.com/open5gs/open5gs
```
To compile with meson:
```
cd open5gs
git checkout v2.7.2
meson build --prefix=`pwd`/install
ninja -C build
```


>The test program has been run on [VirtualBox - CPU: 1, Memory: 4.00 GB] and [Docker for Mac - CPU: 2, Memory: 2.00 GB] with default setting (max.ue: 4,096, pool.packet: 32,768).
Check whether the compilation is correct.(5g core only)
```
./build/tests/registration/registration
```

Run all test programs as below.(you can skip this process)
```
cd build
meson test -v
```

>In some cases, you may encounter a failure — but don't panic. Just check your configuration, make the necessary fixes, and try running it again later.
install this to before you config nrf, amf and upf. next you will get /install folder
```
cd build
ninja install
cd ../
ls
```
#### Configure Open5GS
NRF configuration
```
sudo nano install/etc/open5gs/nrf.yaml
```
edit mcc & mnc
```cmd=
logger:
file:
path: /home/zyzy/open5gs/install/var/log/open5gs/nrf.log
# level: info # fatal|error|warn|info(default)|debug|trace
global:
max:
ue: 1024 # The number of UE can be increased depending on memory size.
# peer: 64
nrf:
serving: # 5G roaming requires PLMN in NRF
- plmn_id:
mcc: 208 #same as oai
mnc: 99 #same as oai
sbi:
server:
- address: 127.0.0.10
port: 7777
```
AMF configuration:
```
sudo nano install/etc/open5gs/amf.yaml
```
edit ngap ip address, mcc & mnc
```cmd=
amf:
sbi:
server:
- address: 127.0.0.5
port: 7777
client:
# nrf:
# - uri: http://127.0.0.10:7777
scp:
- uri: http://127.0.0.200:7777
ngap:
server:
- address: 192.168.60.2 #open5gs interface
metrics:
server:
- address: 127.0.0.5
port: 9090
guami:
- plmn_id:
mcc: 208 #same as oai
mnc: 99 #same as oai
amf_id:
region: 2
set: 1
tai:
- plmn_id:
mcc: 208
mnc: 99
tac: 1
plmn_support:
- plmn_id:
mcc: 208
mnc: 99
s_nssai:
- sst: 1
security:
integrity_order : [ NIA2, NIA1, NIA0 ]
ciphering_order : [ NEA0, NEA1, NEA2 ]
network_name:
full: Open5GS
short: Next
amf_name: open5gs-amf0
time:
```
UPF configuration
```
sudo nano install/etc/open5gs/upf.yaml
```
edit gtpu interface address
```cmd=
logger:
file:
path: /home/zyzy/open5gs/install/var/log/open5gs/upf.log
# level: info # fatal|error|warn|info(default)|debug|trace
global:
max:
ue: 1024 # The number of UE can be increased depending on memory size.
# peer: 64
upf:
pfcp:
server:
- address: 127.0.0.7
client:
# smf: # UPF PFCP Client try to associate SMF PFCP Server
# - address: 127.0.0.4
gtpu:
server:
- address: 192.168.60.2
session:
- subnet: 10.45.0.0/16
gateway: 10.45.0.1
- subnet: 2001:db8:cafe::/48
gateway: 2001:db8:cafe::1
metrics:
server:
- address: 127.0.0.7
port: 9090
```
#### Running Open5GS
to run all NF:
```bash
./install/bin/open5gs-nrfd &
./install/bin/open5gs-scpd &
./install/bin/open5gs-amfd &
./install/bin/open5gs-smfd &
./install/bin/open5gs-upfd &
./install/bin/open5gs-ausfd &
./install/bin/open5gs-udmd &
./install/bin/open5gs-pcfd &
./install/bin/open5gs-nssfd &
./install/bin/open5gs-bsfd &
./install/bin/open5gs-udrd
```
* check **ngap** run in right interface

* check **gtpu** run in right interface

to **stop** open5gs
```bash
sudo pkill open5gs
```
#### Building the WebUI of Open5GS
Node.js is required to build WebUI of Open5GS
```
# Download and import the Nodesource GPG key
sudo apt update
sudo apt install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
# Create deb repository
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
# Run Update and Install
sudo apt update
sudo apt install nodejs -y
```
Install the dependencies to run WebUI
```
cd webui
npm ci
```
The WebUI runs as an npm script.
```
npm run dev
```
Server listening can be changed by setting the environment variable HOSTNAME
```
HOSTNAME=192.168.60.2 npm run dev
```

Open web console to http://<open5gs_ip>:9999, for example: http://192.168.60.2:9999 and login with admin account.
Username : admin
Password : 1423

>Note: You can change the password in Account Menu.
To add subscriber information, you can do WebUI operations in the following order:
Go to Subscriber Menu.
1. Click + Button to add a new subscriber.
1. Fill the IMSI, security context(K, OPc, AMF), and APN of the subscriber.
1. Click SAVE Button

#### Adding a route for the UE to have WAN connectivity
In order to bridge between the PGWU/UPF and WAN (Internet), you must enable IP forwarding and add a NAT rule to your IP Tables.
To enable forwarding and add the NAT rule, enter
```
### Enable IPv4/IPv6 Forwarding
sudo sysctl -w net.ipv4.ip_forward=1
sudo sysctl -w net.ipv6.conf.all.forwarding=1
### Add NAT Rule
sudo iptables -t nat -A POSTROUTING -s 10.45.0.0/16 ! -o ogstun -j MASQUERADE
sudo ip6tables -t nat -A POSTROUTING -s 2001:db8:cafe::/48 ! -o ogstun -j MASQUERADE
```
Configure the firewall correctly. Some operating systems (Ubuntu) by default enable firewall rules to block traffic.
```
sudo ufw status
sudo ufw disable
sudo ufw status
```
Optionally, you may consider the settings below for security purposes.
```
sudo iptables -I INPUT -i ogstun -j ACCEPT
sudo iptables -I INPUT -s 10.45.0.0/16 -j DROP
sudo ip6tables -I INPUT -s 2001:db8:cafe::0/48 -j DROP
```
:books: Install Openairinterface (VM2)
---
#### prepare the required interface
create tun interface
```
sudo nano create_tunnel.sh
```
fill this file with this code:
```
#!/bin/bash
create_tunnel() {
ip link add tun_cu-du type veth
ip link add tun_du-cu type veth
ip link add oai_br0 type bridge
ip addr add 192.168.35.12/24 dev tun_cu-du
ip addr add 192.168.35.13/24 dev tun_du-cu
ip link set oai_br0 up
ip link set tun_cu-du master oai_br0
ip link set tun_du-cu master oai_br0
ip link set up dev tun_cu-du
ip link set up dev tun_du-cu
}
clean_tunnel() {
ip link del tun_cu-du
ip link del tun_du-cu
}
if [ "$#" -eq 0 ]
then
echo "No arguments supplied"
exit 1
else
if [ "$1" == "create" ]
then
create_tunnel;
fi
if [ "$1" == "clean" ]
then
clean_tunnel;
fi
fi
```
Ensure that create_tunnel.sh is executable:
```
sudo chmod +x create_tunnel.sh
```
run the create_tunnel.sh to create the tun interface
```
sudo ./create_tunnel.sh create
```
#### Build OAI from Source Code
Clone Openairinterface5g
```
sudo apt install git cmake build-essentials
git clone https://gitlab.eurecom.fr/oai/openairinterface5g.git
```
Build the source code
```
cd openairinterface5g
source oaienv
cd cmake_targets/
./build_oai -I --gNB --nrUE -w SIMU
```
add `sudo` if you get issue in permission, for example `sudo ./build_oai -I --gNB --nrUE -w SIMU`
Check the compiled binary
```
ls ran_build/build/
```
#### set configuration
```
cd ~/openairinterface5g/cmake_targets/ran_build/build/
```
CU configuration
```
sudo nano ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/cu_gnb.conf
```
edit CU & DU IP
```
Active_gNBs = ( "gNB-Eurecom-CU");
# Asn1_verbosity, choice in: none, info, annoying
Asn1_verbosity = "none";
Num_Threads_PUSCH = 8;
gNBs =
(
{
////////// Identification parameters:
gNB_ID = 0xe00;
# cell_type = "CELL_MACRO_GNB";
gNB_name = "gNB-Eurecom-CU";
// Tracking area code, 0x0000 and 0xfffe are reserved values
tracking_area_code = 1;
plmn_list = ({ mcc = 208; mnc = 99; mnc_length = 2; snssaiList = ({ sst = 1}) });
nr_cellid = 12345678L;
tr_s_preference = "f1";
local_s_address = "192.168.35.12"; //cu ip
remote_s_address = "192.168.35.13"; //du ip
local_s_portc = 501;
local_s_portd = 2152;
remote_s_portc = 500;
remote_s_portd = 2152;
# ------- SCTP definitions
SCTP :
{
# Number of streams to use in input/output
SCTP_INSTREAMS = 2;
SCTP_OUTSTREAMS = 2;
};
////////// AMF parameters:
amf_ip_address = ({ ipv4 = "192.168.60.2"; }); //amf & upf ip
NETWORK_INTERFACES :
{
GNB_IPV4_ADDRESS_FOR_NG_AMF = "192.168.60.8"; //cu to amf
GNB_IPV4_ADDRESS_FOR_NGU = "192.168.60.8"; //cu to upf
GNB_PORT_FOR_S1U = 2152; # Spec 2152
};
```
DU configuration
```
sudo nano ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/du_gnb.conf
```
edit CU & DU IP
```
Active_gNBs = ( "gNB-Eurecom-DU");
# Asn1_verbosity, choice in: none, info, annoying
Asn1_verbosity = "none";
gNBs =
(
{
////////// Identification parameters:
gNB_ID = 0xe00;
gNB_DU_ID = 0xe00;
# cell_type = "CELL_MACRO_GNB";
gNB_name = "gNB-Eurecom-DU";
// Tracking area code, 0x0000 and 0xfffe are reserved values
tracking_area_code = 1;
plmn_list = ({ mcc = 208; mnc = 99; mnc_length = 2; snssaiList = ({ sst = 1 }) });
nr_cellid = 12345678L;
////////// Physical parameters:
min_rxtxtime = 6;
force_256qam_off = 1;
servingCellConfigCommon = (
{
...
MACRLCs = (
{
num_cc = 1;
tr_s_preference = "local_L1";
tr_n_preference = "f1";
local_n_address = "192.168.35.13"; //du ip
remote_n_address = "192.168.35.12"; //cu ip
local_n_portc = 500;
local_n_portd = 2152;
remote_n_portc = 501;
remote_n_portd = 2152;
}
);
...
rfsimulator: {
serveraddr = "server";
serverport = 4043;
options = (); #("saviq"); or/and "chanmod"
modelname = "AWGN";
IQfile = "/tmp/rfsimulator.iqs"
}
```
UE configuration
```
sudo nano ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf
```
make sure all UE parameter same as open5gs webui
```
uicc0 = {
imsi = "208990000007487";
key = "fec86ba6eb707ed08905757b1bb44b8f";
opc= "C42449363BBAD02B66D16BC975D77CC1";
dnn= "internet";
nssai_sst=1;
}
```

#### Run Openairinterface
terminal 1: run CU
```
cd ~/openairinterface5g/cmake_targets/ran_build/build/
sudo ./nr-softmodem -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/cu_gnb.conf --sa --rfsim
```
terminal 2: run DU
```
cd ~/openairinterface5g/cmake_targets/ran_build/build/
sudo ./nr-softmodem -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/du_gnb.conf --sa --rfsim
```
terminal 3: run UE
```
cd ~/openairinterface5g/cmake_targets/ran_build/build/
sudo ./nr-uesoftmodem -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf --sa --rfsim -r 106 --numerology 1 -C 3619200000
```
#### Check ue registration request


#### Check established interface

#### Check GTPU tunnel
open5gs

CU

DU

UE


test ping gtpu tunnel


wireshark result

==Importance== webui trobleshooting


```
VBoxManage modifyhd "/home/zyzy/VirtualBox VMs/zyoai-du/zyoai-du.vdi" --resize 35000
```