# Anomaly Detection Introduction
###### tags: `5G Reading`
Date : 2022-12-30
## Take away
AD(Anomaly Detection)主要與Traffic Steeling的xApp整合使用,將服務不佳的UE名單提交給Traffic Steering進行換手以提升UE服務品質。
## Summary
- AD(Anomaly Detection)為O-RAN SC中由HCLTech(印度通訊系統整合商)所上傳的xApp應用,主要與Traffic Steeling的xApp整合使用。AD將從KPIMON所上傳的各項參數輸入預測模型,找出收到服務不夠好;視為異常的UE列出,將此名單傳送至Traffic Steeling協助進行換手動作(Handover),期望該UE連接至其他基站後能提升其服務品質,完成此流程後AD將進行下一個時間周期的異常檢查。
## Note
- AD執行流程UML:

- AD預期的輸出入內容範例:
- Input: { ‘du-id’ : 1003, ‘nrCellIdentity’ : “c3/B13”, ‘prb_usage’ : 23.0, ‘rsrp’ : 84.0, ‘rsrq’ : 65.0, ‘rssinr’:65.0, ‘targetTput’ : 0.1, ‘throughput’ : , ‘ue-id’ : “Waiting passenger 1”, ‘x’ : -556, ‘y’ : -1160, ‘measTimeStampRf’ : “2021-05-12T07:43:51.652” }
- Output: { ‘ue-id’ : “Waiting passenger 1”, ‘measTimeStampRf’ : “2021-05-12T07:43:51.652”, ‘du-id’ : 1003, ‘Degradation’: “RSRP RSSINR” }
- AD安裝細節:
- **準備執行環境**
```$ cd emerald/dep/bin
$ sudo ./deploy-ric-platform -f ../RECIPE_EXAMPLE/PLATFORM/example_recipe_oran_e_release.yaml 2>&1 | tee ~/deploy-ric-platform.txt
$ sudo helm repo add stable https://charts.helm.sh/stable
$ sudo helm install nfs-release-1 stable/nfs-server-provisioner --namespace ricinfra
$ sudo kubectl patch storageclass nfs -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
$ sudo apt install nfs-common
$ sudo kubectl get pods -A
```
- **透過RIC模組安裝AD**
```$ curl -X 'POST' 'http://172.19.205.83:32080/onboard/api/v1/onboard' -H 'accept: application/json' -H 'Content-Type:application/json' -d '{"config-file.json": { "xapp_name": "ad", "version": "1.0.0", "containers":[{"name": "ad","image":"registry": "nexus3.o-ran-sc.org:10002","name": "o-ran-sc/ric-app-ad","tag": "1.0.0"}}],"messaging": {"ports": [{"name": "rmr-data","container": "ad","port": 4560,"txMessages":["TS_ANOMALY_UPDATE"],"rxMessages": ["TS_ANOMALY_ACK"],"policies":[],"description": "rmr receive data port for ad"},{"name": "rmr-route","container": "ad","port": 4561,"description": "rmr route port for ad"}]},"rmr": {"protPort": "tcp:4560","maxSize": 2072,"numWorkers": 1,"rxMessages": ["TS_ANOMALY_ACK"],"txMessages": ["TS_ANOMALY_UPDATE"],"policies": []}},"co ntrols-schema.json": {}}'
$ curl --location --request GET 'http://172.19.205.83:32080/onboard/api/v1/charts' -H 'Content-Type: application/json'
$ curl --location --request POST 'http://172.19.205.83:32080/appmgr/ric/v1/xapps' -H 'Content-Type: application/json' -d {"xappName":"ad"}'
$ sudo kubectl get pods -A
```
- **檢測其與TS/DB互動關係**
```$ sudo kubectl get pods -A
$ sudo kubectl logs -f -n ricxapp ricxapp-trafficxapp-5985c48dc7-hvvm2
$ sudo kubectl logs -f -n ricxapp ricxapp-ad-54987d6965-t5pvg
$ sudo kubectl logs -f -n ricplt ricplt-influxdb-meta-0
```