Skip to content

Commit

Permalink
Add dev-free5gc-upf
Browse files Browse the repository at this point in the history
Close #22
  • Loading branch information
louisroyer committed Jul 8, 2024
1 parent fbe917f commit e81c092
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,35 @@ environment:
SBI_BINDING_PORT: "8000" # default: "8000"
NRF: "nrf.sbi:8000"
```

### UPF
- On Dockerhub [`louisroyer/dev-free5gc-upf`](https://hub.docker.com/r/louisroyer/dev-free5gc-upf).

Please note that even if this software is not yet properly packaged using `.deb`, the generated binary file `/usr/local/bin/udr` is provided to you under Apache Version 2.0 License. A copy of this license can be found in `/usr/share/common-licenses/Apache-2.0`.
A copy of the source code is available at in the repository [`free5gc/udr`](https://github.com/free5gc/go-upf).

To use this UPF, first install [Free5CG's GTP5G kernel module](https://github.com/free5gc/gtp5g) on your host. Please note that you need to have Linux headers installed on the host to be able to install the module (for example, the package `linux-headers-amd64` on Debian if you are on an amd64 architecture).

Environment variable used to select templating system:
```yaml
environment:
ROUTING_SCRIPT: "docker-setup"
TEMPLATE_SCRIPT: "template-script.sh"
TEMPLATE_SCRIPT_ARGS: ""
CONFIG_FILE: "/etc/free5gc/upf.yaml"
CONFIG_TEMPLATE: "/usr/local/share/free5gc/template-upf.yaml"
```

Environment variables for templating:
```yaml
environment:
N4: "203.0.113.2"
IF_LIST: |-
- addr: "233.252.0.1"
type: N3
DNN_LIST: |-
- dnn: internet
cidr: 10.0.0.0/23
- dnn: edge
cidr: 10.0.3.0/23
```
43 changes: 43 additions & 0 deletions upf/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2024 Louis Royer. All rights reserved.
# Use of this source code is governed by a MIT-style license that can be
# found in the LICENSE file.
# SPDX-License-Identifier: MIT

FROM golang:1.21 AS builder
ARG COMMIT_GTP5GNL=548be7c8e3e46838a1833d324c4f2108d2e1db91 COMMIT=922281ba58b6ca42d73be218671c8feae3658420
RUN : ${COMMIT_GTP5GNL:? Missing build-arg COMMIT_GTP5GNL.} && go install \
github.com/free5gc/go-gtp5gnl/cmd/gogtp5g-tunnel@${COMMIT_GTP5GNL}
RUN : ${COMMIT:? Missing build-arg COMMIT.} && go install \
-ldflags="-X github.com/free5gc/util/version.VERSION=https://github.com/louisroyer-docker/free5gc -X github.com/free5gc/util/version.BUILD_TIME= -X github.com/free5gc/util/version.COMMIT_HASH=${COMMIT} -X github.com/free5gc/util/version.COMMIT_TIME=" \
github.com/free5gc/go-upf/cmd@${COMMIT}


FROM louisroyer/base-irit:latest

LABEL maintainer="Louis Royer <[email protected]>" \
org.opencontainers.image.authors="Louis Royer <[email protected]>" \
org.opencontainers.image.source="https://github.com/louisroyer-docker/free5gc"

# Used to disable caching of next steps, if not build since 1 day,
# allowing to search and apply security upgrades
ARG BUILD_DATE=""

RUN apt-get update -q && DEBIAN_FRONTEND=non-interactive apt-get install -qy --no-install-recommends --no-install-suggests \
docker-setup \
&& apt-get upgrade -qy \
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /go/bin/gogtp5g-tunnel /usr/local/bin/gtp5g-tunnel
COPY --from=builder /go/bin/cmd /usr/local/bin/upf
COPY ./*.sh /usr/local/bin/
COPY ./template-upf.yaml /usr/local/share/free5gc/

ENV ROUTING_SCRIPT="docker-setup" \
ONESHOT="true" \
TEMPLATE_SCRIPT="template-script.sh" \
TEMPLATE_SCRIPT_ARGS="" \
CONFIG_FILE="/etc/free5gc/upf.yaml" \
CONFIG_TEMPLATE="/usr/local/share/free5gc/template-upf.yaml"

ENTRYPOINT ["entrypoint.sh"]
CMD ["--help"]
35 changes: 35 additions & 0 deletions upf/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
# Copyright 2024 Louis Royer. All rights reserved.
# Use of this source code is governed by a MIT-style license that can be
# found in the LICENSE file.
# SPDX-License-Identifier: MIT

set -e
savedargs=( "$@" )
config_opt=1
while [ $# -gt 0 ]; do
if [[ $1 == "--config" || $1 == "-c" ]]; then
config_opt=0
fi
shift
done
set -- "${savedargs[@]}"

if [[ -n "${CONFIG_TEMPLATE}" && -n "${CONFIG_FILE}" ]]; then
if [ -n "${TEMPLATE_SCRIPT}" ]; then
echo "[$(date --iso-8601=s)] Running ${TEMPLATE_SCRIPT}${TEMPLATE_SCRIPT_ARGS:+ }${TEMPLATE_SCRIPT_ARGS} for building ${CONFIG_FILE} from ${CONFIG_TEMPLATE}." > /dev/stderr
"$TEMPLATE_SCRIPT" "$TEMPLATE_SCRIPT_ARGS"
fi
else
config_opt=0
fi

if [ -n "${ROUTING_SCRIPT}" ]; then
"${ROUTING_SCRIPT}"
fi

if [[ $config_opt -eq 1 ]]; then
exec upf --config "$CONFIG_FILE" "$@"
else
exec upf "$@"
fi
48 changes: 48 additions & 0 deletions upf/template-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# Copyright 2024 Louis Royer. All rights reserved.
# Use of this source code is governed by a MIT-style license that can be
# found in the LICENSE file.
# SPDX-License-Identifier: MIT

set -e
mkdir -p "$(dirname "${CONFIG_FILE}")"

if [ -z "$N4" ]; then
echo "Missing mandatory environment variable (N4)." > /dev/stderr
exit 1
fi
if [ -z "$DNN_LIST" ]; then
echo "Missing mandatory environment variable (DNN_LIST)." > /dev/stderr
exit 1
fi
if [ -z "$IF_LIST" ]; then
echo "Missing mandatory environment variable (IF_LIST)." > /dev/stderr
exit 1
fi

IFS=$'\n'
DNN_LIST_SUB=""
for DNN in ${DNN_LIST}; do
if [ -n "${DNN}" ]; then
DNN_LIST_SUB="${DNN_LIST_SUB}\n ${DNN}"
fi
done
IF_LIST_SUB=""
for INTERFACE in ${IF_LIST}; do
if [ -n "${INTERFACE}" ]; then
IF_LIST_SUB="${IF_LIST_SUB}\n ${INTERFACE}"
fi
done


awk \
-v N4="${N4}" \
-v DNN_LIST="${DNN_LIST_SUB}" \
-v IF_LIST="${IF_LIST_SUB}" \
'{
sub(/%N4/, N4);
sub(/%DNN_LIST/, DNN_LIST);
sub(/%IF_LIST/, IF_LIST);
print;
}' \
"${CONFIG_TEMPLATE}" > "${CONFIG_FILE}"
21 changes: 21 additions & 0 deletions upf/template-upf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 1.0.3
description: UPF initial local configuration

# The listen IP and nodeID of the N4 interface on this UPF (Can't set to 0.0.0.0)
pfcp:
addr: %N4 # IP addr for listening
nodeID: %N4 # External IP or FQDN can be reached
retransTimeout: 1s # retransmission timeout
maxRetrans: 3 # the max number of retransmission

gtpu:
forwarder: gtp5g
# The IP list of the N3/N9 interfaces on this UPF
# If there are multiple connection, set addr to 0.0.0.0 or list all the addresses
ifList: %IF_LIST
dnnList: %DNN_LIST

logger: # log output setting
enable: true # true or false
level: info # how detailed to output, value: trace, debug, info, warn, error, fatal, panic
reportCaller: false # enable the caller report or not, value: true or false

0 comments on commit e81c092

Please sign in to comment.