Commit f4dc11fa authored by Raphael Defosseux's avatar Raphael Defosseux

Merge branch 'jinja2-config' into 'develop'

feat(config): changing the configuration file to jinja2-based approach

See merge request oai/cn5g/oai-cn5g-smf!167
parents a41666ec bb6e33a0
# prompt has been removed for easier Ctrl+C Ctrl+V
# please update the following information according to your configuration
INSTANCE=1
PREFIX='/usr/local/etc/oai'
mkdir -m 0777 -p $PREFIX
cp ../../etc/smf.conf $PREFIX
declare -A SMF_CONF
SMF_CONF[@INSTANCE@]=$INSTANCE
# SMF_CONF[@PREFIX@]=$PREFIX
SMF_CONF[@PID_DIRECTORY@]='/var/run'
SMF_CONF[@SMF_INTERFACE_NAME_FOR_N4@]='wlo1'
SMF_CONF[@SMF_INTERFACE_NAME_FOR_SBI@]='wlo1'
SMF_CONF[@SMF_INTERFACE_PORT_FOR_SBI@]='80'
SMF_CONF[@SMF_INTERFACE_HTTP2_PORT_FOR_SBI@]='9090'
SMF_CONF[@SMF_API_VERSION@]='v1'
SMF_CONF[@DNN_NI0@]='oai.ipv4'
SMF_CONF[@TYPE0@]='IPv4'
SMF_CONF[@DNN_RANGE0@]='12.1.1.2 - 12.1.1.128'
SMF_CONF[@DNN_NI1@]='default'
SMF_CONF[@TYPE1@]='IPv4'
SMF_CONF[@DNN_RANGE1@]='12.2.1.2 - 12.2.1.128'
SMF_CONF[@DNN_NI2@]='oai'
SMF_CONF[@TYPE2@]='IPv4'
SMF_CONF[@DNN_RANGE2@]='12.1.1.129 - 12.1.1.224'
SMF_CONF[@DNN_NI3@]='ims'
SMF_CONF[@TYPE3@]='IPv4'
SMF_CONF[@DNN_RANGE3@]='12.2.1.129 - 12.2.1.224'
SMF_CONF[@USE_NETWORK_INSTANCE@]='no'
SMF_CONF[@USE_LOCAL_SUBSCRIPTION_INFO@]='yes'
SMF_CONF[@DOMAIN_ACCESS@]='access.oai.org'
SMF_CONF[@DOMAIN_CORE@]='core.oai.org'
SMF_CONF[@USE_FQDN_DNS@]='no'
SMF_CONF[@ENABLE_USAGE_REPORTING@]='no'
SMF_CONF[@REGISTER_NRF@]='no'
SMF_CONF[@DISCOVER_UPF@]='no'
SMF_CONF[@HTTP_VERSION@]='1'
SMF_CONF[@UE_MTU@]='1358'
SMF_CONF[@NSSAI_SST0@]='222'
SMF_CONF[@NSSAI_SD0@]='123'
SMF_CONF[@NSSAI_SST1@]='1'
SMF_CONF[@NSSAI_SD1@]='0xFFFFFF'
SMF_CONF[@NSSAI_SST2@]='2'
SMF_CONF[@NSSAI_SD2@]='2'
SMF_CONF[@QOS_PROFILE_5QI0@]='6'
SMF_CONF[@QOS_PROFILE_5QI1@]='7'
SMF_CONF[@QOS_PROFILE_5QI2@]='8'
SMF_CONF[@SESSION_AMBR_UL0@]='20Mbps'
SMF_CONF[@SESSION_AMBR_UL1@]='220Mbps'
SMF_CONF[@SESSION_AMBR_UL2@]='20Mbps'
SMF_CONF[@SESSION_AMBR_DL0@]='20Mbps'
SMF_CONF[@SESSION_AMBR_DL1@]='220Mbps'
SMF_CONF[@SESSION_AMBR_DL2@]='20Mbps'
SMF_CONF[@UDM_IPV4_ADDRESS@]='172.16.1.103'
SMF_CONF[@UDM_PORT@]='80'
SMF_CONF[@UDM_API_VERSION@]='v2'
SMF_CONF[@UDM_FQDN@]='oai-udm'
SMF_CONF[@AMF_IPV4_ADDRESS@]='192.168.74.195'
SMF_CONF[@AMF_PORT@]='80'
SMF_CONF[@AMF_API_VERSION@]='v1'
SMF_CONF[@AMF_FQDN@]='oai-amf'
SMF_CONF[@UPF_IPV4_ADDRESS@]='192.168.12.245'
SMF_CONF[@UPF_FQDN_0@]='oai-upf0'
SMF_CONF[@NRF_IPV4_ADDRESS@]='127.0.0.1'
SMF_CONF[@NRF_PORT@]='8080'
SMF_CONF[@NRF_API_VERSION@]='v1'
SMF_CONF[@NRF_FQDN@]='oai-nrf'
SMF_CONF[@DEFAULT_DNS_IPV4_ADDRESS@]='8.8.8.8'
SMF_CONF[@DEFAULT_DNS_SEC_IPV4_ADDRESS@]='4.4.4.4'
for K in "${!SMF_CONF[@]}"; do
egrep -lRZ "$K" $PREFIX | xargs -0 -l sed -i -e "s|$K|${SMF_CONF[$K]}|g"
ret=$?;[[ ret -ne 0 ]] && echo "Tried to replace $K with ${SMF_CONF[$K]}"
done
...@@ -11,31 +11,28 @@ PREFIX='/usr/local/etc/oai' ...@@ -11,31 +11,28 @@ PREFIX='/usr/local/etc/oai'
sudo mkdir -m 0777 -p $PREFIX sudo mkdir -m 0777 -p $PREFIX
cp ../../etc/smf.conf $PREFIX cp ../../etc/smf.conf $PREFIX
declare -A SMF_CONF export CONFIG_FILE=$PREFIX/smf.conf
export MOUNT_CONFIG=NO
SMF_CONF[@INSTANCE@]=$INSTANCE
SMF_CONF[@PREFIX@]=$PREFIX export INSTANCE=1
SMF_CONF[@PID_DIRECTORY@]='/var/run' export SMF_INTERFACE_NAME_FOR_N4='eno1:sn4'
export SMF_INTERFACE_NAME_FOR_SBI='eno1:smf'
SMF_CONF[@SMF_INTERFACE_NAME_FOR_N4@]='eno1:sn4' export UDM_IPV4_ADDRESS='172.16.1.103'
SMF_CONF[@SMF_INTERFACE_NAME_FOR_SBI@]='eno1:smf' export UDM_PORT='80'
export AMF_IPV4_ADDRESS='172.16.1.102'
SMF_CONF[@SMF_INTERFACE_IPV4_ADDRESS_FOR_SBI@]='172.16.1.101' export AMF_PORT='80'
SMF_CONF[@SMF_INTERFACE_PORT_FOR_SBI@]='80' export UPF_IPV4_ADDRESS='172.16.2.102'
SMF_CONF[@SMF_INTERFACE_HTTP2_PORT_FOR_SBI@]='9090'
export DEFAULT_DNS_IPV4_ADDRESS='8.8.8.8'
SMF_CONF[@UDM_IPV4_ADDRESS@]='172.16.1.103' export DEFAULT_DNS_SEC_IPV4_ADDRESS='4.4.4.4'
SMF_CONF[@UDM_PORT@]='80'
# One mandatory slice
SMF_CONF[@AMF_IPV4_ADDRESS@]='172.16.1.102' export DNN_NI0=oai
SMF_CONF[@AMF_PORT@]='80' export TYPE0=IPv4
export DNN_RANGE0='12.1.1.151 - 12.1.1.253'
SMF_CONF[@UPF_IPV4_ADDRESS@]='172.16.2.102' export NSSAI_SST0=1
#export NSSAI_SD0=123
SMF_CONF[@DEFAULT_DNS_IPV4_ADDRESS@]='8.8.8.8' export SESSION_AMBR_UL0=800Mbps
SMF_CONF[@DEFAULT_DNS_SEC_IPV4_ADDRESS@]='4.4.4.4' export SESSION_AMBR_DL0=1000Mbps
for K in "${!SMF_CONF[@]}"; do ../../scripts/entrypoint.py
egrep -lRZ "$K" $PREFIX | xargs -0 -l sed -i -e "s|$K|${SMF_CONF[$K]}|g"
ret=$?;[[ ret -ne 0 ]] && echo "Tried to replace $K with ${SMF_CONF[$K]}"
done
...@@ -55,6 +55,8 @@ ENV TZ=Europe/Paris ...@@ -55,6 +55,8 @@ ENV TZ=Europe/Paris
RUN apt-get update && \ RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get upgrade --yes && \ DEBIAN_FRONTEND=noninteractive apt-get upgrade --yes && \
DEBIAN_FRONTEND=noninteractive apt-get install --yes \ DEBIAN_FRONTEND=noninteractive apt-get install --yes \
python3 \
python3-jinja2 \
psmisc \ psmisc \
net-tools \ net-tools \
bc \ bc \
...@@ -89,7 +91,7 @@ RUN apt-get update && \ ...@@ -89,7 +91,7 @@ RUN apt-get update && \
WORKDIR /openair-smf/bin WORKDIR /openair-smf/bin
COPY --from=oai-smf-builder \ COPY --from=oai-smf-builder \
/openair-smf/build/smf/build/oai_smf \ /openair-smf/build/smf/build/oai_smf \
/openair-smf/scripts/entrypoint.sh \ /openair-smf/scripts/entrypoint.py \
/openair-smf/scripts/healthcheck.sh \ /openair-smf/scripts/healthcheck.sh \
./ ./
...@@ -124,5 +126,5 @@ HEALTHCHECK --interval=10s \ ...@@ -124,5 +126,5 @@ HEALTHCHECK --interval=10s \
--retries=6 \ --retries=6 \
CMD /openair-smf/bin/healthcheck.sh CMD /openair-smf/bin/healthcheck.sh
ENTRYPOINT ["/bin/bash","/openair-smf/bin/entrypoint.sh"] ENTRYPOINT ["python3","/openair-smf/bin/entrypoint.py"]
CMD ["/openair-smf/bin/oai_smf", "-c", "/openair-smf/etc/smf.conf", "-o"] CMD ["/openair-smf/bin/oai_smf", "-c", "/openair-smf/etc/smf.conf", "-o"]
...@@ -80,7 +80,7 @@ def perform_flattening(tag): ...@@ -80,7 +80,7 @@ def perform_flattening(tag):
cmd += ' --change "EXPOSE 8805/udp" ' cmd += ' --change "EXPOSE 8805/udp" '
cmd += ' --change "HEALTHCHECK --interval=10s --timeout=15s --retries=6 CMD /openair-smf/bin/healthcheck.sh" ' cmd += ' --change "HEALTHCHECK --interval=10s --timeout=15s --retries=6 CMD /openair-smf/bin/healthcheck.sh" '
cmd += ' --change "CMD [\\"/openair-smf/bin/oai_smf\\", \\"-c\\", \\"/openair-smf/etc/smf.conf\\", \\"-o\\"]" ' cmd += ' --change "CMD [\\"/openair-smf/bin/oai_smf\\", \\"-c\\", \\"/openair-smf/etc/smf.conf\\", \\"-o\\"]" '
cmd += ' --change "ENTRYPOINT [\\"/bin/bash\\", \\"/openair-smf/bin/entrypoint.sh\\"]" ' cmd += ' --change "ENTRYPOINT [\\"python3\\", \\"/openair-smf/bin/entrypoint.py\\"]" '
cmd += ' - ' + image_prefix + tag cmd += ' - ' + image_prefix + tag
print (cmd) print (cmd)
subprocess.check_output(cmd, shell=True, universal_newlines=True) subprocess.check_output(cmd, shell=True, universal_newlines=True)
......
...@@ -96,6 +96,8 @@ COPY ./rhsm-ca /etc/rhsm/ca ...@@ -96,6 +96,8 @@ COPY ./rhsm-ca /etc/rhsm/ca
RUN rm -f /etc/rhsm-host && \ RUN rm -f /etc/rhsm-host && \
microdnf update -y && \ microdnf update -y && \
microdnf install -y \ microdnf install -y \
python3 \
python3-pip \
tzdata \ tzdata \
# libasan \ # libasan \
procps-ng \ procps-ng \
...@@ -106,6 +108,7 @@ RUN rm -f /etc/rhsm-host && \ ...@@ -106,6 +108,7 @@ RUN rm -f /etc/rhsm-host && \
libevent \ libevent \
findutils \ findutils \
libconfig && \ libconfig && \
pip3 install jinja2 && \
microdnf clean all -y && \ microdnf clean all -y && \
rm -rf /var/cache/yum /var/cache/dnf && \ rm -rf /var/cache/yum /var/cache/dnf && \
# Remove entitlements and Subscription Manager configs # Remove entitlements and Subscription Manager configs
...@@ -116,7 +119,7 @@ RUN rm -f /etc/rhsm-host && \ ...@@ -116,7 +119,7 @@ RUN rm -f /etc/rhsm-host && \
WORKDIR /openair-smf/bin WORKDIR /openair-smf/bin
COPY --from=oai-smf-builder \ COPY --from=oai-smf-builder \
/openair-smf/build/smf/build/oai_smf \ /openair-smf/build/smf/build/oai_smf \
/openair-smf/scripts/entrypoint.sh \ /openair-smf/scripts/entrypoint.py \
/openair-smf/scripts/healthcheck.sh \ /openair-smf/scripts/healthcheck.sh \
./ ./
...@@ -145,5 +148,5 @@ HEALTHCHECK --interval=10s \ ...@@ -145,5 +148,5 @@ HEALTHCHECK --interval=10s \
--retries=6 \ --retries=6 \
CMD /openair-smf/bin/healthcheck.sh CMD /openair-smf/bin/healthcheck.sh
ENTRYPOINT ["/openair-smf/bin/entrypoint.sh"] ENTRYPOINT ["python3", "/openair-smf/bin/entrypoint.py"]
CMD ["/openair-smf/bin/oai_smf", "-c", "/openair-smf/etc/smf.conf", "-o"] CMD ["/openair-smf/bin/oai_smf", "-c", "/openair-smf/etc/smf.conf", "-o"]
...@@ -77,6 +77,8 @@ ENV TZ=Europe/Paris ...@@ -77,6 +77,8 @@ ENV TZ=Europe/Paris
RUN apt-get update && \ RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get upgrade --yes && \ DEBIAN_FRONTEND=noninteractive apt-get upgrade --yes && \
DEBIAN_FRONTEND=noninteractive apt-get install --yes \ DEBIAN_FRONTEND=noninteractive apt-get install --yes \
python3 \
python3-jinja2 \
psmisc \ psmisc \
net-tools \ net-tools \
bc \ bc \
...@@ -111,7 +113,7 @@ RUN apt-get update && \ ...@@ -111,7 +113,7 @@ RUN apt-get update && \
WORKDIR /openair-smf/bin WORKDIR /openair-smf/bin
COPY --from=oai-smf-builder \ COPY --from=oai-smf-builder \
/openair-smf/build/smf/build/oai_smf \ /openair-smf/build/smf/build/oai_smf \
/openair-smf/scripts/entrypoint.sh \ /openair-smf/scripts/entrypoint.py \
/openair-smf/scripts/healthcheck.sh \ /openair-smf/scripts/healthcheck.sh \
./ ./
...@@ -146,5 +148,5 @@ HEALTHCHECK --interval=10s \ ...@@ -146,5 +148,5 @@ HEALTHCHECK --interval=10s \
--retries=6 \ --retries=6 \
CMD /openair-smf/bin/healthcheck.sh CMD /openair-smf/bin/healthcheck.sh
ENTRYPOINT ["/bin/bash","/openair-smf/bin/entrypoint.sh"] ENTRYPOINT ["python3","/openair-smf/bin/entrypoint.py"]
CMD ["/openair-smf/bin/oai_smf", "-c", "/openair-smf/etc/smf.conf", "-o"] CMD ["/openair-smf/bin/oai_smf", "-c", "/openair-smf/etc/smf.conf", "-o"]
jinj2-generated configuration file #
We are switching to `python3-jinja2` tool in order to generate more complex configuration for our 5G core network functions.
Pre-requisites: install python3 and jinja2 packages:
```bash
sudo apt-get install -y python3 python3-jinja2
# or
sudo yum install -y python3 python3-pip
pip3 install jinja2
```
In a container deployment, you will still have to provide environment variables through a `docker-compose-file` or helm charts.
But you can also emulate how the entrypoint behaves locally on your workspace.
## Simple one-slice deployment ##
Create a `test-jinja.sh` file and edit it:
```bash
$ vi test-jinja.sh
cp ./etc/smf.conf ./etc/smf_copy.conf
export CONFIG_FILE=./etc/smf_copy.conf
export MOUNT_CONFIG=NO
export TZ=Europe/Paris
export SMF_INTERFACE_NAME_FOR_N4=eth0
export SMF_INTERFACE_NAME_FOR_SBI=eth0
export DEFAULT_DNS_IPV4_ADDRESS=172.21.3.100
export DEFAULT_DNS_SEC_IPV4_ADDRESS=8.8.8.8
export REGISTER_NRF=yes
export DISCOVER_UPF=yes
export USE_LOCAL_SUBSCRIPTION_INFO=yes
export USE_FQDN_DNS=yes
export AMF_IPV4_ADDRESS=192.168.70.132
export AMF_FQDN=oai-amf
export UDM_IPV4_ADDRESS=192.168.70.137
export UDM_API_VERSION=v2
export UDM_FQDN=oai-udm
export NRF_IPV4_ADDRESS=192.168.70.130
export NRF_FQDN=oai-nrf
export UPF_IPV4_ADDRESS=192.168.70.134
export UPF_FQDN_0=oai-spgwu
export DNN_NI0=oai
export TYPE0=IPv4
export DNN_RANGE0='12.1.1.151 - 12.1.1.253'
export NSSAI_SST0=1
#export NSSAI_SD0=123
export SESSION_AMBR_UL0=200Mbps
export SESSION_AMBR_DL0=400Mbps
./scripts/entrypoint.py
$ chmod 755 test-jinja.sh
$ ./test-jinja2.sh
Configuration file ./etc/smf_copy.conf is ready
```
## List of fields ##
### Features ###
Here is the current list of fields, with their mandatory status and any default values.
If there is no default value associated to a field, it means it is **MANDATORY** to provide one.
| Field Name | Mandatory / Optional | Default value if any |
|:-----------|----------------------|---------------------:|
| INSTANCE | Optional | 0 |
| PID_DIRECTORY | Optional | /var/run |
| UE_MTU | Optional | 1500 |
| REGISTER_NRF | Optional | no |
| DISCOVER_UPF | Optional | no |
| DISCOVER_PCF | Optional | no |
| USE_LOCAL_SUBSCRIPTION_INFO | Optional | no |
| USE_LOCAL_PCC_RULES | Optional | yes |
| USE_FQDN_DNS | Optional | no |
| HTTP_VERSION | Optional | 1 |
| USE_NETWORK_INSTANCE | Optional | 1 |
| ENABLE_USAGE_REPORTING | Optional | no |
### Networking ###
| Field Name | Mandatory / Optional | Default value if any |
|:-----------|----------------------|---------------------:|
| SMF_INTERFACE_NAME_FOR_N4 | Mandatory | |
| SMF_INTERFACE_NAME_FOR_SBI | Mandatory | |
| SMF_INTERFACE_PORT_FOR_SBI | Optional | 80 |
| SMF_INTERFACE_HTTP2_PORT_FOR_SBI | Optional | 8080 |
| SMF_API_VERSION | Optional | v1 |
| DEFAULT_DNS_IPV4_ADDRESS | Mandatory | |
| DEFAULT_DNS_SEC_IPV4_ADDRESS | Mandatory | |
| DEFAULT_CSCF_IPV4_ADDRESS | Optional | 127.0.0.1 |
| AMF_HOSTNAME | Optional | |
| AMF_IPV4_ADDRESS | Mandatory if AMF_HOSTNAME not defined | 0.0.0.0 |
| AMF_PORT | Optional | 80 |
| AMF_API_VERSION | Optional | v1 |
| AMF_FQDN | Optional | localhost |
| UDM_HOSTNAME | Optional | |
| UDM_IPV4_ADDRESS | Mandatory if UDM_HOSTNAME not defined | 0.0.0.0 |
| UDM_PORT | Optional | 80 |
| UDM_API_VERSION | Optional | v1 |
| UDM_FQDN | Optional | localhost |
| NRF_HOSTNAME | Optional | |
| NRF_IPV4_ADDRESS | Mandatory if NRF_HOSTNAME not defined | 0.0.0.0 |
| NRF_PORT | Optional | 80 |
| NRF_API_VERSION | Optional | v1 |
| NRF_FQDN | Optional | localhost |
| PCF_HOSTNAME | Optional | |
| PCF_IPV4_ADDRESS | Mandatory if PCF_HOSTNAME not defined | 0.0.0.0 |
| PCF_PORT | Optional | 80 |
| PCF_API_VERSION | Optional | v1 |
| PCF_FQDN | Optional | localhost |
Currently we are supporting only one UPF.
| Field Name | Mandatory / Optional | Default value if any |
|:-----------|----------------------|---------------------:|
| UPF0_HOSTNAME | Optional | |
| UPF_IPV4_ADDRESS | Mandatory if UPF0_HOSTNAME not defined | 0.0.0.0 |
| UPF_FQDN_0 | Optional | localhost |
| DOMAIN_ACCESS_0 | Optional | access.oai.org |
| DOMAIN_CORE_0 | Optional | core.oai.org |
### Slice Management ###
At least 1 slice (`SLICE0`) **SHALL** be configured. See example in first section above.
We currently support up to 4 slices. When configuring, please do in order (`SLICE0`, `SLICE1`, ...).
The mandatory keywords per slice are `DNN_NIx` and `NSSAI_SSTx`. Once they are both defined for a slice, all parameters **SHALL** be defined.
| Field Name | Mandatory / Optional | Default value if any |
|:-----------|----------------------|---------------------:|
| DNN_NIx | Mandatory | |
| TYPEx | Optional | IPv4 |
| DNN_RANGEx | Mandatory | |
| NSSAI_SSTx | Mandatory | |
| NSSAI_SDx | Optional | 0xFFFFFF |
| QOS_PROFILE_5QIx | Optional | 6 or 7 or 8 or 9 |
| SESSION_AMBR_ULx | Optional | 20Mbps |
| SESSION_AMBR_DLx | Optional | 22Mbps |
`DNN_RANGEx` shall be formatted like this : `'12.2.1.2 - 12.2.1.128'`.
See example in first section above.
This diff is collapsed.
#!/usr/bin/env python3
################################################################################
# Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The OpenAirInterface Software Alliance licenses this file to You under
# the OAI Public License, Version 1.1 (the "License"); you may not use this file
# except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.openairinterface.org/?page_id=698
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
# For more information about the OpenAirInterface (OAI) Software Alliance:
# contact@openairinterface.org
################################################################################
from jinja2 import Environment, FileSystemLoader
import socket
import os
import sys
CONFIG_FILE = str(os.getenv('CONFIG_FILE','/openair-smf/etc/smf.conf'))
MOUNT_CONFIG = str(os.getenv('MOUNT_CONFIG','no')).lower()
def resolve(hostname):
try:
return socket.gethostbyname(hostname)
except socket.error:
print(f"Not able to resolve {hostname}")
def render(filepath,funcs,values):
env = Environment(loader=FileSystemLoader(os.path.dirname(filepath)))
jinja_template = env.get_template(os.path.basename(filepath))
jinja_template.globals.update(funcs)
template_string = jinja_template.render(env=values)
return template_string
env_variables = dict()
#list of all the environment variables
for name, value in os.environ.items():
env_variables.update({name:value})
if MOUNT_CONFIG != "yes":
output = render(CONFIG_FILE,{"resolve":resolve},env_variables)
with open(CONFIG_FILE, "w") as fh:
fh.write(output)
print(f"Configuration file {CONFIG_FILE} is ready")
if len(sys.argv) == 1:
sys.exit(0)
os.execvp(sys.argv[1], sys.argv[1:]) #important for running the network function it works like exec $@
else:
print("Configuration file is mounted to the network function")
#!/bin/bash
set -euo pipefail
CONFIG_DIR="/openair-smf/etc"
# Default values
ENABLE_USAGE_REPORTING=${ENABLE_USAGE_REPORTING:-no}
USE_NETWORK_INSTANCE=${USE_NETWORK_INSTANCE:-no}
USE_LOCAL_SUBSCRIPTION_INFO=${USE_LOCAL_SUBSCRIPTION_INFO:-yes}
DOMAIN_ACCESS=${DOMAIN_ACCESS:-access.oai.org}
DOMAIN_CORE=${DOMAIN_CORE:-core.oai.org}
UE_MTU=${UE_MTU:-1358}
NSSAI_SST0=${NSSAI_SST0:-222}
NSSAI_SD0=${NSSAI_SD0:-123}
NSSAI_SST1=${NSSAI_SST1:-1}
NSSAI_SD1=${NSSAI_SD1:-1}
NSSAI_SST2=${NSSAI_SST2:-1}
NSSAI_SD2=${NSSAI_SD2:-1}
QOS_PROFILE_5QI0=${QOS_PROFILE_5QI0:-6}
QOS_PROFILE_5QI1=${QOS_PROFILE_5QI1:-7}
QOS_PROFILE_5QI2=${QOS_PROFILE_5QI2:-8}
SESSION_AMBR_UL0=${SESSION_AMBR_UL0:-20Mbps}
SESSION_AMBR_DL0=${SESSION_AMBR_DL0:-22Mbps}
SESSION_AMBR_UL1=${SESSION_AMBR_UL1:-20Mbps}
SESSION_AMBR_DL1=${SESSION_AMBR_DL1:-22Mbps}
SESSION_AMBR_UL2=${SESSION_AMBR_UL2:-20Mbps}
SESSION_AMBR_DL2=${SESSION_AMBR_DL2:-22Mbps}
PCF_IPV4_ADDRESS=${PCF_IPV4_ADDRESS:-0.0.0.0}
PCF_PORT=${PCF_PORT:-80}
PCF_API_VERSION=${PCF_API_VERSION:-"v1"}
PCF_FQDN=${PCF_FQDN:-"oai-pcf"}
DISCOVER_PCF=${DISCOVER_PCF:-"no"}
USE_LOCAL_PCC_RULES=${USE_LOCAL_PCC_RULES:-"yes"}
if [[ ${USE_FQDN_DNS} == "yes" ]];then
AMF_IPV4_ADDRESS=${AMF_IPV4_ADDRESS:-0.0.0.0}
NRF_IPV4_ADDRESS=${NRF_IPV4_ADDRESS:-0.0.0.0}
UPF_IPV4_ADDRESS=${UPF_IPV4_ADDRESS:-0.0.0.0}
UDM_IPV4_ADDRESS=${UDM_IPV4_ADDRESS:-0.0.0.0}
PCF_IPV4_ADDRESS=${PCF_IPV4_ADDRESS:-0.0.0.0}
fi
DEFAULT_CSCF_IPV4_ADDRESS=${DEFAULT_CSCF_IPV4_ADDRESS:-127.0.0.1}
HTTP_VERSION=${HTTP_VERSION:-1}
DNN_NI0=${DNN_NI0:-oai.ipv4}
TYPE0=${TYPE0:-IPv4}
DNN_RANGE0=${DNN_RANGE0:-'12.1.1.2 - 12.1.1.128'}
DNN_NI1=${DNN_NI1:-default}
TYPE1=${TYPE1:-IPv4}
DNN_RANGE1=${DNN_RANGE1:-'12.2.1.2 - 12.2.1.128'}
DNN_NI2=${DNN_NI2:-oai}
TYPE2=${TYPE2:-IPv4}
DNN_RANGE2=${DNN_RANGE2:-'12.1.1.129 - 12.1.1.224'}
DNN_NI3=${DNN_NI3:-ims}
TYPE3=${TYPE3:-IPv4v6}
DNN_RANGE3=${DNN_RANGE3:-'12.2.1.129 - 12.2.1.224'}
for c in ${CONFIG_DIR}/*.conf; do
# grep variable names (format: ${VAR}) from template to be rendered
if ! grep -oP '@[a-zA-Z0-9_]+@' ${c}; then
echo "Configuration is already set"
exec "$@"
fi
VARS=$(grep -oP '@[a-zA-Z0-9_]+@' ${c} | sort | uniq | xargs)
echo "Now setting these variables '${VARS}'"
# create sed expressions for substituting each occurrence of ${VAR}
# with the value of the environment variable "VAR"
EXPRESSIONS=""
for v in ${VARS}; do
NEW_VAR=`echo $v | sed -e "s#@##g"`
if [[ -z ${!NEW_VAR+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
EXPRESSIONS="${EXPRESSIONS#';'}"
# render template and inline replace config file
sed -i "${EXPRESSIONS}" ${c}
done
echo "Done setting the configuration"
exec "$@"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment