Add dbuf and pfcp agent

Change-Id: Iefcdbf1e2f32e0e97ec17abab85941615ba5bac6
diff --git a/dbuf/.helmignore b/dbuf/.helmignore
new file mode 100644
index 0000000..c687fff
--- /dev/null
+++ b/dbuf/.helmignore
@@ -0,0 +1,26 @@
+# Copyright 2021-present Open Networking Foundation
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+# Patterns to ignore when building packages.
+# This supports shell glob matching, relative path matching, and
+# negation (prefixed with !). Only one pattern per line.
+.DS_Store
+# Common VCS dirs
+.git/
+.gitignore
+.bzr/
+.bzrignore
+.hg/
+.hgignore
+.svn/
+# Common backup files
+*.swp
+*.bak
+*.tmp
+*.orig
+*~
+# Various IDEs
+.project
+.idea/
+*.tmproj
+.vscode/
diff --git a/dbuf/Chart.yaml b/dbuf/Chart.yaml
new file mode 100644
index 0000000..042e94e
--- /dev/null
+++ b/dbuf/Chart.yaml
@@ -0,0 +1,26 @@
+# Copyright 2021-present Open Networking Foundation
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+apiVersion: v2
+name: dbuf
+description: A Helm chart deploying DBUF
+
+# A chart can be either an 'application' or a 'library' chart.
+#
+# Application charts are a collection of templates that can be packaged into versioned archives
+# to be deployed.
+#
+# Library charts provide useful utilities or functions for the chart developer. They're included as
+# a dependency of application charts to inject those utilities and functions into the rendering
+# pipeline. Library charts do not define any templates and therefore cannot be deployed.
+type: application
+
+# This is the chart version. This version number should be incremented each time you make changes
+# to the chart and its templates, including the app version.
+# Versions are expected to follow Semantic Versioning (https://semver.org/)
+version: 0.0.1
+
+# This is the version number of the application being deployed. This version number should be
+# incremented each time you make changes to the application. Versions are not expected to
+# follow Semantic Versioning. They should reflect the version the application is using.
+appVersion: 0.0.1
diff --git a/dbuf/templates/NOTES.txt b/dbuf/templates/NOTES.txt
new file mode 100644
index 0000000..55b688c
--- /dev/null
+++ b/dbuf/templates/NOTES.txt
@@ -0,0 +1,10 @@
+{{/*
+Copyright 2020-present Open Networking Foundation
+SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+*/}}
+
+Thank you for installing {{ .Chart.Name }}.
+
+Your release is named {{ .Release.Name }}.
+
+This chart deploys DBUF.
\ No newline at end of file
diff --git a/dbuf/templates/_helpers.tpl b/dbuf/templates/_helpers.tpl
new file mode 100644
index 0000000..b8b672a
--- /dev/null
+++ b/dbuf/templates/_helpers.tpl
@@ -0,0 +1,71 @@
+{{/*
+Copyright 2020-present Open Networking Foundation
+SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+*/}}
+
+{{- define "extraParams" -}}
+{{- join "," . -}}
+{{- end -}}
+
+{{/*
+Expand the name of the chart.
+*/}}
+{{- define "dbuf.name" -}}
+{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
+{{- end }}
+
+{{/*
+Create a default fully qualified app name.
+We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
+If release name contains chart name it will be used as a full name.
+*/}}
+{{- define "dbuf.fullname" -}}
+{{- if .Values.fullnameOverride }}
+{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
+{{- else }}
+{{- $name := default .Chart.Name .Values.nameOverride }}
+{{- if contains $name .Release.Name }}
+{{- .Release.Name | trunc 63 | trimSuffix "-" }}
+{{- else }}
+{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
+{{- end }}
+{{- end }}
+{{- end }}
+
+{{/*
+Create chart name and version as used by the chart label.
+*/}}
+{{- define "dbuf.chart" -}}
+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
+{{- end }}
+
+{{/*
+Common labels
+*/}}
+{{- define "dbuf.labels" -}}
+helm.sh/chart: {{ include "dbuf.chart" . }}
+{{ include "dbuf.selectorLabels" . }}
+{{- if .Chart.AppVersion }}
+app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
+{{- end }}
+app.kubernetes.io/managed-by: {{ .Release.Service }}
+{{- end }}
+
+{{/*
+Selector labels
+*/}}
+{{- define "dbuf.selectorLabels" -}}
+app.kubernetes.io/name: {{ include "dbuf.name" . }}
+app.kubernetes.io/instance: {{ .Release.Name }}
+{{- end }}
+
+{{/*
+Create the name of the service account to use
+*/}}
+{{- define "dbuf.serviceAccountName" -}}
+{{- if .Values.serviceAccount.create }}
+{{- default (include "dbuf.fullname" .) .Values.serviceAccount.name }}
+{{- else }}
+{{- default "default" .Values.serviceAccount.name }}
+{{- end }}
+{{- end }}
diff --git a/dbuf/templates/configmap-config.yaml b/dbuf/templates/configmap-config.yaml
new file mode 100644
index 0000000..96368c9
--- /dev/null
+++ b/dbuf/templates/configmap-config.yaml
@@ -0,0 +1,52 @@
+{{/*
+# Copyright 2021-present Open Networking Foundation
+
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+*/}}
+
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ include "dbuf.fullname" . }}
+  labels:
+    {{- include "dbuf.labels" . | nindent 4 }}
+data:
+  config: |
+    #!/bin/sh
+    set -x
+    env
+    export IFS=','
+    for r in $STATIC_ROUTES; do
+      ip route add $r dev $DP_INTERFACE
+    done
+    unset IFS
+    ifconfig
+    while true
+    do
+        echo "Up SR-IOV intercae"
+        ip link set $DP_INTERFACE up
+        echo "Get the IP Address from interface $DP_INTERFACE"
+        ifconfig $DP_INTERFACE
+        #IP Address from ifconfig is addr:10.71.126.127, have to cut it off
+        DP_IP=$(ifconfig $DP_INTERFACE | awk '/inet addr:/ {print $2}' | cut -d':' -f2)
+        echo "IP Address is $DP_IP"
+
+        echo "Generate the netcfg json"
+    cat <<EOF > /tmp/netcfg.json
+        {
+          "apps": {
+            "org.omecproject.up4": {
+              "dbuf": {
+                "serviceAddr": "$GRPC_SERVICE_NAME.$NAMESPACE:$GRPC_PORT",
+                "dataplaneAddr": "$DP_IP:$DP_PORT"
+              }
+            }
+          }
+        }
+    EOF
+
+        cat /tmp/netcfg.json
+        curl --fail -sSL --user $ONOS_USERNAME:$ONOS_PASSWORD --noproxy $ONOS_SERVER -X POST -H 'Content-Type:application/json' \
+        http://$ONOS_SERVER:$ONOS_PORT/onos/v1/network/configuration -d@/tmp/netcfg.json
+        sleep 1m
+    done
diff --git a/dbuf/templates/deployment.yaml b/dbuf/templates/deployment.yaml
new file mode 100644
index 0000000..22d4db7
--- /dev/null
+++ b/dbuf/templates/deployment.yaml
@@ -0,0 +1,105 @@
+
+# Copyright 2020-present Open Networking Foundation
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ include "dbuf.fullname" . }}
+  labels:
+    {{- include "dbuf.labels" . | nindent 4 }}
+spec:
+  replicas: {{ .Values.replicaCount }}
+  selector:
+    matchLabels:
+      {{- include "dbuf.selectorLabels" . | nindent 6 }}
+  template:
+    metadata:
+    {{- with .Values.podAnnotations }}
+      annotations:
+        {{- toYaml . | nindent 8 }}
+    {{- end }}
+      labels:
+        {{- include "dbuf.selectorLabels" . | nindent 8 }}
+    spec:
+      {{- if hasKey .Values.image "pullSecrets" }}
+      imagePullSecrets:
+        {{- range .Values.image.pullSecrets }}
+        - name: {{ . | quote }}
+        {{- end }}
+      {{- end }}
+      securityContext:
+        {{- toYaml .Values.podSecurityContext | nindent 8 }}
+      containers:
+        - name: {{ .Chart.Name }}
+          securityContext:
+            {{- toYaml .Values.securityContext | nindent 12 }}
+          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
+          imagePullPolicy: {{ .Values.image.pullPolicy }}
+          command: [ "dbuf", {{ template "extraParams" .Values.extraParams }} ]
+          resources:
+            requests:
+              intel.com/{{ .Values.sriovResourceName }}: '{{ .Values.sriovNICSize }}'
+            limits:
+              intel.com/{{ .Values.sriovResourceName }}: '{{ .Values.sriovNICSize }}'
+          ports:
+          - name: grpc
+            containerPort: 10000
+            protocol:  {{ .Values.service.grpc.protocol }}
+          - name: exporter
+            containerPort: 8080
+            protocol: {{ .Values.service.stats.protocol }}
+        # Push data plane address to ONOS via netcfgc
+        # Add the static route for sr-iov interface
+        - name: config
+          image: curlimages/curl:7.75.0
+          imagePullPolicy: IfNotPresent
+          env:
+            - name: NAMESPACE
+              valueFrom:
+                fieldRef:
+                  fieldPath: metadata.namespace
+            - name: ONOS_SERVER
+              value: "{{ .Values.onos.server }}"
+            - name: ONOS_PORT
+              value: "{{ .Values.onos.port }}"
+            - name: ONOS_USERNAME
+              value: "{{ .Values.onos.username }}"
+            - name: ONOS_PASSWORD
+              value: "{{ .Values.onos.password }}"
+            - name: GRPC_SERVICE_NAME
+              value: {{ include "dbuf.fullname" . }}
+            - name: GRPC_PORT
+              value: "{{ .Values.service.grpc.port }}"
+            - name: DP_INTERFACE
+              value: "{{ .Values.dataplane.interface }}"
+            - name: DP_PORT
+              value: "{{ .Values.dataplane.port }}"
+            - name: STATIC_ROUTES
+              value: "{{ .Values.network.route }}"
+          volumeMounts:
+            - name: config-script
+              mountPath: /tmp/config
+              subPath: config
+          command: ["sh", "-c", "/tmp/config"]
+          securityContext:
+            runAsUser: 0
+            capabilities:
+              add: ["NET_ADMIN"]
+      {{- with .Values.nodeSelector }}
+      nodeSelector:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      {{- with .Values.affinity }}
+      affinity:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      {{- with .Values.tolerations }}
+      tolerations:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      volumes:
+        - name: config-script
+          configMap:
+            name: {{ include "dbuf.fullname" . }}
+            defaultMode: 0755
diff --git a/dbuf/templates/networks.yaml b/dbuf/templates/networks.yaml
new file mode 100644
index 0000000..84e0cf5
--- /dev/null
+++ b/dbuf/templates/networks.yaml
@@ -0,0 +1,33 @@
+{{/*
+# Copyright 2020-present Open Networking Foundation
+
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+*/}}
+
+apiVersion: "k8s.cni.cncf.io/v1"
+kind: NetworkAttachmentDefinition
+metadata:
+  name: {{ .Values.multusNetworkName }}
+  annotations:
+    k8s.v1.cni.cncf.io/resourceName: intel.com/{{ .Values.sriovResourceName }}
+spec:
+  config: '{
+  "type": "sriov",
+  "name": "sriov-network",
+{{- if hasKey .Values.network "vlan" }}
+  "vlan": {{ .Values.network.vlan }},
+{{- end }}
+  "ipam": {
+    {{- if eq .Values.network.ipam "host-local" }}
+    "type": "host-local",
+    "subnet": "{{ .Values.network.static.subnets }}",
+    "routes": [{
+      "dst": "0.0.0.0/0"
+    }],
+    "gateway": "{{ .Values.network.static.gateway }}"
+    {{- else if eq .Values.network.ipam "dhcp" }}
+    "type": "dhcp"
+
+    {{- end }}
+  }
+}'
diff --git a/dbuf/templates/service.yml b/dbuf/templates/service.yml
new file mode 100644
index 0000000..48df27e
--- /dev/null
+++ b/dbuf/templates/service.yml
@@ -0,0 +1,36 @@
+{{/*
+# Copyright 2021-present Open Networking Foundation
+
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+*/}}
+
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ include "dbuf.fullname" . }}
+  labels:
+    {{- include "dbuf.labels" . | nindent 4 }}
+spec:
+  selector:
+    {{- include "dbuf.selectorLabels" . | nindent 4 }}
+  ports:
+  - name: grpc
+    protocol: {{ .Values.service.grpc.protocol }}
+    port: {{ .Values.service.grpc.port }}
+    targetPort: grpc
+
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ include "dbuf.fullname" . }}-stats
+  labels:
+    {{- include "dbuf.labels" . | nindent 4 }}
+spec:
+  selector:
+    {{- include "dbuf.selectorLabels" . | nindent 4 }}
+  ports:
+  - name: exporter
+    protocol: {{ .Values.service.stats.protocol }}
+    port: {{ .Values.service.stats.port }}
+    targetPort: exporter
diff --git a/dbuf/templates/servicemonitor.yaml b/dbuf/templates/servicemonitor.yaml
new file mode 100644
index 0000000..4290b0b
--- /dev/null
+++ b/dbuf/templates/servicemonitor.yaml
@@ -0,0 +1,23 @@
+{{- if eq .Values.prometheus_enable true }}
+
+{{/*
+# Copyright 2021-present Open Networking Foundation
+
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+*/}}
+
+apiVersion: monitoring.coreos.com/v1
+kind: ServiceMonitor
+metadata:
+  name: dbuf
+  labels:
+    {{- include "dbuf.labels" . | nindent 4 }}
+spec:
+  selector:
+    matchLabels:
+      {{- include "dbuf.selectorLabels" . | nindent 6 }}
+  endpoints:
+  - port: exporter
+    path: /metrics
+    scheme: HTTP
+{{ end }}
diff --git a/dbuf/values.yaml b/dbuf/values.yaml
new file mode 100644
index 0000000..f0408b9
--- /dev/null
+++ b/dbuf/values.yaml
@@ -0,0 +1,65 @@
+# Copyright 2021-present Open Networking Foundation
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+image:
+  repository: registry.aetherproject.org/tost/dbuf
+  pullPolicy: Always
+  tag: "latest"
+
+extraParams:
+  - '"-max_queues=1024"'
+
+replicaCount: 1
+sriovNICSize: 1
+sriovResourceName: intel_sriov_netdevice
+
+# Change both in the same time
+multusNetworkName: dbuf-sriov
+podAnnotations:
+  k8s.v1.cni.cncf.io/networks: dbuf-sriov@net0
+
+podSecurityContext: {}
+resources:
+  requests:
+    intel.com/intel_sriov_netdevice: "1"
+  limits:
+    intel.com/intel_sriov_netdevice: "1"
+
+nodeSelector: {}
+
+tolerations: []
+
+affinity: {}
+
+# onos inforamtion
+onos:
+  server: sdfabric-onos-classic-hs.sdfabric
+  port: 8181
+  username: onos
+  password: rocks
+
+dataplane:
+  port: 2152
+  interface: "net0"
+
+prometheus_enable: true
+service:
+  stats:
+    port: 8080
+    protocol: TCP
+  grpc:
+    port: 10000
+    protocol: TCP
+
+# two options for ipam, dhcp or host-local
+# static is for host-local ipam
+network:
+  #  ipam: dhcp
+  ipam: host-local
+  static:
+    subnets: "10.56.217.0/24"
+    gateway: "10.56.217.1"
+  # route the following subnets via sr-iov interface
+  # route: 10.56.215.0/24,10.56.214.0/24
+  route: ""
+  #vlan: