# Open Air Interface
[Introduction](#Introduction)
[Installation](#Installing-OAI)
## Introduction

Open Air Interface is an open-source software alliance aim to democratising 5G Technology development, established in 2014. Open Air Interface work on entire 5G Techstack, from developing RAN components (such as gNB, CU, DU), 5G Core Network development (creating AMF, SMF, UPF, etc) to develop CI/CD pipeline to seamless testing and integration for all 5G software components.
## Installing OAI
#### Installing git and cmake
```
sudo apt install -y git cmake build-essential
```
#### Cloning OAI repository
```
git clone https://gitlab.eurecom.fr/oai/openairinterface5g.git
```

#### Build from source code
```
git checkout 2022.w40
source oaienv
cd cmake_targets
./build_oai -I
./build_oai --gNB --nrUE -w SIMU
```
## Configure OAI
### Checking interface name
```
ifconfig
```
### Aliasing interface
```
sudo ifconfig enp0s3:CU 192.168.130.82
sudo ifconfig enp0s3:DU 192.168.130.81
```
> Note : You need to retype this command after boot up
### Configure OAI-CU
1. Path to O-CU Config File
```
nano ~/openairinterface5g/targets/PROJECTS/GENERIC-NR-5GC/CONF/cu_gnb.conf
```
2. Configure mcc and mnc based on Free5GC webconsole

3. Modify IP local and remote

4. Setup the IP address of free5GC and the interface for NGU and Setup the network interfaces

### Configure OAI-DU
1. Path to O-DU Config File
```
nano ~/openairinterface5g/targets/PROJECTS/GENERIC-NR-5GC/CONF/du_gnb.conf
```
2. Config O-DU

### Configure UE
1. Path to UE
```
nano ~/openairinterface5g/targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf
```
2. Config UE based on Free5GC webconsole

## End to End Test
### AMF Config
a. Edit file ~/free5gc/config/amfcfg.yaml
```
cd ~/free5gc
sudo nano ./config/amfcfg.yaml
```
b. Find the ngapIpList key
```
...
ngapIpList: # the IP list of N2 interfaces on this AMF
- 127.0.0.1
```
c. Replace localhost address with 192.168.56.101
```
...
ngapIpList: # the IP list of N2 interfaces on this AMF
- 192.168.125.101 # 127.0.0.1
```

d. Save the file and exit from text editor
### SMF Config
a. Edit file ~/free5gc/config/smfcfg.yaml
```
cd ~/free5gc
sudo nano ./config/smfcfg.yaml
```
b. Find interfaces block
```
...
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
```
c. Replace address 127.0.0.8 with your static address
```
...
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
- 192.168.125.101 # 127.0.0.8
```

### UPF Config
a. Edit file ~/free5gc/config/upfcfg.yaml
```
cd ~/free5gc
sudo nano ./config/upfcfg.yaml
```
b. Find gtpu IP line
```
...
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
```
c. Replace address 127.0.0.8 with your static address
```
...
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: 192.168.125.101
type: N3
```
### Move to a directory
```
cd ~/openairinterface5g/cmake_targets/ran_build/build/
```
### Launch CU Component in Terminal 1
```
sudo RFSIMULATOR=server ./nr-softmodem --rfsim --sa -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/cu_gnb.conf
```
### Launch DU Component in Terminal 2
```
sudo RFSIMULATOR=server ./nr-softmodem --rfsim --sa -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/du_gnb.conf
```
### Launch UE in Terminal 3
```
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
```
If not working, try
```
sudo RFSIMULATOR=server ./nr-uesoftmodem -r 106 --numerology 1 --band 78 -C 3619200000 --rfsim --sa --nokrnmod -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf
```
## Log Analysis

The screenshot showing that there AMF detecting a RAN network with IP address 192.168.125.104. The screenshot also showing a user with SUCI defined at free5GC webconsole

The screenshot showing AMF asking NRF about AUSF and UE state transition from Deregistered to Authentication

AUSF started the authentication process and asking NRF for UDM. UDM store the UE subscription data

UDM returning security information to AUSF, then AUSF generate security key. The picture also showing AMF sending authentication request to UE through RU and start an authentication timeout timer.

AMF stopping the timer and AMF failed to validate UE, then AMF sending authentication reject signal and change UE status from authentication to deregistered

## Optional Step
### Set Some Environment Variable
```
echo 'export CONFIG_PATH=~/openairinterface5g/targets/PROJECTS/GENERIC-NR-5GC/CONF/' >> ~/.bashrc
echo 'export RUN_PATH=~/openairinterface5g/cmake_targets/ran_build/build/' >> ~/.bashrc
source ~/.bashrc
```
### Create Three File
```
cat ~/openairinterface5g/run_cu.sh
cat ~/openairinterface5g/run_du.sh
cat ~/openairinterface5g/run_ue.sh
```
### Write the File
#### Write the run_cu.sh
```
sudo nano ~/openairinterface5g/run_cu.sh
```
Write this line:
```
#!/bin/bash
cd $RUN_PATH
sudo RFSIMULATOR=server ./nr-softmodem --rfsim --sa -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/cu_gnb.conf
```
#### Write the run_du.sh
```
sudo nano ~/openairinterface5g/run_du.sh
```
Write this line:
```
#!/bin/bash
cd $RUN_PATH
sudo RFSIMULATOR=server ./nr-softmodem --rfsim --sa -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/du_gnb.conf
```
#### Write the run_ue.sh
```
sudo nano ~/openairinterface5g/run_cu.sh
```
Write this line:
```
#!/bin/bash
cd $RUN_PATH
sudo RFSIMULATOR=server ./nr-uesoftmodem -r 106 --numerology 1 --band 78 -C 3619200000 --rfsim --sa --nokrnmod -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf
```
### Edit the Permission
```
sudo chmod +x ~/openairinterface5g/run_cu.sh
sudo chmod +x ~/openairinterface5g/run_du.sh
sudo chmod +x ~/openairinterface5g/run_ue.sh
```
### Run the shell script In Different terminals
```
cd ~/openairinterface5g
./run_cu.sh
```
```
cd ~/openairinterface5g
./run_du.sh
```
```
cd ~/openairinterface5g
./run_ue.sh
```
> Note: if you want to open new terminal, click alt+f2 to access terminal 2, alt+f3 to access terminal 3
### CU-DU not separated
#### Run OAI-gNB
```
cd ~/oai/cmake_targets/ran_build/build
sudo ./nr-softmodem -O ../../../targets/PROJECTS/GENERIC-NR-5GC/CONF/gnb.sa.band78.fr1.106PRB.usrpb210.conf --rfsim --sa
```
#### Run OAI-UE
```
cd ~/oai/cmake_targets/ran_build/build
sudo RFSIMULATOR=127.0.0.1 ./nr-uesoftmodem -r 106 --numerology 1 --band 78 -C 3619200000 --rfsim --sa
```
#### Result(UE)

#### Result(gNB)

#### Result(Core)

#### Conclusion
UE to gNB was connected, but failed to receive IP address from Core, Possible cause would be misconfiguration in DNN name.