#!/usr/bin/env bash PID_LIST=() UPFNS="UPFns" EXEC_UPFNS="sudo ip netns exec ${UPFNS}" # Setup network namespace sudo ip netns del ${UPFNS} sudo ip link delete veth0 sleep 1 sudo ip netns add ${UPFNS} sudo -E ${EXEC_UPFNS} ip route add default via 172.16.5.4 sudo ip link add veth0 type veth peer name veth1 sudo ifconfig veth0 up sudo ip addr add 172.16.5.4/32 dev veth0 sudo ip route add 172.16.5.3/32 dev veth0 sudo ip link set veth1 netns ${UPFNS} sudo -E ${EXEC_UPFNS} ip link set veth1 up sudo -E ${EXEC_UPFNS} ip addr add 172.16.5.3/32 dev veth1 sudo -E ${EXEC_UPFNS} ip route add 172.16.5.4/32 dev veth1 sudo -E ${EXEC_UPFNS} ip route add default via 172.16.5.4 sudo -E ${EXEC_UPFNS} iptables -t nat -A POSTROUTING -s 60.60.0.0/24 -o veth1 -j MASQUERADE sudo iptables -t nat -A POSTROUTING -s 172.16.5.3/32 -o eno1 -j MASQUERADE #every outgoing packet from the namespace should be NATed sudo -E ${EXEC_UPFNS} ifconfig sudo -E ${EXEC_UPFNS} NFs/upf/build/bin/free5gc-upfd -f config/upfcfg_ralf.yaml & # PID_LIST+=($!) sleep 1 sudo -E NFs/upf/build/bin/free5gc-upfd -f config/upfcfg_ims_ralf.yaml & # aktuell wird immer nur die zweite korrekt gestartet. scheinbar tötet die die erste wieder ... PID_LIST+=($!) sleep 1 #cd ../../.. NF_LIST="nrf amf smf udr pcf udm nssf ausf" export GIN_MODE=release for NF in ${NF_LIST}; do ./bin/${NF} & PID_LIST+=($!) sleep 0.1 done bin/smf --smfcfg config/smfcfg_ims.yaml & PID_LIST+=($!) #sudo ./bin/n3iwf & #SUDO_N3IWF_PID=$! sleep 1 #N3IWF_PID=$(pgrep -P $SUDO_N3IWF_PID) #PID_LIST+=($SUDO_N3IWF_PID $N3IWF_PID) function terminate() { # kill amf first while $(sudo kill -SIGINT ${PID_LIST[3]} 3>/dev/null); do sleep 2 done for ((idx=${#PID_LIST[@]}-1;idx>=0;idx--)); do sudo kill -SIGKILL ${PID_LIST[$idx]} done sudo ip netns del ${UPFNS} } trap terminate SIGINT wait ${PID_LIST}