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 | |
| 62 | info( '*** Adding hardware interface eth1 to switch %s\n' % s1.name) |
| 63 | _intf = Intf( 'eth1', node=s1 ) |
Andy Bavier | 7a08049 | 2018-08-30 14:26:09 -0700 | [diff] [blame] | 64 | |
| 65 | info( '*** Turning off checksum offloading for eth1\n' ) |
| 66 | print quietRun( 'ethtool -K eth1 tx off rx off' ) |
| 67 | |
Andy Bavier | ed9c584 | 2019-05-20 09:53:48 -0700 | [diff] [blame] | 68 | info( '*** Adding VLAN interface to host %s\n' % h1.name) |
| 69 | base = "%s-eth0" % h1.name |
| 70 | h1.cmd( 'ifconfig %s-eth1 10.1.0.1/24 up' % h1.name) |
| 71 | h1.cmd( 'ip link add link %s name %s.222 type vlan proto 802.1Q id 222' % (base, base)) |
| 72 | h1.cmd( 'ip link add link %s.222 name %s.222.111 type vlan proto 802.1Q id 111' % (base, base)) |
| 73 | h1.cmd( 'ifconfig %s.222 up' % base) |
| 74 | h1.cmd( 'ifconfig %s.222.111 up' % base) |
| 75 | h1.cmd( 'ifconfig %s.222.111 172.18.0.10/24' % base) |
| 76 | h1.cmd( 'dnsmasq --dhcp-range=172.18.0.50,172.18.0.150,12h' ) |
| 77 | |
| 78 | onos.start() |
| 79 | s1.start( [onos] ) |
Andy Bavier | 7a08049 | 2018-08-30 14:26:09 -0700 | [diff] [blame] | 80 | |
| 81 | net.start() |
| 82 | CLI( net ) |
| 83 | net.stop() |