Add support for running SiaB with stratum_bmv2 as the fabric switch

- new value file (seba-ponsim-stratum.yaml) to deploy SiaB with Stratum
- new mininet script to use stratum_bmv2 instead of OVS as Fabric switch
- update to ponsim and mininet to use the new Stratum device instead of OVS

Change-Id: I35901b455865cebc0a11de8b155b951e4fa4a9f8
diff --git a/configs/seba-ponsim-stratum.yaml b/configs/seba-ponsim-stratum.yaml
new file mode 100644
index 0000000..171a582
--- /dev/null
+++ b/configs/seba-ponsim-stratum.yaml
@@ -0,0 +1,63 @@
+---
+# Copyright 2019-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Values file for deploying SEBA with Ponsim and Stratum
+# Use this file to deploy the service versions specified in the Helm charts.
+
+images:
+  # Mininet image
+  mininet:
+    repository: 'opencord/mn-stratum-siab'
+    tag: 'master'
+    pullPolicy: Always
+
+# voltha
+etcd-cluster:
+  clusterSize: 1
+
+# in workflow/att-workflow service chart
+att-workflow-driver:
+  # this is mandatory, it's needed to correctly configure the kafka endpoint
+  kafkaService: cord-kafka
+
+# in workflow/tt-workflow service chart
+tt-workflow-driver:
+  image:
+    repository: andybavier/test-image-synchronizer
+    tag: tt-workflow-driver
+
+  # this is mandatory, it's needed to correctly configure the kafka endpoint
+  kafkaService: cord-kafka
+
+# in mininet chart
+# FIXME: check if multicast is working
+enableMulticast: false
+topoScript: '/toposcripts/topo_stratum.py'
+stratumEnabled: true
+
+# in ponsim-pod chart
+bandwidthProfiles: true
+legacyPonsim: false
+
+# fabric
+fabric:
+  enabled: true
+  stratum:
+    driverAppId: 'org.onosproject.drivers.bmv2'
+    # Enable stratum
+    enabled: true
+    # Use BMv2 pipeconf (already in ONOS)
+    pipeconfAppExternal: false
+    pipeconfAppId: 'org.onosproject.pipelines.fabric'
diff --git a/mininet/Chart.yaml b/mininet/Chart.yaml
index 1547112..d3e94e1 100644
--- a/mininet/Chart.yaml
+++ b/mininet/Chart.yaml
@@ -17,4 +17,4 @@
 appVersion: 1.0.0
 description: A Helm chart for Mininet
 name: mininet
-version: 1.0.0
+version: 1.1.0
diff --git a/mininet/templates/deployment.yaml b/mininet/templates/deployment.yaml
index 0f1807d..90d54b2 100644
--- a/mininet/templates/deployment.yaml
+++ b/mininet/templates/deployment.yaml
@@ -40,7 +40,10 @@
         - name: {{ .Chart.Name }}
           image: "{{ .Values.global.registry }}{{ .Values.images.mininet.repository }}:{{ tpl .Values.images.mininet.tag . }}"
           imagePullPolicy: {{ .Values.images.mininet.pullPolicy }}
-          args: ["/toposcripts/topo.py"]
+{{- if $.Values.stratumEnabled }}
+          command: ["python"]
+{{- end }}
+          args: [{{ .Values.topoScript }}]
           stdin: true
           tty: true
           securityContext:
diff --git a/mininet/templates/mn-stratum-service.yaml b/mininet/templates/mn-stratum-service.yaml
new file mode 100644
index 0000000..0cf7d86
--- /dev/null
+++ b/mininet/templates/mn-stratum-service.yaml
@@ -0,0 +1,38 @@
+---
+# Copyright 2019-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Service that exposes the gRPC port to control the stratum_bmv2 instance(s)
+# running inside Mininet
+
+{{- if $.Values.stratumEnabled }}
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ template "mininet.fullname" . }}-stratum
+  namespace: {{ .Values.namespace }}
+  labels:
+    app: {{ template "mininet.name" . }}
+    chart: {{ template "mininet.chart" . }}
+    release: {{ .Release.Name }}
+    heritage: {{ .Release.Service }}
+spec:
+  type: ClusterIP
+  ports:
+  - name: stratum-1
+    port: 50001
+  selector:
+    app: {{ template "mininet.name" . }}
+    release: {{ .Release.Name }}
+{{- end }}
diff --git a/mininet/toposcripts/topo_stratum.py b/mininet/toposcripts/topo_stratum.py
new file mode 100644
index 0000000..0145688
--- /dev/null
+++ b/mininet/toposcripts/topo_stratum.py
@@ -0,0 +1,80 @@
+#!/usr/bin/python
+
+# Copyright 2019-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from mininet.cli import CLI
+from mininet.log import setLogLevel, info, error
+from mininet.net import Mininet
+from mininet.link import Intf
+from mininet.nodelib import LinuxBridge
+from stratum import StratumBmv2Switch
+from mininet.util import quietRun
+
+CPU_PORT = 255
+
+if __name__ == '__main__':
+    setLogLevel( 'info' )
+
+    net = Mininet( topo=None )
+
+    info( '*** Adding switches\n' )
+    agg1 = net.addSwitch( name='agg1', cls=StratumBmv2Switch, cpuport=CPU_PORT)
+    s2 = net.addSwitch( 's2', cls=LinuxBridge )
+
+    info( '*** Creating hosts\n' )
+    h1 = net.addHost( 'h1', ip='10.0.0.1/24')
+    h2 = net.addHost( 'h2', ip='10.1.0.2/24')
+
+    # Topology: pon1 - eth1 - agg1 - h1 - s2 - h2
+    net.addLink( h1, agg1 )
+    net.addLink( h1, s2 )
+    net.addLink( h2, s2 )
+
+{{- range $i, $junk := until (.Values.numOlts|int) -}}
+{{- $intf := printf "eth%d" (add $i 1) }}
+
+    info( '*** Adding hardware interface {{ $intf }} to switch agg1\n')
+    _intf = Intf( '{{ $intf }}', node=agg1 )
+
+    info( '*** Turning off checksum offloading for {{ $intf }}\n' )
+    print quietRun( 'ethtool -K {{ $intf }} tx off rx off' )
+{{- end }}
+
+    info( '*** Adding VLAN interface to host h1\n')
+    h1.cmd( 'ifconfig h1-eth1 10.1.0.1/24 up')
+
+    {{- $onucount := .Values.numOnus|int}}
+{{- range $i, $junk := until (.Values.numOlts|int) -}}
+{{- $stag := add 222 $i }}
+{{- range $j, $junk1 := until ($onucount) -}}
+{{- $ctag := add 111 $j }}
+    h1.cmd( 'ip link add link h1-eth0 name h1-eth0.{{ $stag }} type vlan proto 802.1Q id {{ $stag }}' )
+    h1.cmd( 'ip link add link h1-eth0.{{ $stag }} name h1-eth0.{{ $stag }}.{{ $ctag }} type vlan proto 802.1Q id {{ $ctag }}' )
+    h1.cmd( 'ifconfig h1-eth0.{{ $stag }} up' )
+    h1.cmd( 'ifconfig h1-eth0.{{ $stag }}.{{ $ctag }} up' )
+    h1.cmd( 'ifconfig h1-eth0.{{ $stag }}.{{ $ctag }} 172.{{ add $i 18  }}.{{ $j }}.10/24' )
+{{- end }}
+{{- end }}
+    h1.cmd( 'dnsmasq {{ template "mininet.dhcp_range" . }}' )
+
+{{- if .Values.enableMulticast }}
+    info( '*** Start multicast routing on h1 and source on h2\n')
+    h1.cmd( 'service pimd start' )
+    h2.cmd( 'mcjoin -s -i h2-eth0 -t 2 >& /tmp/mcjoin.log &')
+{{- end }}
+
+    net.start()
+    CLI( net )
+    net.stop()
diff --git a/mininet/values.yaml b/mininet/values.yaml
index 1515347..1916755 100644
--- a/mininet/values.yaml
+++ b/mininet/values.yaml
@@ -49,6 +49,8 @@
             - olt
         topologyKey: kubernetes.io/hostname
 
+stratumEnabled: false
+topoScript: '/toposcripts/topo.py'
 onosOpenflowSvc: "onos-openflow.default.svc.cluster.local"
 vlanMatchDepth: 2
 enableMulticast: true
diff --git a/xos-profiles/ponsim-pod/Chart.yaml b/xos-profiles/ponsim-pod/Chart.yaml
index cf675dc..a1ad9c9 100644
--- a/xos-profiles/ponsim-pod/Chart.yaml
+++ b/xos-profiles/ponsim-pod/Chart.yaml
@@ -13,11 +13,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+apiVersion: v1
 name: ponsim-pod
 description: A Helm chart for loading the Ponsim pod's TOSCA files into XOS
 icon: https://guide.opencord.org/logos/xos.svg
 
-version: 1.3.4
+version: 1.4.0
 
 # xosproject/tosca-loader version
 appVersion: 1.3.1
diff --git a/xos-profiles/ponsim-pod/tosca/020-pod-olt.yaml b/xos-profiles/ponsim-pod/tosca/020-pod-olt.yaml
index 9398a65..74262d4 100644
--- a/xos-profiles/ponsim-pod/tosca/020-pod-olt.yaml
+++ b/xos-profiles/ponsim-pod/tosca/020-pod-olt.yaml
@@ -41,7 +41,11 @@
         device_type: ponsim_olt
         host: olt{{ $i }}.voltha.svc
         port: 50060
+{{- if not $.Values.fabric.stratum.enabled }}
         switch_datapath_id: of:0000000000000001
+{{- else }}
+        switch_datapath_id: device:agg1
+{{- end }}
         switch_port: "{{ add 2 $i }}"
         outer_tpid: "0x8100"
 {{- if $.Values.bandwidthProfiles }}
diff --git a/xos-profiles/ponsim-pod/tosca/030-fabric.yaml b/xos-profiles/ponsim-pod/tosca/030-fabric.yaml
index 950551e..3bf6030 100644
--- a/xos-profiles/ponsim-pod/tosca/030-fabric.yaml
+++ b/xos-profiles/ponsim-pod/tosca/030-fabric.yaml
@@ -30,12 +30,19 @@
     switch#leaf_1:
       type: tosca.nodes.Switch
       properties:
-        driver: ofdpa-ovs
+{{- if not $.Values.fabric.stratum.enabled }}
+        driver: "ofdpa-ovs"
+        ofId: of:0000000000000001
+{{- else }}
+        driver: "stratum-bmv2"
+        pipeconf: 'org.onosproject.pipelines.fabric'
+        managementAddress: "grpc://mininet-stratum:50001?device_id=1"
+        ofId: device:agg1
+{{- end }}
         ipv4Loopback: 192.168.0.201
         ipv4NodeSid: 17
         isEdgeRouter: True
         name: leaf_1
-        ofId: of:0000000000000001
         routerMac: 00:00:02:01:06:01
 
     # Setup the OLT switch ports
@@ -85,7 +92,11 @@
           {
             "dhcpl2relay" : {
               "useOltUplinkForServerPktInOut" : false,
+{{- if not $.Values.fabric.stratum.enabled }}
               "dhcpServerConnectPoints" : [ "of:0000000000000001/1" ]
+{{- else }}
+              "dhcpServerConnectPoints" : [ "device:agg1/1" ]
+{{- end }}
             }
           }
       requirements:
diff --git a/xos-profiles/ponsim-pod/values.yaml b/xos-profiles/ponsim-pod/values.yaml
index 14353e9..01a7d70 100644
--- a/xos-profiles/ponsim-pod/values.yaml
+++ b/xos-profiles/ponsim-pod/values.yaml
@@ -55,3 +55,7 @@
   - of:00000da7f2c143c7
   - of:000032be2d4c2abc
   - of:0000ae9b8dcd58c7
+
+fabric:
+  stratum:
+    enabled: false
diff --git a/xos-profiles/seba-services/Chart.yaml b/xos-profiles/seba-services/Chart.yaml
index c4904b5..d894f8d 100644
--- a/xos-profiles/seba-services/Chart.yaml
+++ b/xos-profiles/seba-services/Chart.yaml
@@ -17,7 +17,7 @@
 name: seba-services
 description: A Helm chart for XOS's "SEBA" profile
 icon: https://guide.opencord.org/logos/cord.svg
-version: 1.4.0
+version: 1.4.1
 
 # xosproject/tosca-loader version
 appVersion: 1.3.1
diff --git a/xos-profiles/seba-services/templates/_tosca.tpl b/xos-profiles/seba-services/templates/_tosca.tpl
index 07de05a..cb4a8e8 100644
--- a/xos-profiles/seba-services/templates/_tosca.tpl
+++ b/xos-profiles/seba-services/templates/_tosca.tpl
@@ -150,6 +150,15 @@
             relationship: tosca.relationships.BelongsToOne
 
 {{- if .fabric.stratum.enabled }}
+    onos_app#stratum-driver:
+      type: tosca.nodes.ONOSApp
+      properties:
+        name: {{ .fabric.stratum.driverAppId }}
+        app_id: {{ .fabric.stratum.driverAppId }}
+      requirements:
+        - owner:
+            node: service#onos
+            relationship: tosca.relationships.BelongsToOne
     onos_app#fabric-pipeconf:
       type: tosca.nodes.ONOSApp
       properties: