SEBA-686 Enable multiple Ponsim OLTs

Change-Id: Ia8cc47492010bcd98f0a8800f70386cd5ca5342b
diff --git a/mininet/Chart.yaml b/mininet/Chart.yaml
index b06bc8c..fdc6e9b 100644
--- a/mininet/Chart.yaml
+++ b/mininet/Chart.yaml
@@ -17,4 +17,4 @@
 appVersion: "1.0"
 description: A Helm chart for Mininet
 name: mininet
-version: 0.4.1
+version: 0.5.0
diff --git a/mininet/templates/_helpers.tpl b/mininet/templates/_helpers.tpl
index 31212af..8396f02 100644
--- a/mininet/templates/_helpers.tpl
+++ b/mininet/templates/_helpers.tpl
@@ -46,3 +46,22 @@
 {{- define "mininet.chart" -}}
 {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
 {{- end -}}
+
+{{/*
+Generate the CNI annotations depending on number of OLTs
+*/}}
+{{- define "mininet.cni" -}}
+{{- printf "calico" -}}
+{{- range $i, $junk := until (.Values.numOlts|int) -}}
+{{- printf ",nni%d" $i -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Generate the DHCP subnets depending on number of OLTs
+*/}}
+{{- define "mininet.dhcp_range" -}}
+{{- range $i, $junk := until (.Values.numOlts|int) -}}
+{{- printf " --dhcp-range=172.18.%d.50,172.18.%d.150,12h" $i $i -}}
+{{- end -}}
+{{- end -}}
\ No newline at end of file
diff --git a/mininet/templates/deployment.yaml b/mininet/templates/deployment.yaml
index f75041e..571e024 100644
--- a/mininet/templates/deployment.yaml
+++ b/mininet/templates/deployment.yaml
@@ -33,10 +33,8 @@
       labels:
         app: {{ template "mininet.name" . }}
         release: {{ .Release.Name }}
-    {{- with .Values.annotations }}
       annotations:
-{{ toYaml . | indent 8 }}
-    {{- end }}
+        cni: {{ template "mininet.cni" . }}
     spec:
       containers:
         - name: {{ .Chart.Name }}
diff --git a/mininet/toposcripts/topo.py b/mininet/toposcripts/topo.py
index dc87317..8e8b6c4 100644
--- a/mininet/toposcripts/topo.py
+++ b/mininet/toposcripts/topo.py
@@ -59,24 +59,34 @@
     net.addLink( h1, s2 )
     net.addLink( h2, s2 )
 
-    info( '*** Adding hardware interface eth1 to switch %s\n' % s1.name)
-    _intf = Intf( 'eth1', node=s1 )
+{{- range $i, $junk := until (.Values.numOlts|int) -}}
+{{- $intf := printf "eth%d" (add $i 1) }}
 
-    info( '*** Turning off checksum offloading for eth1\n' )
-    print quietRun( 'ethtool -K eth1 tx off rx off' )
+    info( '*** Adding hardware interface {{ $intf }} to switch s1\n')
+    _intf = Intf( '{{ $intf }}', node=s1 )
 
-    info( '*** Adding VLAN interface to host %s\n' % h1.name)
-    base = "%s-eth0" % h1.name
-    h1.cmd( 'ifconfig %s-eth1 10.1.0.1/24 up' % h1.name)
-    h1.cmd( 'ip link add link %s name %s.222 type vlan proto 802.1Q id 222' % (base, base))
-    h1.cmd( 'ip link add link %s.222 name %s.222.111 type vlan proto 802.1Q id 111' % (base, base))
-    h1.cmd( 'ifconfig %s.222 up' % base)
-    h1.cmd( 'ifconfig %s.222.111 up' % base)
-    h1.cmd( 'ifconfig %s.222.111 172.18.0.10/24' % base)
-    h1.cmd( 'dnsmasq --dhcp-range=172.18.0.50,172.18.0.150,12h' )
+    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')
+
+{{- range $i, $junk := until (.Values.numOlts|int) -}}
+{{- $stag := add 222 $i }}
+{{- $ctag := 111 }}
+
+    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.18.{{ $i }}.10/24' )
+{{- end }}
+
+    h1.cmd( 'dnsmasq {{ template "mininet.dhcp_range" . }}' )
 
 {{- if .Values.enableMulticast }}
-    info( '*** Start multicast routing on %s and source on %s\n' % (h1.name, h2.name))
+    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 }}
diff --git a/mininet/values.yaml b/mininet/values.yaml
index b583914..2a049d4 100644
--- a/mininet/values.yaml
+++ b/mininet/values.yaml
@@ -45,9 +45,7 @@
             - olt
         topologyKey: kubernetes.io/hostname
 
-annotations:
-  cni: "calico,pon1"
-
 onosOpenflowSvc: "onos-openflow.default.svc.cluster.local"
 vlanMatchDepth: 1
 enableMulticast: false
+numOlts: 1