5G核心网:open5gs和UERANSIM的安装和初步使用

准备环境:

虚拟机1(VB1):Ubuntu22.04,安装open5gs

安装步骤参考官方安装指南:Quickstart | Open5GS

虚拟机2(VB2):Ubuntu18.04,安装UERANSIM

安装步骤参考UERANSIM的github:Installation · aligungr/UERANSIM Wiki · GitHub

VirtualBox全局设定创建Nat网络,VB1和VB2网络连接方式都选Nat网络,并使用刚才创建的Nat网络,并且确认mac地址不同,这样可以保证VB1和VB2在同一个网络中并且不会分配相同的地址。

VB1分配的ip为10.0.2.4,VB2分配的ip为10.0.2.15。

初步使用:

1.配置open5gs

在VB1上,修改/etc/open5gs/amf.yaml中的amf的ngap地址为本机地址10.0.2.4

执行sudo systemctl restart open5gs-amfd.service重启amf服务

2.配置UERANSIM

UERANSIM有两个主要模块nr-gnb和nr-ue,分别模拟5g基站和终端。

第一步:配置并启动gnb

修改config/open5gs-gnb.yaml文件,将其中的linkIp,ngapIp,gtpIp修改为本机ip:10.0.2.15,amfConfigs中的address修改为open5gs的ip:10.0.2.4

启动gnb:

build/nr-gnb -c config/open5gs-gnb.yaml

连接open5gs成功,会有类似如下打印:

$ build/nr-gnb -c config/open5gs-gnb.yaml
UERANSIM v3.2.6
[2023-09-01 16:18:33.943] [sctp] [info] Trying to establish SCTP connection... (10.0.2.4:38412)
[2023-09-01 16:18:33.951] [sctp] [info] SCTP connection established (10.0.2.4:38412)
[2023-09-01 16:18:33.952] [sctp] [debug] SCTP association setup ascId[5]
[2023-09-01 16:18:33.952] [ngap] [debug] Sending NG Setup Request
[2023-09-01 16:18:34.449] [ngap] [debug] NG Setup Response received
[2023-09-01 16:18:34.449] [ngap] [info] NG Setup procedure is successful

第二步:配置并启动ue

修改config/open5gs-ue.yaml文件,将其中的gnbSearchList修改为基站ip(本机ip):10.0.2.15

此时还不能启动nr-ue,否则会打印类似PLMN_NOT_ALLOWED的错误,因为核心网数据库中还没有ue的签约信息。

第三步:添加ue签约信息

在VB1中打开浏览器,输入127.0.0.1:3000,这是open5gs的webui,添加一个签约信息。按照VB2中open5gs-ue.yaml的ue的信息,分别把IMSI, K key and OP key(opc)填入保存。

第四步:启动nr-ue

sudo build/nr-ue -c config/open5gs-ue.yaml

需要添加sudo来创建tun网卡,成功后终端打印如下:

UERANSIM v3.2.6
[2023-09-01 16:19:04.016] [rrc] [debug] New signal detected for cell[1], total [1] cells in coverage
[2023-09-01 16:19:04.021] [nas] [info] UE switches to state [MM-DEREGISTERED/PLMN-SEARCH]
[2023-09-01 16:19:04.021] [nas] [info] Selected plmn[999/70]
[2023-09-01 16:19:04.021] [rrc] [info] Selected cell plmn[999/70] tac[1] category[SUITABLE]
[2023-09-01 16:19:04.021] [nas] [info] UE switches to state [MM-DEREGISTERED/PS]
[2023-09-01 16:19:04.021] [nas] [info] UE switches to state [MM-DEREGISTERED/NORMAL-SERVICE]
[2023-09-01 16:19:04.021] [nas] [debug] Initial registration required due to [MM-DEREG-NORMAL-SERVICE]
[2023-09-01 16:19:04.064] [nas] [debug] UAC access attempt is allowed for identity[0], category[MO_sig]
[2023-09-01 16:19:04.064] [nas] [debug] Sending Initial Registration
[2023-09-01 16:19:04.064] [rrc] [debug] Sending RRC Setup Request
[2023-09-01 16:19:04.065] [rrc] [info] RRC connection established
[2023-09-01 16:19:04.066] [rrc] [info] UE switches to state [RRC-CONNECTED]
[2023-09-01 16:19:04.066] [nas] [info] UE switches to state [MM-REGISTER-INITIATED]
[2023-09-01 16:19:04.067] [nas] [info] UE switches to state [CM-CONNECTED]
[2023-09-01 16:19:04.519] [nas] [debug] Authentication Request received
[2023-09-01 16:19:04.558] [nas] [debug] Security Mode Command received
[2023-09-01 16:19:04.559] [nas] [debug] Selected integrity[2] ciphering[0]
[2023-09-01 16:19:04.681] [nas] [debug] Registration accept received
[2023-09-01 16:19:04.681] [nas] [info] UE switches to state [MM-REGISTERED/NORMAL-SERVICE]
[2023-09-01 16:19:04.681] [nas] [debug] Sending Registration Complete
[2023-09-01 16:19:04.681] [nas] [info] Initial Registration is successful
[2023-09-01 16:19:04.681] [nas] [debug] Sending PDU Session Establishment Request
[2023-09-01 16:19:04.684] [nas] [debug] UAC access attempt is allowed for identity[0], category[MO_sig]
[2023-09-01 16:19:04.888] [nas] [debug] Configuration Update Command received
[2023-09-01 16:19:05.109] [nas] [debug] PDU Session Establishment Accept received
[2023-09-01 16:19:05.110] [nas] [info] PDU Session establishment is successful PSI[1]
[2023-09-01 16:19:05.383] [app] [info] Connection setup for PDU session[1] is successful, TUN interface[uesimtun0, 10.45.0.2] is up.

创建了一个名为uesimtun0的tun网卡。

3.添加路由转发

在VB1上:

修改upf配置文件:/etc/open5g/upf.yaml,把upf->gtpu->addr修改为10.0.2.4,重启upf服务

sudo systemctl restart open5gs-upfd.service

配置路由转发规则: 

### Enable IPv4/IPv6 Forwarding
$ sudo sysctl -w net.ipv4.ip_forward=1
$ sudo sysctl -w net.ipv6.conf.all.forwarding=1

### Add NAT Rule
$ sudo iptables -t nat -A POSTROUTING -s 10.45.0.0/16 ! -o ogstun -j MASQUERADE
$ sudo ip6tables -t nat -A POSTROUTING -s 2001:db8:cafe::/48 ! -o ogstun -j MASQUERADE

关闭防火墙:

$ sudo ufw status
Status: active
$ sudo ufw disable
Firewall stopped and disabled on system startup
$ sudo ufw status
Status: inactive

4.测试:

通过uesimtun0网卡发ping包,看是否成功,并且在wireshark中查看gtp包

$ ping 8.8.8.8 -I uesimtun0
PING 8.8.8.8 (8.8.8.8) from 10.45.0.2 uesimtun0: 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=51 time=216 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=51 time=169 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=51 time=169 ms
64 bytes from 8.8.8.8: icmp_seq=7 ttl=51 time=170 ms
64 bytes from 8.8.8.8: icmp_seq=8 ttl=51 time=168 ms
64 bytes from 8.8.8.8: icmp_seq=12 ttl=51 time=172 ms
64 bytes from 8.8.8.8: icmp_seq=13 ttl=51 time=178 ms

open5gs的日志在/var/log/open5gs/目录下。

参考链接:

https://github.com/s5uishida/open5gs_5gc_ueransim_sample_config

My first 5G Core: Open5Gs and UERANSIM | Nick vs Networking

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值