400 lines
14 KiB
Bash
Executable File
400 lines
14 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -uo pipefail
|
|
|
|
# GLOBAL VARS
|
|
imsi_now=""
|
|
ki_now=""
|
|
opc_now=""
|
|
|
|
function imsi_parser(){
|
|
# echo "IMSI -> KI -> OPC"
|
|
while IFS=, read -r count imsi ki opc
|
|
do
|
|
# echo "[$count]" $imsi "->" $ki "->" "$opc"
|
|
if [ "$1" = "$count" ]; then
|
|
imsi_now="$imsi"
|
|
ki_now="$ki"
|
|
opc_now="$opc"
|
|
return
|
|
fi
|
|
done < input/imsi_data.csv
|
|
}
|
|
|
|
function create_from_path() {
|
|
cd $1
|
|
if echo "$1" | grep -iqF deploy; then
|
|
echo "Deployment Mode"
|
|
cu_confs=`ls -d ./*cu*`
|
|
for x in `ls -d $cu_confs`; do oc create -f $x -n infidel-test; done
|
|
echo "[CU Deployment] Delay, let the script breathe..."
|
|
sleep 10
|
|
du_confs=`ls -d ./*du*`
|
|
for x in `ls -d $du_confs`; do oc create -f $x -n infidel-test; done
|
|
echo "[DU Deployment] Delay, let the script breathe..."
|
|
sleep 10
|
|
ue_confs=`ls -d ./*ue*`
|
|
for x in `ls -d $ue_confs`; do oc create -f $x -n infidel-test; done
|
|
echo "[UE Deployment] Delay, let the script breathe..."
|
|
else
|
|
echo "Custom Mode"
|
|
for x in `ls -d .`; do oc create -f $x -n infidel-test; done
|
|
fi
|
|
cd -
|
|
}
|
|
|
|
function clean_deployments(){
|
|
|
|
for x in $(oc get dc -n infidel-test -o jsonpath="{range .items[*]}{.metadata.name}{'\n'}{end}"); do oc delete dc $x -n infidel-test; done
|
|
for x in $(oc get deployments -n infidel-test -o jsonpath="{range .items[*]}{.metadata.name}{'\n'}{end}" | grep "[0-9][2-9]"); do oc delete deployment $x -n infidel-test; done
|
|
for x in $(oc get network-attachment-definition -n infidel-test -o jsonpath="{range .items[*]}{.metadata.name}{'\n'}{end}" | grep "[0-9][2-9]") ; do oc delete network-attachment-definition $x -n infidel-test; done
|
|
|
|
}
|
|
|
|
function deployment_gen(){
|
|
|
|
SOURCE_FILE="deployments/src/template_deployment.yaml"
|
|
echo "--------------------------[*]"
|
|
echo "${role} -> ${ip}"
|
|
export trainee=$role
|
|
|
|
VARS=$(grep -oP '@[a-zA-Z0-9_]+@' ${SOURCE_FILE} | sort | uniq | xargs)
|
|
EXPRESSIONS=""
|
|
for v in ${VARS}; do
|
|
NEW_VAR=`echo $v | sed -e "s#@##g"`
|
|
if [[ "${!NEW_VAR}x" == "x" ]]; then
|
|
echo "Error: Environment variable '${NEW_VAR}' is not set." \
|
|
"Config file '$(basename $c)' requires all of $VARS."
|
|
exit 1
|
|
fi
|
|
echo $v "->" $NEW_VAR
|
|
EXPRESSIONS="${EXPRESSIONS};s|${v}|${!NEW_VAR}|g"
|
|
done
|
|
|
|
TARGET_FILE="deployments/trainee/gnb-${role}.yaml"
|
|
EXPRESSIONS="${EXPRESSIONS#';'}"
|
|
sed "${EXPRESSIONS}" ${SOURCE_FILE} > ${TARGET_FILE}
|
|
echo "${TARGET_FILE}"
|
|
echo ""
|
|
}
|
|
|
|
function net_core_gen(){
|
|
clear
|
|
rm net/core/*
|
|
echo "***************************"
|
|
echo "Core NET Generation"
|
|
echo "***************************"
|
|
while IFS=, read -r role ip
|
|
do
|
|
SOURCE_FILE="net/src/template_net.yaml"
|
|
echo $role "->" $ip
|
|
trainee=$role
|
|
VARS=$(grep -oP '@[a-zA-Z0-9_]+@' ${SOURCE_FILE} | sort | uniq | xargs)
|
|
EXPRESSIONS=""
|
|
for v in ${VARS}; do
|
|
NEW_VAR=`echo $v | sed -e "s#@##g"`
|
|
if [[ "${!NEW_VAR}x" == "x" ]]; then
|
|
echo "Error: Environment variable '${NEW_VAR}' is not set." \
|
|
"Config file '$(basename $c)' requires all of $VARS."
|
|
exit 1
|
|
fi
|
|
echo $v "->" $NEW_VAR
|
|
EXPRESSIONS="${EXPRESSIONS};s|${v}|${!NEW_VAR}|g"
|
|
done
|
|
|
|
TARGET_FILE="net/core/${role}.yaml"
|
|
EXPRESSIONS="${EXPRESSIONS#';'}"
|
|
sed "${EXPRESSIONS}" ${SOURCE_FILE} > ${TARGET_FILE}
|
|
echo "${TARGET_FILE}"
|
|
echo ""
|
|
done < input/core_net_ipv4.csv
|
|
echo "***************************"
|
|
}
|
|
|
|
|
|
function net_gen(){
|
|
while IFS=, read -r role ip_cu_amf ip_cu_du ip_du_cu ip_ue_du
|
|
do
|
|
echo "IMSI DATA *************************"
|
|
imsi_parser $role
|
|
echo "IMSI" $imsi_now
|
|
echo "KI" $ki_now
|
|
echo "OPC" $opc_now
|
|
|
|
echo "--------------------------[*]"
|
|
# GNB CU_AMF NET
|
|
SOURCE_FILE="net/src/template_net.yaml"
|
|
export trainee="cu-amf-$role"
|
|
export ip="$ip_cu_amf/24"
|
|
|
|
VARS=$(grep -oP '@[a-zA-Z0-9_]+@' ${SOURCE_FILE} | sort | uniq | xargs)
|
|
EXPRESSIONS=""
|
|
for v in ${VARS}; do
|
|
NEW_VAR=`echo $v | sed -e "s#@##g"`
|
|
if [[ "${!NEW_VAR}x" == "x" ]]; then
|
|
echo "Error: Environment variable '${NEW_VAR}' is not set." \
|
|
"Config file '$(basename $c)' requires all of $VARS."
|
|
exit 1
|
|
fi
|
|
echo $v "->" $NEW_VAR
|
|
EXPRESSIONS="${EXPRESSIONS};s|${v}|${!NEW_VAR}|g"
|
|
done
|
|
|
|
TARGET_FILE="net/gnb/cu-amf-${role}.yaml"
|
|
EXPRESSIONS="${EXPRESSIONS#';'}"
|
|
sed "${EXPRESSIONS}" ${SOURCE_FILE} > ${TARGET_FILE}
|
|
echo "${TARGET_FILE}"
|
|
echo ""
|
|
|
|
# GNB CU_DU NET
|
|
SOURCE_FILE="net/src/template_net.yaml"
|
|
export trainee="cu-du-$role"
|
|
export ip="$ip_cu_du/24"
|
|
|
|
VARS=$(grep -oP '@[a-zA-Z0-9_]+@' ${SOURCE_FILE} | sort | uniq | xargs)
|
|
EXPRESSIONS=""
|
|
for v in ${VARS}; do
|
|
NEW_VAR=`echo $v | sed -e "s#@##g"`
|
|
if [[ "${!NEW_VAR}x" == "x" ]]; then
|
|
echo "Error: Environment variable '${NEW_VAR}' is not set." \
|
|
"Config file '$(basename $c)' requires all of $VARS."
|
|
exit 1
|
|
fi
|
|
echo $v "->" $NEW_VAR
|
|
EXPRESSIONS="${EXPRESSIONS};s|${v}|${!NEW_VAR}|g"
|
|
done
|
|
|
|
TARGET_FILE="net/gnb/cu-du-${role}.yaml"
|
|
EXPRESSIONS="${EXPRESSIONS#';'}"
|
|
sed "${EXPRESSIONS}" ${SOURCE_FILE} > ${TARGET_FILE}
|
|
echo "${TARGET_FILE}"
|
|
echo ""
|
|
|
|
# GNB DU_CU NET
|
|
SOURCE_FILE="net/src/template_net.yaml"
|
|
export trainee="du-cu-$role"
|
|
export ip="$ip_du_cu/24"
|
|
|
|
VARS=$(grep -oP '@[a-zA-Z0-9_]+@' ${SOURCE_FILE} | sort | uniq | xargs)
|
|
EXPRESSIONS=""
|
|
for v in ${VARS}; do
|
|
NEW_VAR=`echo $v | sed -e "s#@##g"`
|
|
if [[ "${!NEW_VAR}x" == "x" ]]; then
|
|
echo "Error: Environment variable '${NEW_VAR}' is not set." \
|
|
"Config file '$(basename $c)' requires all of $VARS."
|
|
exit 1
|
|
fi
|
|
echo $v "->" $NEW_VAR
|
|
EXPRESSIONS="${EXPRESSIONS};s|${v}|${!NEW_VAR}|g"
|
|
done
|
|
|
|
TARGET_FILE="net/gnb/du-cu-${role}.yaml"
|
|
EXPRESSIONS="${EXPRESSIONS#';'}"
|
|
sed "${EXPRESSIONS}" ${SOURCE_FILE} > ${TARGET_FILE}
|
|
echo "${TARGET_FILE}"
|
|
echo ""
|
|
|
|
# GNB UE_DU NET
|
|
SOURCE_FILE="net/src/template_net.yaml"
|
|
export trainee="ue-du-$role"
|
|
export ip="$ip_ue_du/24"
|
|
|
|
VARS=$(grep -oP '@[a-zA-Z0-9_]+@' ${SOURCE_FILE} | sort | uniq | xargs)
|
|
EXPRESSIONS=""
|
|
for v in ${VARS}; do
|
|
NEW_VAR=`echo $v | sed -e "s#@##g"`
|
|
if [[ "${!NEW_VAR}x" == "x" ]]; then
|
|
echo "Error: Environment variable '${NEW_VAR}' is not set." \
|
|
"Config file '$(basename $c)' requires all of $VARS."
|
|
exit 1
|
|
fi
|
|
echo $v "->" $NEW_VAR
|
|
EXPRESSIONS="${EXPRESSIONS};s|${v}|${!NEW_VAR}|g"
|
|
done
|
|
|
|
TARGET_FILE="net/gnb/ue-du-${role}.yaml"
|
|
EXPRESSIONS="${EXPRESSIONS#';'}"
|
|
sed "${EXPRESSIONS}" ${SOURCE_FILE} > ${TARGET_FILE}
|
|
echo "${TARGET_FILE}"
|
|
echo ""
|
|
|
|
# GNB CU Deplpoyment
|
|
SOURCE_FILE="deployments/src/template_deployment.yaml"
|
|
echo "--------------------------[*]"
|
|
export trainee="cu-$role"
|
|
export net="oai-cu-amf-$role-net,oai-cu-du-$role-net"
|
|
export ip=$ip_du_cu
|
|
export mode="cu"
|
|
export mode_cap="CU"
|
|
export part_of="oai-amf"
|
|
export part_type="Deployment"
|
|
|
|
VARS=$(grep -oP '@[a-zA-Z0-9_]+@' ${SOURCE_FILE} | sort | uniq | xargs)
|
|
EXPRESSIONS=""
|
|
for v in ${VARS}; do
|
|
NEW_VAR=`echo $v | sed -e "s#@##g"`
|
|
echo $v "->" $NEW_VAR
|
|
if [[ "${!NEW_VAR}x" == "x" ]]; then
|
|
echo "Error: Environment variable '${NEW_VAR}' is not set." \
|
|
"Config file '$(basename $c)' requires all of $VARS."
|
|
exit 1
|
|
fi
|
|
EXPRESSIONS="${EXPRESSIONS};s|${v}|${!NEW_VAR}|g"
|
|
done
|
|
|
|
TARGET_FILE="deployments/trainee/gnb-cu-${role}.yaml"
|
|
EXPRESSIONS="${EXPRESSIONS#';'}"
|
|
sed "${EXPRESSIONS}" ${SOURCE_FILE} > ${TARGET_FILE}
|
|
echo "${TARGET_FILE}"
|
|
echo ""
|
|
|
|
# GNB DU Deplpoyment
|
|
SOURCE_FILE="deployments/src/template_deployment.yaml"
|
|
echo "--------------------------[*]"
|
|
export trainee="du-$role"
|
|
export net="oai-du-cu-$role-net"
|
|
export ip=$ip_du_cu
|
|
export mode="du"
|
|
export mode_cap="TDD_DU"
|
|
export part_of="oai-cu-$role"
|
|
export part_type="DeploymentConfig"
|
|
|
|
VARS=$(grep -oP '@[a-zA-Z0-9_]+@' ${SOURCE_FILE} | sort | uniq | xargs)
|
|
EXPRESSIONS=""
|
|
for v in ${VARS}; do
|
|
NEW_VAR=`echo $v | sed -e "s#@##g"`
|
|
if [[ "${!NEW_VAR}x" == "x" ]]; then
|
|
echo "Error: Environment variable '${NEW_VAR}' is not set." \
|
|
"Config file '$(basename $c)' requires all of $VARS."
|
|
exit 1
|
|
fi
|
|
echo $v "->" $NEW_VAR
|
|
EXPRESSIONS="${EXPRESSIONS};s|${v}|${!NEW_VAR}|g"
|
|
done
|
|
|
|
TARGET_FILE="deployments/trainee/gnb-du-${role}.yaml"
|
|
EXPRESSIONS="${EXPRESSIONS#';'}"
|
|
sed "${EXPRESSIONS}" ${SOURCE_FILE} > ${TARGET_FILE}
|
|
echo "${TARGET_FILE}"
|
|
echo ""
|
|
|
|
# GNB UE_DU Deplpoyment
|
|
SOURCE_FILE="deployments/src/template_ue_deployment.yaml"
|
|
echo "--------------------------[*]"
|
|
export trainee="ue-$role"
|
|
export net="oai-ue-du-$role-net"
|
|
export ip=$ip_ue_du
|
|
export mode="ue"
|
|
export mode_cap="TDD_DU"
|
|
export part_of="oai-du-$role"
|
|
export part_type="DeploymentConfig"
|
|
|
|
VARS=$(grep -oP '@[a-zA-Z0-9_]+@' ${SOURCE_FILE} | sort | uniq | xargs)
|
|
EXPRESSIONS=""
|
|
for v in ${VARS}; do
|
|
NEW_VAR=`echo $v | sed -e "s#@##g"`
|
|
if [[ "${!NEW_VAR}x" == "x" ]]; then
|
|
echo "Error: Environment variable '${NEW_VAR}' is not set." \
|
|
"Config file '$(basename $c)' requires all of $VARS."
|
|
exit 1
|
|
fi
|
|
echo $v "->" $NEW_VAR
|
|
EXPRESSIONS="${EXPRESSIONS};s|${v}|${!NEW_VAR}|g"
|
|
done
|
|
|
|
TARGET_FILE="deployments/trainee/gnb-ue-${role}.yaml"
|
|
EXPRESSIONS="${EXPRESSIONS#';'}"
|
|
sed "${EXPRESSIONS}" ${SOURCE_FILE} > ${TARGET_FILE}
|
|
echo "${TARGET_FILE}"
|
|
echo ""
|
|
|
|
# GNB DEMO_CU Deplpoyment
|
|
# SOURCE_FILE="deployments/src/gnb_access_deployment.yaml"
|
|
# echo "--------------------------[*]"
|
|
# export trainee="ue-demo-$role"
|
|
# export net="oai-ue-du-$role-net"
|
|
# export ip=$ip_ue_du
|
|
# export mode="ue"
|
|
# export mode_cap="TDD_DU"
|
|
# export part_of="oai-du-$role"
|
|
# export part_type="DeploymentConfig"
|
|
|
|
# VARS=$(grep -oP '@[a-zA-Z0-9_]+@' ${SOURCE_FILE} | sort | uniq | xargs)
|
|
# EXPRESSIONS=""
|
|
# for v in ${VARS}; do
|
|
# NEW_VAR=`echo $v | sed -e "s#@##g"`
|
|
# if [[ "${!NEW_VAR}x" == "x" ]]; then
|
|
# echo "Error: Environment variable '${NEW_VAR}' is not set." \
|
|
# "Config file '$(basename $c)' requires all of $VARS."
|
|
# exit 1
|
|
# fi
|
|
# echo $v "->" $NEW_VAR
|
|
# EXPRESSIONS="${EXPRESSIONS};s|${v}|${!NEW_VAR}|g"
|
|
# done
|
|
#
|
|
# TARGET_FILE="deployments/trainee/gnb-demo-ue-${role}.yaml"
|
|
# EXPRESSIONS="${EXPRESSIONS#';'}"
|
|
# sed "${EXPRESSIONS}" ${SOURCE_FILE} > ${TARGET_FILE}
|
|
# echo "${TARGET_FILE}"
|
|
# echo ""
|
|
done < input/main_data.csv
|
|
}
|
|
|
|
PS3="[!] Select operation : "
|
|
select mode in trainee_gnb_and_net clean_deployments create_from_path "Core Net Generation" "Imsi Parser" "Dirty Reload" "Deploy Access Demo";
|
|
do
|
|
case $mode in
|
|
trainee_gnb_and_net)
|
|
rm deployments/trainee/*.yaml
|
|
rm net/gnb/*.yaml
|
|
net_gen
|
|
;;
|
|
create_from_path)
|
|
echo "Where is the Path: "
|
|
echo "[!]-<$(pwd)>"
|
|
read -e -p '[!]-: ' path
|
|
create_from_path $path
|
|
;;
|
|
clean_deployments)
|
|
PS3="[*] Clean Mode : "
|
|
select clear_mode in deployments nets exit;
|
|
do
|
|
case $clear_mode in
|
|
deployments)
|
|
clean_deployments 1
|
|
;;
|
|
nets)
|
|
clean_deployments 2
|
|
;;
|
|
exit)
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
;;
|
|
"Core Net Generation")
|
|
net_core_gen
|
|
;;
|
|
"Imsi Parser")
|
|
imsi_parser
|
|
;;
|
|
"Dirty Reload")
|
|
echo "Dirty Reload..."
|
|
rm deployments/trainee/*.yaml
|
|
rm net/gnb/*.yaml
|
|
net_gen
|
|
clean_deployments 1
|
|
create_from_path net/gnb
|
|
create_from_path deployments/trainee
|
|
;;
|
|
"Deploy Access Demo")
|
|
echo "Editable Deployment"
|
|
;;
|
|
*)
|
|
echo "Invalid option $REPLAY"
|
|
;;
|
|
esac
|
|
done
|
|
|
|
|