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' ) |
| 38 | OVSSwitch13 = partial( OVSSwitch, protocols='OpenFlow13' ) |
Andy Bavier | 8fef610 | 2018-12-21 16:54:26 -0700 | [diff] [blame] | 39 | controllerIp = socket.gethostbyname( '{{ .Values.onosOpenflowSvc }}' ) |
Andy Bavier | 7a08049 | 2018-08-30 14:26:09 -0700 | [diff] [blame] | 40 | net = Mininet( topo=SingleSwitchTopo(1), |
| 41 | controller=lambda name: RemoteController( name, ip=controllerIp, port=6653 ), |
| 42 | switch=OVSSwitch13 |
| 43 | ) |
| 44 | |
| 45 | switch = net.switches[ 0 ] |
| 46 | info( '*** Adding hardware interface eth1 to switch', switch.name, '\n' ) |
| 47 | _intf = Intf( 'eth1', node=switch ) |
| 48 | |
| 49 | info( '*** Turning off checksum offloading for eth1\n' ) |
| 50 | print quietRun( 'ethtool -K eth1 tx off rx off' ) |
| 51 | |
| 52 | bgphost = net.hosts [ 0 ] |
| 53 | info( '*** Adding VLAN interface to host\n') |
| 54 | bgphost.cmd( 'ip link add link h1-eth0 name h1-eth0.222 type vlan id 222' ) |
| 55 | bgphost.cmd( 'ip link add link h1-eth0.222 name h1-eth0.222.111 type vlan id 111' ) |
| 56 | bgphost.cmd( 'ifconfig h1-eth0.222 up' ) |
| 57 | bgphost.cmd( 'ifconfig h1-eth0.222.111 up' ) |
| 58 | bgphost.cmd( 'ifconfig h1-eth0.222.111 172.18.0.10/24' ) |
| 59 | bgphost.cmd( 'dnsmasq --dhcp-range=172.18.0.50,172.18.0.150,12h' ) |
| 60 | |
| 61 | net.start() |
| 62 | CLI( net ) |
| 63 | net.stop() |