Skip to content

Commit

Permalink
Refactor startup and docker files
Browse files Browse the repository at this point in the history
  • Loading branch information
abousselmi committed May 17, 2024
1 parent d409dee commit bcd44e9
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 30 deletions.
19 changes: 11 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ RUN git clone https://gitea.osmocom.org/cellular-infrastructure/libgtpnl \

FROM alpine:3.19

WORKDIR /nf-gtp-gw
WORKDIR /gw

COPY --from=buildenv /libgtpnl/src/.libs/libgtpnl.so* /usr/lib/
COPY --from=buildenv /libgtpnl/tools/.libs/* .
COPY --from=buildenv /libgtpnl/tools/.libs/* /usr/bin/
COPY ./startup.sh ./

RUN apk add --no-cache libmnl iproute2 \
RUN apk add --no-cache libmnl iproute2 tcpdump figlet \
&& ldconfig /

ENV TEID_N3_GNB=100 \
ENV UE_IP=10.10.10.1 \
TEID_N3_GNB=100 \
TEID_N3_UPF=200 \
N3_UPF_IP=127.0.0.1 \
N6_APP_SERVER_IP=127.0.0.2 \
N6_APP_SERVER_SUBNET=127.0.0.0/8
N3_GNB_IP=127.0.0.2 \
N3_UPF_IP=127.0.0.3 \
N6_APP_SERVER_IP=127.0.0.4

ENTRYPOINT ["./startup.sh"]
EXPOSE 2152

CMD ["/bin/sh"]
115 changes: 93 additions & 22 deletions startup.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,108 @@
#!/bin/sh

# User defined variables
#TEID_N3_UPF
#TEID_N3_GNB
#N3_UPF_IP
#N6_APP_SERVER_IP
#N6_APP_SERVER_SUBNET

# Pre-defined variables
set -e

_authors="abousselmi and sofianinho"
_license="LGPLv2"
_version="v1.0.0"

IP_VERSION="ip"
MTU=1500
GTP_DEV="ue-tun"

function log {
echo -e "[INFO] $1"
sleep 1
banner() {
figlet -f big "GTP-GW"
echo "version: $_version"
echo "authors: $_authors"
echo "license: $_license"
echo ""
}

function start {
log "create gtp devices (run in bg mode)"
./gtp-link add $GTP_DEV $IP_VERSION &
log() {
echo -e "$(date +%F-%T) [INFO] $1"
}

checks() {
if [ -z "$UE_IP" ]; then echo "UE_IP is not set.." && exit 1 ; fi
if [ -z "$N3_GNB_IP" ]; then echo "N3_GNB_IP is not set.." && exit 1 ; fi
if [ -z "$N3_UPF_IP" ]; then echo "N3_UPF_IP is not set.." && exit 1 ; fi
if [ -z "$TEID_N3_UPF" ]; then echo "TEID_N3_UPF is not set.." && exit 1 ; fi
if [ -z "$TEID_N3_GNB" ]; then echo "TEID_N3_GNB is not set.." && exit 1 ; fi
if [ -z "$N6_APP_SERVER_IP" ]; then echo "N6_APP_SERVER_IP is not set.." && exit 1 ; fi
}

start() {
log "starting gtp-gw.."

log "add UE ip [$UE_IP] to loopback interface"
ip addr add $UE_IP/32 dev lo

log "create [$GTP_DEV] gtp device"
gtp-link add $GTP_DEV $IP_VERSION > /dev/null 2>&1 &

echo $! > pid

sleep 1

log "configure mtu of gtp devices"
log "set [$GTP_DEV] mtu to [$MTU]"
ip link set mtu $MTU dev $GTP_DEV

log "create gtp tunnel: [TEID_N3_GNB=$TEID_N3_GNB, TEID_N3_UPF=$TEID_N3_UPF, \
N3_UPF_IP=$N3_UPF_IP, N6_APP_SERVER_IP=$N6_APP_SERVER_IP]"
./gtp-tunnel add $GTP_DEV v1 $TEID_N3_UPF $TEID_N3_GNB $N6_APP_SERVER_IP $N3_UPF_IP
log "$(./gtp-tunnel list)"
log "create gtp tunnel"
gtp-tunnel add $GTP_DEV v1 $TEID_N3_UPF $TEID_N3_GNB $UE_IP $N3_UPF_IP

sleep 1

log "configure routes using gtp devices"
ip route add $N6_APP_SERVER_SUBNET dev $GTP_DEV
ip route add $N6_APP_SERVER_IP/32 dev $GTP_DEV

log "------------------------------------------------------------------------"
log "UE if: $GTP_DEV"
log "UE ip: $UE_IP"
log "APP server ip: $N6_APP_SERVER_IP"
log "N3 GNB ip: $N3_GNB_IP"
log "N3 UPF ip: $N3_UPF_IP"
log "GNB GTP TEID: $TEID_N3_GNB"
log "UPF GTP TEID: $TEID_N3_UPF"
log "------------------------------------------------------------------------"
log "$(gtp-tunnel list)"
log "------------------------------------------------------------------------"
}

stop() {
log "stopping gtp-gw.."

log "delete gtp-tunnel"
gtp-tunnel del $GTP_DEV v1 $TEID_N3_UPF $IP_VERSION

log "delete the gtp device"
gtp-link del $GTP_DEV

log "kill the gtp device process"
kill -9 $(cat pid)
}

usage() {
echo ""
echo "Usage: $0 <start|stop>"
echo ""
}

start
sleep infinity
case "$1" in
-h | --help | help)
usage
exit
;;
start | add | create)
banner
checks
start
;;
stop | delete | del)
checks
stop
;;
*)
usage
exit
;;
esac

0 comments on commit bcd44e9

Please sign in to comment.