From e81c09290d6f65a02eafa365196862366d173a94 Mon Sep 17 00:00:00 2001 From: Louis Royer Date: Mon, 8 Jul 2024 12:30:05 +0200 Subject: [PATCH] Add dev-free5gc-upf Close #22 --- README.md | 32 ++++++++++++++++++++++++++++ upf/Dockerfile | 43 +++++++++++++++++++++++++++++++++++++ upf/entrypoint.sh | 35 ++++++++++++++++++++++++++++++ upf/template-script.sh | 48 ++++++++++++++++++++++++++++++++++++++++++ upf/template-upf.yaml | 21 ++++++++++++++++++ 5 files changed, 179 insertions(+) create mode 100644 upf/Dockerfile create mode 100755 upf/entrypoint.sh create mode 100755 upf/template-script.sh create mode 100644 upf/template-upf.yaml diff --git a/README.md b/README.md index c11aa9d..a867a76 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/upf/Dockerfile b/upf/Dockerfile new file mode 100644 index 0000000..bfc0939 --- /dev/null +++ b/upf/Dockerfile @@ -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 " \ + org.opencontainers.image.authors="Louis Royer " \ + 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"] diff --git a/upf/entrypoint.sh b/upf/entrypoint.sh new file mode 100755 index 0000000..4f2a96a --- /dev/null +++ b/upf/entrypoint.sh @@ -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 diff --git a/upf/template-script.sh b/upf/template-script.sh new file mode 100755 index 0000000..d51c331 --- /dev/null +++ b/upf/template-script.sh @@ -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}" diff --git a/upf/template-upf.yaml b/upf/template-upf.yaml new file mode 100644 index 0000000..9dd2893 --- /dev/null +++ b/upf/template-upf.yaml @@ -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