AETHER-575 Make SPGW settings configurable

Also remove unnecessary ZMQ releated configs from SPGW and enable
multi-upfs always.

Change-Id: I68741669b8db7c221c41814f55146d54fd17c81b
diff --git a/omec/omec-control-plane/Chart.yaml b/omec/omec-control-plane/Chart.yaml
index ca7a7bb..a0aac72 100644
--- a/omec/omec-control-plane/Chart.yaml
+++ b/omec/omec-control-plane/Chart.yaml
@@ -10,4 +10,4 @@
 name: omec-control-plane
 icon: https://guide.opencord.org/logos/cord.svg
 
-version: 0.3.5
+version: 0.4.0
diff --git a/omec/omec-control-plane/templates/bin/_spgwc-run.sh.tpl b/omec/omec-control-plane/templates/bin/_spgwc-run.sh.tpl
index 9a185e6..0a5b680 100644
--- a/omec/omec-control-plane/templates/bin/_spgwc-run.sh.tpl
+++ b/omec/omec-control-plane/templates/bin/_spgwc-run.sh.tpl
@@ -12,15 +12,13 @@
 
 mkdir -p /opt/cp/config
 cd /opt/cp/config
+cp /etc/cp/config/{*.cfg,*.json} .
 
-cp /etc/cp/config/{adc_rules.cfg,cp_config.cfg,interface.cfg,meter_profile.cfg,pcc_rules.cfg,sdf_rules.cfg,app_config.cfg} .
-sed -i "s/CP_ADDR/$POD_IP/g" interface.cfg
+if [ ! -d "/dev/hugepages" ]; then
+    MEMORY="--no-huge -m $((MEM_LIMIT-1024))"
+fi
+CORES="-c $(taskset -p $$ | awk '{print $NF}')"
+EAL_ARGS="${CORES} ${MEMORY} --no-pci"
 
-{{- if .Values.config.spgwc.pfcp }}
-cp /etc/cp/config/{cp.cfg,subscriber_mapping.json} .
-sed -i "s/CP_ADDR/$POD_IP/g" cp.cfg
 cat /opt/cp/config/subscriber_mapping.json
-{{- end }}
-
-. cp_config.cfg
-ngic_controlplane $EAL_ARGS -- $APP_ARGS
+ngic_controlplane $EAL_ARGS -- -f /etc/cp/config/
diff --git a/omec/omec-control-plane/templates/configmap-spgwc.yaml b/omec/omec-control-plane/templates/configmap-spgwc.yaml
index 3853a10..2ebbe95 100644
--- a/omec/omec-control-plane/templates/configmap-spgwc.yaml
+++ b/omec/omec-control-plane/templates/configmap-spgwc.yaml
@@ -13,78 +13,40 @@
   labels:
 {{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
 data:
-{{- if .Values.config.spgwc.pfcp }}
   cp.cfg: |
     [GLOBAL]
     CP_TYPE = 03
     GX_CONFIG = 0
-    S11_IP = CP_ADDR
-    S11_PORT = 2123
-    S5S8_IP = CP_ADDR
     S5S8_PORT = 2123
-    PFCP_IP = CP_ADDR
-    PFCP_PORT = 8805
-    UPF_PFCP_IP = 127.0.0.1
     UPF_PFCP_PORT = 8805
+    S11_PORT = {{ .Values.config.spgwc.s11.port }}
+    PFCP_PORT = {{ .Values.config.spgwc.n4.port }}
     PROMETHEUS_PORT = {{ .Values.config.spgwc.prometheus.port }}
-    HTTP_PORT = {{ .Values.config.spgwc.http.port }}
-    TRANSMIT_TIMER = 2
-    PERIODIC_TIMER = 10
-    TRANSMIT_COUNT = 5
-    REQUEST_TIMEOUT=1800000
-    REQUEST_TRIES=3
-    CP_LOGGER = 0
+    HTTP_PORT = {{ .Values.config.spgwc.rest.port }}
+    TRANSMIT_TIMER = {{ .Values.config.spgwc.global.transmitTimerSec }}
+    PERIODIC_TIMER = {{ .Values.config.spgwc.global.periodicTimerSec }}
+    TRANSMIT_COUNT = {{ .Values.config.spgwc.global.transmitCount }}
+    REQUEST_TIMEOUT = {{ .Values.config.spgwc.global.requestTimeoutMilliSec }}
+    REQUEST_TRIES = {{ .Values.config.spgwc.global.requestTries }}
+    CP_LOGGER = {{ .Values.config.spgwc.global.cpLogger }}
     [NAMESERVER_CONFIG]
     [CACHE]
-    concurrent=25
-    percentage=80
-    interval_seconds=60
-    query_timeout_ms=1000
-    query_tries=1
+    concurrent = {{ .Values.config.spgwc.dns.cache.concurrent }}
+    percentage = {{ .Values.config.spgwc.dns.cache.percentage }}
+    interval_seconds = {{ .Values.config.spgwc.dns.cache.intervalSec }}
+    query_timeout_ms = {{ .Values.config.spgwc.dns.cache.queryTimeoutMilliSec }}
+    query_tries = {{ .Values.config.spgwc.dns.cache.queryTries }}
     [APP]
-    frequency_seconds=3
-    filename=appqueries.json
-    nameserver= {{ .Values.config.spgwc.nameserver}}
+    frequency_seconds = {{ .Values.config.spgwc.dns.app.frequencySec }}
+    filename = {{ .Values.config.spgwc.dns.app.filename }}
+    nameserver = {{ .Values.config.spgwc.dns.app.nameserver }}
     [OPS]
-    frequency_seconds=3
-    filename=opsqueries.json
-    nameserver= {{ .Values.config.spgwc.nameserver}}
+    frequency_seconds = {{ .Values.config.spgwc.dns.ops.frequencySec }}
+    filename = {{ .Values.config.spgwc.dns.ops.filename }}
+    nameserver = {{ .Values.config.spgwc.dns.ops.nameserver }}
     [IP_POOL_CONFIG]
     IP_POOL_IP= {{.Values.config.spgwc.ueIpPool.ip }}
     IP_POOL_MASK= {{ .Values.config.spgwc.ueIpPool.mask }}
-{{- end }}
-  cp_config.cfg: |
-    if [ ! -d "/dev/hugepages" ]; then
-        MEMORY="--no-huge -m $((MEM_LIMIT-1024))"
-    fi
-    CORES="-c $(taskset -p $$ | awk '{print $NF}')"
-    EAL_ARGS="${CORES} ${MEMORY} --no-pci"
-
-    MGMT_INFO="-s ${POD_IP} -w {{ .Values.config.spgwc.s1uAddr }}"
-    APN_INFO="-i {{ .Values.config.spgwc.ueIpPool.ip }} -p {{ .Values.config.spgwc.ueIpPool.mask }} -a {{ .Values.config.spgwc.apn }}"
-    MISC="-l 2"
-    SPGW_CFG="-d 03"
-
-{{- if .Values.config.spgwc.multiUpfs }}
-    CONFIG_UPDATE_FOLDER="-f /etc/cp/config/"
-    APP_ARGS="${MGMT_INFO} ${APN_INFO} ${MISC} ${SPGW_CFG} ${CONFIG_UPDATE_FOLDER}"
-{{- else }}
-    APP_ARGS="${MGMT_INFO} ${APN_INFO} ${MISC} ${SPGW_CFG} "
-{{- end }}
-  interface.cfg: |
-    [0]
-    zmq_protocol = tcp
-    cp_comm_ip = CP_ADDR
-    cp_comm_port = 21
-{{- if .Values.config.spgwc.multiUpfs }}
-    cp_nb_ip = CP_ADDR
-    cp_nb_port = 21
-    dp_comm_ip = 127.0.0.1
-    dp_comm_port = 20
-{{- else }}
-    dp_comm_ip = {{ .Values.config.spgwc.dpComm.addr }}
-    dp_comm_port = {{ .Values.config.spgwc.dpComm.port }}
-{{- end }}
   spgwc-run.sh: |
 {{ tuple "bin/_spgwc-run.sh.tpl" . | include "omec-control-plane.template" | indent 4 }}
 {{- range $key, $value := .Values.config.spgwc.cfgFiles }}
diff --git a/omec/omec-control-plane/templates/service-spgwc.yaml b/omec/omec-control-plane/templates/service-spgwc.yaml
index 2704ecd..c97689a 100644
--- a/omec/omec-control-plane/templates/service-spgwc.yaml
+++ b/omec/omec-control-plane/templates/service-spgwc.yaml
@@ -17,21 +17,17 @@
   selector:
 {{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
   ports:
-  - name: cp-comm
-    port: {{ .Values.config.spgwc.cpComm.port }}
-{{- if .Values.config.spgwc.multiUpfs }}
-    protocol: TCP
-{{- else }}
-    protocol: UDP
-{{- end }}
   - name: s11
     port: {{ .Values.config.spgwc.s11.port }}
     protocol: UDP
+  - name: pfcp
+    port: {{ .Values.config.spgwc.n4.port }}
+    protocol: UDP
   - name: prometheus-exporter
     port: {{ .Values.config.spgwc.prometheus.port }}
     protocol: TCP
-  - name: restendpoint
-    port: {{ .Values.config.spgwc.http.port }}
+  - name: rest
+    port: {{ .Values.config.spgwc.rest.port }}
     protocol: TCP
 ---
 apiVersion: v1
@@ -44,19 +40,7 @@
   clusterIP: None
   selector:
 {{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
-  ports:
-  - name: cp-comm
-    port: {{ .Values.config.spgwc.cpComm.port }}
-{{- if .Values.config.spgwc.multiUpfs }}
-    protocol: TCP
-{{- else }}
-    protocol: UDP
-{{- end }}
-  - name: s11
-    port: {{ .Values.config.spgwc.s11.port }}
-    protocol: UDP
-{{- if not .Values.config.spgwc.multiUpfs }}
-{{- if or .Values.config.spgwc.cpComm.nodePort.enabled .Values.config.spgwc.s11.nodePort.enabled }}
+{{- if or .Values.config.spgwc.s11.nodePort.enabled .Values.config.spgwc.n4.nodePort.enabled .Values.config.spgwc.prometheus.nodePort.enabled .Values.config.spgwc.rest.nodePort.enabled }}
 ---
 apiVersion: v1
 kind: Service
@@ -69,28 +53,29 @@
   selector:
 {{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
   ports:
+{{- if .Values.config.spgwc.s11.nodePort.enabled }}
+  - name: s11
+    port: {{ .Values.config.spgwc.s11.port }}
+    protocol: UDP
+    nodePort: {{ .Values.config.spgwc.s11.nodePort.port }}
+{{- end }}
+{{- if .Values.config.spgwc.n4.nodePort.enabled }}
+  - name: pfcp
+    port: {{ .Values.config.spgwc.n4.port }}
+    protocol: UDP
+    nodePort: {{ .Values.config.spgwc.n4.nodePort.port }}
+{{- end }}
 {{- if .Values.config.spgwc.prometheus.nodePort.enabled }}
   - name: prometheus-exporter
     port: {{ .Values.config.spgwc.prometheus.port }}
     protocol: TCP
     nodePort: {{ .Values.config.spgwc.prometheus.nodePort.port }}
 {{- end }}
-{{- if .Values.config.spgwc.cpComm.nodePort.enabled }}
-  - name: cp-comm
-    port: {{ .Values.config.spgwc.cpComm.port }}
+{{- if .Values.config.spgwc.rest.nodePort.enabled }}
+  - name: rest
+    port: {{ .Values.config.spgwc.rest.port }}
     protocol: TCP
-{{- end }}
-{{- if .Values.config.spgwc.s11.nodePort.enabled }}
-  - name: s11
-    port: {{ .Values.config.spgwc.s11.port }}
-    protocol: UDP
-{{- end }}
-{{- if .Values.config.spgwc.http.nodePort.enabled }}
-  - name: restendpoint
-    port: {{ .Values.config.spgwc.http.port }}
-    protocol: TCP
-    nodePort: {{ .Values.config.spgwc.http.nodePort.port }}
-{{- end }}
+    nodePort: {{ .Values.config.spgwc.rest.nodePort.port }}
 {{- end }}
 {{- end }}
 {{- end }}
diff --git a/omec/omec-control-plane/templates/statefulset-spgwc.yaml b/omec/omec-control-plane/templates/statefulset-spgwc.yaml
index 707cb71..6269c3f 100644
--- a/omec/omec-control-plane/templates/statefulset-spgwc.yaml
+++ b/omec/omec-control-plane/templates/statefulset-spgwc.yaml
@@ -33,34 +33,8 @@
         {{ .Values.nodeSelectors.spgwc.label }}: {{ .Values.nodeSelectors.spgwc.value }}
     {{- end }}
       serviceAccountName: spgwc
-      initContainers:
-    {{- if .Values.config.mme.deploy }}
-      - name: spgwc-dep-check
-        image: {{ .Values.images.tags.depCheck | quote }}
-        imagePullPolicy: {{ .Values.images.pullPolicy }}
-        securityContext:
-          allowPrivilegeEscalation: false
-          readOnlyRootFilesystem: false
-          runAsUser: 0
-        env:
-          - name: POD_NAME
-            valueFrom:
-              fieldRef:
-                apiVersion: v1
-                fieldPath: metadata.name
-          - name: NAMESPACE
-            valueFrom:
-              fieldRef:
-                apiVersion: v1
-                fieldPath: metadata.namespace
-          - name: PATH
-            value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/
-          - name: COMMAND
-            value: "echo done"
-          - name: DEPENDENCY_POD_JSON
-            value: '[{"labels": {"app": "mme"}, "requireSameNode": false}]'
-    {{- end }}
     {{- if .Values.config.coreDump.enabled }}
+      initContainers:
 {{ tuple "spgwc" . | include "omec-control-plane.coredump_init" | indent 6 }}
     {{- end }}
       containers:
@@ -78,13 +52,13 @@
         livenessProbe:
           httpGet:
             path: /liveness
-            port: {{ .Values.config.spgwc.http.port }}
+            port: {{ .Values.config.spgwc.rest.port }}
           initialDelaySeconds: 10
           periodSeconds: 3
         readinessProbe:
           httpGet:
             path: /readiness
-            port: {{ .Values.config.spgwc.http.port }}
+            port: {{ .Values.config.spgwc.rest.port }}
           initialDelaySeconds: 10
           periodSeconds: 3
 {{- if semverCompare ">=1.16-0" .Capabilities.KubeVersion.GitVersion }}
@@ -92,7 +66,7 @@
           #looks like available only in 1.16 K8s version and above
           httpGet:
             path: /startup
-            port: {{ .Values.config.spgwc.http.port }}
+            port: {{ .Values.config.spgwc.rest.port }}
           failureThreshold: 30
           periodSeconds: 10
 {{- end }}
diff --git a/omec/omec-control-plane/values.yaml b/omec/omec-control-plane/values.yaml
index a4a2e0d..c8ef894 100644
--- a/omec/omec-control-plane/values.yaml
+++ b/omec/omec-control-plane/values.yaml
@@ -249,47 +249,48 @@
     deploy: true
     podAnnotations:
       field.cattle.io/workloadMetrics: '[{"path":"/metrics","port":9089,"schema":"HTTP"}]'
-    pfcp: true
-    apn: internet
-    # ueStaticPool is used only when multiUpfs is not enabled.
-    # In case of multiUpfs, use app_config.cfg to provide static pool per DP.
-    #ueStaticPool: 10.250.255.0/24
-    ueStaticPool: None
-    ueIpPool:
-      ip: 10.250.0.0
-      mask: 255.255.0.0
-    # This address must match to S1U IP address configured in omec-data-plane
-    s1uAddr: 192.168.251.3
+    global:
+      transmitTimerSec: 2
+      periodicTimerSec: 10
+      transmitCount: 5
+      requestTimeoutMilliSec: 5000
+      requestTries: 3
+      cpLogger: 0
     #DNS Server - 3gpp compliant DNS server
-    nameserver: 127.0.0.1
+    dns:
+      cache:
+        concurrent: 25
+        percentage: 80
+        intervalSec: 60
+        queryTimeoutMilliSec: 1000
+        queryTries: 1
+      app:
+        frequencySec: 3
+        filename: "appqueries.json"
+        nameserver: "127.0.0.1"
+      ops:
+        frequencySec: 3
+        filename: "opsqueries.json"
+        nameserver: "127.0.0.1"
+    ueIpPool:
+      ip: "10.250.0.0"
+      mask: "255.255.0.0"
     s11:
+      port: 2123
       nodePort:
         enabled: false
         port: 32123
-      port: 2123
-    # ZMQ mode is used for cp-dp communication when multiple UPFs is set
-    # Otherwise, direct UDP mode is used
-    # Note that enabling NodePort is valid only in direct UDP mode
-    multiUpfs: true
-    cpComm:
+    n4:
+      port: 8805
       nodePort:
         enabled: false
         port: 30021
-      port: 21
-    # dpComm is required only when direct UDP mode is used
-    # When you deploy CP and DP to separate clusters in direct UDP mode, enable nodePort
-    # from both cpComm(omec-control-plane) and dpComm(omec-data-plane) and
-    # set "addr" to remote cluster's entry node IP and
-    # "port" to dpComm.nodePort.port value configured in omec-data-plane.
-    dpComm:
-      addr: spgwu
-      port: 20
     prometheus:
       port: 9089
       nodePort:
         enabled: false
         port: 30084
-    http:
+    rest:
       port: 8080
       nodePort:
         enabled: false
@@ -330,7 +331,7 @@
             mtu: 1460
         user-plane-profiles:
           user-plane1:
-            user-plane: upf-headless
+            user-plane: upf
             qos-tags:
               tag1: BW
             access-tags:
@@ -349,7 +350,7 @@
           intranet-only:
             type: intranet-only
             filter: only_private_network
-          apps-only: 
+          apps-only:
             type: specific-network
             filter: only_apps_network
           specific-app:
@@ -359,21 +360,6 @@
             type: excluding-this-app
             filter: exclude-app-name
     cfgFiles:
-      app_config.cfg: |
-        [GLOBAL]
-        NUM_DP_SELECTION_RULES = 2
-        [DP_SELECTION_RULE_1]
-        DPID = 1
-        DPNAME = onf-menlo
-        MCC = 315
-        MNC = 010
-        TAC = 202
-        [DP_SELECTION_RULE_2]
-        DPID = 2
-        DPNAME = oaisim
-        MCC = 208
-        MNC = 01
-        TAC = 1
       adc_rules.cfg: |
         [GLOBAL]
         NUM_ADC_RULES = 0
@@ -385,7 +371,6 @@
         NUM_PCC_FILTERS = 1
         UL_AMBR_MTR_PROFILE_IDX = 1
         DL_AMBR_MTR_PROFILE_IDX = 2
-
         [PCC_FILTER_1]
         RULE_NAME = DefaultRule
         RATING_GROUP = 9
@@ -408,7 +393,6 @@
       sdf_rules.cfg: |
         [GLOBAL]
         NUM_SDF_FILTERS = 1
-
         [SDF_FILTER_1]
         DIRECTION = downlink_only
         IPV4_REMOTE = 13.2.1.113