# OpenAirInterface
---
## Requirements
- I will use 2 VM for gNodeB and CORE
- 4-2-40 flavor
- Use CPU from Hardware OS who running hypervisor AVX2
- `grep -i "avx2" /proc/cpuinfo` Command to check or make sure if AVX2 CPU is used by the VM
---
## gNodeB instalation (VM1)
1. Update and Upgrade the system
```bash
sudo apt-get update && sudo apt-get -y upgrade
```
2. Install kernel low-latency
```bash
sudo apt-get -y install linux-image-lowlatency-hwe-22.04 linux-headers-lowlatency-hwe-22.04
# Update bootloader dan reboot
sudo update-grub
sudo reboot
uname -r
```
3. install git if we dont have
```bash
sudo apt-get -y install git
```
4. Cloning and create working directory
```bash
mkdir OAI-GnodeB
cd OAI-GnodeB
# cloning oai from source
git clone https://gitlab.eurecom.fr/oai/openairinterface5g.git
cd openairinterface5g
git fetch --all --tags
git checkout v2.1.0
source oaienv
cd cmake_targets
```
5. Installing gNodeB
```bash
sudo ./build_oai -I --gNB --nrUE -w SIMU
```
**Note** :
- `-I` is for install all the dependency that needed
- `--gNB` is for build gnodeb
- `nrUE` is for build simulator UE for testing
- `-w SIMU` is for build RF simulator
---
## Open5gs core Instalation (VM2)
1. Install mongoDB for the database
```bash
# impor mongoDB gpg key
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb-server-7.0.gpg
# add mongoDB repository
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
# Instal MongoDB
sudo apt-get update
sudo apt-get install -y mongodb-org
```
2. Install open5GS core
```bash
# Add PPA Open5GS
sudo add-apt-repository ppa:open5gs/latest
sudo apt-get update
# Instal all the component of open5gs
sudo apt-get install -y open5gs
```
3. Install open5gs web-ui
```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
```
You can now install open5gs WebUI
```bash
$ curl -fsSL https://open5gs.org/open5gs/assets/webui/install | sudo -E bash -
```
to check and troubleshoot u can check in
`/lib/systemd/system/open5gs-webui.service`
to acces web-ui u can check in
`http://localhost:9999`
4. If u want to use NGINX for Reverse Proxy
```bash
# Install NGINX
sudo apt-get update
sudo apt-get install -y nginx
```
```bash
# Create file for the sevice
sudo nano /etc/nginx/sites-available/open5gs-webui
```
```bash
server {
listen 3000;
server_name _;
location / {
proxy_pass http://127.0.0.1:9999;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
#Copy and paste this into this file
```
```bash
# Activate our situs
sudo ln -s /etc/nginx/sites-available/open5gs-webui /etc/nginx/sites-enabled/
# (Opsional) Hapus link situs default agar tidak bentrok
sudo rm /etc/nginx/sites-enabled/default
# Cek konfigurasi and restart NGINX
sudo nginx -t
sudo systemctl restart nginx
```
Acces it in `http://<IP_VM_Core_Anda>:3000`
# Running the scenario
---
we will running OAI as a GNB and UE creator. Open5gs will be the core. Before we run a scenario make sure that u have connected between each vm. if u use in local computer like VMware u can check in this section.

U can setting the network adapter like that.
1. First step is we have to create subscriber in open5gs webui.

- add the IMSI and save
2. Create a file for GNB in VM gnodeb or u can copy from
`/home/rafi/oai-new/openairinterface5g/targets/PROJECTS/GENERIC-NR-5GC/CONF` there is many templates for the project in openairinterfaces
3. get match or u can use by default of mcc and mnc

- and dont forget to change the IP of `amf_ip_address` with your IP VM open5gs, `for the NETWORK_INTERFACE` U can use IP from VM OAI or gnb.

4. Set up ur file for UE
- u can use format file like this
```bash
# Hanya USIM & NAS; RF di-set via CLI
uicc0 = {
imsi = "001010123456789";
key = "465B5CE8B199B49FAA5F0A2EE238A6BC";
opc = "E8ED289DEBA952E4283B54E88E6183CA";
dnn = "internet";
nssai_sst = 1;
# sd = 000000; # opsio
};
#use_suci = false;
```
5. if the UE and the GNB already set up we can run it with manual CLI or bash script
- Bash script for UE
```bash
#!/usr/bin/env bash
set -euo pipefail
BUILD_DIR=~/oai-new/openairinterface5g/cmake_targets/ran_build/build
USIM_CONF=~/oai-new/openairinterface5g/RISET5G/nr-ue/oai_test.conf
cd "$BUILD_DIR"
# UE sebagai CLIENT rfsim (pastikan bukan server)
unset RFSIMULATOR || true
# Cek file USIM ada
if [[ ! -f "$USIM_CONF" ]]; then
echo "ERROR: USIM config tidak ditemukan di: $USIM_CONF"
echo "Buat dulu file-nya seperti contoh yang kuberi di langkah (1)."
exit 1
fi
echo "Menjalankan UE rfsim (client) dengan USIM config: $USIM_CONF"
echo "Pastikan gNB rfsim (server) sudah jalan lebih dulu dan listen di 127.0.0.1:4043."
exec sudo ./nr-uesoftmodem --rfsim --rfsimulator.serveraddr 127.0.0.1 \
-C 3619200000 --CO 0 --band 78 -r 51 --numerology 1 \
--ue-scan-carrier \
-O "$USIM_CONF"
```
- Bash script for gnb
```bash
_gnb_rfsim.sh
#!/usr/bin/env bash
set -euo pipefail
cd ~/oai-new/openairinterface5g/cmake_targets/ran_build/build
# gNB sebagai SERVER rfsim
exec sudo -E env RFSIMULATOR=server ./nr-softmodem \
--sa \
-O /home/rafi/oai-new/openairinterface5g/RISET5G/gnodeb/gnb_rfsim_new.conf \
-r 51 --numerology 1 --rfsim
```
6. Setting up the core components
- First thing u have to know is u have to make sure the NRF is running before the other components.
- Change the IP in amf with ur ip VM core and matching up the mcc and mnc

- also check in `upf.yaml` and change the IP with urs

- now u can save it and restart the component