## Demo Open5Gs, OAI gNB, and FlexRIC intergration.

We use proxmox for the vms with specifications bellow:
VM1 core network:
- Ubuntu 22.04
- 4 Core
- 4 GB RAM
- 50 GB storage
VM gNB:
- Ubuntu 22.04
- 8 Core
- 16 GB RAM
- 50 GB storage
VM UPF:
- Ubuntu 22.04
- 4 Core
- 8 GB RAM
- 50 GB storage
*note:*
- *I already tried using Free5GC as the core network for the OAI gNB, but Free5GC is not compatible with the OAI gNB.*
- ***UERANSIM is not compatible for flexric because it doesn’t have E2 support**.*
### 1.1 Installing GO
```bash
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
```
### 1.2 Installing MongoDB
```bash
sudo apt -y update
sudo apt -y install mongodb wget git
sudo systemctl start mongodb
```
### 1.3 Installing Open5GS
*Ubuntu* makes it easy to install Open5GS as shown below.
```bash
sudo add-apt-repository ppa:open5gs/latest
sudo apt update
sudo apt install open5gs
```
note: you can see tutorial for other OS [here](https://open5gs.org/open5gs/docs/guide/01-quickstart/).
### 1.4 Installing Open5GS webUI
The WebUI allows you to interactively edit subscriber data. While it is not essential to use this, it makes things easier when you are just starting out on your Open5GS adventure. (A [command line tool](https://github.com/open5gs/open5gs/blob/main/misc/db/open5gs-dbctl) is available for advanced users).
1. Installing Node.js for Ubuntu and Debian:
```bash
# 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
```
2. To install [Node.js](https://nodejs.org/) on *openSUSE*, run the following:
```bash
sudo zypper install nodejs8
```
You can now install WebUI of Open5G
```bash
curl -fsSL https://open5gs.org/open5gs/assets/webui/install | sudo -E bash -
```
## 1.5 Setup 5G Core
Since we are using a private environment, there is no need to modify the PLMN in NRF and AMF.
If you are aiming to connect an external gNB to your core, you will also need to change the NGAP bind address of the AMF **and** the GTPU bind address of the UPF. If you are running an gNB stack locally, you will not need to make these changes.
Modify [/etc/open5gs/amf.yaml](https://github.com/open5gs/open5gs/blob/main/configs/open5gs/amf.yaml.in) to set the NGAP IP address.
```bash
ngap:
server:
- - address: 127.0.0.5
+ - address: 192.168.1.160
metrics:
server:
- address: 127.0.0.5
port: 9090
guami:
```
Modify [/etc/open5gs/upf.yaml](https://github.com/open5gs/open5gs/blob/main/configs/open5gs/upf.yaml.in) to set the GTP-U address.
```bash
gtpu:
server:
- - address: 127.0.0.7
+ - address: 192.168.1.160
session:
- subnet: 10.45.0.1/16
- subnet: 2001:db8:cafe::1/48
```
After changing config files, please restart Open5GS daemons.
```bash
sudo systemctl restart open5gs-nrfd
sudo systemctl restart open5gs-amfd
sudo systemctl restart open5gs-upfd
```
### Register Subscriber information
Connect to `http://localhost:9999` and login with **admin** account.
Username : admin
Password : 1423
**Tip:** You can change the password in *Account* Menu.
To add subscriber information, you can do WebUI operations in the following order:
1. Go to `Subscriber` Menu.
2. Click `+` Button to add a new subscriber.
3. Fill the IMSI.

4. 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
```bash
### 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.
```bash
sudo ufw status
> Status: active
sudo ufw disable
> Firewall stopped and disabled on system startup
sudo ufw status
> Status: inactive
```
### **1.6 Starting and Stopping Open5GS**
When you install the software using the package manager, it is setup to run as a systemd service. You can stop and restart the components and network functions as follows:
```bash
$ sudo systemctl stop open5gs-mmed
$ sudo systemctl stop open5gs-sgwcd
$ sudo systemctl stop open5gs-smfd
$ sudo systemctl stop open5gs-amfd
$ sudo systemctl stop open5gs-sgwud
$ sudo systemctl stop open5gs-upfd
$ sudo systemctl stop open5gs-hssd
$ sudo systemctl stop open5gs-pcrfd
$ sudo systemctl stop open5gs-nrfd
$ sudo systemctl stop open5gs-scpd
$ sudo systemctl stop open5gs-seppd
$ sudo systemctl stop open5gs-ausfd
$ sudo systemctl stop open5gs-udmd
$ sudo systemctl stop open5gs-pcfd
$ sudo systemctl stop open5gs-nssfd
$ sudo systemctl stop open5gs-bsfd
$ sudo systemctl stop open5gs-udrd
$ sudo systemctl stop open5gs-webui
```
```bash
$ sudo systemctl restart open5gs-mmed
$ sudo systemctl restart open5gs-sgwcd
$ sudo systemctl restart open5gs-smfd
$ sudo systemctl restart open5gs-amfd
$ sudo systemctl restart open5gs-sgwud
$ sudo systemctl restart open5gs-upfd
$ sudo systemctl restart open5gs-hssd
$ sudo systemctl restart open5gs-pcrfd
$ sudo systemctl restart open5gs-nrfd
$ sudo systemctl restart open5gs-scpd
$ sudo systemctl restart open5gs-seppd
$ sudo systemctl restart open5gs-ausfd
$ sudo systemctl restart open5gs-udmd
$ sudo systemctl restart open5gs-pcfd
$ sudo systemctl restart open5gs-nssfd
$ sudo systemctl restart open5gs-bsfd
$ sudo systemctl restart open5gs-udrd
$ sudo systemctl restart open5gs-webui
```
## 2. Installing OAI gNB & UE
### 2.1 OAI pre-requisites
- A *recent* CMake (at least v3.15).
```bash
sudo apt-get update
sudo apt-get install ca-certificates gpg wget
test -f /usr/share/doc/kitware-archive-keyring/copyright ||
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null
## For Ubuntu Noble Numbat (24.04):
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ noble main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
sudo apt-get update
## For Ubuntu Jammy Jellyfish (22.04):
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
sudo apt-get update
## For Ubuntu Focal Fossa (20.04):
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ focal main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
sudo apt-get update
sudo apt-get install kitware-archive-keyring
```
- SWIG (at least v.4.1).
SWIG as an interface generator to enable the multi-language feature (i.e., C/C++ and Python) for the xApps. Please, check your SWIG version (i.e, `swig -version`) and install it from scratch if necessary as described here: [https://swig.org/svn.html](https://swig.org/svn.html) or via the code below:
```bash
git clone https://github.com/swig/swig.git
cd swig
git checkout release-4.1
./autogen.sh
./configure --prefix=/usr/
make -j8make install
```
### 2.2 Download the required dependencies.
```bash
sudo apt install libsctp-dev python3.8 cmake-curses-gui libpcre2-dev python-dev
```
### 2.3 Deployment
```bash
git clone https://gitlab.eurecom.fr/oai/openairinterface5g oai
cd oai/
cd cmake_targets/
./build_oai -I -w SIMU --gNB --nrUE --build-e2 --ninja
```
- `I` option is to install pre-requisites, you only need it the first time you build the softmodem or when some oai dependencies have changed.
- `w` option is to select the radio head support you want to include in your build. Radio head support is provided via a shared library, which is called the "oai device" The build script creates a soft link from `liboai_device.so` to the true device which will be used at run-time (here the USRP one, liboai_usrpdevif.so). The RF simulatorRF simulator is implemented as a specific device replacing RF hardware, it can be specifically built using `w SIMU` option, but is also built during any softmodem build.
- `-gNB` is to build the `nr-softmodem` and `nr-cuup` executables and all required shared libraries
- `-nrUE` is to build the `nr-uesoftmodem` executable and all required shared libraries
- `-ninja` is to use the ninja build tool, which speeds up compilation
- `-build-e2` option is to use the E2 agent, integrated within RAN.
If the openair2/E2AP/flexric folder is empty, try manually the following commands:
```bash
git submodule init
git submodule update
```
### 2.4 Configure OAI gNB and UE
2.4.1 Configure CU
modify oai/targets/PROJECTS/GENERIC-NR-5GC/CONF/cu_gnb.conf. Change the MCC and MNC according to the core network PLMN.

And change the IP address to match the AMF and the IP of the VM.

Add this code to the configuration:
```bash
e2_agent = {
near_ric_ip_addr = "127.0.0.1";
sm_dir = "/usr/local/lib/flexric/"
}
```
2.4.2 Configure DU
modify oai/targets/PROJECTS/GENERIC-NR-5GC/CONF/du_gnb.conf. Change the MCC and MNC according to the core network PLMN.

Add this code to the configuration:
```bash
e2_agent = {
near_ric_ip_addr = "127.0.0.1";
sm_dir = "/usr/local/lib/flexric/"
}
```
2.4.3 Configure UE
modify oai/targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf. Change the IMSI and key , OPC, dnn, and nssai.

## Installing Flexric

By default, FlexRIC will build the nearRT-RIC with E2AP v2 and KPM v2. If you want a different version, edit the variable E2AP_VERSION and KPM_VERSION at FlexRIC's CMakeLists.txt file. Note that OAI's and FlexRIC's E2AP_VERSION and KPM_VERSION need to match due to O-RAN incompatibilities among versions.
### 3.1 Clone FlexRIC repository
```bash
git clone https://gitlab.eurecom.fr/mosaic5g/flexric flexric
cd flexric/
git checkout f1c08ed2b9b1eceeda7941dd7bf435db0168dd56
```
### 3.2 Build FlexRIC
```bash
mkdir build && cd build && cmake .. && make -j8
```
### 3.3 Installation of Service Model (SMs)
```bash
sudo make install
```
## 4. Demo
## 4.1 Start FlexRIC Near RT RIC
```bash
./flexric/build/examples/ric/nearRT-RIC
```

## 4.2 Start CU, DU, and UE
```bash
sudo ./nr-softmodem -O oai/targets/PROJECTS/GENERIC-NR-5GC/CONF/cu_gnb.conf --rfsim
sudo ./nr-softmodem -O oai/targets/PROJECTS/GENERIC-NR-5GC/CONF/du_gnb.conf --rfsim -E
cd oai/cmake_targets/ran_build/build
sudo .oai/cmake_targets/ran_build/build/nr-uesoftmodem -r 106 --numerology 1 --band 78 -C 3619200000 --rfsim --rfsimulator.serveraddr 127.0.0.1
```
## 4.2.1 CU ouput:

Here, it shows that the AMF NG request was successful, as well as the E2 agent setup response, meaning the CU is connected to the RIC.
### 4.2.2 DU output:

here, it shows the GTP connection successful.

here, it shows that DU is connected to the RIC.
### 4.2.3 UE output:

the UE is successfully connected to the RU simulation.
### 4.2.4 RIC output:

### 4.2.4 UE connectivity test:

```bash
ping -I oaitun_ue1 8.8.8.8
```

### 4.2.5 xApps
```bash
cd flexric
.build/examples/xApp/c/monitor/xapp_kpm_moni
```

Start different xApps
- start the RC monitor xApp - aperiodic subscription for "UE RRC State Change"
```bash
cd flexric
./build/examples/xApp/c/monitor/xapp_rc_moni
```
- start the RC control xApp - RAN control function "QoS flow mapping configuration" (e.g. creating a new DRB)
```bash
cd flexric
./build/examples/xApp/c/kpm_rc/xapp_kpm_rc
```
- start the (MAC + RLC + PDCP + GTP) monitor xApp
```bash
cd flexric
./build/examples/xApp/c/monitor/xapp_gtp_mac_rlc_pdcp_moni
```
next ====> multi ue