COMAC-168,COMAC-171 Assign static IP to S1U and SGI iface on SPGWU

SPGWC requires S1U address of SPGWU in its configuration. When they are
deployed in a separate cluster, SPGWC cannot consult K8S for the IP
address like it is doing now. This is a temporary fix until we add an
ability to support multiple instances of SPGWU and load balancer for them.
Also, rename/restructued network related values in omec-data-plane/values.yaml
and use the values directly from configmap instead of passing them as an
environment variable.

Change-Id: Ib02017408c1671e9a003b0f6dc77e4b4d5dad070
diff --git a/omec/omec-data-plane/Chart.yaml b/omec/omec-data-plane/Chart.yaml
index 2f8d0e1..b1480f3 100644
--- a/omec/omec-data-plane/Chart.yaml
+++ b/omec/omec-data-plane/Chart.yaml
@@ -18,4 +18,4 @@
 appVersion: "1.0"
 description: OMEC data plane services
 name: omec-data-plane
-version: 0.1.0
+version: 0.1.1
diff --git a/omec/omec-data-plane/templates/bin/_spgwu-run.sh.tpl b/omec/omec-data-plane/templates/bin/_spgwu-run.sh.tpl
index 9582e14..9c185c0 100644
--- a/omec/omec-data-plane/templates/bin/_spgwu-run.sh.tpl
+++ b/omec/omec-data-plane/templates/bin/_spgwu-run.sh.tpl
@@ -22,8 +22,6 @@
 cd $RUN_DIR/config
 cp /etc/dp/config/{cdr.cfg,dp_config.cfg,interface.cfg} .
 
-sed -i "s/CP_ADDR/$CP_ADDR/g" interface.cfg
-sed -i "s/CP_PORT/$CP_PORT/g" interface.cfg
 sed -i "s/DP_ADDR/$DP_ADDR/g" interface.cfg
 
 source dp_config.cfg
diff --git a/omec/omec-data-plane/templates/bin/_spgwu-setup-af-iface.sh.tpl b/omec/omec-data-plane/templates/bin/_spgwu-setup-af-iface.sh.tpl
index ad8eded..714d79c 100644
--- a/omec/omec-data-plane/templates/bin/_spgwu-setup-af-iface.sh.tpl
+++ b/omec/omec-data-plane/templates/bin/_spgwu-setup-af-iface.sh.tpl
@@ -17,8 +17,8 @@
 
 set -ex
 
-UL_IFACE="{{- .Values.config.spgwu.s1uAfDev -}}"
-DL_IFACE="{{- .Values.config.spgwu.sgiAfDev -}}"
+UL_IFACE="{{ .Values.config.spgwu.s1u.device }}-veth"
+DL_IFACE="{{ .Values.config.spgwu.sgi.device }}-veth"
 
 if ! ip link show $UL_IFACE; then
     s1u_mac=$(ip addr show dev s1u-net | awk '$1=="link/ether"{print $2}')
diff --git a/omec/omec-data-plane/templates/configmap-spgwu.yaml b/omec/omec-data-plane/templates/configmap-spgwu.yaml
index 2db74f3..c2698ae 100644
--- a/omec/omec-data-plane/templates/configmap-spgwu.yaml
+++ b/omec/omec-data-plane/templates/configmap-spgwu.yaml
@@ -26,18 +26,30 @@
     if [ ! -d "/dev/hugepages" ]; then
         MEMORY="--no-huge -m $((MEM_LIMIT-1024))"
     fi
-
     CORES="-c $(taskset -p $$ | awk '{print $NF}')"
-    EAL_ARGS="${CORES} ${MEMORY} ${DEVICES}"
+    EAL_ARGS="${CORES} ${MEMORY} {{ .Values.config.spgwu.devices }}"
 
-    SPGW_CFG="--spgw_cfg 03"
+    {{- if .Values.config.sriov.enabled }}
+    S1U_DEVNAME={{ .Values.config.spgwu.s1u.device }}
+    {{- else }}
+    S1U_DEVNAME={{ .Values.config.spgwu.s1u.device }}-veth
+    {{- end }}
+    {{- if .Values.config.sriov.enabled }}
+    SGI_DEVNAME={{ .Values.config.spgwu.sgi.device }}
+    {{- else }}
+    SGI_DEVNAME={{ .Values.config.spgwu.sgi.device }}-veth
+    {{- end }}
+
     S1U_IP=$(ip -4 addr show dev ${S1U_DEVNAME} | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
     SGI_IP=$(ip -4 addr show dev ${SGI_DEVNAME} | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
     S1U_MAC=$(ip addr show dev ${S1U_DEVNAME} | awk '$1=="link/ether"{print $2}')
     SGI_MAC=$(ip addr show dev ${SGI_DEVNAME} | awk '$1=="link/ether"{print $2}')
+
     S1U="--s1u_ip ${S1U_IP} --s1u_mac ${S1U_MAC} --ul_iface ${S1U_DEVNAME}"
-    SGI="--sgi_ip ${SGI_IP} --sgi_mac ${SGI_MAC} --dl_iface ${SGI_DEVNAME} --sgi_gw_ip ${RTR_SGI_IP} --sgi_mask ${SGI_MASK}"
+    SGI="--sgi_ip ${SGI_IP} --sgi_mac ${SGI_MAC} --dl_iface ${SGI_DEVNAME} --sgi_gw_ip {{ .Values.networks.sgi.gateway }} --sgi_mask {{ .Values.networks.sgi.mask }}"
     MISC="--log 1"
+    SPGW_CFG="--spgw_cfg 03"
+
     APP_ARGS="${S1U} ${SGI} ${MISC} ${SPGW_CFG}"
   cdr.cfg: |
     CDR_PATH=./cdr
@@ -46,8 +58,8 @@
     [0]
     dp_comm_ip = DP_ADDR
     dp_comm_port = 20
-    cp_comm_ip = CP_ADDR
-    cp_comm_port = CP_PORT
+    cp_comm_ip = {{ .Values.config.spgwu.spgwc.addr }}
+    cp_comm_port = {{ .Values.config.spgwu.spgwc.port }}
 {{- 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/daemonset-sriov-dp.yaml b/omec/omec-data-plane/templates/daemonset-sriov-dp.yaml
index 9c3ceea..ad22876 100644
--- a/omec/omec-data-plane/templates/daemonset-sriov-dp.yaml
+++ b/omec/omec-data-plane/templates/daemonset-sriov-dp.yaml
@@ -38,7 +38,7 @@
         imagePullPolicy: {{ .Values.images.pullPolicy }}
         command: [ "bash", "-c" ]
         args:
-        - cp /tmp/cni/bin/{sriov,vfioveth,centralip,jq} /host/opt/cni/bin/
+        - cp /tmp/cni/bin/{sriov,vfioveth,static} /host/opt/cni/bin/
         volumeMounts:
         - name: cni-bin
           mountPath: /host/opt/cni/bin
diff --git a/omec/omec-data-plane/templates/networks.yaml b/omec/omec-data-plane/templates/networks.yaml
index a82e3ae..c2e4a95 100644
--- a/omec/omec-data-plane/templates/networks.yaml
+++ b/omec/omec-data-plane/templates/networks.yaml
@@ -28,15 +28,7 @@
   config: '{
     "type": {{ .Values.networks.cniPlugin | quote }},
     "ipam": {
-        "type": {{ .Values.networks.ipam | quote }},
-    {{- if eq .Values.networks.ipam "host-local" }}
-        "subnet": {{ .Values.networks.s1u.subnet | quote }},
-        "gateway": {{ .Values.networks.s1u.gateway | quote }}
-    {{- else if eq .Values.networks.ipam "centralip" }}
-        "ipType": "cluster",
-        "network": {{ .Values.networks.s1u.subnet | quote }},
-        "etcdURL": {{ .Values.networks.etcdurl | quote }}
-    {{- end }}
+        "type": {{ .Values.networks.ipam | quote }}
     }
   }'
 ---
@@ -52,14 +44,6 @@
   config: '{
     "type": {{ .Values.networks.cniPlugin | quote }},
     "ipam": {
-        "type": {{ .Values.networks.ipam | quote }},
-    {{- if eq .Values.networks.ipam "host-local" }}
-        "subnet": {{ .Values.networks.sgi.subnet | quote }},
-        "gateway": {{ .Values.networks.sgi.gateway | quote }}
-    {{- else if eq .Values.networks.ipam "centralip" }}
-        "ipType": "cluster",
-        "network": {{ .Values.networks.sgi.subnet | quote }},
-        "etcdURL": {{ .Values.networks.etcdurl | quote }}
-    {{- end }}
+        "type": {{ .Values.networks.ipam | quote }}
     }
   }'
diff --git a/omec/omec-data-plane/templates/statefulset-spgwu.yaml b/omec/omec-data-plane/templates/statefulset-spgwu.yaml
index b1a2c1a..21e8d57 100644
--- a/omec/omec-data-plane/templates/statefulset-spgwu.yaml
+++ b/omec/omec-data-plane/templates/statefulset-spgwu.yaml
@@ -33,8 +33,16 @@
 {{ tuple "spgwu" . | include "omec-data-plane.metadata_labels" | indent 8 }}
       annotations:
         k8s.v1.cni.cncf.io/networks: '[
-                { "name": "s1u-net", "interface": "s1u-net" },
-                { "name": "sgi-net", "interface": "sgi-net" }
+          {
+            "name": "s1u-net",
+            "interface": {{ .Values.config.spgwu.s1u.device | quote }},
+            "ips": {{ .Values.config.spgwu.s1u.ip | quote }}
+          },
+          {
+            "name": "sgi-net",
+            "interface": {{ .Values.config.spgwu.sgi.device | quote }},
+            "ips": {{ .Values.config.spgwu.sgi.ip | quote }}
+          }
         ]'
     spec:
     {{- if .Values.nodeSelectors.enabled }}
@@ -80,32 +88,10 @@
               containerName: spgwu
               resource: limits.memory
               divisor: 1Mi
-        - name: S1U_DEVNAME
-        {{- if .Values.config.sriov.enabled }}
-          value: s1u-net
-        {{- else }}
-          value: {{ .Values.config.spgwu.s1uAfDev | quote }}
-        {{- end }}
-        - name: SGI_DEVNAME
-        {{- if .Values.config.sriov.enabled }}
-          value: sgi-net
-        {{- else }}
-          value: {{ .Values.config.spgwu.sgiAfDev | quote }}
-        {{- end }}
-        - name: DEVICES
-          value: {{ .Values.config.spgwu.devices | quote }}
-        - name: CP_ADDR
-          value: {{ .Values.config.spgwu.spgwc.addr | quote }}
-        - name: CP_PORT
-          value: {{ .Values.config.spgwu.spgwc.port | quote }}
         - name: DP_ADDR
           valueFrom:
             fieldRef:
               fieldPath: status.podIP
-        - name: RTR_SGI_IP
-          value: {{ .Values.config.spgwu.rtrSgiIp | quote }}
-        - name: SGI_MASK
-          value: {{ .Values.config.spgwu.sgiMask | quote }}
         command: ["bash", "-xc"]
         args:
         - ip a;
diff --git a/omec/omec-data-plane/values.yaml b/omec/omec-data-plane/values.yaml
index d21f1cf..60a454b 100644
--- a/omec/omec-data-plane/values.yaml
+++ b/omec/omec-data-plane/values.yaml
@@ -58,25 +58,26 @@
     spgwc:
       addr: spgwc
       port: 21
-    # s1u and sgi interfaces are fixed to "s1u-net" and "sgi-net"
-    # Note that s1uAfDev and sgiAfDev are valid only when sriov is disabled
-    # setup-af-iface.sh script creates additional veth pair with the names here
-    s1uAfDev: s1u-veth
-    sgiAfDev: sgi-veth
-    # set "--no-pci --vdev eth_af_packet0,iface=s1u-net --vdev eth_af_packet1,iface=sgi-net"
+    # Provide the S1U and SGI networks facing device name and IP address
+    s1u:
+      device: s1u-net
+      ip: 119.0.0.3/24
+    sgi:
+      device: sgi-net
+      ip: 13.1.1.3/24
+    # Set "--no-pci --vdev eth_af_packet0,iface=s1u-net --vdev eth_af_packet1,iface=sgi-net"
     # when sriov is disabled
     devices: ""
-    rtrSgiIp: 13.1.1.254
-    sgiMask: 255.255.255.0
 
 networks:
   cniPlugin: vfioveth
-  ipam: centralip
-  # etcdurl is required only when centralip IPAM is used
-  etcdurl: http://localhost:32379
+  # Currently, we do not support dynamic IP allocation
+  ipam: static
   s1u:
     subnet: 119.0.0.0/24
+    mask: 255.255.255.0
     gateway: 119.0.0.254
   sgi:
     subnet: 13.1.1.0/24
+    mask: 255.255.255.0
     gateway: 13.1.1.254