EDGEPOD-60 Add support of multiple UPFs

- Enable configuring multiple UPF mode
- Add support of ZMQ mode when multple UPF enabled
- Change to create three types of services for each application,
  cluster IP, headless, and external

Change-Id: Ic004a4ff7cdc5708d28ce2717677041f71b4d819
diff --git a/omec/omec-control-plane/Chart.yaml b/omec/omec-control-plane/Chart.yaml
index 62d8ca8..30b8654 100644
--- a/omec/omec-control-plane/Chart.yaml
+++ b/omec/omec-control-plane/Chart.yaml
@@ -19,4 +19,4 @@
 name: omec-control-plane
 icon: https://guide.opencord.org/logos/cord.svg
 
-version: 0.1.13
+version: 0.1.14
diff --git a/omec/omec-control-plane/templates/_helpers.tpl b/omec/omec-control-plane/templates/_helpers.tpl
index 53bd471..7427461 100644
--- a/omec/omec-control-plane/templates/_helpers.tpl
+++ b/omec/omec-control-plane/templates/_helpers.tpl
@@ -37,18 +37,18 @@
 {{- end -}}
 
 {{/*
-Return s6a service for Diameter identity, realm, and hostname for a given application.
+Return domain name for Diameter identity, realm, and hostname for a given application.
 */}}
 {{- define "omec-control-plane.diameter_endpoint" -}}
 {{- $service := index . 0 -}}
 {{- $type := index . 1 -}}
 {{- $context := index . 2 -}}
 {{- if eq $type "identity" -}}
-{{- printf "%s-s6a.%s.svc.%s" $service $context.Release.Namespace $context.Values.config.clusterDomain -}}
+{{- printf "%s.%s.svc.%s" $service $context.Release.Namespace $context.Values.config.clusterDomain -}}
 {{- else if eq $type "realm" -}}
 {{- printf "%s.svc.%s" $context.Release.Namespace $context.Values.config.clusterDomain -}}
 {{- else if eq $type "host" -}}
-{{- printf "%s-s6a" $service -}}
+{{- printf "%s" $service -}}
 {{- end -}}
 {{- end -}}
 
diff --git a/omec/omec-control-plane/templates/configmap-spgwc.yaml b/omec/omec-control-plane/templates/configmap-spgwc.yaml
index a331c91..4a049c2 100644
--- a/omec/omec-control-plane/templates/configmap-spgwc.yaml
+++ b/omec/omec-control-plane/templates/configmap-spgwc.yaml
@@ -37,10 +37,18 @@
     APP_ARGS="${MGMT_INFO} ${APN_INFO} ${MISC} ${SPGW_CFG}"
   interface.cfg: |
     [0]
-    dp_comm_ip = {{ .Values.config.spgwc.dpComm.addr }}
-    dp_comm_port = {{ .Values.config.spgwc.dpComm.port }}
+    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-hss.yaml b/omec/omec-control-plane/templates/service-hss.yaml
index dbfccf5..14bfbda 100644
--- a/omec/omec-control-plane/templates/service-hss.yaml
+++ b/omec/omec-control-plane/templates/service-hss.yaml
@@ -18,19 +18,46 @@
 apiVersion: v1
 kind: Service
 metadata:
-  name: hss-s6a
+  name: hss
   labels:
 {{ tuple "hss" . | include "omec-control-plane.metadata_labels" | indent 4 }}
 spec:
   selector:
 {{ tuple "hss" . | include "omec-control-plane.metadata_labels" | indent 4 }}
-{{- if .Values.config.hss.s6a.nodePort.enabled }}
-  type: NodePort
-{{- end }}
   ports:
   - name: s6a
     port: 3868
     protocol: TCP
-  {{- if .Values.config.hss.s6a.nodePort.enabled }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: hss-headless
+  labels:
+{{ tuple "hss" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+spec:
+  selector:
+{{ tuple "hss" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+  clusterIP: None
+  ports:
+  - name: s6a
+    port: 3868
+    protocol: TCP
+{{- if .Values.config.hss.s6a.nodePort.enabled }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: hss-external
+  labels:
+{{ tuple "hss" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+spec:
+  selector:
+{{ tuple "hss" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+  type: NodePort
+  ports:
+  - name: s6a
+    port: 3868
+    protocol: TCP
     nodePort: {{ .Values.config.hss.s6a.nodePort.port }}
-  {{- end }}
+{{- end }}
diff --git a/omec/omec-control-plane/templates/service-mme.yaml b/omec/omec-control-plane/templates/service-mme.yaml
index b8b6a30..7012f84 100644
--- a/omec/omec-control-plane/templates/service-mme.yaml
+++ b/omec/omec-control-plane/templates/service-mme.yaml
@@ -21,54 +21,68 @@
 apiVersion: v1
 kind: Service
 metadata:
-  name: mme-s11
+  name: mme
   labels:
 {{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
 spec:
   selector:
 {{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
-{{- if .Values.config.mme.s11.nodePort.enabled }}
-  type: NodePort
-{{- end }}
+  type: ClusterIP
   ports:
-  - name: s11
-    port: {{ index $configJsonS11 "egtp_default_port" }}
-    protocol: UDP
+    - name: s11
+      port: {{ index $configJsonS11 "egtp_default_port" }}
+      protocol: UDP
+    - name: s6a
+      port: 3868
+      protocol: TCP
+    - name: s1ap
+      port: {{ index $configJsonS1ap "sctp_port" }}
+      protocol: SCTP
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: mme-headless
+  labels:
+{{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+spec:
+  selector:
+{{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+  clusterIP: None
+  ports:
+    - name: s11
+      port: {{ index $configJsonS11 "egtp_default_port" }}
+      protocol: UDP
+    - name: s6a
+      port: 3868
+      protocol: TCP
+    - name: s1ap
+      port: {{ index $configJsonS1ap "sctp_port" }}
+      protocol: SCTP
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: mme-external
+  labels:
+{{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+spec:
+  selector:
+{{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+  type: NodePort
+  ports:
   {{- if .Values.config.mme.s11.nodePort.enabled }}
-    nodePort: {{ .Values.config.mme.s11.nodePort.port }}
+    - name: s11
+      port: {{ index $configJsonS11 "egtp_default_port" }}
+      protocol: UDP
+      nodePort: {{ .Values.config.mme.s11.nodePort.port }}
   {{- end }}
----
-apiVersion: v1
-kind: Service
-metadata:
-  name: mme-s6a
-  labels:
-{{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
-{{- if .Values.config.mme.s6a.nodePort.enabled }}
-  type: NodePort
-{{- end }}
-spec:
-  selector:
-{{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
-  ports:
-  - name: s6a
-    port: 3868
-    protocol: TCP
   {{- if .Values.config.mme.s6a.nodePort.enabled }}
-    nodePort: {{ .Values.config.mme.s6a.nodePort.port }}
+    - name: s6a
+      port: 3868
+      protocol: TCP
+      nodePort: {{ .Values.config.mme.s6a.nodePort.port }}
   {{- end }}
----
-apiVersion: v1
-kind: Service
-metadata:
-  name: mme-s1ap
-  labels:
-{{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
-spec:
-  selector:
-{{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
-  type: NodePort
-  ports:
     - name: s1ap
       port: {{ index $configJsonS1ap "sctp_port" }}
       nodePort: {{ index $configJsonS1ap "sctp_port_external" }}
diff --git a/omec/omec-control-plane/templates/service-spgwc.yaml b/omec/omec-control-plane/templates/service-spgwc.yaml
index b406350..fe1e68c 100644
--- a/omec/omec-control-plane/templates/service-spgwc.yaml
+++ b/omec/omec-control-plane/templates/service-spgwc.yaml
@@ -18,39 +18,69 @@
 apiVersion: v1
 kind: Service
 metadata:
-  name: spgwc-cp-comm
+  name: spgwc
   labels:
 {{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
 spec:
+  type: ClusterIP
   selector:
 {{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
-{{- if .Values.config.spgwc.cpComm.nodePort.enabled }}
-  type: NodePort
-{{- end }}
   ports:
   - name: cp-comm
-    port: 21
+    port: {{ .Values.config.spgwc.cpComm.port }}
+{{- if .Values.config.spgwc.multiUpfs }}
+    protocol: TCP
+{{- else }}
     protocol: UDP
-  {{- if .Values.config.spgwc.cpComm.nodePort.enabled }}
-    nodePort: {{ .Values.config.spgwc.cpComm.nodePort.port }}
-  {{- end }}
+{{- end }}
+  - name: s11
+    port: {{ .Values.config.spgwc.s11.port }}
+    protocol: UDP
 ---
 apiVersion: v1
 kind: Service
 metadata:
-  name: spgwc-s11
+  name: spgwc-headless
   labels:
 {{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
 spec:
+  clusterIP: None
   selector:
 {{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
-{{- if .Values.config.spgwc.s11.nodePort.enabled }}
-  type: NodePort
-{{- end }}
   ports:
-  - name: s11
-    port: 2123
+  - name: cp-comm
+    port: {{ .Values.config.spgwc.cpComm.port }}
+{{- if .Values.config.spgwc.multiUpfs }}
+    protocol: TCP
+{{- else }}
     protocol: UDP
-  {{- if .Values.config.spgwc.s11.nodePort.enabled }}
-    nodePort: {{ .Values.config.spgwc.s11.nodePort.port }}
-  {{- end }}
+{{- 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 }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: spgwc-external
+  labels:
+{{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+spec:
+  type: NodePort
+  selector:
+{{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+  ports:
+{{- if .Values.config.spgwc.cpComm.nodePort.enabled }}
+  - name: cp-comm
+    port: {{ .Values.config.spgwc.cpComm.port }}
+    protocol: TCP
+{{- end }}
+{{- if .Values.config.spgwc.s11.nodePort.enabled }}
+  - name: s11
+    port: {{ .Values.config.spgwc.s11.port }}
+    protocol: UDP
+{{- end }}
+{{- end }}
+{{- end }}
diff --git a/omec/omec-control-plane/templates/statefulset-hss.yaml b/omec/omec-control-plane/templates/statefulset-hss.yaml
index 291205e..93c8721 100644
--- a/omec/omec-control-plane/templates/statefulset-hss.yaml
+++ b/omec/omec-control-plane/templates/statefulset-hss.yaml
@@ -28,6 +28,7 @@
 {{ tuple "hss" . | include "omec-control-plane.metadata_labels" | indent 4 }}
 spec:
   replicas: 1
+  serviceName: hss-headless
   selector:
     matchLabels:
 {{ tuple "hss" . | include "omec-control-plane.metadata_labels" | indent 6 }}
diff --git a/omec/omec-control-plane/templates/statefulset-mme.yaml b/omec/omec-control-plane/templates/statefulset-mme.yaml
index bb8b3c6..ff64007 100644
--- a/omec/omec-control-plane/templates/statefulset-mme.yaml
+++ b/omec/omec-control-plane/templates/statefulset-mme.yaml
@@ -24,6 +24,7 @@
 {{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
 spec:
   replicas: 1
+  serviceName: mme-headless
   selector:
     matchLabels:
 {{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 6 }}
diff --git a/omec/omec-control-plane/templates/statefulset-spgwc.yaml b/omec/omec-control-plane/templates/statefulset-spgwc.yaml
index 9faadca..ebc0cd0 100644
--- a/omec/omec-control-plane/templates/statefulset-spgwc.yaml
+++ b/omec/omec-control-plane/templates/statefulset-spgwc.yaml
@@ -24,6 +24,7 @@
 {{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
 spec:
   replicas: 1
+  serviceName: spgwc-headless
   selector:
     matchLabels:
 {{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 6 }}
diff --git a/omec/omec-control-plane/values.yaml b/omec/omec-control-plane/values.yaml
index 053fb94..de131b3 100644
--- a/omec/omec-control-plane/values.yaml
+++ b/omec/omec-control-plane/values.yaml
@@ -181,7 +181,7 @@
                   - id: frequency
                     type: integer
   mme:
-    spgwAddr: spgwc-s11
+    spgwAddr: spgwc
     s11:
       nodePort:
         enabled: false
@@ -232,16 +232,23 @@
       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:
       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:
-      # IMPORTANT: when you deploy CP and DP to separate clusters, 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.
-      addr: spgwu-dp-comm
+      addr: spgwu
       port: 20
     cfgFiles:
       # See https://github.com/omec-project/ngic-rtc/tree/master/config for details
@@ -278,4 +285,14 @@
         SDF_FILTER_IDX = 99998
       sdf_rules.cfg: |
         [GLOBAL]
-        NUM_SDF_FILTERS = 0
+        NUM_SDF_FILTERS = 1
+
+        [SDF_FILTER_1]
+        DIRECTION = downlink_only
+        IPV4_REMOTE = 13.2.1.113
+        IPV4_REMOTE_MASK = 255.255.255.0
+        PROTOCOL = 17
+        LOCAL_LOW_LIMIT_PORT = 0
+        LOCAL_HIGH_LIMIT_PORT = 65535
+        REMOTE_LOW_LIMIT_PORT = 0
+        REMOTE_HIGH_LIMIT_PORT = 65535
diff --git a/omec/omec-data-plane/Chart.yaml b/omec/omec-data-plane/Chart.yaml
index 21f163a..1510a0b 100644
--- a/omec/omec-data-plane/Chart.yaml
+++ b/omec/omec-data-plane/Chart.yaml
@@ -19,4 +19,4 @@
 name: omec-data-plane
 icon: https://guide.opencord.org/logos/cord.svg
 
-version: 0.1.6
+version: 0.1.7
diff --git a/omec/omec-data-plane/templates/configmap-spgwu.yaml b/omec/omec-data-plane/templates/configmap-spgwu.yaml
index 3a589d0..81319c1 100644
--- a/omec/omec-data-plane/templates/configmap-spgwu.yaml
+++ b/omec/omec-data-plane/templates/configmap-spgwu.yaml
@@ -57,10 +57,20 @@
     MASTER_CDR=./cdr/master.csv
   interface.cfg: |
     [0]
+    zmq_protocol = tcp
     dp_comm_ip = DP_ADDR
     dp_comm_port = 20
+{{- if .Values.config.spgwu.multiUpfs }}
+    cp_nb_ip = {{ .Values.config.spgwu.cpComm.addr }}
+    cp_nb_port = {{ .Values.config.spgwu.cpComm.port }}
     cp_comm_ip = {{ .Values.config.spgwu.cpComm.addr }}
     cp_comm_port = {{ .Values.config.spgwu.cpComm.port }}
+    zmq_dp_ip=127.0.0.1
+    zmq_cp_ip=127.0.0.1
+{{- else }}
+    cp_comm_ip = {{ .Values.config.spgwu.cpComm.addr }}
+    cp_comm_port = {{ .Values.config.spgwu.cpComm.port }}
+{{- end }}
 {{- if not .Values.config.sriov.enabled }}
   setup-af-iface.sh: |
 {{ tuple "bin/_spgwu-setup-af-iface.sh.tpl" . | include "omec-data-plane.template" | indent 4 }}
diff --git a/omec/omec-data-plane/templates/service-spgwu.yaml b/omec/omec-data-plane/templates/service-spgwu.yaml
index 22c212b..6985e22 100644
--- a/omec/omec-data-plane/templates/service-spgwu.yaml
+++ b/omec/omec-data-plane/templates/service-spgwu.yaml
@@ -19,19 +19,54 @@
 apiVersion: v1
 kind: Service
 metadata:
-  name: spgwu-dp-comm
+  name: spgwu
   labels:
 {{ tuple "spgwu" . | include "omec-data-plane.metadata_labels" | indent 4 }}
 spec:
   selector:
 {{ tuple "spgwu" . | include "omec-data-plane.metadata_labels" | indent 4 }}
-{{- if .Values.config.spgwu.dpComm.nodePort.enabled }}
-  type: NodePort
-{{- end }}
   ports:
   - name: dp-comm
-    port: 20
+    port: {{ .Values.config.spgwu.dpComm.port }}
+{{- if .Values.config.spgwu.multiUpfs }}
+    protocol: TCP
+{{- else }}
     protocol: UDP
-  {{- if .Values.config.spgwu.dpComm.nodePort.enabled }}
+{{- end }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: spgwu-headless
+  labels:
+{{ tuple "spgwu" . | include "omec-data-plane.metadata_labels" | indent 4 }}
+spec:
+  clusterIP: None
+  selector:
+{{ tuple "spgwu" . | include "omec-data-plane.metadata_labels" | indent 4 }}
+  ports:
+  - name: dp-comm
+    port: {{ .Values.config.spgwu.dpComm.port }}
+{{- if .Values.config.spgwu.multiUpfs }}
+    protocol: TCP
+{{- else }}
+    protocol: UDP
+{{- end }}
+{{- if and (not .Values.config.spgwu.multiUpfs) .Values.config.spgwu.dpComm.nodePort.enabled }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: spgwu-external
+  labels:
+{{ tuple "spgwu" . | include "omec-data-plane.metadata_labels" | indent 4 }}
+spec:
+  selector:
+{{ tuple "spgwu" . | include "omec-data-plane.metadata_labels" | indent 4 }}
+  type: NodePort
+  ports:
+  - name: dp-comm
+    port: {{ .Values.config.spgwu.dpComm.port }}
+    protocol: UDP
     nodePort: {{ .Values.config.spgwu.dpComm.nodePort.port }}
-  {{- end }}
+{{- end }}
diff --git a/omec/omec-data-plane/templates/statefulset-spgwu.yaml b/omec/omec-data-plane/templates/statefulset-spgwu.yaml
index 11749e7..07f9082 100644
--- a/omec/omec-data-plane/templates/statefulset-spgwu.yaml
+++ b/omec/omec-data-plane/templates/statefulset-spgwu.yaml
@@ -19,6 +19,7 @@
 kind: StatefulSet
 metadata:
   name: spgwu
+  serviceName: spgwu-headless
   labels:
 {{ tuple "spgwu" . | include "omec-data-plane.metadata_labels" | indent 4 }}
 spec:
diff --git a/omec/omec-data-plane/values.yaml b/omec/omec-data-plane/values.yaml
index 78a69dc..0089751 100644
--- a/omec/omec-data-plane/values.yaml
+++ b/omec/omec-data-plane/values.yaml
@@ -48,17 +48,22 @@
     sgi:
       device: sgi-net
       ip: 13.1.1.3/24
+    # Note that zmq is used for cp-dp commmunication when multiple UPFs is set
+    # Otherwise, direct UDP communication is used
+    # TODO: unify cp-dp comm to ZMQ for both multi and single UPF scenario
+    multiUpfs: true
     cpComm:
       # IMPORTANT: when you deploy CP and DP to separate clusters, 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 cpComm.nodePort.port value configured in omec-control-plane.
-      addr: spgwc-cp-comm
+      addr: spgwc
       port: 21
     dpComm:
       nodePort:
         enabled: false
         port: 30020
+      port: 20
     # Set "--no-pci --vdev eth_af_packet0,iface=s1u-net --vdev eth_af_packet1,iface=sgi-net"
     # when sriov is disabled
     devices: ""