blob: 1ac31d62346cc9956ce77b5b18e6026657cc0001 [file] [log] [blame]
Andy Bavier7a080492018-08-30 14:26:09 -07001#!/usr/bin/python
2
3# Copyright 2017-present Open Networking Foundation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import re
18import sys
19import socket
20
21from mininet.cli import CLI
22from mininet.log import setLogLevel, info, error
23from mininet.net import Mininet
24from mininet.link import Intf
Andy Baviered9c5842019-05-20 09:53:48 -070025from mininet.topo import Topo, SingleSwitchTopo
26from mininet.node import OVSSwitch, Controller, RemoteController
27from mininet.nodelib import LinuxBridge
Andy Bavier7a080492018-08-30 14:26:09 -070028from functools import partial
29from mininet.util import quietRun
30
31if __name__ == '__main__':
32 setLogLevel( 'info' )
33
Andy Bavier6ca22c02019-04-02 14:03:49 -070034 print quietRun( 'ovs-vsctl set Open_vSwitch . other_config:vlan-limit={{ .Values.vlanMatchDepth }}' )
Andy Bavier7a080492018-08-30 14:26:09 -070035 OVSSwitch13 = partial( OVSSwitch, protocols='OpenFlow13' )
Andy Bavier8fef6102018-12-21 16:54:26 -070036 controllerIp = socket.gethostbyname( '{{ .Values.onosOpenflowSvc }}' )
Andy Bavier7a080492018-08-30 14:26:09 -070037
Andy Baviered9c5842019-05-20 09:53:48 -070038 net = Mininet( topo=None )
39
40 info( '*** Adding controllers\n' )
41 onos = net.addController( name='onos', controller=RemoteController, ip=controllerIp, port=6653 )
42
43 info( '*** Adding switches\n' )
44 s1 = net.addSwitch( name='s1', cls=OVSSwitch13 )
45 s2 = net.addSwitch( 's2', cls=LinuxBridge )
46
47 info( '*** Creating hosts\n' )
48 h1 = net.addHost( 'h1', ip='10.0.0.1/24')
49 h2 = net.addHost( 'h2', ip='10.1.0.2/24')
50
51 # Topology: pon1 - eth1 - s1 - h1 - s2 - h2
52 net.addLink( h1, s1 )
53 net.addLink( h1, s2 )
54 net.addLink( h2, s2 )
55
Andy Baviere21a5f52019-05-28 15:39:52 -070056{{- range $i, $junk := until (.Values.numOlts|int) -}}
57{{- $intf := printf "eth%d" (add $i 1) }}
Andy Bavier7a080492018-08-30 14:26:09 -070058
Andy Baviere21a5f52019-05-28 15:39:52 -070059 info( '*** Adding hardware interface {{ $intf }} to switch s1\n')
60 _intf = Intf( '{{ $intf }}', node=s1 )
Andy Bavier7a080492018-08-30 14:26:09 -070061
Andy Baviere21a5f52019-05-28 15:39:52 -070062 info( '*** Turning off checksum offloading for {{ $intf }}\n' )
63 print quietRun( 'ethtool -K {{ $intf }} tx off rx off' )
64{{- end }}
65
66 info( '*** Adding VLAN interface to host h1\n')
67 h1.cmd( 'ifconfig h1-eth1 10.1.0.1/24 up')
68
Sreeju7d7fc072019-06-13 12:03:00 -060069 {{- $onucount := .Values.numOnus|int}}
Andy Baviere21a5f52019-05-28 15:39:52 -070070{{- range $i, $junk := until (.Values.numOlts|int) -}}
71{{- $stag := add 222 $i }}
Sreeju7d7fc072019-06-13 12:03:00 -060072{{- range $j, $junk1 := until ($onucount) -}}
73{{- $ctag := add 111 $j }}
Andy Baviere21a5f52019-05-28 15:39:52 -070074 h1.cmd( 'ip link add link h1-eth0 name h1-eth0.{{ $stag }} type vlan proto 802.1Q id {{ $stag }}' )
75 h1.cmd( 'ip link add link h1-eth0.{{ $stag }} name h1-eth0.{{ $stag }}.{{ $ctag }} type vlan proto 802.1Q id {{ $ctag }}' )
76 h1.cmd( 'ifconfig h1-eth0.{{ $stag }} up' )
77 h1.cmd( 'ifconfig h1-eth0.{{ $stag }}.{{ $ctag }} up' )
Sreeju7d7fc072019-06-13 12:03:00 -060078 h1.cmd( 'ifconfig h1-eth0.{{ $stag }}.{{ $ctag }} 172.{{ add $i 18 }}.{{ $j }}.10/24' )
Andy Baviere21a5f52019-05-28 15:39:52 -070079{{- end }}
Sreeju7d7fc072019-06-13 12:03:00 -060080{{- end }}
Andy Baviere21a5f52019-05-28 15:39:52 -070081 h1.cmd( 'dnsmasq {{ template "mininet.dhcp_range" . }}' )
Andy Baviered9c5842019-05-20 09:53:48 -070082
Andy Bavier3031e9d2019-05-22 14:16:07 -070083{{- if .Values.enableMulticast }}
Andy Baviere21a5f52019-05-28 15:39:52 -070084 info( '*** Start multicast routing on h1 and source on h2\n')
Andy Bavier3031e9d2019-05-22 14:16:07 -070085 h1.cmd( 'service pimd start' )
86 h2.cmd( 'mcjoin -s -i h2-eth0 -t 2 >& /tmp/mcjoin.log &')
87{{- end }}
88
Andy Baviered9c5842019-05-20 09:53:48 -070089 onos.start()
90 s1.start( [onos] )
Andy Bavier7a080492018-08-30 14:26:09 -070091
92 net.start()
93 CLI( net )
94 net.stop()