# OpenAirInterface (OAI)
## FOLDER STRUCTOR

* openair1裡面存儲的是OAI PHY主要的函數 (L1)
* openair2裡面存儲的是L2的函數,即包含MAC,RLC和PDCP等。 (DU)
* openair3主要存儲的是L3相關的函數,即跟控制台,核心網相關的內容比較多。 (CU)
* default interface between all entities is implemented using a UDP socket.
## NR CONFIGURE STRUCTOR

* configure檔位於`/ci-script/conf_files`及`targets/PROJECTS/GENERIC-NR-5GC/CONF/`
## BUILD
1. `cd /openairinterface5g`
2. `source oaienv`
3. `cd cmake_targets`
4. `sudo ./build_oai -I --gNB --nrUE -w SIMU`
* -I: Installs required packages such as LibXML, asn1.1 compiler, freediameter, ...
* --gNB: build nr-softmodem
* --nrUE: build nr-uesoftmodem
* -w: Adds this RF board support (EXMIMO, USRP, BLADERF, LMSSDR, IRIS, ADRV9371_ZC706, SIMU, AW2SORI, None (Default))
## RUN gNB
### the Monolithic gNB
`sudo RFSIMULATOR=server ./nr-softmodem --rfsim --rfsimulator.serveraddr 10.255.174.33 --sa -O ../../../ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.usrpn310.conf
`
### the Splited gNB
1. CU: `sudo ./nr-softmodem --sa -O ../../../ci-scripts/conf_files/gNB_SA_CU.conf`
2. DU: `sudo RFSIMULATOR=server ./nr-softmodem --rfsim --rfsimulator.serveraddr 10.255.174.33 --sa -O ../../../ci-scripts/conf_files/gNB_SA_DU.conf`
* RFSIMULATOR=server: 設定基站的RFSIMULATOR為TCP server
* . /nr-softmodem: NR 基站可執行程式
* -O: 基站配置檔
* --parallel-config PARALLEL_SINGLE_THREAD: 創建獨立的並行線程
* --rfsim: 採用RFSIMULATOR,而不是正式的RF硬體
* --phy-test: gNB會在每次調度週期隨機產生一些DL下行數據進行發送,並停止MAC layer。
* --noS1: 沒有真實的核心網,採用核心網模擬器。
* --nokrnmod 1: 沒有核心網是設置該flag
* --sa: StandAlone type
## RUN UE
`sudo RFSIMULATOR=10.255.174.33 ./nr-uesoftmodem -r 106 --numerology 1 --band 78 -C 3619200000 --rfsim --sa --nokrnmod --noS1 -O ../../../ci-scripts/conf_files/ue_test_sa.conf`
## ISSUES
### dnn not supported or not subscribed in the slice
***
Reason: The first byte in dnn.value is redundantly added 1.
***
Resolution: The mm_msg->uplink_nas_transport.dnn.value[0] in `openair3/NAS/NR_UE/nr_nas_msg_sim.c:748` should be change to dnnSize instead to dnnSize+1
***
Decription: According to 3GPP TS23.003, the first byte is recorded to length of field. Thus it doesn't need to add more number.

And the DNN structor is such as:

### discard NR PDU, integrity failed
***
Reason: UE can not recognize the ciphering algorithm that is gNB use.
***
Resolution: set ciphering algorithm, which is in the configuration of gNB, as nea0.
***
## CALL FLOW

* The gray block is a infinite while loop.
* The red block is corresponding to IF selecting of function.
* The dashed line is there is a new thread.
## eNB connect remoted RU with sim RF
1. `add ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c in oairu case in CMAKELIST.txt`
2. `sudo RFSIMULATOR=server ./lte-softmodem --noS1 --nokrnmod --rfsim -O ../../../ci-scripts/conf_files/enb.band7.tm1.50PRB.usrpb210.conf`
3. `sudo RFSIMULATOR=server ./oairu --rfsim -O ../../../ci-scripts/conf_files/rru.fdd.band7.conf`
***
Because there is no oairu of NR, the above process can not implement for now.
## elt, FIFO and Tpool
The Tpool and FIFO are used to manage the computing resource.
### elt
elt is a message cantaining the task information, wherein the
1. `processingFunc`: the target task function and
2. `responseFifo`: the queue name that elt will be send to after the elt's task has been executed.
3. `msgData`: the data passed to processingFunc. It can be added automatically, or you can set it to a buffer you are managing

### FIFO
The notifiedFIFO holds task messages - elt. the computing resource will pull task from it to execute.
there are three kinds of FIFO for DL, such as `L1_tx_free`, `L1_tx_filled` and `L1_tx_out`,
and two kinds of FIFO for UL, such as `resp_L1` and `respDecode`,
and one kind of FIFO for Tpool, such as `incomingFiFO`.

### Tpool
In NR, Tpool is only initialized by `init_gNB_Tpool`, which will assign a thread for each avaliable core. That means there is only one Tpool in nr main process. And each thread will run one_thread function, which will pull a elt from the queue - `incomingFifo` and run it immediately.

### DL FIFO flow

### UL FIFO flow

**the nr_schedule_response is call by rx_func, and rx_func is called by ru_thread, so a round of DL FIFO flow is included in a round of UL FIFO flow.**