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/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