---
# System prepended metadata

title: OAI gNB/UE Installation & Execution
tags: [Construction]

---

# OAI gNB/UE Installation & Execution
###### tags: `Construction`

## OAI gNB/UE pre-requisites
#### Basic requirement
| OS/Kernel                  | Version                                 |
|:-------------------------- |:----------------------------------------|
| Host operating system      | Linux Ubuntu 18.04 or 20.04 or 22.04    |
| Kernel                     | 4.15.0.142.lowlatency                   |



## Build OAI gNB/UE
#### Clone and build the dependency for the first time
```sh
# Clone OAI project in Develop Branch
git clone https://gitlab.eurecom.fr/oai/openairinterface5g.git -b develop
cd openairinterface5g/

# Build ONLY FOR the FIRST time
source oaienv
cd cmake_targets
export BUILD_UHD_FROM_SOURCE=True
export UHD_VERSION=4.3.0.0-rc1 #(optional UHD_VERSION=4.4.0.0)
./build_oai -I

# Sometimes you will get error `no GPG public key or ppa public key XXXXXXXXX_Key`
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys XXXXXXXXX_Key
```

#### Build OAI gNB for USRP
```sh
./build_oai -w USRP --gNB
```

#### Build OAI nrUE for USRP
```sh
./build_oai -w USRP --nrUE
```

#### Build other libraries
* Use `./build_oai help` to check what library you need.
```sh
--build-lib <libraries>
# Build optional shared library, <libraries> can be one or several of 
# telnetsrv 
# enbscope 
# uescope 
# nrscope 
# nrqtscope 
# ldpc_cuda 
# ldpc_t1 
# websrv 
# oai_iqplayer

# You can build the libraries you need separatedly.
./ build_oai --build-lib xxx -- build-lib yyy

# OR just build all libraries
./build_oai --build-lib all
```
## Build OAI CN 
```shell
git clone https://gitlab.eurecom.fr/oai/cn5g/oai-cn5g-fed.git
```

## Run OAI CN
```shell
## Build OAI CN
cd ~/oai-cn5g-fed/docker-compose
docker-compose -f docker-compose-basic-nrf.yaml up -d # up
docker ps -a

docker-compose -f docker-compose-basic-nrf.yaml down # down

```
![](https://hackmd.io/_uploads/BkcAn_8nh.png)

```sh
docker exec -it mysql /bin/bash
mysql -uroot -plinux -D oai_db
show tables;
select * from AuthenticationSubscription;
```
![](https://hackmd.io/_uploads/BJPu4nOh2.png)


Run OAI gNB
```shell=
cd ~/openairinterface5g
cd cmake_targets/ran_build/build
sudo ./nr-softmodem -O [where the config file is] --sa -E --gNBs.[0].min_rxtxtime 6
e.q. sudo ./nr-softmodem -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/gnb.sa.band78.fr1.106PRB.usrpb210.conf --sa -E --gNBs.[0].min_rxtxtime 6 --continuous-tx
# --gNBs.[0].min_rxtxtime 6 --> To ensure that the rx tx time advance is 6 slots
```
* Optional: RUN OAI gNB with RF Simulator
```sh
sudo RFSIMULATOR=server ./nr-softmodem --rfsim --sa -O [where the config file is]
```

* If you have 5G CN
<font color=#FF0000> **!!! Check PLMN elements in config file to match with corresponding OAI CN !!!** </font> 
For example: 
![](https://i.imgur.com/b3faHsP.png)
![](https://i.imgur.com/O5ACDSf.png)



## Run OAI UE 
#### Step 1
Only if you need to connect to 5G CN; or skip this step
* Modify UE config file to match with the OAI CN database 
* There are two options to deploy it.
    1. Modify UE's information to match the CN
    2. Add UE's information into Database
```sh
# UE Configuration 
<your oai directory>/openairinterface5g/targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf

# Database (take oai_db2.sql for example)
<your oai CN directory>/oai-cn5g-fed/docker-compose/oai_db2.sql
```
![](https://i.imgur.com/TKchZD8.png)
```
uicc0 = {
imsi = "208950000000031";  #SUPI
key = "0C0A34601D4F07677303652C0462535B";  #secret key for imsi
opc= "63bfa50ee6523365ff14c1f45f88737d";  #secret key for operator
dnn= "oai";
nssai_sst=1;
nssai_sd=1;
}
```
    
#### Step 2: 
Run OAI UE with USRP B210
```sh
# Without 5G CN
sudo ./nr-uesoftmodem -r 106 --numerology 1 --band 78 -C 3619200000 --sa  -E --ue-fo-compensation


# With 5G CN
sudo ./nr-uesoftmodem -r 106 --numerology 1 --band 78 -C 3619200000 --sa  -O [corresponding UE config file] -E

or 

sudo ./nr-uesoftmodem -r 106 --numerology 1 --band 78 -C 3619200000 --ue-fo-compensation --sa -E -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf

# Optional With RF simulator
sudo RFSIMULATOR=127.0.0.1 ./nr-uesoftmodem -r 106 --numerology 1 --band 78 -C 3619200000    --rfsim --sa --nokrnmod -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf
    

# -r: bandwidth in terms of RBs (default value 106)
# -- numerology: numerology index (default value 1)
# --band: NR band number (default value 78)
# --C: downlink carrier frequency in Hz (default value 0)
# --C0: uplink frequency offset for FDD in Hz (default value 0)
# -s: SSB start subcarrier (default value 512) 
# --sa: Standalone mode
# --ue-fo-compensation : frequency output conpensation
```