Daniele Moro | 93c2c50 | 2019-11-05 16:01:36 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | # Copyright 2019-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 | from mininet.cli import CLI |
| 18 | from mininet.log import setLogLevel, info, error |
| 19 | from mininet.net import Mininet |
| 20 | from mininet.link import Intf |
| 21 | from mininet.nodelib import LinuxBridge |
| 22 | from stratum import StratumBmv2Switch |
| 23 | from mininet.util import quietRun |
| 24 | |
| 25 | CPU_PORT = 255 |
| 26 | |
| 27 | if __name__ == '__main__': |
| 28 | setLogLevel( 'info' ) |
| 29 | |
| 30 | net = Mininet( topo=None ) |
| 31 | |
| 32 | info( '*** Adding switches\n' ) |
| 33 | agg1 = net.addSwitch( name='agg1', cls=StratumBmv2Switch, cpuport=CPU_PORT) |
| 34 | s2 = net.addSwitch( 's2', cls=LinuxBridge ) |
| 35 | |
| 36 | info( '*** Creating hosts\n' ) |
| 37 | h1 = net.addHost( 'h1', ip='10.0.0.1/24') |
| 38 | h2 = net.addHost( 'h2', ip='10.1.0.2/24') |
| 39 | |
| 40 | # Topology: pon1 - eth1 - agg1 - h1 - s2 - h2 |
| 41 | net.addLink( h1, agg1 ) |
| 42 | net.addLink( h1, s2 ) |
| 43 | net.addLink( h2, s2 ) |
| 44 | |
| 45 | {{- range $i, $junk := until (.Values.numOlts|int) -}} |
| 46 | {{- $intf := printf "eth%d" (add $i 1) }} |
| 47 | |
| 48 | info( '*** Adding hardware interface {{ $intf }} to switch agg1\n') |
| 49 | _intf = Intf( '{{ $intf }}', node=agg1 ) |
| 50 | |
| 51 | info( '*** Turning off checksum offloading for {{ $intf }}\n' ) |
| 52 | print quietRun( 'ethtool -K {{ $intf }} tx off rx off' ) |
| 53 | {{- end }} |
| 54 | |
| 55 | info( '*** Adding VLAN interface to host h1\n') |
| 56 | h1.cmd( 'ifconfig h1-eth1 10.1.0.1/24 up') |
| 57 | |
| 58 | {{- $onucount := .Values.numOnus|int}} |
| 59 | {{- range $i, $junk := until (.Values.numOlts|int) -}} |
| 60 | {{- $stag := add 222 $i }} |
| 61 | {{- range $j, $junk1 := until ($onucount) -}} |
| 62 | {{- $ctag := add 111 $j }} |
| 63 | h1.cmd( 'ip link add link h1-eth0 name h1-eth0.{{ $stag }} type vlan proto 802.1Q id {{ $stag }}' ) |
| 64 | h1.cmd( 'ip link add link h1-eth0.{{ $stag }} name h1-eth0.{{ $stag }}.{{ $ctag }} type vlan proto 802.1Q id {{ $ctag }}' ) |
| 65 | h1.cmd( 'ifconfig h1-eth0.{{ $stag }} up' ) |
| 66 | h1.cmd( 'ifconfig h1-eth0.{{ $stag }}.{{ $ctag }} up' ) |
| 67 | h1.cmd( 'ifconfig h1-eth0.{{ $stag }}.{{ $ctag }} 172.{{ add $i 18 }}.{{ $j }}.10/24' ) |
| 68 | {{- end }} |
| 69 | {{- end }} |
| 70 | h1.cmd( 'dnsmasq {{ template "mininet.dhcp_range" . }}' ) |
| 71 | |
| 72 | {{- if .Values.enableMulticast }} |
| 73 | info( '*** Start multicast routing on h1 and source on h2\n') |
| 74 | h1.cmd( 'service pimd start' ) |
| 75 | h2.cmd( 'mcjoin -s -i h2-eth0 -t 2 >& /tmp/mcjoin.log &') |
| 76 | {{- end }} |
| 77 | |
| 78 | net.start() |
| 79 | CLI( net ) |
| 80 | net.stop() |