blob: 121bb38faf13855ca9e9a3f9fca536dedc1549a5 [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 Baviered9c5842019-05-20 09:53:48 -070034 info( '*** Installing required software\n' )
Andy Bavier7a080492018-08-30 14:26:09 -070035 print quietRun( 'apt-get update' )
Andy Baviered9c5842019-05-20 09:53:48 -070036 print quietRun( 'apt-get -y install dnsmasq ethtool wget pimd bridge-utils' )
37 print quietRun( 'wget https://github.com/troglobit/mcjoin/releases/download/v2.4/mcjoin_2.4_amd64.deb' )
38 print quietRun( 'dpkg -i mcjoin_2.4_amd64.deb' )
Andy Bavier7a080492018-08-30 14:26:09 -070039
Andy Bavier6ca22c02019-04-02 14:03:49 -070040 print quietRun( 'ovs-vsctl set Open_vSwitch . other_config:vlan-limit={{ .Values.vlanMatchDepth }}' )
Andy Bavier7a080492018-08-30 14:26:09 -070041 OVSSwitch13 = partial( OVSSwitch, protocols='OpenFlow13' )
Andy Bavier8fef6102018-12-21 16:54:26 -070042 controllerIp = socket.gethostbyname( '{{ .Values.onosOpenflowSvc }}' )
Andy Bavier7a080492018-08-30 14:26:09 -070043
Andy Baviered9c5842019-05-20 09:53:48 -070044 net = Mininet( topo=None )
45
46 info( '*** Adding controllers\n' )
47 onos = net.addController( name='onos', controller=RemoteController, ip=controllerIp, port=6653 )
48
49 info( '*** Adding switches\n' )
50 s1 = net.addSwitch( name='s1', cls=OVSSwitch13 )
51 s2 = net.addSwitch( 's2', cls=LinuxBridge )
52
53 info( '*** Creating hosts\n' )
54 h1 = net.addHost( 'h1', ip='10.0.0.1/24')
55 h2 = net.addHost( 'h2', ip='10.1.0.2/24')
56
57 # Topology: pon1 - eth1 - s1 - h1 - s2 - h2
58 net.addLink( h1, s1 )
59 net.addLink( h1, s2 )
60 net.addLink( h2, s2 )
61
Andy Baviere21a5f52019-05-28 15:39:52 -070062{{- range $i, $junk := until (.Values.numOlts|int) -}}
63{{- $intf := printf "eth%d" (add $i 1) }}
Andy Bavier7a080492018-08-30 14:26:09 -070064
Andy Baviere21a5f52019-05-28 15:39:52 -070065 info( '*** Adding hardware interface {{ $intf }} to switch s1\n')
66 _intf = Intf( '{{ $intf }}', node=s1 )
Andy Bavier7a080492018-08-30 14:26:09 -070067
Andy Baviere21a5f52019-05-28 15:39:52 -070068 info( '*** Turning off checksum offloading for {{ $intf }}\n' )
69 print quietRun( 'ethtool -K {{ $intf }} tx off rx off' )
70{{- end }}
71
72 info( '*** Adding VLAN interface to host h1\n')
73 h1.cmd( 'ifconfig h1-eth1 10.1.0.1/24 up')
74
Sreeju7d7fc072019-06-13 12:03:00 -060075 {{- $onucount := .Values.numOnus|int}}
Andy Baviere21a5f52019-05-28 15:39:52 -070076{{- range $i, $junk := until (.Values.numOlts|int) -}}
77{{- $stag := add 222 $i }}
Sreeju7d7fc072019-06-13 12:03:00 -060078{{- range $j, $junk1 := until ($onucount) -}}
79{{- $ctag := add 111 $j }}
Andy Baviere21a5f52019-05-28 15:39:52 -070080 h1.cmd( 'ip link add link h1-eth0 name h1-eth0.{{ $stag }} type vlan proto 802.1Q id {{ $stag }}' )
81 h1.cmd( 'ip link add link h1-eth0.{{ $stag }} name h1-eth0.{{ $stag }}.{{ $ctag }} type vlan proto 802.1Q id {{ $ctag }}' )
82 h1.cmd( 'ifconfig h1-eth0.{{ $stag }} up' )
83 h1.cmd( 'ifconfig h1-eth0.{{ $stag }}.{{ $ctag }} up' )
Sreeju7d7fc072019-06-13 12:03:00 -060084 h1.cmd( 'ifconfig h1-eth0.{{ $stag }}.{{ $ctag }} 172.{{ add $i 18 }}.{{ $j }}.10/24' )
Andy Baviere21a5f52019-05-28 15:39:52 -070085{{- end }}
Sreeju7d7fc072019-06-13 12:03:00 -060086{{- end }}
Andy Baviere21a5f52019-05-28 15:39:52 -070087 h1.cmd( 'dnsmasq {{ template "mininet.dhcp_range" . }}' )
Andy Baviered9c5842019-05-20 09:53:48 -070088
Andy Bavier3031e9d2019-05-22 14:16:07 -070089{{- if .Values.enableMulticast }}
Andy Baviere21a5f52019-05-28 15:39:52 -070090 info( '*** Start multicast routing on h1 and source on h2\n')
Andy Bavier3031e9d2019-05-22 14:16:07 -070091 h1.cmd( 'service pimd start' )
92 h2.cmd( 'mcjoin -s -i h2-eth0 -t 2 >& /tmp/mcjoin.log &')
93{{- end }}
94
Andy Baviered9c5842019-05-20 09:53:48 -070095 onos.start()
96 s1.start( [onos] )
Andy Bavier7a080492018-08-30 14:26:09 -070097
98 net.start()
99 CLI( net )
100 net.stop()