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 |
| 25 | from mininet.topo import SingleSwitchTopo |
| 26 | from mininet.node import OVSSwitch, RemoteController |
| 27 | from functools import partial |
| 28 | from mininet.util import quietRun |
| 29 | |
| 30 | if __name__ == '__main__': |
| 31 | setLogLevel( 'info' ) |
| 32 | |
| 33 | info( '*** Installing required software' ) |
| 34 | print quietRun( 'apt-get update' ) |
| 35 | print quietRun( 'apt-get -y install dnsmasq ethtool' ) |
| 36 | |
| 37 | info( '*** Creating network\n' ) |
Andy Bavier | 6ca22c0 | 2019-04-02 14:03:49 -0700 | [diff] [blame] | 38 | 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] | 39 | OVSSwitch13 = partial( OVSSwitch, protocols='OpenFlow13' ) |
Andy Bavier | 8fef610 | 2018-12-21 16:54:26 -0700 | [diff] [blame] | 40 | controllerIp = socket.gethostbyname( '{{ .Values.onosOpenflowSvc }}' ) |
Andy Bavier | 7a08049 | 2018-08-30 14:26:09 -0700 | [diff] [blame] | 41 | net = Mininet( topo=SingleSwitchTopo(1), |
| 42 | controller=lambda name: RemoteController( name, ip=controllerIp, port=6653 ), |
| 43 | switch=OVSSwitch13 |
| 44 | ) |
| 45 | |
| 46 | switch = net.switches[ 0 ] |
| 47 | info( '*** Adding hardware interface eth1 to switch', switch.name, '\n' ) |
| 48 | _intf = Intf( 'eth1', node=switch ) |
| 49 | |
| 50 | info( '*** Turning off checksum offloading for eth1\n' ) |
| 51 | print quietRun( 'ethtool -K eth1 tx off rx off' ) |
| 52 | |
| 53 | bgphost = net.hosts [ 0 ] |
| 54 | info( '*** Adding VLAN interface to host\n') |
Andy Bavier | 6ca22c0 | 2019-04-02 14:03:49 -0700 | [diff] [blame] | 55 | bgphost.cmd( 'ip link add link h1-eth0 name h1-eth0.222 type vlan proto 802.1Q id 222' ) |
| 56 | bgphost.cmd( 'ip link add link h1-eth0.222 name h1-eth0.222.111 type vlan proto 802.1Q id 111' ) |
Andy Bavier | 7a08049 | 2018-08-30 14:26:09 -0700 | [diff] [blame] | 57 | bgphost.cmd( 'ifconfig h1-eth0.222 up' ) |
| 58 | bgphost.cmd( 'ifconfig h1-eth0.222.111 up' ) |
| 59 | bgphost.cmd( 'ifconfig h1-eth0.222.111 172.18.0.10/24' ) |
| 60 | bgphost.cmd( 'dnsmasq --dhcp-range=172.18.0.50,172.18.0.150,12h' ) |
| 61 | |
| 62 | net.start() |
| 63 | CLI( net ) |
| 64 | net.stop() |