Categories
5G SA Mobile Networks

My first 5G Core: Open5Gs and UERANSIM

While 5G SA devices are still in their early stages, and 5G RAN hardware / gNodeBs are hard to come by, so today we’ll cover using UERANSIM to simulate UEs and 5G RAN, to put test calls through our 5GC.

Bringing your 5G Core Online

We’ll use Open5Gs for all the 5GC components, and install on any recent Ubuntu distribution.

Installation is nice and easy;

$ sudo apt update 
$ sudo apt install software-properties-common 
$ sudo add-apt-repository ppa:open5gs/latest 
$ sudo apt update 
$ sudo apt install open5gs

The first point of contact we’ll need to talk about is the AMF,

The AMF – the Access and Mobility Function is reached by the gNodeB over the N2 interface. The AMF handles our 5G NAS messaging, which is the messaging used by the UEs / Devices to request data services, manage handovers between gNodeBs when moving around the network, and authenticate to the network.

By default the AMF binds to a loopback IP, which is fine if everything is running on the same box, but becomes an issue for real gNodeBs or if we’re running UERANSIM on a different machine. This means we’ll need to configure our AMF to bind to the IP of the machine it’s running on, by configuring the AMF in /etc/open5gs/amf.conf, so we’ll change the ngap addr to bind the AMF to the machine’s IP, for me this is 10.0.1.99,

ngap:
  - addr: 10.0.1.99

In the amf.conf there’s a number of things we can change and configure; such as the PLMN and network name, the NRF parameters, however for now we’ll keep it simple and leave everything else as default.

To allow the changes to take effect, we’ll restart the Open5GS AMF service to make our changes take effect;

$ sudo systemcl restart open5gs-amfd

Setting up the Simulator

We’re using UERANSIM as our UE & RAN Simulator, so we’ll need to get it installed, you may need to adjust the Java path if you’re using a different version of Java or have it installed in a different directory.

$ sudo apt update 
$ sudo apt upgrade 
$ sudo apt install make g++ openjdk-11-jdk maven libsctp-dev lksctp-tools
$ git clone https://github.com/aligungr/UERANSIM.git
$ cd UERANSIM
$ export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/
$ sh build.sh

Once we’ve got the software installed we’ll need to put together the basic settings. For now UERANSIM doesn’t implement the Network Repository Function (My current favorite function of 5GC), so we’ll need to manually define the AMF address, and populated the PLMN, tracking, areas, etc.

Configuring the Simulator

This is configured in the UERANSIM folder under config/ folder,

Quick note here – UERANSIM allows us to have different profiles with different settings, for testing different networks. Luckily for us, there’s a premade profile with settings that match what Open5GS has out of the box. To use it we’ll edit the profile.yaml file in the config/ folder, and ensure that the selected profile is open5gs:

selected-profile: 'open5gs'

Once that’s done we’ll open the folder in config called Open5Gs where we’ll enter our details,

We’ll start with the gnb.yaml file, where we set the parameters of our simulated gNodeb, we need to set the host to be the IP of our AMF, in my case it’s 10.0.1.99

You’ll also need to set the IP of the host machine (the machine running EURANSIM) so it can set the correct source address and listen on the right IP, my laptop’s IP is 10.0.1.252 so I’ve put that into the config

host: 10.0.1.252
gtpPort: 2152

...

amfConfigs:
  - guami:
      mcc: 901
      mnc: 70
      amfRegionId:
        hex: '2a'
      amfSetId:
        hex: '5580'
      amfPointer:
        hex: 'a8'
    host: 10.0.1.99
    port: 38412

If you’d changed the PLMN (MCC/MNC) or the TAC setup in the AMF config on Open5GS you’d have to update the gnb.conf to reflect the changes.

Configuring a Subscriber to Simulate

Next we’ll need to configure our Subscribers, by default the ue.yaml file contains a subscriber identity, authentication keys and DNN (Like an APN) to use,

snn: '5G:mnc070.mcc901.3gppnetwork.org'
key: '465B5CE8B199B49FAA5F0A2EE238A6BC'
op: 'E8ED289DEBA952E4283B54E88E6183CA'
amf: '8000'
imei: '356938035643803'
supi: 'imsi-901700000000003'

smsOverNasSupported: true
dnn: 'internet'

requestedNssai:
  - sst:
      value: 1
    sd:
      hex: '010203'

We’ll leave this as it is, but we’ll need to add that subscrber to the Open5GS UDM/UDR/HSS,

For this we’ll open the Open5GS WebUI, and add a subscriber,

We’ll enter the IMSI, K key and OP key (make sure you’ve selected OP and not OPc), and save. If you’re observant you may notice the values match the defaults in the Open5GS Web UI, just without the spaces.

Running UERANSIM

Now for the fun part – Running it all!

UERANSIM is written in Java (That’s why we installed it earlier) and relies on the JAVA_HOME variable being set containing your Java home directory.

We’ll move back into the UERANSIM folder and run:

$ sh run.sh

From here if all goes well you’ll see UERANSIM register to the AMF as a gNodeB (using the N2 interface),

You’ll get some indication in the Open5Gs logs that a new gNodeB has connected as well:

==> /var/log/open5gs/amf.log <==
11/12 20:31:20.851: [amf] INFO: gNB-S1 accepted[10.0.1.252]:51410 in ng-path module (../src/amf/ngap-sctp.c:107)
11/12 20:31:20.851: [amf] INFO: gNB-N1 accepted[10.0.1.252] in master_sm module (../src/amf/amf-sm.c:555)
11/12 20:31:20.851: [amf] INFO: [Added] Number of gNBs is now 1 (../src/amf/context.c:866)
If you run a Wireshark filter for ‘ngap’ you should see the gNodeB registering with the AMF;

So next up let’s register a UE (this will use the N1 interface between the simulated UE and the AMF),

We’ll see the successful authentication, and presto, we’re registered on the 5GC,

At this point (November 2020) UERANSIM can create bearers, and is very close to being able to direct traffic down them, for now UERANSIM sets up the bearer, does a DNS request to google.com and tries to ping it. More advanced functionality is in the works though, so keep an eye on the UERANSIM GitHub page and contribute code if you can, and consider supporting them on Patreon if you can’t, they’re doing great work.

I’ll do a follow up from this post when the functionality is supported, and on the protocols you’ll want to trace in Wireshark for 5G, but kick back safe in the knowledge you’ve got a 5G core operational before anyone else!

7 replies on “My first 5G Core: Open5Gs and UERANSIM”

Hi Nick,

Thank you for the guide that you have provided. I have installed Open5gs and the simulator in a single Linux box and I managed to start all the services correctly. However, when I try to start the simulator, I got the following message;

WARNING: All global logs are written to: logs/global.log
WARNING: All logs of UEs and gNBs are written to their own log files: logs/*
WARNING: All load testing logs are written to: logs/loadtest.log
INFO: Selected profile: “open5gs”
[2020-11-18 13:09:15.419] [INFO] [CONNECTION] [air] TUN Bridge has been started.
[2020-11-18 13:09:15.523] [INFO] [CONNECTION] [gnb-1] Trying to establish SCTP connection… (127.0.0.5:38412)
[2020-11-18 13:09:15.539] [INFO] [CONNECTION] [gnb-1] SCTP connection established
Exception in thread “main” tr.havelsan.ueransim.mts.MtsException: no constructor found for given parameter names for type UeConfig
at tr.havelsan.ueransim.mts.MtsConstruct.construct(MtsConstruct.java:99)
at tr.havelsan.ueransim.mts.MtsConstruct.construct(MtsConstruct.java:163)
at tr.havelsan.ueransim.app.app.AppConfig.createUeConfig(AppConfig.java:41)
at tr.havelsan.ueransim.app.app.UeRanSim.initialize(UeRanSim.java:69)
at tr.havelsan.ueransim.app.app.UeRanSim.(UeRanSim.java:53)
at tr.havelsan.ueransim.app.app.AppBuilder.build(AppBuilder.java:75)
at tr.havelsan.ueransim.app.app.entry.MainApp.main(MainApp.java:20)
[2020-11-18 13:09:16.606] [SUCCESS] [PROCEDURE_RESULT] [gnb-1] NGSetup procedure is successful

So I am not getting the prompt for “list of possible test”. May I know if you happened to have such an issue?

Thanks
Luke

Hi Luke,
I haven’t had the issue, UERANSIM is evolving quickly, many commits per day, so maybe best to try the latest version today, or go back to a commit from a few weeks ago and see if you have the same issue.

I’m also binding the AMF IP, I haven’t tried all on the same machine,but may be worth binding the AMF IP to the IP of the machine it’s running on incase there’s some issues with using Loopbacks.

If that doesn’t work just open an issue on the UERANSIM Github issues page,

Nick

Hi Nick,
Thanks for your guidances which totally helps me a lot.But after following all your steps from the article,sadly the SCTP connections couldn’t established.I got the following message:

WARNING: All global logs are written to: logs/global.log

WARNING: All logs of UEs and gNBs are written to their own log files: logs/*

WARNING: All load testing logs are written to: logs/loadtest.log

INFO: Selected profile: “open5gs”

[2020-11-19 15:22:47.403] [INFO] [CONNECTION] [air] TUN Bridge has been started.

[2020-11-19 15:22:47.490] [INFO] [CONNECTION] [gnb-1] Trying to establish SCTP connection… (192.168.56.129:38412)

[2020-11-19 15:28:28.901] [ERROR] [CONNECTION] [gnb-1] SCTP connection could not established:connetion time out.

I built OPEN5Gs and UERANSIM on two different virtual machines.Have you met the same issue?
Thanks a lot.

Hi Nick…good instructive. I deployed UESIM on one machine and 5GC on the other. I changed the ngap_server to my interfaces IP and the log reflects that:

11/19 20:47:45.533: [app] INFO: Configuration: ‘/etc/open5gs/amf.yaml’ (../src/main.c:54)
11/19 20:47:45.533: [app] INFO: File Logging: ‘/var/log/open5gs/amf.log’ (../src/main.c:57)
11/19 20:47:45.535: [app] INFO: AMF initialize…done (../src/amf/app.c:33)
11/19 20:47:45.535: [sbi] INFO: sbi_server() [127.0.0.5]:7777 (../lib/sbi/server.c:297)
11/19 20:47:45.536: [amf] INFO: ngap_server() [192.168.40.250]:38412 (../src/amf/ngap-sctp.c:55)

However SCTP keeps failing with an ABORT from UESIM. Any idea what could cause that?
21:17:40.137207 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto SCTP (132), length 68)
192.168.40.210.52345 > chia1848TB.38412: sctp
1) [INIT] [init tag: 1322236571] [rwnd: 106496] [OS: 10] [MIS: 65535] [init TSN: 4088205810]
21:17:40.137288 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto SCTP (132), length 292)
chia1848TB.38412 > 192.168.40.210.52345: sctp
1) [INIT ACK] [init tag: 2281304756] [rwnd: 106496] [OS: 30] [MIS: 10] [init TSN: 3721079048]
21:17:40.137591 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto SCTP (132), length 36)
192.168.40.210.52345 > chia1848TB.38412: sctp
1) [ABORT]

Hi Carlos,
I’m not sure if UERANSIM uses a user-plane SCTP stack, but if so it could be that the kernel SCTP stack is interfering. To be sure, use the following IPTABLES command to stop this:
iptables -t filter -I OUTPUT -p sctp –chunk-types any ABORT -j DROP

Hi Nick,thanks for your guidance.I have done all the steps in your article,but I can’t establish SCTP connection.There is the response I got: [email protected]:~/UERANSIM# ./run.sh
WARNING: All global logs are written to: logs/global.log
WARNING: All logs of UEs and gNBs are written to their own log files: logs/*
WARNING: All load testing logs are written to: logs/loadtest.log
INFO: Selected profile: “open5gs”
[2020-11-20 12:11:18.805] [INFO] [CONNECTION] [air] TUN Bridge has been started.
[2020-11-20 12:11:18.886] [INFO] [CONNECTION] [gnb-1] Trying to establish SCTP connection… (192.168.56.129:38412)
[2020-11-20 12:16:59.951] [ERROR] [CONNECTION] [gnb-1] SCTP connection could not established: 连接超时. I notice that in your article’s picture there is no Tun Bridge while running UERANSIM and I wonder does the Tun Bridge make the error happen.Any help will be grateful.

For those having issues with connection timeout do a basic check that you have communication between the 2 machines. I had opn5gs and EURANSIM running on different VMs and the issue was down to connectivity between the two. If you are using VMs for this, ensure internal network is set in networks settings (virtualbox).

Leave a Reply

Your email address will not be published. Required fields are marked *