Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # Mininet model for Simple Leaf-Spine Network |
| 3 | |
| 4 | # Copyright 2017-present Open Networking Foundation |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | |
| 18 | from mininet.topo import Topo |
| 19 | from mininet.net import Mininet |
| 20 | from mininet.node import Host, OVSSwitch, RemoteController |
| 21 | from mininet.log import setLogLevel |
| 22 | from mininet.cli import CLI |
| 23 | |
| 24 | |
| 25 | "Create custom topo." |
| 26 | |
| 27 | net = Mininet() |
| 28 | |
| 29 | # Add leaf switch and hosts in rack 1 |
| 30 | # subnet: 10.0.1.0/24 |
| 31 | s10 = net.addSwitch('s10', dpid='0000000000000011') |
| 32 | h11 = net.addHost('h11', mac='00:00:10:00:01:11', ip='10.0.1.11/24', defaultRoute='via 10.0.1.1') |
| 33 | h12 = net.addHost('h12', mac='00:00:10:00:01:12', ip='10.0.1.12/24', defaultRoute='via 10.0.1.1') |
| 34 | h13 = net.addHost('h13', mac='00:00:10:00:01:13', ip='10.0.1.13/24', defaultRoute='via 10.0.1.1') |
| 35 | h14 = net.addHost('h14', mac='00:00:10:00:01:14', ip='10.0.1.14/24', defaultRoute='via 10.0.1.1') |
| 36 | d11 = net.addHost('d11', mac='00:00:10:00:01:a1', ip='10.0.1.111/24', defaultRoute='via 10.0.1.1') |
| 37 | d12 = net.addHost('d12', mac='00:00:10:00:01:a2', ip='10.0.1.112/24', defaultRoute='via 10.0.1.1') |
| 38 | net.addLink(s10, h11) |
| 39 | net.addLink(s10, h12) |
| 40 | net.addLink(s10, h13) |
| 41 | net.addLink(s10, h14) |
| 42 | net.addLink(s10, d11) |
| 43 | net.addLink(s10, d12) |
| 44 | |
| 45 | # Add leaf switch and hosts in rack 2 |
| 46 | # subnet: 10.0.2.0/24 |
| 47 | s20 = net.addSwitch('s20', dpid='0000000000000012') |
| 48 | h21 = net.addHost('h21', mac='00:00:10:00:02:21', ip='10.0.2.21/24', defaultRoute='via 10.0.2.1') |
| 49 | h22 = net.addHost('h22', mac='00:00:10:00:02:22', ip='10.0.2.22/24', defaultRoute='via 10.0.2.1') |
| 50 | h23 = net.addHost('h23', mac='00:00:10:00:02:23', ip='10.0.2.23/24', defaultRoute='via 10.0.2.1') |
| 51 | h24 = net.addHost('h24', mac='00:00:10:00:02:24', ip='10.0.2.24/24', defaultRoute='via 10.0.2.1') |
| 52 | d21 = net.addHost('d21', mac='00:00:10:00:02:b1', ip='10.0.2.221/24', defaultRoute='via 10.0.2.1') |
| 53 | d22 = net.addHost('d22', mac='00:00:10:00:02:b2', ip='10.0.2.222/24', defaultRoute='via 10.0.2.1') |
| 54 | net.addLink(s20, h21) |
| 55 | net.addLink(s20, h22) |
| 56 | net.addLink(s20, h23) |
| 57 | net.addLink(s20, h24) |
| 58 | net.addLink(s20, d21) |
| 59 | net.addLink(s20, d22) |
| 60 | |
| 61 | # Add spine switches and nat |
| 62 | # subnet: 10.0.0.0/16 |
| 63 | ss1 = net.addSwitch('ss1', dpid='0000000000000021') |
| 64 | ss2 = net.addSwitch('ss2', dpid='0000000000000022') |
| 65 | net.addLink(ss1, s10) |
| 66 | net.addLink(ss1, s20) |
| 67 | net.addLink(ss2, s10) |
| 68 | net.addLink(ss2, s20) |
| 69 | |
| 70 | # Add External Router |
| 71 | #h31 = net.addHost('h31', mac='00:00:10:00:00:31', ip='10.0.0.31/24', defaultRoute='via 10.0.0.1') |
| 72 | #h32 = net.addHost('h32', mac='00:00:10:00:00:32', ip='10.0.0.32/24', defaultRoute='via 10.0.0.1') |
| 73 | #net.addLink(ss1, h31); |
| 74 | #net.addLink(ss2, h32); |
| 75 | |
| 76 | # Add ONOS/RemoteController; set your ONOS node ip address |
| 77 | net.addController(RemoteController('c1', ip='10.10.108.140')) |
| 78 | |
| 79 | # Main |
| 80 | setLogLevel('info') |
| 81 | net.start() |
| 82 | |
| 83 | # reveal hosts to switches |
| 84 | #for h in [h11, h12, h13, h14, d11, d12] : |
| 85 | # net.ping(hosts=[h, h31], timeout='1') |
| 86 | # net.ping(hosts=[h, h31], timeout='1') |
| 87 | #for h in [h21, h22, h23, h24, d21, d22] : |
| 88 | # net.ping(hosts=[h, h32], timeout='1') |
| 89 | # net.ping(hosts=[h, h32], timeout='1') |
| 90 | |
| 91 | # do interactive shell |
| 92 | CLI(net) |
| 93 | net.stop() |
| 94 | |