@NTUST
# [Dawn] Demo of RIC benchmarking
- Reference:[RIC benchmarking (OSC)](https://wiki.o-ran-sc.org/display/RICP/RIC+benchmarking) & [Build e2simul:0.0.2 (Yueh-Huan Note)](https://hackmd.io/@Yueh-Huan/Hy3ZMJBeu) & [Run e2simul:0.0.2 (Yueh-Huan Note)](https://hackmd.io/@Yueh-Huan/Hy81ferlO)
:::info
**Introduction:**
- Performance RIC benchmarking is a feature that aims to **provide the performance metrics** on both the RAN and Near-RT RIC platform.
- It involves the **communication of E2 simulator from RAN side to Near-RT RIC platform** infrastructure that uses the xApp onboarded on RIC platform.
- The Bouncer xApp **interacts messages with E2 simulator** through the Near RT RIC platform pods and **records the time that provides metrics on latency/throughput on the RIC platform and on the xApp onboarded** on RIC platfom.
**Aims:**
- [x] [Check Point 1:Bouncer xApp interacts with E2simulator using the Near- RT RIC platform for sending the RIC Subscription Request and receiving Response for the same.](#42-Logs-of-E2SIM)
- [x] [Check Point 2:Bouncer xApp receives the RIC indication and sends the Control Message.](#41-Logs-of-bouncer-xApp)
- [x] [Check Point 3:This communication is stored in a file with timestamp to determine the latency/throughput as part of Performance RIC benchmarking purpose.](#5-Result)
:::
## 1. Flow for reference only


## 2. Install E2SIM
### 2.1 Prepare source code
``` shell=
git clone "https://gerrit.o-ran-sc.org/r/it/test"
cd test/ric_benchmarking/e2-interface/e2sim/e2sm_examples/kpm_e2sm/
```

### 2.2 Modify the Dockerfile
- Find the address of the e2term-sctp-alpha:
``` shell=
kubectl get service -n ricplt
```

- Modify the address of service-ricplt-e2term-sctp-alpha in the Dockerfile:
``` shell=
vim Dockerfile
```


### 2.3 Build image
``` shell=
docker build -f Dockerfile -t nexus3.o-ran-sc.org:10002/oran-ric/e2simulator:2.0.0 .
```

### 2.4 helm install
- Restart the e2mgr & e2term:
``` shell=
kubectl rollout restart deployment --namespace ricplt deployment-ricplt-e2mgr deployment-ricplt-e2term-alpha
```

- Modify the namespace:
``` shell=
cd helm
vim values.yaml
```


- Helm install:
``` shell=
helm install -n e2sim . --namespace ricplt
```

- Check the pod of the e2sim:
``` shell=
kubectl get pod -n ricplt
```

## 3. Deploy the bouncer xApp
### 3.1 On-board the bouncer xApp
``` shell=
touch bouncer.json
vim bouncer.json
```

``` json=
{
"config-file.json":{
"xapp_name": "bouncer-xapp",
"version": "2.0.0",
"containers": [
{
"name": "bouncer-xapp",
"image": {
"registry": "nexus3.o-ran-sc.org:10004",
"name": "o-ran-sc/ric-app-bouncer",
"tag": "2.0.0"
}
}
],
"messaging": {
"ports": [
{
"name": "rmr-data",
"container": "bouncer-xapp",
"port": 4560,
"rxMessages": ["RIC_SUB_RESP", "RIC_INDICATION"],
"txMessages": ["RIC_SUB_REQ"],
"policies": [1],
"description": "rmr receive data port for Bouncer xApp"
},
{
"name": "rmr-route",
"container": "bouncer-xapp",
"port": 4561,
"description": "rmr route port for Bouncer xApp"
}
]
},
"rmr": {
"protPort": "tcp:4560",
"maxSize": 2072,
"numWorkers": 1,
"txMessages": ["RIC_SUB_REQ"],
"rxMessages": ["RIC_SUB_RESP", "RIC_INDICATION"],
"policies": [1]
}
}
}
```

``` shell=
curl --location --request POST "http://<Your Kong IP>:32080/onboard/api/v1/onboard" --header 'Content-Type: application/json' -d "@bouncer.json"
```

### 3.2 Deploy the bouncer xApp
``` shell=
curl --location --request POST "http://<Your Kong IP>:32080/appmgr/ric/v1/xapps" --header 'Content-Type: application/json' --data-raw '{"xappName": "bouncer-xapp"}' -v
```

## 4. Check the logs
### 4.1 Logs of bouncer xApp



### 4.2 Logs of E2SIM











## 5. Result
- Round trip time for each interaction are **recorded and stored in the timestamp.txt file** that gets created in the container
### 5.1 Bouncer xApp
- Find the pod of the bouncer xapp:
``` shell=
kubectl get pod -n ricxapp
```

- Enter the container of the bouncer xapp:
``` shell=
kubectl exec -it <bouncer xapp pod> -n ricxapp /bin/bash
ls
```

- View the file "timestamp.txt"
``` shell=
cd tmp
ls
cat timestamp.txt
```


### 5.2 E2SIM
- Find the pod of the E2SIM:
``` shell=
kubectl get pod -n ricplt
```

- Enter the container of the E2SIM & View the file "e2sim_timestamp.txt":
``` shell=
kubectl exec -it <E2SIM pod> -n ricplt /bin/bash
ls
cat e2sim_timestamp.txt
```

## Record of Bug & Solution
### Bug:Subscription Failed
The E2SIM can't receive the Subscription request from the bouncer xApp, and the bouncer xApp send the request over and over.
- Log of the e2sim

- Log of the bouncer xApp

### Solve
- Restart the e2sim
``` shell=
kubectl rollout restart deployment --namespace ricplt e2sim
```
- Restart the bouncer xapp
``` shell=
kubectl rollout restart deployment --namespace ricxapp ricxapp-bouncer-xapp
```
- You had tried to restart the e2sim and bouncer xapp, but it still failed. Maybe you need to check the logs of rtmgr & e2mgr & e2term, you can try to the following commands to solve it.
## Command which you could use
### Undeploy xApp
``` shell=
curl --location --request DELETE "http://<Your Kong IP>:32080/appmgr/ric/v1/xapps/bouncer-xapp" --header 'Content-Type: application/json'
```
### Restart
- rtmgr
``` shell=
kubectl rollout restart deployment --namespace ricplt deployment-ricplt-rtmgr
```
- e2mgr & e2term
``` shell=
kubectl rollout restart deployment --namespace ricplt deployment-ricplt-e2mgr deployment-ricplt-e2term-alpha
```
- e2sim
``` shell=
kubectl rollout restart deployment --namespace ricplt e2sim
```
### Redeploy xApp
``` shell=
curl --location --request POST "http://<Your Kong IP>:32080/appmgr/ric/v1/xapps" --header 'Content-Type: application/json' --data-raw '{"xappName": "bouncer-xapp"}' -v
```