---
# System prepended metadata

title: End-to-end testing using Free5GC and UERANSIM
tags: [Integration]

---


:::success
List the essential information of this chapter.
1. Install Free5GC
2. Install UERANSIM
3. Test the E2E between UE and 5GC. (UE can ping to DN)
:::


---
![free5gc.drawio](https://hackmd.io/_uploads/BJ6wI6fhA.svg)

### 1. Install Free5GC
#### Prerequisites
1. Linux Kernel Version
In order to use the UPF element, you must use the 5.0.0-23-generic or 5.4.x version of the Linux kernel. free5gc uses the gtp5g kernel module, which has been tested and compiled against that kernel versions only. If you installed Ubuntu 20.04, the version should be like 5.4.x. To determine the version of the Linux kernel you are using:
```=
$ uname -r
5.4.0-169-generic
```
2. Install Golang

```=
wget https://dl.google.com/go/go1.18.10.linux-amd64.tar.gz
sudo tar -C /usr/local -zxvf go1.18.10.linux-amd64.tar.gz
mkdir -p ~/go/{bin,pkg,src}
#The following assume that your shell is bash:
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export GOROOT=/usr/local/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOPATH/bin:$GOROOT/bin' >> ~/.bashrc
echo 'export GO111MODULE=auto' >> ~/.bashrc
source ~/.bashrc
```
3. Control-plane Supporting Packages
```=
sudo apt -y update
sudo apt -y install mongodb wget git
sudo systemctl start mongodb
```
4. User-plane Supporting Packages
```=
sudo apt -y update
sudo apt -y install git gcc g++ cmake autoconf libtool pkg-config libmnl-dev libyaml-dev
```
5.  Linux Host Network Settings
```=
sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -o <dn_interface> -j MASQUERADE
sudo iptables -A FORWARD -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1400
sudo systemctl stop ufw
sudo systemctl disable ufw # prevents the firewall to wake up after a OS reboot
```
Note: In Ubuntu Server 20.04 and 22.04 the dn_interface may be called `enp0s3` or `enp0s4` by default, but in this time i use `ens34`. Use the command ip a to help to figure it out

#### Install Control Plane Elements
1. Clone the free5GC repository
   * To install the latest stable build (v3.3.0): 
   ```=
   cd ~
   git clone --recursive -b v3.3.0 -j `nproc`https://github.com/free5gc/free5gc.git
   cd free5gc
   ```
   * (Alternatively) to install the latest nightly build:
   ```=
   cd ~/free5gc
   git checkout main
   git submodule sync
   git submodule update --init --jobs `nproc`
   git submodule foreach git checkout main
   git submodule foreach git pull --jobs `nproc`
   ```
2. Compile network function services in `free5gc`
    * To do so individually (e.g., AMF only):
    ```=
    cd ~/free5gc
    make amf
    ```
    * To build all network functions:
    ```=
    cd ~/free5gc
    make
    ```

#### Install User Plane Function (UPF)
1. As noted above, the GTP kernel module used by the UPF requires that you use Linux kernel version 5.0.0-23-generic or 5.4.x. To verify your version:
```=
uname -r
```
2. Retrieve the 5G GTP-U kernel module using git and build it
```=
git clone -b v0.8.3 https://github.com/free5gc/gtp5g.git
cd gtp5g
make
sudo make install
```
3. Build the UPF (you may skip this step if you built all network functions above):
    * to build using make:
    ```=
    cd ~/free5gc
    make upf
    ```
4. Customize the UPF as desired. The UPF configuration file in `run.sh` is
`free5gc/config/upfcfg.yaml.`

#### Install WebConsole
1. Before building WebConsole, install nodejs and yarn packages first:
```=
sudo apt remove cmdtest
sudo apt remove 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
sudo apt update
sudo apt install -y nodejs yarn
```
:::warning
If your nodejs version have problem, you can change it from this source.
https://www.freecodecamp.org/news/how-to-install-node-js-on-ubuntu/
:::
2. Build WebConsole
    * to build using make:
    ```=
    cd ~/free5gc
   make webconsole
    ```
    * (Alternatively) to build manually:
    ```=
    cd ~/free5gc/webconsole/frontend
    yarn install
    yarn build
    rm -rf ../public
    cp -R build ../public
    cd ..
    go build -o bin/webconsole server.go
    ```
### 2. Install UERANSIM
#### Download UERANSIM
```=
cd ~
git clone https://github.com/aligungr/UERANSIM
cd UERANSIM
git checkout 3a96298
```
#### Update and upgrade ueransim VM
```=
sudo apt update
sudo apt upgrade
```
#### Install required tools
```=
sudo apt install make
sudo apt install g++
sudo apt install libsctp-dev lksctp-tools
sudo apt install iproute2
sudo snap install cmake --classic
```
#### Build UERANSIM
```=
cd ~/UERANSIM
make
```
### 3. Test the E2E between UE and 5GC. (UE can ping to DN)
#### Setting free5GC and UERANSIM Parameters
In free5gc VM, we need to edit three files:
```
~/free5gc/config/amfcfg.yaml
~/free5gc/config/smfcfg.yaml
~/free5gc/config/upfcfg.yaml
```
First SSH into free5gc VM, and change ~/free5gc/config/amfcfg.yaml:
```
cd ~/free5gc
nano config/amfcfg.yaml
```
Replace ngapIpList IP from 127.0.0.1 to 10.99.1.150, namely from:
```
...
  ngapIpList:  # the IP list of N2 interfaces on this AMF
  - 127.0.0.1
```
into
```
...
  ngapIpList:  # the IP list of N2 interfaces on this AMF
  - 10.99.1.150  # 127.0.0.1
```
![image](https://hackmd.io/_uploads/HJ6kOvccp.png)

Next edit ~/free5gc/config/smfcfg.yaml:
```
nano config/smfcfg.yaml
```
and in the entry inside userplaneInformation / upNodes / UPF / interfaces / endpoints, change the IP from 127.0.0.8 to 10.99.1.150, namely from:
```
...
  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
```
into
```
...
  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
       - 10.99.1.150  # 127.0.0.8
```
![image](https://hackmd.io/_uploads/SylF_Dqqa.png)

Finally, edit ~/free5gc/config/upfcfg.yaml，and chage gtpu IP from 127.0.0.8 into 192.168.56.101, namely from:
```
...
  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
```
into
```
...
  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: 10.99.1.150  # 127.0.0.8
        type: N3
```
![image](https://hackmd.io/_uploads/H188qP99T.png)

#### Setting UERANSIM
In the ueransim VM, there are two files related to free5GC：
```
~/UERANSIM/config/free5gc-gnb.yaml
~/UERANSIM/config/free5gc-ue.yaml
```
The second file is for UE, which we don’t have to change if the data inside is consistent with the (default) registration data we set using WebConsole previously.

First SSH into ueransim, and edit the file ~/UERANSIM/config/free5gc-gnb.yaml, and change the ngapIp IP, as well as the gtpIp IP, from 127.0.0.1 to 10.99.1.237，and also change the IP in amfConfigs into 10.99.1.150, that is, from:
```
...
  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
```
into
```
...
  ngapIp: 10.99.1.237 # 127.0.0.1   # gNB's local IP address for N2 Interface (Usually same with local IP)
  gtpIp: 10.99.1.237  # 127.0.0.1    # gNB's local IP address for N3 Interface (Usually same with local IP)

  # List of AMF address information
  amfConfigs:
    - address: 10.99.1.150  # 127.0.0.1
```
![image](https://hackmd.io/_uploads/Sy4mADc5a.png)

Next we examine the file ~/UERANSIM/config/free5gc-ue.yaml，and see if the settings is consistent with those in free5GC (via WebConsole), for example:
```
# 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

...
```
The data appear to be the same as what we set in WebConsole.

#### Testing UERANSIM against free5GC
SSH into free5gc. If you have rebooted free5gc, remember to run:
```
sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -o <dn_interface> -j MASQUERADE
sudo systemctl stop ufw
```
Note: In Ubuntu Server 20.04 and 22.04 the dn_interface may be called enp0s3 or enp0s4 by default. Use the command ip a to help to figure it out

In addition, execute the following command:
```
sudo iptables -I FORWARD 1 -j ACCEPT
```
Tip: As per the information on the appendix page, it's possible to use a script to reload the config above automatically after reboot

Also, make sure you have make proper changes to the free5GC configuration files, then run ./run.sh:
```
cd ~/free5gc
./run.sh
```
At this time free5GC has been started.

Next, prepare three additional SSH terminals from your host machine (if you know how to use tmux, you can use just one).

In terminal 1: SSH into ueransim, make sure UERANSIM is built, and configuration files have been changed correctly, then execute nr-gnb:
```
cd ~/UERANSIM
build/nr-gnb -c config/free5gc-gnb.yaml
```
In terminal 2, SSH into ueransim, and execute nr-ue with admin right:
```
cd ~/UERANSIM
sudo build/nr-ue -c config/free5gc-ue.yaml # for multiple-UEs, use -n and -t for number and delay
```
In terminal 3, SSH into ueransim, and ping 192.168.56.101 to see free5gc is alive. Then, use ifconfig to see if the tunnel uesimtun0 has been created (by nr-ue)
![image](https://hackmd.io/_uploads/HJ7IUryoT.png)

Now use ping:
```
ping -I uesimtun0 google.com
```
![image](https://hackmd.io/_uploads/B1qYUrksa.png)

The End to end Testing is successed

#### Problem
:::danger
Problem, the uesimtun0 not appear:
![image](https://hackmd.io/_uploads/SkCoGO55a.png)

![image](https://hackmd.io/_uploads/SkORfO55p.png)

the image below is webconsole status, as you can see the registered UE is CONNECTED

![image](https://hackmd.io/_uploads/ryC7d-LqT.png)

![image](https://hackmd.io/_uploads/HJU2EzI5p.png)

![image](https://hackmd.io/_uploads/rkTNrBDq6.png)

the image below when i tested ping the free5gc VM from UERANSIM VM : 

![image](https://hackmd.io/_uploads/SkqACDc9T.png)

the image below when i tested ping the UERANSIM VM from free5gc : 

![image](https://hackmd.io/_uploads/BJ6-1Oc9T.png)

the image below when i check with wireshark 

![image](https://hackmd.io/_uploads/S18bbOqca.png)
there is no response for the PDU session establishment
:::


#### Problem Solving
:::success
After i troubleshoot the problem, the main problem is on my VM configuration. My 2 VMs have different physical networks, so there is no connection. then the solution is to equalize the physical network interface so that the 2 VMs can connect and communicate with each other.

![image](https://hackmd.io/_uploads/HJ7IUryoT.png)

![image](https://hackmd.io/_uploads/SyAIwrJia.png)

:::



