Tutorial: Create a GTP-U tunnel in Ubuntu using OVS

Guillaume Belanger
3 min readNov 26, 2023

In the context of 5G, GTP-U tunnels are used in the User Plane Function (UPF) to connect 5G mobile subscribers with the internet. If we were to create our own implementation of a UPF, using Open vSwitch to manage those tunnels is a viable option. In this tutorial, we will go through the process of creating a GTP-U tunnel on Ubuntu 22.04 using Open vSwitch (OVS).

Pre-requisites

  • A Ubuntu 22.04 machine

1. Use LXC to create networks

Install LXD:

sudo snap install lxd

Create 2 networks named ran and data :

lxc network create ran
lxc network create data

2. Create a virtual machine with Multipass

Install Multipass:

sudo snap install multipass

Change the backend to use lxd :

multipass set local.driver=lxd

Restart Multipass:

sudo snap restart multipass.multipassd

Create a Ubuntu 22.04 virtual machine with 2 extra ports on the ran and data networks:

multipass launch --name=demo --network=ran --network=data 22.04

Open a shell in the virtual machine:

multipass shell demo

This Virtual Machine should have 4 network interfaces:

ubuntu@demo:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp5s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 52:54:00:f6:11:22 brd ff:ff:ff:ff:ff:ff
inet 10.215.207.224/24 metric 100 brd 10.215.207.255 scope global dynamic enp5s0
valid_lft 3522sec preferred_lft 3522sec
inet6 fd42:126e:f344:d11b:5054:ff:fef6:1122/64 scope global mngtmpaddr noprefixroute
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fef6:1122/64 scope link
valid_lft forever preferred_lft forever
3: enp6s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 52:54:00:f1:64:fa brd ff:ff:ff:ff:ff:ff
inet 10.13.31.129/24 metric 200 brd 10.13.31.255 scope global dynamic enp6s0
valid_lft 3522sec preferred_lft 3522sec
inet6 fd42:567b:718a:5df4:5054:ff:fef1:64fa/64 scope global mngtmpaddr noprefixroute
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fef1:64fa/64 scope link
valid_lft forever preferred_lft forever
4: enp7s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 52:54:00:f5:4b:e5 brd ff:ff:ff:ff:ff:ff
inet 10.242.77.251/24 metric 200 brd 10.242.77.255 scope global dynamic enp7s0
valid_lft 3522sec preferred_lft 3522sec
inet6 fd42:2d7f:9b46:c53a:5054:ff:fef5:4be5/64 scope global mngtmpaddr noprefixroute
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fef5:4be5/64 scope link
valid_lft forever preferred_lft forever

Note the last 2 interfaces (here enp6s0 and enp7s0).

3. Use OVS to create a GTP-U tunnel

Install OVS

sudo apt update
sudo apt install openvswitch-switch

Create a bridge in the userspace:

sudo ovs-vsctl add-br br0
sudo ovs-vsctl set bridge br0 datapath_type=netdev

To utilize the additional network interfaces in your GTP-U setup, assign one interface to connect to the RAN and the other to the data network:

sudo ovs-vsctl add-port br0 enp6s0
sudo ovs-vsctl add-port br0 enp7s0

Create a new GTP-U tunnel with a TEID of 5000 and a remote IP address of 172.31.1.1 . In a typical 5G network, those values would have been provided my the Session Management Function (SMF).

sudo ovs-vsctl add-port br0 gtpu0 -- set int gtpu0 type=gtpu options:key=5000 options:remote_ip=172.31.1.1

Your OVS configuration should look like this:

ubuntu@demo:~$ sudo ovs-vsctl show
556cfaf2-9476-419f-b52f-cc79f109044d
Bridge br0
datapath_type: netdev
Port enp7s0
Interface enp7s0
Port enp6s0
Interface enp6s0
Port gtpu0
Interface gtpu0
type: gtpu
options: {key="5000", remote_ip="172.31.1.1"}
Port br0
Interface br0
type: internal
ovs_version: "2.17.7"

There you go, you have a GTP-U tunnel! 🎊

4. Destroy the environment

Exit from the demo virtual machine shell:

exit

Delete the virtual machine

multipass delete demo
multipass purge

Delete the lxc networks:

lxc network delete ran
lxc network delete data

Remove Multipass and LXD:

sudo snap remove multipass --purge
sudo snap remove lxd --purge

--

--

Guillaume Belanger

Guillaume is a software developer from Montreal who writes about bip bop stuff.