initial sdcore-helm-charts update

Change-Id: I91788de083b0f906ce4b32ac226f616fb2647ef9
diff --git a/omec-control-plane/templates/bin/_config4g-run.sh.tpl b/omec-control-plane/templates/bin/_config4g-run.sh.tpl
new file mode 100644
index 0000000..b568195
--- /dev/null
+++ b/omec-control-plane/templates/bin/_config4g-run.sh.tpl
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+# Copyright 2020-present Open Networking Foundation
+#
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+set -xe
+
+{{- if .Values.config.coreDump.enabled }}
+cp /free5gc/webconsole/webconsole /tmp/coredump/
+{{- end }}
+
+cd /free5gc
+
+cat config/webuicfg.conf
+
+./webconsole/webconsole -webuicfg config/webuicfg.conf
diff --git a/omec-control-plane/templates/bin/_hss-bootstrap.sh.tpl b/omec-control-plane/templates/bin/_hss-bootstrap.sh.tpl
new file mode 100644
index 0000000..b6d8fda
--- /dev/null
+++ b/omec-control-plane/templates/bin/_hss-bootstrap.sh.tpl
@@ -0,0 +1,132 @@
+#!/bin/bash
+
+# Copyright 2018 Intel Corporation
+# Copyright 2019-present Open Networking Foundation
+#
+# SPDX-License-Identifier: Apache-2.0
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+set -ex
+
+function provision_users() {
+    count=${1}
+    imsi=${2}
+    msisdn=${3}
+    apn=${4}
+    key=${5}
+    opc=${6}
+    sqn=${7}
+    cassandra_ip=${8}
+    mmeidentity=${9}
+    mmerealm=${10}
+
+    for (( i=1; i<=$count; i++ ))
+    do
+        echo "IMSI=$imsi MSISDN=$msisdn"
+        cqlsh $cassandra_ip -e "INSERT INTO vhss.users_imsi (imsi, msisdn, access_restriction, key, opc, mmehost, mmeidentity_idmmeidentity, mmerealm, rand, sqn, subscription_data, supported_features) VALUES ('$imsi', $msisdn, 41, '$key', '$opc','$mmeidentity', 3, '$mmerealm', '2683b376d1056746de3b254012908e0e', $sqn, '{\"Subscription-Data\":{\"Access-Restriction-Data\":41,\"Subscriber-Status\":0,\"Network-Access-Mode\":2,\"Regional-Subscription-Zone-Code\":[\"0x0123\",\"0x4567\",\"0x89AB\",\"0xCDEF\",\"0x1234\",\"0x5678\",\"0x9ABC\",\"0xDEF0\",\"0x2345\",\"0x6789\"],\"MSISDN\":\"0x$msisdn\",\"AMBR\":{\"Max-Requested-Bandwidth-UL\":50000000,\"Max-Requested-Bandwidth-DL\":100000000},\"APN-Configuration-Profile\":{\"Context-Identifier\":0,\"All-APN-Configurations-Included-Indicator\":0,\"APN-Configuration\":{\"Context-Identifier\":0,\"PDN-Type\":0,\"Served-Party-IP-Address\":[\"0.0.0.0\"],\"Service-Selection\":\"$apn\",\"EPS-Subscribed-QoS-Profile\":{\"QoS-Class-Identifier\":9,\"Allocation-Retention-Priority\":{\"Priority-Level\":15,\"Pre-emption-Capability\":0,\"Pre-emption-Vulnerability\":0}},\"AMBR\":{\"Max-Requested-Bandwidth-UL\":50000000,\"Max-Requested-Bandwidth-DL\":100000000},\"PDN-GW-Allocation-Type\":0,\"MIP6-Agent-Info\":{\"MIP-Home-Agent-Address\":[\"172.26.17.183\"]}}},\"Subscribed-Periodic-RAU-TAU-Timer\":0}}', '{\"Supported-Features\":{\"Vendor-Id\": 10415, \"Feature-List-ID\": 2, \"Feature-List\": 134217728}}');"
+
+        if [ $? -ne 0 ];then
+           echo -e "oops! Something went wrong adding $imsi to vhss.users_imsi!\n"
+           exit 1
+        fi
+
+        cqlsh $cassandra_ip -e "INSERT INTO vhss.msisdn_imsi (msisdn, imsi) VALUES ($msisdn, '$imsi');"
+        if [ $? -ne 0 ];then
+           echo -e "oops! Something went wrong adding $imsi to vhss.msisdn_imsi!\n"
+           exit 1
+        fi
+
+        echo -e "Added $imsi\n"
+
+        imsi=`expr $imsi + 1`;
+        msisdn=`expr $msisdn + 1`
+    done
+}
+
+function provision_staticusers() {
+    imsi=${1}
+    msisdn=${2}
+    apn=${3}
+    key=${4}
+    opc=${5}
+    sqn=${6}
+    cassandra_ip=${7}
+    mmeidentity=${8}
+    mmerealm=${9}
+    staticAddr=${10}
+
+    echo "IMSI=$imsi MSISDN=$msisdn"
+    cqlsh $cassandra_ip -e "INSERT INTO vhss.users_imsi (imsi, msisdn, access_restriction, key, opc, mmehost, mmeidentity_idmmeidentity, mmerealm, rand, sqn, subscription_data, supported_features) VALUES ('$imsi', $msisdn, 41, '$key', '$opc','$mmeidentity', 3, '$mmerealm', '2683b376d1056746de3b254012908e0e', $sqn, '{\"Subscription-Data\":{\"Access-Restriction-Data\":41,\"Subscriber-Status\":0,\"Network-Access-Mode\":2,\"Regional-Subscription-Zone-Code\":[\"0x0123\",\"0x4567\",\"0x89AB\",\"0xCDEF\",\"0x1234\",\"0x5678\",\"0x9ABC\",\"0xDEF0\",\"0x2345\",\"0x6789\"],\"MSISDN\":\"0x$msisdn\",\"AMBR\":{\"Max-Requested-Bandwidth-UL\":50000000,\"Max-Requested-Bandwidth-DL\":100000000},\"APN-Configuration-Profile\":{\"Context-Identifier\":0,\"All-APN-Configurations-Included-Indicator\":0,\"APN-Configuration\":{\"Context-Identifier\":0,\"PDN-Type\":0,\"Served-Party-IP-Address\":[\"$staticAddr\"],\"Service-Selection\":\"$apn\",\"EPS-Subscribed-QoS-Profile\":{\"QoS-Class-Identifier\":9,\"Allocation-Retention-Priority\":{\"Priority-Level\":15,\"Pre-emption-Capability\":0,\"Pre-emption-Vulnerability\":0}},\"AMBR\":{\"Max-Requested-Bandwidth-UL\":50000000,\"Max-Requested-Bandwidth-DL\":100000000},\"PDN-GW-Allocation-Type\":0,\"MIP6-Agent-Info\":{\"MIP-Home-Agent-Address\":[\"172.26.17.183\"]}}},\"Subscribed-Periodic-RAU-TAU-Timer\":0}}', '{\"Supported-Features\":{\"Vendor-Id\": 10415, \"Feature-List-ID\": 2, \"Feature-List\": 134217728}}');"
+
+    cqlsh $cassandra_ip -e "INSERT INTO vhss.msisdn_imsi (msisdn, imsi) VALUES ($msisdn, '$imsi');"
+    echo -e "Added $imsi\n"
+}
+
+function provision_mme() {
+    id=$1
+    isdn=$2
+    host=$3
+    realm=$4
+    uereachability=$5
+    cassandra_ip=$6
+
+    cqlsh $cassandra_ip -e "INSERT INTO vhss.mmeidentity (idmmeidentity, mmeisdn, mmehost, mmerealm, ue_reachability) VALUES ($id, '$isdn', '$host', '$realm', $uereachability);"
+    if [ $? -ne 0 ];then
+       echo -e "oops! Something went wrong adding to vhss.mmeidentity!\n"
+       exit 1
+    fi
+
+    cqlsh $cassandra_ip -e "INSERT INTO vhss.mmeidentity_host (idmmeidentity, mmeisdn, mmehost, mmerealm, ue_reachability) VALUES ($id, '$isdn', '$host', '$realm', $uereachability);"
+    if [ $? -ne 0 ];then
+       echo -e "oops! Something went wrong adding to vhss.mmeidentity_host!\n"
+       exit 1
+    fi
+
+    echo -e "Added mme $id\n"
+}
+
+until cqlsh --file /opt/c3po/hssdb/oai_db.cql {{ .Values.config.hss.hssdb }};
+    do echo "Provisioning HSSDB";
+    sleep 2;
+done
+
+{{- if .Values.config.hss.bootstrap.enabled }}
+{{- range .Values.config.hss.bootstrap.users }}
+provision_users \
+    {{ .count }} \
+    {{ .imsiStart }} \
+    {{ .msisdnStart }} \
+    {{ .apn }} \
+    {{ .key }} \
+    {{ .opc }} \
+    {{ .sqn }} \
+    {{ $.Values.config.hss.hssdb }} \
+    {{ .mme_identity }} \
+    {{ .mme_realm }}
+{{- end }}
+
+{{- range .Values.config.hss.bootstrap.staticusers }}
+provision_staticusers \
+    {{ .imsi }} \
+    {{ .msisdn }} \
+    {{ .apn }} \
+    {{ .key }} \
+    {{ .opc }} \
+    {{ .sqn }} \
+    {{ $.Values.config.hss.hssdb }} \
+    {{ .mme_identity }} \
+    {{ .mme_realm }} \
+    {{ .staticAddr }}
+{{- end }}
+
+{{- range .Values.config.hss.bootstrap.mmes }}
+provision_mme \
+    {{ .id }} \
+    {{ .isdn }} \
+    {{ .mme_identity }} \
+    {{ .mme_realm }} \
+    {{ .unreachability }} \
+    {{ $.Values.config.hss.hssdb }}
+{{- end }}
+{{- end }}
+
diff --git a/omec-control-plane/templates/bin/_hss-run.sh.tpl b/omec-control-plane/templates/bin/_hss-run.sh.tpl
new file mode 100644
index 0000000..6f2d8e9
--- /dev/null
+++ b/omec-control-plane/templates/bin/_hss-run.sh.tpl
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+# Copyright 2019-present Open Networking Foundation
+#
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+set -ex
+
+{{- if .Values.config.coreDump.enabled }}
+cp /bin/hss /tmp/coredump/
+{{- end }}
+
+CONF_DIR="/opt/c3po/hss/conf"
+LOGS_DIR="/opt/c3po/hss/logs"
+mkdir -p $CONF_DIR $LOGS_DIR
+
+cp /etc/hss/conf/{acl.conf,hss.json,hss.conf,oss.json} $CONF_DIR
+cat $CONF_DIR/{hss.json,hss.conf}
+
+cd $CONF_DIR
+make_certs.sh {{ tuple "hss" "host" . | include "omec-control-plane.diameter_endpoint" }} {{ tuple "hss" "realm" . | include "omec-control-plane.diameter_endpoint" }}
+
+cd ..
+hss -j $CONF_DIR/hss.json
diff --git a/omec-control-plane/templates/bin/_mme-init.sh.tpl b/omec-control-plane/templates/bin/_mme-init.sh.tpl
new file mode 100644
index 0000000..256da0d
--- /dev/null
+++ b/omec-control-plane/templates/bin/_mme-init.sh.tpl
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+# Copyright 2019-present Open Networking Foundation
+#
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+set -ex
+
+cp /opt/mme/config/config.json /opt/mme/config/shared/config.json
+cd /opt/mme/config/shared
+
+# Set local IP address for s1ap and s11 networks to the config
+jq --arg MME_LOCAL_IP "$POD_IP" '.mme.ip_addr=$MME_LOCAL_IP' config.json > config.tmp && mv config.tmp config.json
+jq --arg MME_LOCAL_IP "$POD_IP" '.s1ap.s1ap_local_addr=$MME_LOCAL_IP' config.json > config.tmp && mv config.tmp config.json
+jq --arg MME_LOCAL_IP "$POD_IP" '.s11.egtp_local_addr=$MME_LOCAL_IP' config.json > config.tmp && mv config.tmp config.json
+
+# Set SPGWC address to the config
+# We need to convert service domain name to actual IP address
+# because mme apps does not take domain address - should be fixed in openmme
+SPGWC_ADDR=$(dig +short +search {{ .Values.config.mme.spgwAddr }})
+jq --arg SPGWC_ADDR "$SPGWC_ADDR" '.s11.sgw_addr //= $SPGWC_ADDR' config.json > config.tmp && mv config.tmp config.json
+jq --arg SPGWC_ADDR "$SPGWC_ADDR" '.s11.pgw_addr //= $SPGWC_ADDR' config.json > config.tmp && mv config.tmp config.json
+
+# Add additional redundant keys - should be fixed in openmme
+HSS_TYPE=$(jq -r '.s6a.host_type' config.json)
+HSS_HOST=$(jq -r '.s6a.host' config.json)
+jq --arg HSS_TYPE "$HSS_TYPE" '.s6a.hss_type=$HSS_TYPE' config.json > config.tmp && mv config.tmp config.json
+jq --arg HSS_HOST "$HSS_HOST" '.s6a.host_name=$HSS_HOST' config.json > config.tmp && mv config.tmp config.json
+
+# Copy the final configs for each applications
+cp /opt/mme/config/shared/config.json /opt/mme/config/shared/mme.json
+cp /opt/mme/config/shared/config.json /opt/mme/config/shared/s11.json
+cp /opt/mme/config/shared/config.json /opt/mme/config/shared/s1ap.json
+cp /opt/mme/config/shared/config.json /opt/mme/config/shared/s6a.json
+cp /opt/mme/config/s6a_fd.conf /opt/mme/config/shared/s6a_fd.conf
+
+#This multiple copies of config needs some cleanup. For now I want 
+#that after running mme_init config to be present in the target directory
+cp /opt/mme/config/shared/* /openmme/target/conf/
+
+# Generate certs
+MME_IDENTITY={{ tuple "mme" "identity" . | include "omec-control-plane.diameter_endpoint" | quote }};
+DIAMETER_HOST=$(echo $MME_IDENTITY | cut -d'.' -f1)
+DIAMETER_REALM={{ tuple "mme" "realm" . | include "omec-control-plane.diameter_endpoint" | quote }};
+
+cp /openmme/target/conf/make_certs.sh /opt/mme/config/shared/make_certs.sh
+cd /opt/mme/config/shared
+./make_certs.sh $DIAMETER_HOST $DIAMETER_REALM
diff --git a/omec-control-plane/templates/bin/_mme-run.sh.tpl b/omec-control-plane/templates/bin/_mme-run.sh.tpl
new file mode 100644
index 0000000..c739aa6
--- /dev/null
+++ b/omec-control-plane/templates/bin/_mme-run.sh.tpl
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+# Copyright 2019-present Open Networking Foundation
+#
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+APPLICATION=$1
+
+{{- if .Values.config.coreDump.enabled }}
+cp /openmme/target/bin/$APPLICATION /tmp/coredump/
+{{- end }}
+
+# copy config files to openmme target directly
+cp /opt/mme/config/shared/* /openmme/target/conf/
+
+cd /openmme/target
+export LD_LIBRARY_PATH=/usr/local/lib:./lib
+
+case $APPLICATION in
+    "mme-app")
+      echo "Starting mme-app"
+      echo "conf/mme.json"
+      cat conf/mme.json
+      ./bin/mme-app
+      ;;
+    "s1ap-app")
+      echo "Starting s1ap-app"
+      echo "conf/s1ap.json"
+      cat conf/s1ap.json
+      ./bin/s1ap-app
+      ;;
+    "s6a-app")
+      echo "Starting s6a-app"
+      echo "conf/s6a.json"
+      cat conf/s6a.json
+      echo "conf/s6a_fd.conf"
+      cat conf/s6a_fd.conf
+      ./bin/s6a-app
+      ;;
+    "s11-app")
+      echo "Starting s11-app"
+      echo "conf/s11.json"
+      cat conf/s11.json
+      ./bin/s11-app
+      ;;
+    *)
+      echo "invalid app $APPLICATION"
+      ;;
+esac
diff --git a/omec-control-plane/templates/bin/_pcrf-bootstrap.sh.tpl b/omec-control-plane/templates/bin/_pcrf-bootstrap.sh.tpl
new file mode 100644
index 0000000..4afc210
--- /dev/null
+++ b/omec-control-plane/templates/bin/_pcrf-bootstrap.sh.tpl
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+# Copyright 2020-present Open Networking Foundation
+#
+# SPDX-License-Identifier: Apache-2.0
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+set -ex
+
+until cqlsh --file /opt/c3po/pcrfdb/pcrf_cassandra.cql {{ .Values.config.pcrf.pcrfdb }};
+    do echo "Provisioning PCRFDB";
+    sleep 2;
+done
+
diff --git a/omec-control-plane/templates/bin/_pcrf-run.sh.tpl b/omec-control-plane/templates/bin/_pcrf-run.sh.tpl
new file mode 100644
index 0000000..7be50a6
--- /dev/null
+++ b/omec-control-plane/templates/bin/_pcrf-run.sh.tpl
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Copyright 2020-present Open Networking Foundation
+#
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+set -ex
+
+{{- if .Values.config.coreDump.enabled }}
+cp /bin/pcrf /tmp/coredump/
+{{- end }}
+
+CONF_DIR="/opt/c3po/pcrf/conf"
+LOGS_DIR="/opt/c3po/pcrf/logs"
+#TODO - Need to remove logs directory
+mkdir -p $CONF_DIR $LOGS_DIR
+
+cp /etc/pcrf/conf/{acl.conf,pcrf.json,pcrf.conf,oss.json,subscriber_mapping.json} $CONF_DIR
+cat $CONF_DIR/{pcrf.json,pcrf.conf}
+
+cd $CONF_DIR
+make_certs.sh {{ tuple "pcrf" "host" . | include "omec-control-plane.diameter_endpoint" }} {{ tuple "pcrf" "realm" . | include "omec-control-plane.diameter_endpoint" }}
+
+cd ..
+pcrf -j $CONF_DIR/pcrf.json
diff --git a/omec-control-plane/templates/bin/_spgwc-init.sh.tpl b/omec-control-plane/templates/bin/_spgwc-init.sh.tpl
new file mode 100644
index 0000000..82ca533
--- /dev/null
+++ b/omec-control-plane/templates/bin/_spgwc-init.sh.tpl
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+# Copyright 2021-present Open Networking Foundation
+#
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+while ! curl -f --connect-timeout 5 http://spgwc:8080/startup
+do
+  echo Waiting for SPGWC to be ready
+  sleep 5
+done
+echo SPGWC is ready
+
+echo Posting to sync URL {{ .Values.config.spgwc.managedByRoc.syncUrl }}
+while ! curl --connect-timeout 5 -f -X POST {{ .Values.config.spgwc.managedByRoc.syncUrl }}
+do
+  echo Failed posting to sync URL
+  sleep 5
+done
+echo
+
+echo Sleeping forever
+while true
+do
+  sleep 86400
+done
\ No newline at end of file
diff --git a/omec-control-plane/templates/bin/_spgwc-run.sh.tpl b/omec-control-plane/templates/bin/_spgwc-run.sh.tpl
new file mode 100644
index 0000000..fd1096d
--- /dev/null
+++ b/omec-control-plane/templates/bin/_spgwc-run.sh.tpl
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+# Copyright 2019-present Open Networking Foundation
+#
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+APPLICATION=$1
+set -xe
+
+mkdir -p /opt/cp/config
+cd /opt/cp/config
+cp /etc/cp/config/{*.json,*.conf} .
+
+case $APPLICATION in
+    "ngic_controlplane")
+      echo "Starting ngic controlplane app"
+      cat /opt/cp/config/cp.json
+      cat /opt/cp/config/subscriber_mapping.json
+      {{- if .Values.config.coreDump.enabled }}
+      cp /bin/ngic_controlplane /tmp/coredump/
+      {{- end }}
+
+      ngic_controlplane -f /etc/cp/config/
+      ;;
+
+    "gx-app")
+      echo "Starting gx-app"
+      SPGWC_IDENTITY={{ tuple "spgwc" "identity" . | include "omec-control-plane.diameter_endpoint" | quote }};
+      DIAMETER_HOST=$(echo $SPGWC_IDENTITY| cut -d'.' -f1)
+      DIAMETER_REALM={{ tuple "spgwc" "realm" . | include "omec-control-plane.diameter_endpoint" | quote }};
+      chmod +x /bin/make_certs.sh
+      cp /bin/make_certs.sh /opt/cp/config
+      /bin/make_certs.sh $DIAMETER_HOST $DIAMETER_REALM
+      {{- if .Values.config.coreDump.enabled }}
+      cp /bin/gx_app /tmp/coredump/
+      {{- end }}
+      cd /opt/cp/
+      gx_app
+      ;;
+
+    *)
+      echo "invalid app $APPLICATION"
+      ;;
+esac