UERANSIM容器使用教程

本文详细介绍了如何使用CLI工具nr-cli来操作和管理UERANSIM中的gNB和UE控制台,包括如何进入交互式shell执行命令、释放用户连接、建立和注销PDU会话以及TUN接口的使用。此外,还提到了通过docker-compose管理容器的重启和关闭方法,以及监控资源使用情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

1. 容器控制台(CLI)的使用

nr-cli用法:

nr-cli更多用法 

1.1 gNB控制台

进入容器通过交互式shell执行命令

 需要查看更多命令,请输入commands

进一步调查子命令的用法和帮助信息 

1.2 UE控制台

2. 常用交互式命令 

2.1  gNB shell

2.2 UE Shell命令

2.2 tunX接口使用

 ping命令

nr-binder命令 

3. 容器的重启和关闭

3.1 容器的重启

3.2 UERANSIM的关闭


官网给出的大多为基于UERANSIM软件的操作方式,并未拓展太多基于容器化的UERANSIM操作方式,该教程旨在探索容器化UERANSIM的操作方式。

1. 容器控制台(CLI)的使用

我们为 gNB 和 UE 提供工具。nr-cli

注意:UE 和 gNB 具有不同的 CLI 命令。例如,在 gNB 中,您可以检查 AMF 连接状态,或者在 UE 中可以触发取消注册。本文件对更多细节作了解释。

nr-cli用法:

  • nr-cli <node-name> 其中node-name包括了UE的imsi名称和gNB的名称

如何获得UE和gNB的名称? 

  • 您可以使用以下命令查询环境中的当前 UE 和 gNB:
docker-compose#  docker exec -it <ueransim容器名> ./nr-cli --dump

由此可以获得UERANSIM的名称UERANSIM-gnb-208-95-1和UE的imsi,接下来就可以进一步使用CLI控制台 

nr-cli更多用法 

  • 使用nr-cli --help命令
docker-compose$ docker exec -it ueransim ./nr-cli --help
WARNING: Error loading config file: /home/lab/.docker/config.json: open /home/lab/.docker/config.json: permission denied
UERANSIM v3.2.5 | Command Line Interface | Copyright (c) 2023 ALİ GÜNGÖR
Usage:
  nr-cli <node-name> [option...]
  nr-cli --dump

Options:
  -d, --dump            List all UE and gNBs in the environment
  -e, --exec <command>  Execute the given command directly without an interactive shell
  -h, --help            Show this help message and exit
  -v, --version         Show version information and exit

1.1 gNB控制台

ocker-compose# docker exec -it ueransim ./nr-cli UERANSIM-gnb-208-95-1
--------------------------------------------------------------------------------------------
$ commands
info       | Show some information about the gNB
status     | Show some status information about the gNB
amf-list   | List all AMFs associated with the gNB
amf-info   | Show some status information about the given AMF
ue-list    | List all UEs associated with the gNB
ue-count   | Print the total number of UEs connected the this gNB
ue-release | Request a UE context release for the given UE
------------------------------------------------------------------------------------------
  • 进入容器通过交互式shell执行命令

docker-compose# docker exec -it <ueransim容器名> ./nr-cli UERANSIM-gnb-208-95-1
--------------------------------------------------------------------------------------------
$
  •  需要查看更多命令,请输入commands

  • 进一步调查子命令的用法和帮助信息 

$ amf-info --help
$ ue-list --version

1.2 UE控制台

$ docker exec -it ueransim ./nr-cli imsi-208950000000130
--------------------------------------------------------------------------------------------
$ commands
info           | Show some information about the UE
status         | Show some status information about the UE
timers         | Dump current status of the timers in the UE
rls-state      | Show status information about RLS
coverage       | Dump available cells and PLMNs in the coverage
ps-establish   | Trigger a PDU session establishment procedure
ps-list        | List all PDU sessions
ps-release     | Trigger a PDU session release procedure
ps-release-all | Trigger PDU session release procedures for all active sessions
deregister     | Perform a de-registration by the UE
--------------------------------------------------------------------------------------------

控制台,可以进一步调查子命令的用法和帮助信息(传送门) 

下面来介绍一些基站常用交互式shell命令

2. 常用交互式命令 

2.1  gNB shell

通过交互式shell在基站侧释放用户连接,从连接态(CONNECTED)转向空闲态(IDLE)

docker-compose# docker exec -it ueransim ./nr-cli UERANSIM-gnb-208-95-1
--------------------------------------------------------------------------------------------
$ commands
info       | Show some information about the gNB
status     | Show some status information about the gNB
amf-list   | List all AMFs associated with the gNB
amf-info   | Show some status information about the given AMF
ue-list    | List all UEs associated with the gNB
ue-count   | Print the total number of UEs connected the this gNB
ue-release | Request a UE context release for the given UE
----------------------------------------------------------------------------------------------
$ ue-list
- ue-id: 1
  ran-ngap-id: 1
  amf-ngap-id: 1
--------------------------------------------------------------------------------------------
$ amf-list
- id: 2
--------------------------------------------------------------------------------------------
$ status
is-ngap-up: true
--------------------------------------------------------------------------------------------
$ ue-count
1
--------------------------------------------------------------------------------------------
$ ue-release --help
Request a UE context release for the given UE 
Usage:
  ue-release <ue-id>
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
$ ue-release 1
Requesting UE context release
--------------------------------------------------------------------------------------------
$ ue-list

--------------------------------------------------------------------------------------------
$ ue-count
0
--------------------------------------------------------------------------------------------
$ status
is-ngap-up: true
--------------------------------------------------------------------------------------------
$

 

 通过交互式命令,我们原始连接的ue已经被释放,可以通过ueransim的日志验证这一点:

2.2 UE Shell命令

使用交互式命令来建立或注销PDU会话

查询用法:

--------------------------------------------------------------------------------------------
$ ps-establish
Trigger a PDU session establishment procedure 
Usage:
  ps-establish <session-type> [options]

Examples:
  ps-establish IPv4 --sst 1 --sd 1 --dnn internet
  ps-establish IPv4 --emergency

Options:
  --sst <value>    SST value of the PDU session
  --sd <value>     SD value of the PDU session
  -n, --dnn <apn>  DNN/APN value of the PDU session
  -e, --emergency  Request as an emergency session
--------------------------------------------------------------------------------------------

PDU会话列表:

--------------------------------------------------------------------------------------------
$ ps-list
PDU Session1: 
 state: PS-ACTIVE
 session-type: IPv4
 apn: default
 s-nssai: 
  sst: 0xde
  sd: 0x00007b
 emergency: false
 address: 12.1.1.5
 ambr: up[50Mb/s] down[100Mb/s]
 data-pending: false
--------------------------------------------------------------------------------------------

新的PDU会话建立:

--------------------------------------------------------------------------------------------
$ ps-establish IPV4 -n default       
PDU session establishment procedure triggered
--------------------------------------------------------------------------------------------

查询

 

我们可以查询uaransim的日志来查看PUD会话建立情况

 成功建立 

ping验证:

值得注意的是,虽然一个UE能够创建多个tunX接口,但是对于核心网而言还是只有一个用户接入,只是该用户有了不同的业务接口而已,可以通过基站shell查询:

  

2.2 tunX接口使用

值得注意的是:

UERANSIM提供了一个TUN接口,以便使用UE的互联网连接。在版本 v2.2.1 中,将自动应用所有 TUN 配置。UERANSIM为每个 PDU 会话设置一个 TUN 接口。成功建立PDU会话后,UE会自动执行以下操作:

  1. 将创建一个 TUN 接口。
  2. 配置路由表、IP 规则和 IP 路由。

注意:路由配置可能与您的当前设置冲突。如果不需要自动路由配置(第 2 项),可以只使用启动 UE(nr-ue --no-route-config)。但是,TUN 接口始终在 PDU 会话建立后创建(第 1 项)。

注意:在同一台计算机上使用 UE 和核心网络通常会导致问题。请使用 2 台不同的机器进行 UERANSIM 和核心网络。(可以使用虚拟机或非虚拟机)

  •  ping命令

docker-compose# docker exec -it ueransim0 ping -I uesimtun0 <ping 的ip地址>

图中的202.108.22.5为百度的ip 

使用 docker stats命令查看各容器资源的使用情况

  • nr-binder命令 

详见另外一篇文章

3. 容器的重启和关闭

3.1 容器的重启

在ueransim的容器中我们可以直接输入UE和gNB的命令来实现ueransim的gNB和UE重启,而不需要关闭整个容器,这样确保了容器中的数据不丢失

首先我们需要查看ueransim容器中的entrypoint.sh脚本

root@1dacc8a170b6:/ueransim/bin# vi entrypoint.sh
SD_0=${SD_0:-128}
SST_1=${SST_1:-1}
SD_1=${SD_1:-0}
SST_2=${SST_2:-129}
SD_2=${SD_2:-129}


if [[ ${USE_FQDN} == "yes" ]];then
    NGAPPeerAddr=(`getent hosts $AMF_FQDN | awk '{print $1}'`)
    echo -e "\nResolving AMF by FQDN : $AMF_FQDN - $NGAPPeerAddr"
fi

for c in ${CONFIG_DIR}/*.yaml; do
    # grep variable names (format: ${VAR}) from template to be rendered
    VARS=$(grep -oP '@[a-zA-Z0-9_]+@' ${c} | sort | uniq | xargs)
    echo "Now setting these variables '${VARS}'"

    # create sed expressions for substituting each occurrence of ${VAR}
    # with the value of the environment variable "VAR"
    EXPRESSIONS=""
    for v in ${VARS}; do
        NEW_VAR=$(echo $v | sed -e "s#@##g")
        if [[ -z ${!NEW_VAR+x} ]]; then
            echo "Error: Environment variable '${NEW_VAR}' is not set." \
                "Config file '$(basename $c)' requires all of $VARS."
            exit 1
        fi
        EXPRESSIONS="${EXPRESSIONS};s|${v}|${!NEW_VAR}|g"
    done
    EXPRESSIONS="${EXPRESSIONS#';'}"

    # render template and inline replace config file
    sed -i "${EXPRESSIONS}" ${c}
done
echo "Done setting the configuration"
echo "### Running ueransim ###"

echo "Running gnb"
/ueransim/bin/nr-gnb -c /ueransim/etc/custom-gnb.yaml &

sleep 1
echo "Running ue"
/ueransim/bin/nr-ue -c /ueransim/etc/custom-ue.yaml -n $NUMBER_OF_UE
exec "$@"

 可以发现其给出了运行gnb和ue的命令,总结如下:

  • gNB
root@1dacc8a170b6:/ueransim/bin# /ueransim/bin/nr-gnb -c /ueransim/etc/custom-gnb.yaml
[2023-04-13 01:27:48.118] [sctp] [info] SCTP connection established (192.168.70.132:38412)
[2023-04-13 01:27:48.118] [sctp] [debug] SCTP association setup ascId[21]
[2023-04-13 01:27:48.118] [ngap] [debug] Sending NG Setup Request
[2023-04-13 01:27:48.138] [ngap] [debug] NG Setup Response received
[2023-04-13 01:27:48.138] [ngap] [info] NG Setup procedure is successful
  • UE
root@1dacc8a170b6:/ueransim/bin# /ueransim/bin/nr-ue -c /ueransim/etc/custom-ue.yaml
UERANSIM v3.2.5
[2023-04-13 01:29:04.299] [nas] [info] UE switches to state [MM-DEREGISTERED/PLMN-SEARCH]
[2023-04-13 01:29:04.300] [rrc] [debug] New signal detected for cell[1], total [1] cells in coverage
[2023-04-13 01:29:04.301] [nas] [info] Selected plmn[208/95]
[2023-04-13 01:29:04.301] [rrc] [info] Selected cell plmn[208/95] tac[40960] category[SUITABLE]
[2023-04-13 01:29:04.301] [nas] [info] UE switches to state [MM-DEREGISTERED/PS]
[2023-04-13 01:29:04.301] [nas] [info] UE switches to state [MM-DEREGISTERED/NORMAL-SERVICE]
[2023-04-13 01:29:04.301] [nas] [debug] Initial registration required due to [MM-DEREG-NORMAL-SERVICE]
[2023-04-13 01:29:04.302] [nas] [debug] UAC access attempt is allowed for identity[0], category[MO_sig]
[2023-04-13 01:29:04.302] [nas] [debug] Sending Initial Registration
[2023-04-13 01:29:04.302] [nas] [info] UE switches to state [MM-REGISTER-INITIATED]
[2023-04-13 01:29:04.302] [rrc] [debug] Sending RRC Setup Request
[2023-04-13 01:29:04.305] [rrc] [info] RRC connection established
[2023-04-13 01:29:04.305] [rrc] [info] UE switches to state [RRC-CONNECTED]
[2023-04-13 01:29:04.305] [nas] [info] UE switches to state [CM-CONNECTED]
[2023-04-13 01:29:04.425] [nas] [debug] Authentication Request received
[2023-04-13 01:29:04.436] [nas] [debug] Security Mode Command received
[2023-04-13 01:29:04.436] [nas] [debug] Selected integrity[1] ciphering[1]
[2023-04-13 01:29:04.449] [nas] [debug] Registration accept received
[2023-04-13 01:29:04.449] [nas] [info] UE switches to state [MM-REGISTERED/NORMAL-SERVICE]
[2023-04-13 01:29:04.449] [nas] [debug] Sending Registration Complete
[2023-04-13 01:29:04.449] [nas] [info] Initial Registration is successful
[2023-04-13 01:29:04.449] [nas] [debug] Sending PDU Session Establishment Request
[2023-04-13 01:29:04.449] [nas] [debug] UAC access attempt is allowed for identity[0], category[MO_sig]
[2023-04-13 01:29:04.725] [nas] [debug] PDU Session Establishment Accept received
[2023-04-13 01:29:04.725] [nas] [info] PDU Session establishment is successful PSI[1]
[2023-04-13 01:29:04.747] [app] [info] Connection setup for PDU session[1] is successful, TUN interface[uesimtun1, 12.1.1.3] is up.

3.2 UERANSIM的关闭

docker-compose -f ueransim.yaml down

当我们直接关闭UERANSIM容器时,可以通过查询AMF日志判断USRANSIM是否断开连接:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值