Start PCRF pod.

Change-Id: I42e1b62698faba0d8bf3e01dd1f78fd5018de1d9
diff --git a/omec/omec-control-plane/Chart.yaml b/omec/omec-control-plane/Chart.yaml
index 37548ae..0948462 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.5.1
+version: 0.6.1
diff --git a/omec/omec-control-plane/templates/bin/_pcrf-bootstrap.sh.tpl b/omec/omec-control-plane/templates/bin/_pcrf-bootstrap.sh.tpl
new file mode 100644
index 0000000..4afc210
--- /dev/null
+++ b/omec/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/omec-control-plane/templates/bin/_pcrf-run.sh.tpl b/omec/omec-control-plane/templates/bin/_pcrf-run.sh.tpl
new file mode 100644
index 0000000..72050cd
--- /dev/null
+++ b/omec/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} $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/omec-control-plane/templates/bin/_spgwc-run.sh.tpl b/omec/omec-control-plane/templates/bin/_spgwc-run.sh.tpl
index 0a5b680..1528dc2 100644
--- a/omec/omec-control-plane/templates/bin/_spgwc-run.sh.tpl
+++ b/omec/omec-control-plane/templates/bin/_spgwc-run.sh.tpl
@@ -4,21 +4,48 @@
 #
 # SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
 
+APPLICATION=$1
 set -xe
 
-{{- if .Values.config.coreDump.enabled }}
-cp /bin/ngic_controlplane /tmp/coredump/
-{{- end }}
-
 mkdir -p /opt/cp/config
 cd /opt/cp/config
-cp /etc/cp/config/{*.cfg,*.json} .
+cp /etc/cp/config/{*.cfg,*.json,*.conf,*.sh} .
 
-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"
+case $APPLICATION in
+    "ngic_controlplane")
+      echo "Starting ngic controlplane app"
+      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"
+      cat /opt/cp/config/subscriber_mapping.json
+      {{- if .Values.config.coreDump.enabled }}
+      cp /bin/ngic_controlplane /tmp/coredump/
+      {{- end }}
 
-cat /opt/cp/config/subscriber_mapping.json
-ngic_controlplane $EAL_ARGS -- -f /etc/cp/config/
+      ngic_controlplane $EAL_ARGS -- -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
+    
+
+
diff --git a/omec/omec-control-plane/templates/configmap-pcrf.yaml b/omec/omec-control-plane/templates/configmap-pcrf.yaml
new file mode 100644
index 0000000..e4177a1
--- /dev/null
+++ b/omec/omec-control-plane/templates/configmap-pcrf.yaml
@@ -0,0 +1,107 @@
+{{/*
+# Copyright 2020-present Open Networking Foundation
+
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+Default values for mcord-vepc-helm.
+This is a YAML-formatted file.
+Declare variables to be passed into your templates.
+*/}}
+
+{{- if .Values.config.pcrf.deploy }}
+{{- $pcrfJson := index .Values.config.pcrf.cfgFiles "pcrf.json" }}
+{{- $pcrfJsonCommon := index $pcrfJson "common" }}
+{{- $pcrfJsonHss := index $pcrfJson "pcrf" }}
+
+{{- $_ := .Values.config.pcrf.prometheus.port | set $pcrfJsonCommon "prom_port" -}}
+{{- if not (hasKey $pcrfJsonCommon "originhost") -}}
+{{- $_ := tuple "pcrf" "identity" . | include "omec-control-plane.diameter_endpoint" | set $pcrfJsonCommon "originhost" -}}
+{{- end }}
+{{- if not (hasKey $pcrfJsonCommon "originrealm") -}}
+{{- $_ := tuple "pcrf" "realm" . | include "omec-control-plane.diameter_endpoint" | set $pcrfJsonCommon "originrealm" -}}
+{{- end }}
+{{- if not (hasKey $pcrfJsonHss "casssrv") -}}
+{{- $_ := .Values.cassandra.fullnameOverride | set $pcrfJsonHss "casssrv" -}}
+{{- end }}
+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: pcrf
+  labels:
+{{ tuple "pcrf" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+data:
+  acl.conf: |
+  {{- if hasKey .Values.config.pcrf.acl "oldTls" }}
+    ALLOW_OLD_TLS {{ .Values.config.pcrf.acl.oldTls }}
+  {{- end }}
+  {{- if hasKey .Values.config.pcrf.acl "ipSec" }}
+    ALLOW_IPSEC {{ .Values.config.pcrf.acl.ipSec }}
+  {{- end }}
+  pcrf.conf: |
+    Identity = {{ tuple "pcrf" "identity" . | include "omec-control-plane.diameter_endpoint" | quote }};
+    Realm = {{ tuple "pcrf" "realm" . | include "omec-control-plane.diameter_endpoint" | quote }};
+    TLS_Cred = "/opt/c3po/pcrf/conf/{{ tuple "pcrf" "host" . | include "omec-control-plane.diameter_endpoint" }}.cert.pem",
+               "/opt/c3po/pcrf/conf/{{ tuple "pcrf" "host" . | include "omec-control-plane.diameter_endpoint" }}.key.pem";
+    TLS_CA = "/opt/c3po/pcrf/conf/cacert.pem";
+    No_SCTP;
+    Prefer_TCP;
+    No_IPv6;
+    SCTP_streams = 3;
+    NoRelay;
+    AppServThreads = 4;
+    Port = 3868;
+    SecPort = 5868;
+    LoadExtension = "/usr/local/lib/freeDiameter/acl_wl.fdx" : "/opt/c3po/pcrf/conf/acl.conf";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_3gpp2_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_draftload_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_etsi283034_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc4004_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc4006bis_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc4072_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc4590_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc5447_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc5580_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc5777_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc5778_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc6734_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc6942_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc7155_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc7683_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc7944_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29061_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29128_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29154_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29173_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29212_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29214_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29215_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29217_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29229_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29272_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29273_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29329_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29336_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29337_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29338_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29343_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29344_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29345_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29368_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29468_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts32299_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_CreditControl.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_Gx.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_NAS.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_Rx.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_Sd.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_St.fdx";
+  pcrf-run.sh: |
+{{ tuple "bin/_pcrf-run.sh.tpl" . | include "omec-control-plane.template" | indent 4 }}
+  pcrf-bootstrap.sh: |
+{{ tuple "bin/_pcrf-bootstrap.sh.tpl" . | include "omec-control-plane.template" | indent 4 }}
+{{- range $key, $value := .Values.config.pcrf.cfgFiles }}
+  {{ $key }}: |-
+{{ toPrettyJson $value | indent 4 }}
+{{- end }}
+{{- end }}
diff --git a/omec/omec-control-plane/templates/configmap-spgwc.yaml b/omec/omec-control-plane/templates/configmap-spgwc.yaml
index 2ebbe95..dea3c0a 100644
--- a/omec/omec-control-plane/templates/configmap-spgwc.yaml
+++ b/omec/omec-control-plane/templates/configmap-spgwc.yaml
@@ -5,6 +5,17 @@
 */}}
 
 {{- if .Values.config.spgwc.deploy }}
+{{- $configJson := index .Values.config.spgwc.jsonCfgFiles "config.json" }}
+{{- $configJsonSpgwc := index $configJson "spgwc" }}
+{{- $configJsonGx := index $configJson "gx" }}
+
+{{- if not (hasKey $configJsonGx "host") -}}
+{{- $_ := tuple "pcrf" "identity" . | include "omec-control-plane.diameter_endpoint" | set $configJsonGx "host" -}}
+{{- end }}
+{{- if not (hasKey $configJsonGx "realm") -}}
+{{- $_ := tuple "pcrf" "realm" . | include "omec-control-plane.diameter_endpoint" | set $configJsonGx "realm" -}}
+{{- end }}
+
 ---
 apiVersion: v1
 kind: ConfigMap
@@ -16,7 +27,7 @@
   cp.cfg: |
     [GLOBAL]
     CP_TYPE = 03
-    GX_CONFIG = 0
+    GX_CONFIG = {{ .Values.config.spgwc.global.gx_config }}
     S5S8_PORT = 2123
     UPF_PFCP_PORT = 8805
     S11_PORT = {{ .Values.config.spgwc.s11.port }}
@@ -47,12 +58,62 @@
     [IP_POOL_CONFIG]
     IP_POOL_IP= {{.Values.config.spgwc.ueIpPool.ip }}
     IP_POOL_MASK= {{ .Values.config.spgwc.ueIpPool.mask }}
+  gx.conf: |
+    Identity = {{ tuple "spgwc" "identity" . | include "omec-control-plane.diameter_endpoint" | quote }};
+    Realm = {{ tuple "spgwc" "realm" . | include "omec-control-plane.diameter_endpoint" | quote }};
+    TLS_Cred = "config/{{ tuple "spgwc" "host" . | include "omec-control-plane.diameter_endpoint" }}.cert.pem",
+               "config/{{ tuple "spgwc" "host" . | include "omec-control-plane.diameter_endpoint" }}.key.pem";
+    TLS_CA = "config/cacert.pem";
+    AppServThreads = 40;
+    SCTP_streams = 3;
+    NoRelay;
+    No_IPv6;
+    #Port = 3868;
+    #SecPort = 3869;
+
+    ConnectPeer = {{ index $configJsonGx "host" | quote }} { No_TLS; port = 3868; };
+
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_3gpp2_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_draftload_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_etsi283034_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc4004_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc4006bis_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc4072_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc4590_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc5447_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc5580_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc5777_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc5778_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc6734_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc6942_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc7155_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc7683_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc7944_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29061_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29128_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29154_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29173_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29212_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29214_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29215_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29217_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29229_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29272_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29273_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29329_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29336_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29337_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29338_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29343_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29344_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29345_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29368_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29468_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_ts32299_avps.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_CreditControl.fdx";
+    LoadExtension = "/usr/local/lib/freeDiameter/dict_Gx.fdx";
   spgwc-run.sh: |
 {{ tuple "bin/_spgwc-run.sh.tpl" . | include "omec-control-plane.template" | indent 4 }}
-{{- range $key, $value := .Values.config.spgwc.cfgFiles }}
-  {{ $key }}: |-
-{{ $value | indent 4 }}
-{{- end }}
 {{- range $key, $value := .Values.config.spgwc.jsonCfgFiles }}
   {{ $key }}: |-
 {{ toPrettyJson $value | indent 4 }}
diff --git a/omec/omec-control-plane/templates/service-pcrf.yaml b/omec/omec-control-plane/templates/service-pcrf.yaml
new file mode 100644
index 0000000..d423cd9
--- /dev/null
+++ b/omec/omec-control-plane/templates/service-pcrf.yaml
@@ -0,0 +1,66 @@
+{{/*
+# Copyright 2020-present Open Networking Foundation
+
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+*/}}
+
+{{- if .Values.config.pcrf.deploy }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: pcrf
+  labels:
+{{ tuple "pcrf" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+spec:
+  selector:
+{{ tuple "pcrf" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+  ports:
+  - name: gx
+    port: 3868
+    protocol: TCP
+  - name: prometheus-exporter
+    port: {{ .Values.config.pcrf.prometheus.port }}
+    protocol: TCP
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: pcrf-headless
+  labels:
+{{ tuple "pcrf" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+spec:
+  selector:
+{{ tuple "pcrf" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+  clusterIP: None
+  ports:
+  - name: gx
+    port: 3868
+    protocol: TCP
+---
+{{- if or (.Values.config.pcrf.prometheus.nodePort.enabled) (.Values.config.pcrf.gx.nodePort.enabled) }}
+apiVersion: v1
+kind: Service
+metadata:
+  name: pcrf-external
+  labels:
+{{ tuple "pcrf" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+spec:
+  selector:
+{{ tuple "pcrf" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+  type: NodePort
+  ports:
+  {{- if .Values.config.pcrf.prometheus.nodePort.enabled }}
+    - name: prometheus-exporter
+      port: {{ .Values.config.pcrf.prometheus.port }}
+      protocol: TCP
+      nodePort: {{ .Values.config.pcrf.prometheus.nodePort.port }}
+  {{- end }}
+  {{- if .Values.config.pcrf.gx.nodePort.enabled }}
+  - name: gx
+    port: 3868
+    protocol: TCP
+    nodePort: {{ .Values.config.pcrf.gx.nodePort.port }}
+  {{- end }}
+{{- end }}
+{{- end }}
diff --git a/omec/omec-control-plane/templates/statefulset-pcrf.yaml b/omec/omec-control-plane/templates/statefulset-pcrf.yaml
new file mode 100644
index 0000000..fe6c73e
--- /dev/null
+++ b/omec/omec-control-plane/templates/statefulset-pcrf.yaml
@@ -0,0 +1,95 @@
+{{/*
+# Copyright 2020-present Open Networking Foundation
+
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+Default values for mcord-vepc-helm.
+This is a YAML-formatted file.
+Declare variables to be passed into your templates.
+*/}}
+
+{{- if .Values.config.pcrf.deploy }}
+{{ tuple "pcrf" . | include "omec-control-plane.service_account" }}
+---
+apiVersion: apps/v1
+kind: StatefulSet
+metadata:
+  name: pcrf
+  labels:
+{{ tuple "pcrf" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+spec:
+  replicas: 1
+  serviceName: pcrf-headless
+  selector:
+    matchLabels:
+{{ tuple "pcrf" . | include "omec-control-plane.metadata_labels" | indent 6 }}
+  template:
+    metadata:
+      labels:
+{{ tuple "pcrf" . | include "omec-control-plane.metadata_labels" | indent 8 }}
+    spec:
+    {{- if .Values.nodeSelectors.enabled }}
+      nodeSelector:
+        {{ .Values.nodeSelectors.pcrf.label }}: {{ .Values.nodeSelectors.pcrf.value }}
+    {{- end }}
+    {{- if .Values.images.credentials }}
+      imagePullSecrets:
+        - name: {{ .Release.Name }}.registry
+    {{- end }}
+      serviceAccountName: pcrf
+      initContainers:
+      - name: pcrf-bootstrap
+        image: {{ .Values.images.tags.pcrfdb }}
+        imagePullPolicy: {{ .Values.images.pullPolicy }}
+        command: ["/opt/c3po/pcrf/pcrf-bootstrap.sh"]
+        volumeMounts:
+        - name: pcrf-script
+          mountPath: /opt/c3po/pcrf/pcrf-bootstrap.sh
+          subPath: pcrf-bootstrap.sh
+    {{- if .Values.config.coreDump.enabled }}
+{{ tuple "pcrf" . | include "omec-control-plane.coredump_init" | indent 6 }}
+    {{- end }}
+      containers:
+      - name: pcrf
+        image: {{ .Values.images.tags.pcrf }}
+        imagePullPolicy: {{ .Values.images.pullPolicy }}
+      {{- if .Values.config.coreDump.enabled }}
+        securityContext:
+          privileged: true
+          runAsUser: 0
+      {{- end }}
+        stdin: true
+        tty: true
+        command: ["bash", "-c", "/opt/c3po/pcrf/pcrf-run.sh"]
+      {{- if .Values.resources.enabled }}
+        resources:
+{{ toYaml .Values.resources.pcrf | indent 10 }}
+      {{- end }}
+        volumeMounts:
+        - name: pcrf-script
+          mountPath: /opt/c3po/pcrf/pcrf-run.sh
+          subPath: pcrf-run.sh
+        - name: pcrf-config
+          mountPath: /etc/pcrf/conf
+      {{- if .Values.config.coreDump.enabled }}
+        - name: coredump
+          mountPath: /tmp/coredump
+      {{- end }}
+      volumes:
+      - name: pcrf-script
+        configMap:
+          name: pcrf
+          defaultMode: 493
+      - name: pcrf-config
+        configMap:
+          name: pcrf
+          defaultMode: 420
+    {{- if .Values.config.coreDump.enabled }}
+      - name: host-rootfs
+        hostPath:
+          path: /
+      - name: coredump
+        hostPath:
+          path: {{ .Values.config.coreDump.path }}
+    {{- end }}
+{{- end }}
diff --git a/omec/omec-control-plane/templates/statefulset-spgwc.yaml b/omec/omec-control-plane/templates/statefulset-spgwc.yaml
index 91fe84f..3a387de 100644
--- a/omec/omec-control-plane/templates/statefulset-spgwc.yaml
+++ b/omec/omec-control-plane/templates/statefulset-spgwc.yaml
@@ -52,7 +52,9 @@
       {{- end }}
         stdin: true
         tty: true
-        command: ["/opt/cp/scripts/spgwc-run.sh"]
+        command: ["bash", "-xc"]
+        args: 
+        - /opt/cp/scripts/spgwc-run.sh ngic_controlplane
         livenessProbe:
           httpGet:
             path: /liveness
@@ -95,6 +97,49 @@
           subPath: spgwc-run.sh
         - name: cp-config
           mountPath: /etc/cp/config
+        - name: shared-app
+          mountPath: /tmp
+      {{- if .Values.config.coreDump.enabled }}
+        - name: coredump
+          mountPath: /tmp/coredump
+      {{- end }}
+
+      - name: gx-app
+        image: {{ .Values.images.tags.spgwc }}
+        imagePullPolicy: {{ .Values.images.pullPolicy }}
+      {{- if .Values.config.coreDump.enabled }}
+        securityContext:
+          privileged: true
+          runAsUser: 0
+      {{- end }}
+        stdin: true
+        tty: true
+        command: ["bash", "-xc"]
+        args:
+        - /opt/cp/scripts/spgwc-run.sh gx-app
+        env:
+        - name: MEM_LIMIT
+          valueFrom:
+            resourceFieldRef:
+              containerName: spgwc
+              resource: limits.memory
+              divisor: 1Mi
+        - name: POD_IP
+          valueFrom:
+            fieldRef:
+              fieldPath: status.podIP
+      {{- if .Values.resources.enabled }}
+        resources:
+{{ toYaml .Values.resources.spgwc | indent 10 }}
+      {{- end }}
+        volumeMounts:
+        - name: cp-script
+          mountPath: /opt/cp/scripts/spgwc-run.sh
+          subPath: spgwc-run.sh
+        - name: cp-config
+          mountPath: /etc/cp/config
+        - name: shared-app
+          mountPath: /tmp
       {{- if .Values.config.coreDump.enabled }}
         - name: coredump
           mountPath: /tmp/coredump
@@ -108,10 +153,12 @@
         configMap:
           name: spgwc
           defaultMode: 420
-    {{- if .Values.config.coreDump.enabled }}
+      - name: shared-app
+        emptyDir: {}
       - name: host-rootfs
         hostPath:
           path: /
+    {{- if .Values.config.coreDump.enabled }}
       - name: coredump
         hostPath:
           path: {{ .Values.config.coreDump.path }}
diff --git a/omec/omec-control-plane/values.yaml b/omec/omec-control-plane/values.yaml
index 13b0a33..8bbf289 100644
--- a/omec/omec-control-plane/values.yaml
+++ b/omec/omec-control-plane/values.yaml
@@ -11,6 +11,8 @@
     hss: docker.io/omecproject/c3po-hss:master-latest
     mme: docker.io/omecproject/nucleus:master-latest
     spgwc: docker.io/omecproject/spgw:master-latest
+    pcrf: omecproject/c3po-pcrf:pcrf-latest
+    pcrfdb: omecproject/c3po-pcrfdb:pcrf-latest
     depCheck: quay.io/stackanetes/kubernetes-entrypoint:v0.3.1
   pullPolicy: IfNotPresent
   credentials: {}
@@ -24,6 +26,9 @@
   hss:
     label: omec-cp
     value: enabled
+  pcrf:
+    label: omec-cp
+    value: enabled
   mme:
     label: omec-cp
     value: enabled
@@ -33,6 +38,13 @@
 
 resources:
   enabled: true
+  pcrf:
+    requests:
+      cpu: 2
+      memory: 1Gi
+    limits:
+      cpu: 2
+      memory: 1Gi
   hss:
     requests:
       cpu: 2
@@ -84,8 +96,95 @@
 config:
   clusterDomain: cluster.local
   coreDump:
-    enabled: false
+    enabled: true
     path: /tmp/coredump
+  pcrf:
+    deploy: true
+    pcrfdb: cassandra
+    gx:
+      nodePort:
+        enabled: false
+        port: 33868
+    prometheus:
+      port: 9089
+      nodePort:
+        enabled: false
+        port: 30086
+    # Provide the peer whitelist extension
+    # The peer name must be a fqdn. We allow also a special "*" character as the
+    # first label of the fqdn, to allow all fqdn with the same domain name.
+    # Example: *.example.net will allow host1.example.net and host2.example.net
+    acl:
+      oldTls: "*.cluster.local"
+      #ipSec:
+    bootstrap:
+      enabled: false
+    # See https://github.com/omec-project/c3po for details of config options
+    cfgFiles:
+      pcrf.json:
+        common:
+          fdcfg: conf/pcrf.conf
+          # Origin host and realm will be set automatically if unset
+          #originhost: ""
+          #originrealm: ""
+        pcrf:
+          gtwhost: "*"
+          gtwport: 9080
+          restport: 9081
+          ossport: 9082
+          # casssrv will be set to cassandra in the same cluster if unset
+          #casssrv: ""
+          casskeyspace: vpcrf
+          casshost: "cassandra"
+          cassusr: root
+          casspwd: root
+          cassdb: vpcrf
+          casscoreconnections: 2
+          cassmaxconnections: 8
+          cassioqueuesize: 32768
+          cassiothreads: 2
+          randv: true
+          optkey: "63bfa50ee6523365ff14c1f45f88737d"
+          reloadkey: false
+          logsize: 20
+          lognumber: 5
+          logname: logs/pcrf.log
+          logqsize: 8192
+          statlogsize: 20
+          statlognumber: 5
+          statlogname: logs/pcrf_stat.log
+          auditlogsize: 20
+          auditlognumber: 5
+          auditlogname: logs/pcrf_audit.log
+          statfreq: 2000
+          numworkers: 4
+          concurrent: 10
+          ossfile: conf/oss.json
+          verifyroamingsubscribers: false
+      oss.json:
+        option:
+          id: url
+          type: string
+        services:
+          - id: logger
+            commands:
+              - id: describe_loggers
+              - id: set_logger_level
+                options:
+                  - id: name
+                    type: string
+                  - id: level
+                    type: integer
+          - id: stats
+            commands:
+              - id: describe_stats_frequency
+              - id: describe_stats_live
+              - id: set_stats_frequency
+                options:
+                  - id: frequency
+                    type: integer
+
+
   hss:
     deploy: true
     podAnnotations:
@@ -193,6 +292,7 @@
                 options:
                   - id: frequency
                     type: integer
+
   mme:
     deploy: true
     podAnnotations:
@@ -233,6 +333,8 @@
             plmn2: "mcc=208,mnc=01"
           apnlist:
             internet: "spgwc"
+          feature_list:
+            dcnr_support: "disabled"
           security:
             #int_alg_list: "[EIA0]"
             int_alg_list: "[EIA1, EIA2, EIA0]"
@@ -261,6 +363,7 @@
       requestTimeoutMilliSec: 5000
       requestTries: 3
       cpLogger: 0
+      gx_config: 0
     #DNS Server - 3gpp compliant DNS server
     dns:
       cache:
@@ -301,6 +404,12 @@
         enabled: false
         port: 30080
     jsonCfgFiles:
+      config.json:
+        gx:
+          host_type: freediameter
+          # host and realm will be set dynamically if unset
+          #host:
+          #realm:
       subscriber_mapping.json:
         subscriber-selection-rules:
           - priority: 5