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'
sudo 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@]='eno1:sn4'
SMF_CONF[@SMF_INTERFACE_NAME_FOR_SBI@]='eno1:smf'
SMF_CONF[@SMF_INTERFACE_IPV4_ADDRESS_FOR_SBI@]='172.16.1.101'
SMF_CONF[@SMF_INTERFACE_PORT_FOR_SBI@]='80'
SMF_CONF[@SMF_INTERFACE_HTTP2_PORT_FOR_SBI@]='9090'
SMF_CONF[@UDM_IPV4_ADDRESS@]='172.16.1.103'
SMF_CONF[@UDM_PORT@]='80'
SMF_CONF[@AMF_IPV4_ADDRESS@]='172.16.1.102'
SMF_CONF[@AMF_PORT@]='80'
SMF_CONF[@UPF_IPV4_ADDRESS@]='172.16.2.102'
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
export CONFIG_FILE=$PREFIX/smf.conf
export MOUNT_CONFIG=NO
export INSTANCE=1
export SMF_INTERFACE_NAME_FOR_N4='eno1:sn4'
export SMF_INTERFACE_NAME_FOR_SBI='eno1:smf'
export UDM_IPV4_ADDRESS='172.16.1.103'
export UDM_PORT='80'
export AMF_IPV4_ADDRESS='172.16.1.102'
export AMF_PORT='80'
export UPF_IPV4_ADDRESS='172.16.2.102'
export DEFAULT_DNS_IPV4_ADDRESS='8.8.8.8'
export DEFAULT_DNS_SEC_IPV4_ADDRESS='4.4.4.4'
# One mandatory slice
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=800Mbps
export SESSION_AMBR_DL0=1000Mbps
../../scripts/entrypoint.py
......@@ -55,6 +55,8 @@ ENV TZ=Europe/Paris
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get upgrade --yes && \
DEBIAN_FRONTEND=noninteractive apt-get install --yes \
python3 \
python3-jinja2 \
psmisc \
net-tools \
bc \
......@@ -89,7 +91,7 @@ RUN apt-get update && \
WORKDIR /openair-smf/bin
COPY --from=oai-smf-builder \
/openair-smf/build/smf/build/oai_smf \
/openair-smf/scripts/entrypoint.sh \
/openair-smf/scripts/entrypoint.py \
/openair-smf/scripts/healthcheck.sh \
./
......@@ -124,5 +126,5 @@ HEALTHCHECK --interval=10s \
--retries=6 \
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"]
......@@ -80,7 +80,7 @@ def perform_flattening(tag):
cmd += ' --change "EXPOSE 8805/udp" '
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 "ENTRYPOINT [\\"/bin/bash\\", \\"/openair-smf/bin/entrypoint.sh\\"]" '
cmd += ' --change "ENTRYPOINT [\\"python3\\", \\"/openair-smf/bin/entrypoint.py\\"]" '
cmd += ' - ' + image_prefix + tag
print (cmd)
subprocess.check_output(cmd, shell=True, universal_newlines=True)
......
......@@ -96,6 +96,8 @@ COPY ./rhsm-ca /etc/rhsm/ca
RUN rm -f /etc/rhsm-host && \
microdnf update -y && \
microdnf install -y \
python3 \
python3-pip \
tzdata \
# libasan \
procps-ng \
......@@ -106,6 +108,7 @@ RUN rm -f /etc/rhsm-host && \
libevent \
findutils \
libconfig && \
pip3 install jinja2 && \
microdnf clean all -y && \
rm -rf /var/cache/yum /var/cache/dnf && \
# Remove entitlements and Subscription Manager configs
......@@ -116,7 +119,7 @@ RUN rm -f /etc/rhsm-host && \
WORKDIR /openair-smf/bin
COPY --from=oai-smf-builder \
/openair-smf/build/smf/build/oai_smf \
/openair-smf/scripts/entrypoint.sh \
/openair-smf/scripts/entrypoint.py \
/openair-smf/scripts/healthcheck.sh \
./
......@@ -145,5 +148,5 @@ HEALTHCHECK --interval=10s \
--retries=6 \
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"]
......@@ -77,6 +77,8 @@ ENV TZ=Europe/Paris
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get upgrade --yes && \
DEBIAN_FRONTEND=noninteractive apt-get install --yes \
python3 \
python3-jinja2 \
psmisc \
net-tools \
bc \
......@@ -111,7 +113,7 @@ RUN apt-get update && \
WORKDIR /openair-smf/bin
COPY --from=oai-smf-builder \
/openair-smf/build/smf/build/oai_smf \
/openair-smf/scripts/entrypoint.sh \
/openair-smf/scripts/entrypoint.py \
/openair-smf/scripts/healthcheck.sh \
./
......@@ -146,5 +148,5 @@ HEALTHCHECK --interval=10s \
--retries=6 \
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"]
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.
......@@ -22,26 +22,29 @@
SMF =
{
FQDN = "oai-smf-svc";
INSTANCE = @INSTANCE@; # 0 is the default
PID_DIRECTORY = "@PID_DIRECTORY@"; # /var/run is the default
INSTANCE = {{ env["INSTANCE"] if "INSTANCE" in env.keys() else 0 }}; # 0 is the default
PID_DIRECTORY = "{{ env["PID_DIRECTORY"] if "PID_DIRECTORY" in env.keys() else '/var/run' }}"; # /var/run is the default
INTERFACES :
{
N4 :
{
# SMF binded interface for N4 communication (UPF)
INTERFACE_NAME = "@SMF_INTERFACE_NAME_FOR_N4@"; # YOUR NETWORK CONFIG HERE
INTERFACE_NAME = "{{ env["SMF_INTERFACE_NAME_FOR_N4"] }}"; # YOUR NETWORK CONFIG HERE
IPV4_ADDRESS = "read";
};
SBI :
{
# SMF binded interface for SBI interface (e.g., communication with AMF, UDM)
INTERFACE_NAME = "@SMF_INTERFACE_NAME_FOR_SBI@"; # YOUR NETWORK CONFIG HERE
INTERFACE_NAME = "{{ env["SMF_INTERFACE_NAME_FOR_SBI"] }}"; # YOUR NETWORK CONFIG HERE
IPV4_ADDRESS = "read";
PORT = @SMF_INTERFACE_PORT_FOR_SBI@; # YOUR NETWORK CONFIG HERE (default: 80)
HTTP2_PORT = @SMF_INTERFACE_HTTP2_PORT_FOR_SBI@; # YOUR NETWORK CONFIG HERE
API_VERSION = "@SMF_API_VERSION@"; # YOUR SMF API VERSION CONFIG HERE
# YOUR NETWORK CONFIG HERE (default: 80)
PORT = {{ env["SMF_INTERFACE_PORT_FOR_SBI"] if "SMF_INTERFACE_PORT_FOR_SBI" in env.keys() else '80' }};
# YOUR NETWORK CONFIG HERE (default: 8080)
HTTP2_PORT = {{ env["SMF_INTERFACE_HTTP2_PORT_FOR_SBI"] if "SMF_INTERFACE_HTTP2_PORT_FOR_SBI" in env.keys() else '8080' }};
# YOUR NETWORK CONFIG HERE (default: v1)
API_VERSION = "{{ env["SMF_API_VERSION"] if "SMF_API_VERSION" in env.keys() else 'v1' }}";
};
};
......@@ -52,90 +55,212 @@ SMF =
DNN_LIST = (
# PDU_SESSION_TYPE choice in {IPv4, IPv6, IPv4v6}
# DNN IP ADDRESS RANGE format is for example: "12.2.1.2 - 12.2.1.128"
{DNN_NI = "@DNN_NI0@"; PDU_SESSION_TYPE = "@TYPE0@"; IPV4_RANGE = "@DNN_RANGE0@"; IPV6_PREFIX = "2001:1:2::/64"},
{DNN_NI = "@DNN_NI1@"; PDU_SESSION_TYPE = "@TYPE1@"; IPV4_RANGE = "@DNN_RANGE1@"; IPV6_PREFIX = "3001:1:2::/64"},
{DNN_NI = "@DNN_NI2@"; PDU_SESSION_TYPE = "@TYPE2@"; IPV4_RANGE = "@DNN_RANGE2@"; IPV6_PREFIX = "4001:1:2::/64"},
{DNN_NI = "@DNN_NI3@"; PDU_SESSION_TYPE = "@TYPE3@"; IPV4_RANGE = "@DNN_RANGE3@"; IPV6_PREFIX = "5001:1:2::/64"}
{%- if env["DNN_NI0"] is defined %}
{
DNN_NI = "{{ env["DNN_NI0"] }}";
PDU_SESSION_TYPE = "{{ env["TYPE0"] if "TYPE0" in env.keys() else 'IPv4' }}";
IPV4_RANGE = "{{ env["DNN_RANGE0"] }}";
IPV6_PREFIX = "2001:1:2::/64"
}
{%- if env["DNN_NI1"] is defined %}
,{
DNN_NI = "{{ env["DNN_NI1"] }}";
PDU_SESSION_TYPE = "{{ env["TYPE1"] if "TYPE1" in env.keys() else 'IPv4' }}";
IPV4_RANGE = "{{ env["DNN_RANGE1"] }}";
IPV6_PREFIX = "2001:1:2::/64"
}
{%- endif %}
{%- if env["DNN_NI2"] is defined %}
,{
DNN_NI = "{{ env["DNN_NI2"] }}";
PDU_SESSION_TYPE = "{{ env["TYPE2"] if "TYPE2" in env.keys() else 'IPv4' }}";
IPV4_RANGE = "{{ env["DNN_RANGE2"] }}";
IPV6_PREFIX = "2001:1:2::/64"
}
{%- endif %}
{%- if env["DNN_NI3"] is defined %}
,{
DNN_NI = "{{ env["DNN_NI3"] }}";
PDU_SESSION_TYPE = "{{ env["TYPE3"] if "TYPE3" in env.keys() else 'IPv4' }}";
IPV4_RANGE = "{{ env["DNN_RANGE3"] }}";
IPV6_PREFIX = "2001:1:2::/64"
}
{%- endif %}
{%- endif %}
);
# DNS address communicated to UEs
DEFAULT_DNS_IPV4_ADDRESS = "@DEFAULT_DNS_IPV4_ADDRESS@"; # YOUR DNS CONFIG HERE
DEFAULT_DNS_SEC_IPV4_ADDRESS = "@DEFAULT_DNS_SEC_IPV4_ADDRESS@"; # YOUR DNS CONFIG HERE
DEFAULT_DNS_IPV4_ADDRESS = "{{ env["DEFAULT_DNS_IPV4_ADDRESS"] }}"; # YOUR DNS CONFIG HERE
DEFAULT_DNS_SEC_IPV4_ADDRESS = "{{ env["DEFAULT_DNS_SEC_IPV4_ADDRESS"] }}"; # YOUR DNS CONFIG HERE
DEFAULT_DNS_IPV6_ADDRESS = "2001:4860:4860::8888"; # YOUR DNS CONFIG HERE
DEFAULT_DNS_SEC_IPV6_ADDRESS = "2001:4860:4860::8844"; # YOUR DNS CONFIG HERE
#Default P-CSCF server
DEFAULT_CSCF_IPV4_ADDRESS = "@DEFAULT_CSCF_IPV4_ADDRESS@";
#Default P-CSCF server
DEFAULT_CSCF_IPV4_ADDRESS = "{{ env["DEFAULT_CSCF_IPV4_ADDRESS"] if "DEFAULT_CSCF_IPV4_ADDRESS" in env.keys() else '127.0.0.1' }}";
DEFAULT_CSCF_IPV6_ADDRESS = "fe80::7915:f408:1787:db8b";
#Default UE MTU
UE_MTU = @UE_MTU@;
UE_MTU = {{ env["UE_MTU"] if "UE_MTU" in env.keys() else '1500' }};
# SUPPORT FEATURES
SUPPORT_FEATURES:
{
# STRING, {"yes", "no"},
REGISTER_NRF = "@REGISTER_NRF@"; # Set to yes if SMF resgisters to an NRF
DISCOVER_UPF = "@DISCOVER_UPF@"; # Set to yes to enable UPF discovery and selection
DISCOVER_PCF = "@DISCOVER_PCF@"; # Set to yes to enable PCF discovery and selection
FORCE_PUSH_PROTOCOL_CONFIGURATION_OPTIONS = "no"; # Non standard feature, normally should be set to "no",
# but you may need to set to yes for UE that do not explicitly request a PDN address through NAS signalling
USE_LOCAL_SUBSCRIPTION_INFO = "@USE_LOCAL_SUBSCRIPTION_INFO@"; # Set to yes if SMF uses local subscription information instead of from an UDM
USE_LOCAL_PCC_RULES = "@USE_LOCAL_PCC_RULES@"; # Set to yes if SMF uses local PCC rules instead of from an PCF
USE_FQDN_DNS = "@USE_FQDN_DNS@"; # Set to yes if AMF/UDM/NRF/UPF will relying on a DNS to resolve FQDN
HTTP_VERSION = @HTTP_VERSION@; # Default: 1
USE_NETWORK_INSTANCE = "@USE_NETWORK_INSTANCE@" # Set yes if network instance is to be used for given UPF
ENABLE_USAGE_REPORTING = "@ENABLE_USAGE_REPORTING@" # Set yes if UE USAGE REPORTING is to be done at UPF
# Set to yes if SMF resgisters to an NRF
REGISTER_NRF = "{{ env["REGISTER_NRF"] if "REGISTER_NRF" in env.keys() else 'no' }}";
# Set to yes to enable UPF discovery and selection
DISCOVER_UPF = "{{ env["DISCOVER_UPF"] if "DISCOVER_UPF" in env.keys() else 'no' }}";
# Set to yes to enable PCF discovery and selection
DISCOVER_PCF = "{{ env["DISCOVER_PCF"] if "DISCOVER_PCF" in env.keys() else 'no' }}";
# Non standard feature, normally should be set to "no",
# but you may need to set to yes for UE that do not explicitly request a PDN address through NAS signalling
FORCE_PUSH_PROTOCOL_CONFIGURATION_OPTIONS = "no";
# Set to yes if SMF uses local subscription information instead of from an UDM
USE_LOCAL_SUBSCRIPTION_INFO = "{{ env["USE_LOCAL_SUBSCRIPTION_INFO"] if "USE_LOCAL_SUBSCRIPTION_INFO" in env.keys() else 'no' }}";
# Set to yes if SMF uses local PCC rules instead of from an PCF
USE_LOCAL_PCC_RULES = "{{ env["USE_LOCAL_PCC_RULES"] if "USE_LOCAL_PCC_RULES" in env.keys() else 'yes' }}";
# Set to yes if AMF/UDM/NRF/UPF will relying on a DNS to resolve FQDN
USE_FQDN_DNS = "{{ env["USE_FQDN_DNS"] if "USE_FQDN_DNS" in env.keys() else 'no' }}";
# Default: 1
HTTP_VERSION = {{ env["HTTP_VERSION"] if "HTTP_VERSION" in env.keys() else '1' }};
# Set yes if network instance is to be used for given UPF
USE_NETWORK_INSTANCE = "{{ env["USE_NETWORK_INSTANCE"] if "USE_NETWORK_INSTANCE" in env.keys() else 'no' }}";
# Set yes if UE USAGE REPORTING is to be done at UPF
ENABLE_USAGE_REPORTING = "{{ env["ENABLE_USAGE_REPORTING"] if "ENABLE_USAGE_REPORTING" in env.keys() else 'no' }}"
}
AMF :
{
IPV4_ADDRESS = "@AMF_IPV4_ADDRESS@"; # YOUR AMF CONFIG HERE
PORT = @AMF_PORT@; # YOUR AMF CONFIG HERE (default: 80)
API_VERSION = "@AMF_API_VERSION@"; # YOUR AMF API VERSION FOR SBI CONFIG HERE
FQDN = "@AMF_FQDN@" # YOUR AMF FQDN CONFIG HERE
{%- if env["AMF_HOSTNAME"] is defined %}
IPV4_ADDRESS = "{{ resolve(env["AMF_HOSTNAME"]) }}";
{%- else %}
IPV4_ADDRESS = "{{ env["AMF_IPV4_ADDRESS"] if "AMF_IPV4_ADDRESS" in env.keys() else '0.0.0.0' }}";
{%- endif %}
PORT = {{ env["AMF_PORT"] if "AMF_PORT" in env.keys() else '80' }};
API_VERSION = "{{ env["AMF_API_VERSION"] if "AMF_API_VERSION" in env.keys() else 'v1' }}";
FQDN = "{{ env["AMF_FQDN"] if "AMF_FQDN" in env.keys() else 'localhost' }}"
};
UDM :
{
IPV4_ADDRESS = "@UDM_IPV4_ADDRESS@"; # YOUR UDM CONFIG HERE
PORT = @UDM_PORT@; # YOUR UDM CONFIG HERE (default: 80)
API_VERSION = "@UDM_API_VERSION@"; # YOUR UDM API VERSION FOR SBI CONFIG HERE
FQDN = "@UDM_FQDN@" # YOUR UDM FQDN CONFIG HERE
{%- if env["UDM_HOSTNAME"] is defined %}
IPV4_ADDRESS = "{{ resolve(env["UDM_HOSTNAME"]) }}";
{%- else %}
IPV4_ADDRESS = "{{ env["UDM_IPV4_ADDRESS"] if "UDM_IPV4_ADDRESS" in env.keys() else '0.0.0.0' }}";
{%- endif %}
PORT = {{ env["UDM_PORT"] if "UDM_PORT" in env.keys() else '80' }};
API_VERSION = "{{ env["UDM_API_VERSION"] if "UDM_API_VERSION" in env.keys() else 'v1' }}";
FQDN = "{{ env["UDM_FQDN"] if "UDM_FQDN" in env.keys() else 'localhost' }}"
};
NRF :
{
IPV4_ADDRESS = "@NRF_IPV4_ADDRESS@"; # YOUR NRF CONFIG HERE
PORT = @NRF_PORT@; # YOUR NRF CONFIG HERE (default: 80)
API_VERSION = "@NRF_API_VERSION@"; # YOUR NRF API VERSION FOR SBI CONFIG HERE
FQDN = "@NRF_FQDN@" # YOUR NRF FQDN CONFIG HERE
{%- if env["NRF_HOSTNAME"] is defined %}
IPV4_ADDRESS = "{{ resolve(env["NRF_HOSTNAME"]) }}";
{%- else %}
IPV4_ADDRESS = "{{ env["NRF_IPV4_ADDRESS"] if "NRF_IPV4_ADDRESS" in env.keys() else '0.0.0.0' }}";
{%- endif %}
PORT = {{ env["NRF_PORT"] if "NRF_PORT" in env.keys() else '80' }};
API_VERSION = "{{ env["NRF_API_VERSION"] if "NRF_API_VERSION" in env.keys() else 'v1' }}";
FQDN = "{{ env["NRF_FQDN"] if "NRF_FQDN" in env.keys() else 'localhost' }}"
};
PCF :
{
IPV4_ADDRESS = "@PCF_IPV4_ADDRESS@"; # YOUR PCF CONFIG HERE
PORT = @PCF_PORT@; # YOUR PCF CONFIG HERE (default: 80)
API_VERSION = "@PCF_API_VERSION@"; # YOUR PCF API VERSION FOR SBI CONFIG HERE
FQDN = "@PCF_FQDN@" # YOUR PCF FQDN CONFIG HERE
{%- if env["PCF_HOSTNAME"] is defined %}
IPV4_ADDRESS = "{{ resolve(env["PCF_HOSTNAME"]) }}";
{%- else %}
IPV4_ADDRESS = "{{ env["PCF_IPV4_ADDRESS"] if "PCF_IPV4_ADDRESS" in env.keys() else '0.0.0.0' }}";
{%- endif %}
PORT = {{ env["PCF_PORT"] if "PCF_PORT" in env.keys() else '80' }};
API_VERSION = "{{ env["PCF_API_VERSION"] if "PCF_API_VERSION" in env.keys() else 'v1' }}";
FQDN = "{{ env["PCF_FQDN"] if "PCF_FQDN" in env.keys() else 'localhost' }}"
};
UPF_LIST = (
{IPV4_ADDRESS = "@UPF_IPV4_ADDRESS@" ; FQDN = "@UPF_FQDN_0@"; NWI_LIST = ({DOMAIN_ACCESS = "@DOMAIN_ACCESS@", DOMAIN_CORE = "@DOMAIN_CORE@"})} # YOUR UPF CONFIG HERE
); # NWI_LIST IS OPTIONAL PARAMETER
{
{%- if env["UPF0_HOSTNAME"] is defined %}
IPV4_ADDRESS = "{{ resolve(env["UPF0_HOSTNAME"]) }}";
{%- else %}
IPV4_ADDRESS = "{{ env["UPF_IPV4_ADDRESS"] if "UPF_IPV4_ADDRESS" in env.keys() else '0.0.0.0' }}";
{%- endif %}
FQDN = "{{ env["UPF_FQDN_0"] if "UPF_FQDN_0" in env.keys() else 'localhost' }}";
NWI_LIST = (
{
DOMAIN_ACCESS = "{{ env["DOMAIN_ACCESS_0"] if "DOMAIN_ACCESS_0" in env.keys() else 'access.oai.org' }}",
DOMAIN_CORE = "{{ env["DOMAIN_CORE_0"] if "DOMAIN_CORE_0" in env.keys() else 'core.oai.org' }}"
}
)
}
);
LOCAL_CONFIGURATION :
{
SESSION_MANAGEMENT_SUBSCRIPTION_LIST = (
{ NSSAI_SST = @NSSAI_SST0@, NSSAI_SD = "@NSSAI_SD0@", DNN = "@DNN_NI0@", DEFAULT_SESSION_TYPE = "@TYPE0@", DEFAULT_SSC_MODE = 1,
QOS_PROFILE_5QI = @QOS_PROFILE_5QI0@, QOS_PROFILE_PRIORITY_LEVEL = 1, QOS_PROFILE_ARP_PRIORITY_LEVEL = 1, QOS_PROFILE_ARP_PREEMPTCAP = "NOT_PREEMPT",
QOS_PROFILE_ARP_PREEMPTVULN = "NOT_PREEMPTABLE", SESSION_AMBR_UL = "@SESSION_AMBR_UL0@", SESSION_AMBR_DL = "@SESSION_AMBR_DL0@"},
{ NSSAI_SST = @NSSAI_SST1@; NSSAI_SD = "@NSSAI_SD1@", DNN = "@DNN_NI1@", DEFAULT_SESSION_TYPE = "@TYPE1@", DEFAULT_SSC_MODE = 1,
QOS_PROFILE_5QI = @QOS_PROFILE_5QI1@, QOS_PROFILE_PRIORITY_LEVEL = 1, QOS_PROFILE_ARP_PRIORITY_LEVEL = 1, QOS_PROFILE_ARP_PREEMPTCAP = "NOT_PREEMPT",
QOS_PROFILE_ARP_PREEMPTVULN = "NOT_PREEMPTABLE", SESSION_AMBR_UL = "@SESSION_AMBR_UL1@", SESSION_AMBR_DL = "@SESSION_AMBR_DL1@"},
{ NSSAI_SST = @NSSAI_SST2@; NSSAI_SD = "@NSSAI_SD2@", DNN = "@DNN_NI2@", DEFAULT_SESSION_TYPE = "@TYPE2@", DEFAULT_SSC_MODE = 1,
QOS_PROFILE_5QI = @QOS_PROFILE_5QI2@, QOS_PROFILE_PRIORITY_LEVEL = 1, QOS_PROFILE_ARP_PRIORITY_LEVEL = 1, QOS_PROFILE_ARP_PREEMPTCAP = "NOT_PREEMPT",
QOS_PROFILE_ARP_PREEMPTVULN = "NOT_PREEMPTABLE", SESSION_AMBR_UL = "@SESSION_AMBR_UL2@", SESSION_AMBR_DL = "@SESSION_AMBR_DL2@"}
{%- if env["NSSAI_SST0"] is defined %}
{
NSSAI_SST = {{ env["NSSAI_SST0"] }},
NSSAI_SD = "{{ env["NSSAI_SD0"] if "NSSAI_SD0" in env.keys() else '0xFFFFFF' }}",
DNN = "{{ env["DNN_NI0"] }}",
DEFAULT_SESSION_TYPE = "{{ env["TYPE0"] if "TYPE0" in env.keys() else 'IPv4' }}",
DEFAULT_SSC_MODE = 1,
QOS_PROFILE_5QI = {{ env["QOS_PROFILE_5QI0"] if "QOS_PROFILE_5QI0" in env.keys() else '6' }},
QOS_PROFILE_PRIORITY_LEVEL = 1,
QOS_PROFILE_ARP_PRIORITY_LEVEL = 1,
QOS_PROFILE_ARP_PREEMPTCAP = "NOT_PREEMPT",
QOS_PROFILE_ARP_PREEMPTVULN = "NOT_PREEMPTABLE",
SESSION_AMBR_UL = "{{ env["SESSION_AMBR_UL0"] if "SESSION_AMBR_UL0" in env.keys() else '1000Mbps' }}",
SESSION_AMBR_DL = "{{ env["SESSION_AMBR_DL0"] if "SESSION_AMBR_DL0" in env.keys() else '1500Mbps' }}"
}
{%- if env["NSSAI_SST1"] is defined %}
,{
NSSAI_SST = {{ env["NSSAI_SST1"] }},
NSSAI_SD = "{{ env["NSSAI_SD1"] if "NSSAI_SD1" in env.keys() else '0xFFFFFF' }}",
DNN = "{{ env["DNN_NI1"] }}",
DEFAULT_SESSION_TYPE = "{{ env["TYPE1"] if "TYPE1" in env.keys() else 'IPv4' }}",
DEFAULT_SSC_MODE = 1,
QOS_PROFILE_5QI = {{ env["QOS_PROFILE_5QI1"] if "QOS_PROFILE_5QI1" in env.keys() else '7' }},
QOS_PROFILE_PRIORITY_LEVEL = 1,
QOS_PROFILE_ARP_PRIORITY_LEVEL = 1,
QOS_PROFILE_ARP_PREEMPTCAP = "NOT_PREEMPT",
QOS_PROFILE_ARP_PREEMPTVULN = "NOT_PREEMPTABLE",
SESSION_AMBR_UL = "{{ env["SESSION_AMBR_UL1"] if "SESSION_AMBR_UL1" in env.keys() else '1000Mbps' }}",
SESSION_AMBR_DL = "{{ env["SESSION_AMBR_DL1"] if "SESSION_AMBR_DL1" in env.keys() else '1500Mbps' }}"
}
{%- endif %}
{%- if env["NSSAI_SST2"] is defined %}
,{
NSSAI_SST = {{ env["NSSAI_SST2"] }},
NSSAI_SD = "{{ env["NSSAI_SD2"] if "NSSAI_SD2" in env.keys() else '0xFFFFFF' }}",
DNN = "{{ env["DNN_NI2"] }}",
DEFAULT_SESSION_TYPE = "{{ env["TYPE2"] if "TYPE2" in env.keys() else 'IPv4' }}",
DEFAULT_SSC_MODE = 1,
QOS_PROFILE_5QI = {{ env["QOS_PROFILE_5QI2"] if "QOS_PROFILE_5QI2" in env.keys() else '8'}},
QOS_PROFILE_PRIORITY_LEVEL = 1,
QOS_PROFILE_ARP_PRIORITY_LEVEL = 1,
QOS_PROFILE_ARP_PREEMPTCAP = "NOT_PREEMPT",
QOS_PROFILE_ARP_PREEMPTVULN = "NOT_PREEMPTABLE",
SESSION_AMBR_UL = "{{ env["SESSION_AMBR_UL2"] if "SESSION_AMBR_UL2" in env.keys() else '1000Mbps' }}",
SESSION_AMBR_DL = "{{ env["SESSION_AMBR_DL2"] if "SESSION_AMBR_DL2" in env.keys() else '1500Mbps' }}"
}
{%- endif %}
{%- if env["NSSAI_SST3"] is defined %}
,{
NSSAI_SST = {{ env["NSSAI_SST3"] }},
NSSAI_SD = "{{ env["NSSAI_SD3"] if "NSSAI_SD3" in env.keys() else '0xFFFFFF' }}",
DNN = "{{ env["DNN_NI3"] }}",
DEFAULT_SESSION_TYPE = "{{ env["TYPE3"] if "TYPE3" in env.keys() else 'IPv4' }}",
DEFAULT_SSC_MODE = 1,
QOS_PROFILE_5QI = {{ env["QOS_PROFILE_5QI3"] if "QOS_PROFILE_5QI3" in env.keys() else '9' }},
QOS_PROFILE_PRIORITY_LEVEL = 1,
QOS_PROFILE_ARP_PRIORITY_LEVEL = 1,
QOS_PROFILE_ARP_PREEMPTCAP = "NOT_PREEMPT",
QOS_PROFILE_ARP_PREEMPTVULN = "NOT_PREEMPTABLE",
SESSION_AMBR_UL = "{{ env["SESSION_AMBR_UL3"] if "SESSION_AMBR_UL3" in env.keys() else '1000Mbps' }}",
SESSION_AMBR_DL = "{{ env["SESSION_AMBR_DL3"] if "SESSION_AMBR_DL3" in env.keys() else '1500Mbps' }}"
}
{%- endif %}
{%- endif %}
);
};
......
#!/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