Andy Bavier | 7a08049 | 2018-08-30 14:26:09 -0700 | [diff] [blame] | 1 | #!/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 | |
| 17 | import re |
| 18 | import sys |
| 19 | import socket |
| 20 | |
| 21 | from mininet.cli import CLI |
| 22 | from mininet.log import setLogLevel, info, error |
| 23 | from mininet.net import Mininet |
| 24 | from mininet.link import Intf |
Andy Bavier | ed9c584 | 2019-05-20 09:53:48 -0700 | [diff] [blame] | 25 | from mininet.topo import Topo, SingleSwitchTopo |
| 26 | from mininet.node import OVSSwitch, Controller, RemoteController |
| 27 | from mininet.nodelib import LinuxBridge |
Andy Bavier | 7a08049 | 2018-08-30 14:26:09 -0700 | [diff] [blame] | 28 | from functools import partial |
| 29 | from mininet.util import quietRun |
| 30 | |
| 31 | if __name__ == '__main__': |
| 32 | setLogLevel( 'info' ) |
| 33 | |
Andy Bavier | ed9c584 | 2019-05-20 09:53:48 -0700 | [diff] [blame] | 34 | info( '*** Installing required software\n' ) |
Andy Bavier | 7a08049 | 2018-08-30 14:26:09 -0700 | [diff] [blame] | 35 | print quietRun( 'apt-get update' ) |
Andy Bavier | ed9c584 | 2019-05-20 09:53:48 -0700 | [diff] [blame] | 36 | 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 Bavier | 7a08049 | 2018-08-30 14:26:09 -0700 | [diff] [blame] | 39 | |
Andy Bavier | 6ca22c0 | 2019-04-02 14:03:49 -0700 | [diff] [blame] | 40 | print quietRun( 'ovs-vsctl set Open_vSwitch . other_config:vlan-limit={{ .Values.vlanMatchDepth }}' ) |
Andy Bavier | 7a08049 | 2018-08-30 14:26:09 -0700 | [diff] [blame] | 41 | OVSSwitch13 = partial( OVSSwitch, protocols='OpenFlow13' ) |
Andy Bavier | 8fef610 | 2018-12-21 16:54:26 -0700 | [diff] [blame] | 42 | controllerIp = socket.gethostbyname( '{{ .Values.onosOpenflowSvc }}' ) |
Andy Bavier | 7a08049 | 2018-08-30 14:26:09 -0700 | [diff] [blame] | 43 | |
Andy Bavier | ed9c584 | 2019-05-20 09:53:48 -0700 | [diff] [blame] | 44 | 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 Bavier | e21a5f5 | 2019-05-28 15:39:52 -0700 | [diff] [blame] | 62 | {{- range $i, $junk := until (.Values.numOlts|int) -}} |
| 63 | {{- $intf := printf "eth%d" (add $i 1) }} |
Andy Bavier | 7a08049 | 2018-08-30 14:26:09 -0700 | [diff] [blame] | 64 | |
Andy Bavier | e21a5f5 | 2019-05-28 15:39:52 -0700 | [diff] [blame] | 65 | info( '*** Adding hardware interface {{ $intf }} to switch s1\n') |
| 66 | _intf = Intf( '{{ $intf }}', node=s1 ) |
Andy Bavier | 7a08049 | 2018-08-30 14:26:09 -0700 | [diff] [blame] | 67 | |
Andy Bavier | e21a5f5 | 2019-05-28 15:39:52 -0700 | [diff] [blame] | 68 | 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 | |
Sreeju | 7d7fc07 | 2019-06-13 12:03:00 -0600 | [diff] [blame] | 75 | {{- $onucount := .Values.numOnus|int}} |
Andy Bavier | e21a5f5 | 2019-05-28 15:39:52 -0700 | [diff] [blame] | 76 | {{- range $i, $junk := until (.Values.numOlts|int) -}} |
| 77 | {{- $stag := add 222 $i }} |
Sreeju | 7d7fc07 | 2019-06-13 12:03:00 -0600 | [diff] [blame] | 78 | {{- range $j, $junk1 := until ($onucount) -}} |
| 79 | {{- $ctag := add 111 $j }} |
Andy Bavier | e21a5f5 | 2019-05-28 15:39:52 -0700 | [diff] [blame] | 80 | 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' ) |
Sreeju | 7d7fc07 | 2019-06-13 12:03:00 -0600 | [diff] [blame] | 84 | h1.cmd( 'ifconfig h1-eth0.{{ $stag }}.{{ $ctag }} 172.{{ add $i 18 }}.{{ $j }}.10/24' ) |
Andy Bavier | e21a5f5 | 2019-05-28 15:39:52 -0700 | [diff] [blame] | 85 | {{- end }} |
Sreeju | 7d7fc07 | 2019-06-13 12:03:00 -0600 | [diff] [blame] | 86 | {{- end }} |
Andy Bavier | e21a5f5 | 2019-05-28 15:39:52 -0700 | [diff] [blame] | 87 | h1.cmd( 'dnsmasq {{ template "mininet.dhcp_range" . }}' ) |
Andy Bavier | ed9c584 | 2019-05-20 09:53:48 -0700 | [diff] [blame] | 88 | |
Andy Bavier | 3031e9d | 2019-05-22 14:16:07 -0700 | [diff] [blame] | 89 | {{- if .Values.enableMulticast }} |
Andy Bavier | e21a5f5 | 2019-05-28 15:39:52 -0700 | [diff] [blame] | 90 | info( '*** Start multicast routing on h1 and source on h2\n') |
Andy Bavier | 3031e9d | 2019-05-22 14:16:07 -0700 | [diff] [blame] | 91 | h1.cmd( 'service pimd start' ) |
| 92 | h2.cmd( 'mcjoin -s -i h2-eth0 -t 2 >& /tmp/mcjoin.log &') |
| 93 | {{- end }} |
| 94 | |
Andy Bavier | ed9c584 | 2019-05-20 09:53:48 -0700 | [diff] [blame] | 95 | onos.start() |
| 96 | s1.start( [onos] ) |
Andy Bavier | 7a08049 | 2018-08-30 14:26:09 -0700 | [diff] [blame] | 97 | |
| 98 | net.start() |
| 99 | CLI( net ) |
| 100 | net.stop() |