端到端OAI核心网部署与调试
本文意义
为了广大读者可以对5G核心网和OAI项目有个初步的了解,本文基于oai-cn5g-fed已经编译好的5G核心网网元,用容器的方式部署在WSL2中,并且用开源项目UERANSIM作为5GRAN作为5G接入网模拟器及UE作为终端模拟器,实现SA模式从UE模拟器可以连接外网的功能,可以让读者对SA的整个工作流程有个大体的了解。
部署步骤
部署步骤一共分为五步:
第一步:前期准备
在WSL2基础上预装ubuntu20.04操作系统,WSL1不支持docker,如何从WSL1升级到WSL2,请参考
WSL2需要 hyper-V的支持,但是家庭版windows系统不支持hyper-V,要安装hyper-V请参考
第二步:部署5G核心网
本文使用oai-cn5g-fed中的minimalist中的Scenario 2模式,会部署出4个容器,分别为AMF/SMF/UPF/MYSQL。此部署没有使用wireshark进行远程抓包,所以在前期准备中不需要安装wireshark和tshark:
- 运行 sudo sysctl net.ipv4.conf.all.forwarding=1 && sudo sysctl net.ipv4.conf.all.forwarding=1 为了防止报文被安全策略拦截
- 运行 docker network create --driver=bridge --subnet=192.168.70.128/26 -o "com.docker.network.bridge.name"="demo-oai" 创建网桥用于核心网网元之间的通信和与5GRAN simulator之间通信。
- 启动SA核心网: python3 core-network.py --type start-mini --scenario 2 启动成功的话会有如下打印:
Pulling oai-amf (oaisoftwarealliance/oai-amf:v1.5.0)...
Pulling oai-smf (oaisoftwarealliance/oai-smf:v1.5.0)...
Pulling oai-spgwu (oaisoftwarealliance/oai-spgwu-tiny:v1.5.0)...
Creating oai-ext-dn ... done
Creating mysql ... done
Creating oai-amf ... done
Creating oai-smf ... done
Creating oai-spgwu ... done
v1.5.0: Pulling from oaisoftwarealliance/oai-amf
Digest: sha256:da3d517229245c2b4fbb1d70d450947de9f7d5634aa8c5311f07ceb84529fb68
Status: Downloaded newer image for oaisoftwarealliance/oai-amf:v1.5.0
v1.5.0: Pulling from oaisoftwarealliance/oai-smf
Digest: sha256:67c20d22b66c8549814134ff7d3ad7dd40cf771e44cb4276ebe73723866cd760
Status: Downloaded newer image for oaisoftwarealliance/oai-smf:v1.5.0
v1.5.0: Pulling from oaisoftwarealliance/oai-spgwu-tiny
Digest: sha256:03e372bf13dee4c944309e54c1991681b890e94e6a7836f8c4a9797d353d541d
Status: Downloaded newer image for oaisoftwarealliance/oai-spgwu-tiny:v1.5.0
[2023-02-11 18:25:04,730] root:DEBUG: OAI 5G Core network started, checking the health status of the containers... takes few secs....
[2023-02-11 18:25:04,730] root:DEBUG: docker-compose -f docker-compose-mini-nonrf.yaml ps -a
[2023-02-11 18:25:24,304] root:DEBUG: All components are healthy, please see below for more details....
Name Command State Ports
-----------------------------------------------------------------------------------------
mysql docker-entrypoint.sh mysqld Up (healthy) 3306/tcp, 33060/tcp
oai-amf python3 /openair-amf/bin/e ... Up (healthy) 38412/sctp, 80/tcp, 9090/tcp
oai-ext-dn /bin/bash -c ip route add ... Up (healthy)
oai-smf python3 /openair-smf/bin/e ... Up (healthy) 80/tcp, 8080/tcp, 8805/udp
oai-spgwu python3 /openair-spgwu-tin ... Up (healthy) 2152/udp, 8805/udp
[2023-02-11 18:25:24,304] root:DEBUG: Checking if the containers are configured....
[2023-02-11 18:25:24,304] root:DEBUG: Checking if SMF is able to connect with UPF....
[2023-02-11 18:25:24,551] root:DEBUG: UPF receiving heathbeats from SMF....
[2023-02-11 18:25:24,551] root:DEBUG: OAI 5G Core network is configured and healthy....
如果有问题,根据log提示一一解决,或者留言,我会经常上线看一下,一起讨论解决。
第三步:部署5GRAN simulator
笔者使用UERANSIM源代码在ubuntu20.04中编译,在编译过程中遇到cmake版本太低的问题,解决方法。
在启动之前请核对两部分的信息:
- 5GRAN simulator和5G core network配置文件中的MCC/MNC/TAC信息一致,并且把5G RAN配置文件中的ngapIp/gtpIp配置为之前部署核心网时创建的网桥的网关地址,amfConfigs使用部署amf时的IP地址和端口号;5G core network配置文件 oai-cn5g-fed/docker-compose/docker-compose-min-nonrf.ymal
oai-amf:
container_name: "oai-amf"
image: oaisoftwarealliance/oai-amf:v1.5.0
environment:
- TZ=Europe/paris
- MCC=208
- MNC=95
- REGION_ID=128
- AMF_SET_ID=1
- SERVED_GUAMI_MCC_0=208
- SERVED_GUAMI_MNC_0=95
- SERVED_GUAMI_REGION_ID_0=128
- SERVED_GUAMI_AMF_SET_ID_0=1
- SERVED_GUAMI_MCC_1=460
- SERVED_GUAMI_MNC_1=11
- SERVED_GUAMI_REGION_ID_1=10
- SERVED_GUAMI_AMF_SET_ID_1=1
- PLMN_SUPPORT_MCC=208
- PLMN_SUPPORT_MNC=95
- PLMN_SUPPORT_TAC=0xa000
5GRAN simulator 配置文件 config/open5gs-gnb.yaml
mcc: '208' # Mobile Country Code value
mnc: '95' # Mobile Network Code value (2 or 3 digits)
nci: '0x000000010' # NR Cell Identity (36-bit)
idLength: 32 # NR gNB ID length in bits [22...32]
tac: 0xa000 # Tracking Area Code
linkIp: 127.0.0.1 # gNB's local IP address for Radio Link Simulation (Usually same with local IP)
ngapIp: 192.168.70.129 # gNB's local IP address for N2 Interface (Usually same with local IP)
gtpIp: 192.168.70.129 # gNB's local IP address for N3 Interface (Usually same with local IP)
# List of AMF address information
amfConfigs:
- address: 192.168.70.132
port: 38412
# List of supported S-NSSAIs by this gNB
运行启动命令:
./build/nr-gnb -c config/open5gs-gnb.yaml
root@brian-homebook:/mnt/c/study/OAI/UERANSIM# ./build/nr-gnb -c config/open5gs-gnb.yaml
UERANSIM v3.2.6
[2023-02-12 12:51:13.821] [sctp] [info] Trying to establish SCTP connection... (192.168.70.132:38412)
[2023-02-12 12:51:13.822] [sctp] [info] SCTP connection established (192.168.70.132:38412)
[2023-02-12 12:51:13.823] [sctp] [debug] SCTP association setup ascId[3]
[2023-02-12 12:51:13.823] [ngap] [debug] Sending NG Setup Request
[2023-02-12 12:51:13.833] [ngap] [debug] NG Setup Response received
[2023-02-12 12:51:13.833] [ngap] [info] NG Setup procedure is successful
第四步运行UE simulator
运行启动命令之前先核对UE配置文件中的启动脚本和核心网中此UE的参数:MCC/MNC/key/op,核心网默认应该没有下面supi的参数,所以需要进入mysql容器中,手动把要接入的UE的信息提前输入到数据库中,具体命令:
#Login to mysql container once the container is running
(docker-compose-host)$ docker exec -it mysql /bin/bash
(mysql-container)$ mysql -uroot -plinux -D oai_db
mysql> INSERT INTO users VALUES
('208950000000136','380561234567','55000000000001',NULL,'PURGED',50,40000000,100000000,47,0000000000,1,0x0C0A34601D4F07677303652C0462535B,0,0,0x40,'ebd07771ace8677a',0x63bfa50ee6523365ff14c1f45f88737d);
UE的配置文件:config/open5gs-ue.yaml
# IMSI number of the UE. IMSI = [MCC|MNC|MSISDN] (In total 15 digits)
supi: 'imsi-208950000000136'
# Mobile Country Code value of HPLMN
mcc: '208'
# Mobile Network Code value of HPLMN (2 or 3 digits)
mnc: '95'
# Permanent subscription key
key: '0C0A34601D4F07677303652C0462535B'
# Operator code (OP or OPC) of the UE
op: '63bfa50ee6523365ff14c1f45f88737d'
# This value specifies the OP type and it can be either 'OP' or 'OPC'
opType: 'OPC'
# Authentication Management Field (AMF) value
amf: '8000'
# IMEI number of the device. It is used if no SUPI is provided
imei: '356938035643803'
# IMEISV number of the device. It is used if no SUPI and IMEI is provided
imeiSv: '4370816125816151'
因为我们用的是UE simulator,需要在amf的配置文件中把NIA0改为NIA2,因为UE simulator不支持NIA0,配置文件:/openair-amf/etc/amf.conf
NAS:
{
ORDERED_SUPPORTED_INTEGRITY_ALGORITHM_LIST = ["NIA2", "NIA1", "NIA2"] ;
ORDERED_SUPPORTED_CIPHERING_ALGORITHM_LIST = ["NEA2", "NEA1", "NEA2"] ;
};
运行UE simulator:
root@brian-homebook:/mnt/c/study/OAI/UERANSIM# ./build/nr-ue -c config/open5gs-ue.yaml
UERANSIM v3.2.6
[2023-02-14 18:12:16.843] [nas] [info] UE switches to state [MM-DEREGISTERED/PLMN-SEARCH]
[2023-02-14 18:12:16.844] [rrc] [debug] UE[1] new signal detected
[2023-02-14 18:12:16.858] [rrc] [debug] New signal detected for cell[1], total [1] cells in coverage
[2023-02-14 18:12:16.859] [nas] [info] Selected plmn[208/95]
[2023-02-14 18:12:16.859] [rrc] [info] Selected cell plmn[208/95] tac[40960] category[SUITABLE]
[2023-02-14 18:12:16.860] [nas] [info] UE switches to state [MM-DEREGISTERED/PS]
[2023-02-14 18:12:16.860] [nas] [info] UE switches to state [MM-DEREGISTERED/NORMAL-SERVICE]
[2023-02-14 18:12:16.860] [nas] [debug] Initial registration required due to [MM-DEREG-NORMAL-SERVICE]
[2023-02-14 18:12:16.860] [nas] [debug] UAC access attempt is allowed for identity[0], category[MO_sig]
[2023-02-14 18:12:16.860] [nas] [debug] Sending Initial Registration
[2023-02-14 18:12:16.878] [nas] [info] UE switches to state [MM-REGISTER-INITIATED]
[2023-02-14 18:12:16.878] [rrc] [debug] Sending RRC Setup Request
[2023-02-14 18:12:16.879] [rrc] [info] RRC Setup for UE[1]
[2023-02-14 18:12:16.879] [rrc] [info] RRC connection established
[2023-02-14 18:12:16.879] [rrc] [info] UE switches to state [RRC-CONNECTED]
[2023-02-14 18:12:16.879] [nas] [info] UE switches to state [CM-CONNECTED]
[2023-02-14 18:12:16.879] [ngap] [debug] Initial NAS message received from UE[1]
[2023-02-14 18:12:16.919] [nas] [debug] Authentication Request received
[2023-02-14 18:12:16.921] [nas] [debug] Security Mode Command received
[2023-02-14 18:12:16.921] [nas] [debug] Selected integrity[2] ciphering[2]
[2023-02-14 18:12:16.926] [ngap] [debug] Initial Context Setup Request received
[2023-02-14 18:12:16.926] [nas] [debug] Registration accept received
[2023-02-14 18:12:16.926] [nas] [info] UE switches to state [MM-REGISTERED/NORMAL-SERVICE]
[2023-02-14 18:12:16.926] [nas] [debug] Sending Registration Complete
[2023-02-14 18:12:16.926] [nas] [info] Initial Registration is successful
[2023-02-14 18:12:16.926] [nas] [debug] Sending PDU Session Establishment Request
[2023-02-14 18:12:16.927] [nas] [debug] UAC access attempt is allowed for identity[0], category[MO_sig]
[2023-02-14 18:12:17.161] [ngap] [info] PDU session resource(s) setup for UE[1] count[1]
[2023-02-14 18:12:17.162] [nas] [debug] PDU Session Establishment Accept received
[2023-02-14 18:12:17.162] [nas] [info] PDU Session establishment is successful PSI[1]
[2023-02-14 18:12:17.188] [app] [info] Connection setup for PDU session[1] is successful, TUN interface[uesimtun0, 12.1.1.2] is up.
第五步,用UE simulator上网
UE simulator运行成功之后,用ifconfig可以看到多了一个接口,这个接口就是UE的接口:
uesimtun0: flags=369<UP,POINTOPOINT,NOTRAILERS,RUNNING,PROMISC> mtu 1400
inet 12.1.1.2 netmask 255.255.255.255 destination 12.1.1.2
inet6 fe80::bb44:1037:c007:110f prefixlen 64 scopeid 0x20<link>
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 500 (UNSPEC)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9 bytes 544 (544.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
用这个接口ping外网的网址,能得到回应,说明UE simulator可以上网:
root@brian-homebook:/home/briachen# ping www.baidu.com -I uesimtun0
PING www.a.shifen.com (14.215.177.38) from 12.1.1.2 uesimtun0: 56(84) bytes of data.
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=51 time=32.6 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=51 time=31.5 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=51 time=32.6 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=4 ttl=51 time=31.1 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=5 ttl=51 time=31.1 ms
^C
--- www.a.shifen.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4006ms
最后感谢北邮的小牛同学的大力支持,有了他的大力支持,大大加快了部署的进度,哔哩哔哩上有小牛的视频,大家有兴趣可以看看。如果读者们在部署的过程中遇到什么问题,请留言,我会经常上线跟大家讨论,后续会继续出编译运行OAI各个组件的文章,尽请期待。