Building Open5GS from Sources

This post explains how to compile and install the source code on Debian/Ubuntu based Linux Distribution.

Note: Ubuntu 16.04(xenial) and earlier versions, and Debian 9(stretch) and earlier versions are not supported.

Getting MongoDB


Install MongoDB with package manager. It is used as database for the HSS and PCRF.

$ sudo apt update
$ sudo apt install mongodb
$ sudo systemctl start mongodb (if '/usr/bin/mongod' is not running)
$ sudo systemctl enable mongodb (ensure to automatically start it on system boot)

Setting up TUN device (not persistent after rebooting)


Create the TUN device with the interface name ogstun.

$ sudo ip tuntap add name ogstun mode tun
$ sudo ip addr add 10.45.0.1/16 dev ogstun
$ sudo ip addr add cafe::1/64 dev ogstun
$ sudo ip link set ogstun up

Tip: The script provided in $GIT_REPO/misc/netconf.sh makes it easy to configure the TUN device as follows:
$ sudo ./misc/netconf.sh

Building Open5GS


Install the dependencies for building the source code.

$ sudo apt install python3-pip python3-setuptools python3-wheel ninja-build build-essential flex bison git libsctp-dev libgnutls28-dev libgcrypt-dev libssl-dev libidn11-dev libmongoc-dev libbson-dev libyaml-dev libnghttp2-dev libmicrohttpd-dev libcurl4-gnutls-dev libnghttp2-dev meson

Git clone.

$ git clone https://github.com/open5gs/open5gs

To compile with meson:

$ cd open5gs
$ meson build --prefix=`pwd`/install
$ ninja -C build

Please free up enough memory space on the VM and run the test program.

The test program has been run on [VirtualBox - CPU: 1, Memory: 4.00 GB] and [Docker for Mac - CPU: 2, Memory: 2.00 GB] with default setting (max.ue: 4,096, pool.packet: 32,768).

Check whether the compilation is correct.

$ ./build/tests/attach/attach ## EPC Only
$ ./build/tests/registration/registration ## 5G Core Only

Run all test programs as below.

$ cd build
$ meson test -v

Tip: You can also check the result of ninja -C build test with a tool that captures packets. If you are running wireshark, select the loopback interface and set FILTER to s1ap || gtpv2 || pfcp || diameter || gtp || ngap || http2.data.data || http2.headers. You can see the virtually created packets. testattach.pcapng/testregistration.pcapng

You need to perform the installation process.

$ cd build
$ ninja install
$ cd ../

Configure Open5GS


5G Core

Modify install/etc/open5gs/amf.yaml to set the NGAP IP address, PLMN ID, TAC and NSSAI.

$ diff -u /etc/open5gs/amf.yaml.old /etc/open5gs/amf.yaml
--- amf.yaml	2020-09-05 20:52:28.652234967 -0400
+++ amf.yaml.new	2020-09-05 20:55:07.453114885 -0400
@@ -165,23 +165,23 @@
       - addr: 127.0.0.5
         port: 7777
     ngap:
-      - addr: 127.0.0.5
+      - addr: 10.10.0.5
     guami:
       - plmn_id:
-          mcc: 901
-          mnc: 70
+          mcc: 001
+          mnc: 01
         amf_id:
           region: 2
           set: 1
     tai:
       - plmn_id:
-          mcc: 901
-          mnc: 70
-        tac: 1
+          mcc: 001
+          mnc: 01
+        tac: 2
     plmn:
       - plmn_id:
-          mcc: 901
-          mnc: 70
+          mcc: 001
+          mnc: 01
         s_nssai:
           - sst: 1
     security:

Modify install/etc/open5gs/upf.yaml to set the GTP-U and PFCP IP address.

$ diff -u /etc/open5gs/upf.yaml.old /etc/open5gs/upf.yaml
--- upf.yaml	2020-09-05 20:52:28.652234967 -0400
+++ upf.yaml.new	2020-09-05 20:52:55.279052142 -0400
@@ -137,9 +137,7 @@
     pfcp:
       - addr: 127.0.0.7
     gtpu:
-      - addr:
-        - 127.0.0.7
-        - ::1
+      - addr: 10.11.0.7
     pdn:
       - addr: 10.45.0.1/16
       - addr: cafe::1/64
4G EPC

Modify install/etc/open5gs/mme.yaml to set the S1AP IP address, PLMN ID, and TAC.

$ diff -u /etc/open5gs/mme.yaml.old /etc/open5gs/mme.yaml
--- mme.yaml	2020-09-05 20:52:28.648235143 -0400
+++ mme.yaml.new	2020-09-05 20:56:05.434484208 -0400
@@ -204,20 +204,20 @@
 mme:
     freeDiameter: /home/acetcom/Documents/git/open5gs/install/etc/freeDiameter/mme.conf
     s1ap:
-      addr: 127.0.0.2
+      addr: 10.10.0.2
     gtpc:
       addr: 127.0.0.2
     gummei:
       plmn_id:
-        mcc: 901
-        mnc: 70
+        mcc: 001
+        mnc: 01
       mme_gid: 2
       mme_code: 1
     tai:
       plmn_id:
-        mcc: 901
-        mnc: 70
-      tac: 1
+        mcc: 001
+        mnc: 01
+      tac: 2
     security:
         integrity_order : [ EIA1, EIA2, EIA0 ]
         ciphering_order : [ EEA0, EEA1, EEA2 ]

Modify install/etc/open5gs/sgwu.yaml to set the GTP-U IP address.

$ diff -u /etc/open5gs/sgwu.yaml.old /etc/open5gs/sgwu.yaml
--- sgwu.yaml	2020-09-05 20:50:39.393022566 -0400
+++ sgwu.yaml.new	2020-09-05 20:51:06.667838823 -0400
@@ -51,7 +51,7 @@
 #
 sgwu:
     gtpu:
-      addr: 127.0.0.6
+      addr: 10.11.0.6
     pfcp:
       addr: 127.0.0.6

If you modify the config files while Open5GS daemons are running, please restart them

Running Open5GS


$ cd install/bin/
$ ./install/bin/open5gs-mmed 
Open5GS daemon v1.3.0-213-gd190548+

08/21 22:53:47.328: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/mme.yaml' (../src/main.c:54)
08/21 22:53:47.328: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/mme.log' (../src/main.c:57)
08/21 22:53:47.365: [app] INFO: MME initialize...done (../src/mme/app-init.c:33)
08/21 22:53:47.365: [gtp] INFO: gtp_server() [127.0.0.2]:2123 (../lib/gtp/path.c:32)
08/21 22:53:47.365: [gtp] INFO: gtp_connect() [127.0.0.3]:2123 (../lib/gtp/path.c:59)
08/21 22:53:47.366: [mme] INFO: s1ap_server() [127.0.0.2]:36412 (../src/mme/s1ap-sctp.c:57)

$ ./install/bin/open5gs-sgwcd 
Open5GS daemon v1.3.0-213-gd190548+

08/21 22:54:43.059: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/sgwc.yaml' (../src/main.c:54)
08/21 22:54:43.059: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/sgwc.log' (../src/main.c:57)
08/21 22:54:43.065: [app] INFO: SGW-C initialize...done (../src/sgwc/app.c:31)
08/21 22:54:43.066: [gtp] INFO: gtp_server() [127.0.0.3]:2123 (../lib/gtp/path.c:32)
08/21 22:54:43.066: [pfcp] INFO: pfcp_server() [127.0.0.3]:8805 (../lib/pfcp/path.c:32)
08/21 22:54:43.066: [pfcp] INFO: ogs_pfcp_connect() [127.0.0.6]:8805 (../lib/pfcp/path.c:60)

$ ./install/bin/open5gs-smfd
Open5GS daemon v1.3.0-213-gd190548+

08/21 22:54:56.000: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/smf.yaml' (../src/main.c:54)
08/21 22:54:56.000: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/smf.log' (../src/main.c:57)
08/21 22:54:56.050: [gtp] INFO: gtp_server() [127.0.0.4]:2123 (../lib/gtp/path.c:32)
08/21 22:54:56.050: [app] INFO: SMF initialize...done (../src/smf/app.c:31)
08/21 22:54:56.050: [gtp] INFO: gtp_server() [::1]:2123 (../lib/gtp/path.c:32)
08/21 22:54:56.050: [pfcp] INFO: pfcp_server() [127.0.0.4]:8805 (../lib/pfcp/path.c:32)
08/21 22:54:56.050: [pfcp] INFO: pfcp_server() [::1]:8805 (../lib/pfcp/path.c:32)
08/21 22:54:56.050: [pfcp] INFO: ogs_pfcp_connect() [127.0.0.7]:8805 (../lib/pfcp/path.c:60)
08/21 22:54:56.051: [sbi] INFO: sbi_server() [127.0.0.4]:7777 (../lib/sbi/server.c:298)

$ ./install/bin/open5gs-amfd
Open5GS daemon v1.3.0-213-gd190548+

08/21 22:55:14.015: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/amf.yaml' (../src/main.c:54)
08/21 22:55:14.015: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/amf.log' (../src/main.c:57)
08/21 22:55:14.039: [app] INFO: AMF initialize...done (../src/amf/app.c:33)
08/21 22:55:14.040: [sbi] INFO: sbi_server() [127.0.0.5]:7777 (../lib/sbi/server.c:298)
08/21 22:55:14.040: [amf] INFO: ngap_server() [127.0.0.5]:38412 (../src/amf/ngap-sctp.c:56)

$ ./install/bin/open5gs-sgwud 
Open5GS daemon v1.3.0-213-gd190548+

08/21 22:54:10.357: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/sgwu.yaml' (../src/main.c:54)
08/21 22:54:10.357: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/sgwu.log' (../src/main.c:57)
08/21 22:54:10.360: [pfcp] INFO: pfcp_server() [127.0.0.6]:8805 (../lib/pfcp/path.c:32)
08/21 22:54:10.360: [app] INFO: SGW-U initialize...done (../src/sgwu/app.c:31)
08/21 22:54:10.361: [gtp] INFO: gtp_server() [127.0.0.6]:2152 (../lib/gtp/path.c:32)

$ ./install/bin/open5gs-upfd 
Open5GS daemon v1.3.0-213-gd190548+

08/21 22:54:21.596: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/upf.yaml' (../src/main.c:54)
08/21 22:54:21.596: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/upf.log' (../src/main.c:57)
08/21 22:54:21.601: [pfcp] INFO: pfcp_server() [127.0.0.7]:8805 (../lib/pfcp/path.c:32)
08/21 22:54:21.601: [app] INFO: UPF initialize...done (../src/upf/app.c:31)
08/21 22:54:21.601: [gtp] INFO: gtp_server() [127.0.0.7]:2152 (../lib/gtp/path.c:32)
08/21 22:54:21.601: [gtp] INFO: gtp_server() [::1]:2152 (../lib/gtp/path.c:32)

$ ./install/bin/open5gs-hssd
Open5GS daemon v1.3.0-213-gd190548+

08/21 22:57:17.450: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/hss.yaml' (../src/main.c:54)
08/21 22:57:17.450: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/hss.log' (../src/main.c:57)
08/21 22:57:17.451: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99)
08/21 22:57:17.519: [app] INFO: HSS initialize...done (../src/hss/app-init.c:31)

$ ./install/bin/open5gs-pcrfd 
Open5GS daemon v1.3.0-213-gd190548+

08/21 22:57:45.894: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/pcrf.yaml' (../src/main.c:54)
08/21 22:57:45.894: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/pcrf.log' (../src/main.c:57)
08/21 22:57:45.896: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99)
08/21 22:57:45.997: [app] INFO: PCRF initialize...done (../src/pcrf/app-init.c:31)

$ ./install/bin/open5gs-nrfd
Open5GS daemon v1.3.0-213-gd190548+

08/21 22:56:35.472: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/nrf.yaml' (../src/main.c:54)
08/21 22:56:35.472: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/nrf.log' (../src/main.c:57)
08/21 22:56:35.472: [app] INFO: NRF initialize...done (../src/nrf/app.c:31)
08/21 22:56:35.473: [sbi] INFO: sbi_server() [127.0.0.10]:7777 (../lib/sbi/server.c:298)
08/21 22:56:35.473: [sbi] INFO: sbi_server() [::1]:7777 (../lib/sbi/server.c:298

$ ./install/bin/open5gs-ausfd
Open5GS daemon v1.3.0-213-gd190548+

08/21 22:55:41.899: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/ausf.yaml' (../src/main.c:54)
08/21 22:55:41.899: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/ausf.log' (../src/main.c:57)
08/21 22:55:41.900: [app] INFO: AUSF initialize...done (../src/ausf/app.c:31)
08/21 22:55:41.900: [sbi] INFO: sbi_server() [127.0.0.11]:7777 (../lib/sbi/server.c:298)

$ ./install/bin/open5gs-udmd 
Open5GS daemon v1.3.0-213-gd190548+

08/21 22:56:02.154: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/udm.yaml' (../src/main.c:54)
08/21 22:56:02.154: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/udm.log' (../src/main.c:57)
08/21 22:56:02.155: [app] INFO: UDM initialize...done (../src/udm/app.c:31)
08/21 22:56:02.155: [sbi] INFO: sbi_server() [127.0.0.12]:7777 (../lib/sbi/server.c:298)

$ ./install/bin/open5gs-udrd 
Open5GS daemon v1.3.0-213-gd190548+

08/21 22:56:15.810: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/udr.yaml' (../src/main.c:54)
08/21 22:56:15.810: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/udr.log' (../src/main.c:57)
08/21 22:56:15.813: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99)
08/21 22:56:15.813: [app] INFO: UDR initialize...done (../src/udr/app.c:31)
08/21 22:56:15.813: [sbi] INFO: sbi_server() [127.0.0.13]:7777 (../lib/sbi/server.c:298)

Several command line options are provided.

$ ./install/bin/open5gs-amfd -h
Usage: ./install/bin/open5gs-amfd [options]
Options:
   -c filename    : set configuration file
   -l filename    : set logging file
   -e level       : set global log-level (default:info)
   -m domain      : set log-domain (e.g. mme:sgw:gtp)
   -d             : print lots of debugging information
   -t             : print tracing information for developer
   -D             : start as a daemon
   -v             : show version number and exit
   -h             : show this message and exit

You can also copy the binaries to /usr/bin to be able to run them from anywhere on the system.

$ cp open5gs* /usr/bin/

For convenience, you can execute all NFs at once by using the following command.

$ ./build/tests/app/5gc ## 5G Core Only with ./build/configs/sample.yaml
$ ./build/tests/app/epc -c ./build/configs/srslte.yaml ## EPC Only with ./build/configs/srslte.yaml
$ ./build/tests/app/app ## Both 5G Core and EPC with ./build/configs/sample.yaml

Building the WebUI of Open5GS


Node.js is required to build WebUI of Open5GS

$ sudo apt install curl
$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
$ sudo apt install nodejs

Install the dependencies to run WebUI

$ cd webui
$ npm install

The WebUI runs as an npm script.

$ npm run dev

Server listening can be changed by setting the environment variable HOSTNAME or PORT as below.

$ HOSTNAME=192.168.0.11 npm run dev
$ PORT=7777 npm run dev

Register Subscriber Information


Connect to http://127.0.0.1:3000 and login with admin account.

Username : admin
Password : 1423

Note: You can change the password in Account Menu.

To add subscriber information, you can do WebUI operations in the following order:

  1. Go to Subscriber Menu.
  2. Click + Button to add a new subscriber.
  3. Fill the IMSI, security context(K, OPc, AMF), and APN of the subscriber.
  4. Click SAVE Button

Tip: This addition immediately affects Open5GS without restarting any daemon.

IP routing + NAT for UE internet connectivity


To allow your phones to connect to the internet, you must run the following command on the host running Open5GS-PGW:

### Check IP Table 'forward'
$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

### Check IP Table 'nat'
$ sudo iptables -L -t nat
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination

### Enable IPv4 Forwarding
$ sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

### Add NAT Rule
$ sudo iptables -t nat -A POSTROUTING -s 10.45.0.0/16 ! -o ogstun -j MASQUERADE

Note: The above assumes you do not have any existing rules in the filter and nat tables. If a program such as docker has already set up rules, you may need to add the Open5GS related rules differently.

Turn on your eNodeB and Phone


  • You can see actual traffic through wireshark – [srsenb.pcapng].
  • You can view the log at $INSTALL_PREFIX/var/log/open5gs/*.log.

Troubleshooting


Debugging tools can help you troubleshoot problems.

  • GDB can be used as below:

    $ gdb ./open5gs-amfd
    
  • On Mac OS X, you can use the LLDB.

    $ lldb ./open5gs-amfd
    

You can use the command line option[-d] to record more logs.

$ ./tests/app/app -d
Open5GS daemon v1.3.0-213-gd190548+

08/21 23:01:54.246: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/build/configs/sample.yaml' (../src/main.c:54)
08/21 23:01:54.246: [thread] DEBUG: [0x7f8de4d25018] worker signal (../lib/core/ogs-thread.c:66)
08/21 23:01:54.246: [thread] DEBUG: [0x7f8de4d25018] thread started (../lib/core/ogs-thread.c:101)
Open5GS daemon v1.3.0-213-gd190548+

08/21 23:01:54.254: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/build/configs/sample.yaml' (../src/main.c:54)
08/21 23:01:54.254: [thread] DEBUG: [0x7ff8d13be818] worker signal (../lib/core/ogs-thread.c:66)
08/21 23:01:54.254: [nrf] DEBUG: nrf_state_initial(): INIT (../src/nrf/nrf-sm.c:25)
08/21 23:01:54.254: [nrf] DEBUG: nrf_state_operational(): ENTRY (../src/nrf/nrf-sm.c:50)
08/21 23:01:54.254: [thread] DEBUG: [0x7ff8d13be818] thread started (../lib/core/ogs-thread.c:101)
08/21 23:01:54.254: [app] INFO: NRF initialize...done (../src/nrf/app.c:31)
08/21 23:01:54.255: [sbi] INFO: sbi_server() [127.0.0.10]:7777 (../lib/sbi/server.c:298)
08/21 23:01:54.255: [sbi] INFO: sbi_server() [::1]:7777 (../lib/sbi/server.c:298)
08/21 23:01:54.296: [thread] DEBUG: [0x7f8de4d25098] worker signal (../lib/core/ogs-thread.c:66)
08/21 23:01:54.296: [thread] DEBUG: [0x7f8de4d25098] thread started (../lib/core/ogs-thread.c:101)
Open5GS daemon v1.3.0-213-gd190548+

08/21 23:01:54.315: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/build/configs/sample.yaml' (../src/main.c:54)
08/21 23:01:54.319: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99)
08/21 23:01:54.332: [app] INFO: PCRF initialize...done (../src/pcrf/app-init.c:31)
08/21 23:01:54.347: [thread] DEBUG: [0x7f8de4d25118] worker signal (../lib/core/ogs-thread.c:66)
08/21 23:01:54.347: [thread] DEBUG: [0x7f8de4d25118] thread started (../lib/core/ogs-thread.c:101)
Open5GS daemon v1.3.0-213-gd190548+

...