---
# System prepended metadata

title: 建設Near-RT RIC環境

---

# 建設Near-RT RIC環境
:::info
Installation Environment：
* VM：Ubuntu 20.04.2 LTS

Platform Environment：
* Kubernetes：1.16.0
* Helm：3.5.4
* Docker：20.10.21
:::
:::warning
在安裝環境時，請在安裝ubuntu前多配置一張介面卡，並選擇**僅限主機介面卡**
![image](https://hackmd.io/_uploads/H1IqCNHvC.png)
:::
---
## 安裝 RIC

創建安裝 O-RAN 環境資料夾 
```bash
su

mkdir j_release
```
進入資料夾後執行以下指令
```bash
cd j_release

git clone https://gerrit.o-ran-sc.org/r/ric-plt/ric-dep

cd ric-dep/bin 

sudo ./install_k8s_and_helm.sh
```
:::warning
如果在輸入**sudo ./install_k8s_and_helm.sh**卡在以下畫面無限循環
請ctrl+c強制結束後再執行一次**sudo ./install_k8s_and_helm.sh**
![image](https://hackmd.io/_uploads/B1ekhBcIkl.png)

:::

上述指令執行完成後在**ric-dep**資料夾下新增一個存放鏡像資訊的txt檔案
```bash
# go back to ric-dep
cd ..

sudo vim versions.txt

# Write in versions.txt
nexus3.o-ran-sc.org:10004/o-ran-sc/ric-plt-a1:3.2.2                
nexus3.o-ran-sc.org:10002/o-ran-sc/ric-plt-appmgr:0.5.8
nexus3.o-ran-sc.org:10002/o-ran-sc/ric-plt-dbaas:0.6.4
nexus3.o-ran-sc.org:10002/o-ran-sc/ric-plt-e2mgr:6.0.5
nexus3.o-ran-sc.org:10002/o-ran-sc/ric-plt-e2:6.0.6
nexus3.o-ran-sc.org:10002/o-ran-sc/ric-plt-rtmgr:0.9.6
nexus3.o-ran-sc.org:10002/o-ran-sc/ric-plt-submgr:0.10.2
nexus3.o-ran-sc.org:10002/o-ran-sc/ric-plt-vespamgr:0.7.5
nexus3.o-ran-sc.org:10002/o-ran-sc/ric-plt-o1:0.6.3
nexus3.o-ran-sc.org:10002/o-ran-sc/ric-plt-alarmmanager:0.5.16
nexus3.o-ran-sc.org:10002/o-ran-sc/it-dep-init:0.0.1
docker.io/prom/prometheus:v2.18.1
docker.io/kong/kubernetes-ingress-controller:0.7.0
docker.io/kong:3.6
docker.io/prom/alertmanager:v0.20.0
```
![image](https://hackmd.io/_uploads/SJmh3U9PC.png)

儲存後執行以下指令
```bash
for i in `cat versions.txt`; do echo $i; docker pull $i; done

cd bin

sudo ./install_common_templates_to_helm.sh

sudo ./install -f ../RECIPE_EXAMPLE/example_recipe_oran_j_release.yaml
```
執行完成後可透過以下指令查看安裝情形
```
kubectl get pods -n ricplt
```

![image](https://hackmd.io/_uploads/BJnRJD9PR.png)

# 安裝dms_cli
可在任何資料夾下執行 這部分的目的是為了用pip3安裝dms_cli
```bash
#Git clone appmgr
git clone "https://gerrit.o-ran-sc.org/r/ric-plt/appmgr"

#Delete origin xapp_onboarder
rm -rf appmgr/xapp_orchestrater/dev/xapp_onboarder

#Go to xapp_onboarder dir
cd appmgr/xapp_orchestrater/dev

#Clone the modified xapp_onboarder
git clone https://github.com/judeabc20221/xapp_onboarder

#Change dir to xapp_onboarder
cd xapp_onboarder

#If pip3 is not installed, install using the following command
apt install python3-pip

#In case dms_cli binary is already installed, it can be uninstalled using following command
pip3 uninstall xapp_onboarder

#Install xapp_onboarder using following command
pip3 install ./
```
更多參考資料：https://docs.o-ran-sc.org/projects/o-ran-sc-ric-plt-ric-dep/en/latest/installation-guides.html#getting-and-preparing-deployment-scripts
# 安裝chartmuseum
需要安裝這個dms_cli才可以正常運作
```bash
docker run --rm --name chartmuseum -u 0 -it -d -p 8090:8080 -e DEBUG=1 -e STORAGE=local -e STORAGE_LOCAL_ROOTDIR=/charts -v $(pwd)/charts:/charts chartmuseum/chartmuseum:latest

export CHART_REPO_URL=http://0.0.0.0:8090
```

並且每開一個terminal 都須輸入以下指令 改變chart url
```bash
export CHART_REPO_URL=http://0.0.0.0:8090
```
# 使用dms_cli部署xApp
這部分以hw-python為例
```bash
cd

export CHART_REPO_URL=http://0.0.0.0:8090

git clone https://github.com/o-ran-sc/ric-app-hw-python

```
修改config.json裡面的image
```bash
vim ./ric-app-hw-python/init/config-file.json
```
![image](https://hackmd.io/_uploads/rkOyvU5LJg.png)

輸入以下指令部署xApp
```bash
dms_cli onboard ./ric-app-hw-python/init/config-file.json ./ric-app-hw-python/init/schema.json
```

出現下圖代表部署成功
![image](https://hackmd.io/_uploads/HyFhMPq8kg.png)

onboard成功後要install
```bash
dms_cli install hw-python 1.0.0 ricxapp
```
參數是根據config.json最一開始的內容
![image](https://hackmd.io/_uploads/HJnRrw9Lkx.png)

install完成會顯示如下
![image](https://hackmd.io/_uploads/rkpC7v98kl.png)

可以輸入以下指令確認部署情況
```bash
kubectl get pods -n ricxapp
```
![image](https://hackmd.io/_uploads/rkJLIvcIyl.png)

# 偵測含有非法RMR訊息以及Rest API的xApp
接下來是偵測非法RMR訊息與Rest API的部分
先把原本的xApp uninstall 輸入以下指令 這個可以完全移除一個xApp
```bash
helm delete hw-python -n ricxapp
```

在hw-python的config.json新增非法的RMR訊息與Rest API
```bash
vim ./ric-app-hw-python/init/config-file.json
```

將以下config.json部分
![image](https://hackmd.io/_uploads/B1DGxiqUye.png)
新增一個非法RMR訊息 **RIC_E2_SETUP_REQ**
![image](https://hackmd.io/_uploads/rJJwlj9U1x.png)
然後在db後面新增一段Rest API，裡面包含非法的Rest API **/v1/nodeb/shutdown**
```json=
    "restapi": {
        "appmgr": {
            "get": [
                "/xapp/list"
            ],
            "post": [
                "/subscription"
            ]
        },
        "e2mgr": {
            "put": [
                "/v1/nodeb/shutdown"
            ],
            "get": [
                "/health"
            ]
        }
    }
```
![image](https://hackmd.io/_uploads/HJ0S-icIkg.png)

新增完後使用dms_cli嘗試Onboard
```bash
dms_cli onboard ./ric-app-hw-python/init/config-file.json ./ric-app-hw-python/init/schema.json
```

出現以下畫面代表偵測程式運作正常 有檔住寫有非法RMR訊息與Rest API的xApp的部署
![image](https://hackmd.io/_uploads/rkPRzicIyx.png)


# 偵測程式說明
我們的RMR訊息以及Rest API偵測都是去看config.json裡面的資訊
我們在Q2已有整理出非法RMR訊息清單
並且禁止的RMR跟Rest API都是寫在xapp_onboarder/detection_api/detection_api.json裡面
![image](https://hackmd.io/_uploads/S1WmXj9U1x.png)

## RMR訊息
RMR訊息在config.json裡面有兩段會出現 一個是messaging/port 另一個是單獨的rmr
![image](https://hackmd.io/_uploads/S1U9ov9L1l.png)
![image](https://hackmd.io/_uploads/By7hoPq8kg.png)

## Rest API
Rest API則是本年度計畫想要求新加的 原本的config.json並沒有Rest API這項
裡面將每個元件所需要的四種api所用的API URL個別列出
![image](https://hackmd.io/_uploads/B1M9ed9LJe.png)
