blob: dafbbc6f0466cc8dda2408f09e0cc09a31de1c6c [file] [log] [blame]
Lee Yongjae5ef62ba2017-11-17 12:00:45 +09001#!/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
18from mininet.topo import Topo
19from mininet.net import Mininet
20from mininet.node import Host, OVSSwitch, RemoteController
21from mininet.log import setLogLevel
22from mininet.cli import CLI
23
24
25"Create custom topo."
26
27net = Mininet()
28
29# Add leaf switch and hosts in rack 1
30# subnet: 10.0.1.0/24
31s10 = net.addSwitch('s10', dpid='0000000000000011')
32h11 = net.addHost('h11', mac='00:00:10:00:01:11', ip='10.0.1.11/24', defaultRoute='via 10.0.1.1')
33h12 = net.addHost('h12', mac='00:00:10:00:01:12', ip='10.0.1.12/24', defaultRoute='via 10.0.1.1')
34h13 = net.addHost('h13', mac='00:00:10:00:01:13', ip='10.0.1.13/24', defaultRoute='via 10.0.1.1')
35h14 = net.addHost('h14', mac='00:00:10:00:01:14', ip='10.0.1.14/24', defaultRoute='via 10.0.1.1')
36d11 = net.addHost('d11', mac='00:00:10:00:01:a1', ip='10.0.1.111/24', defaultRoute='via 10.0.1.1')
37d12 = net.addHost('d12', mac='00:00:10:00:01:a2', ip='10.0.1.112/24', defaultRoute='via 10.0.1.1')
38net.addLink(s10, h11)
39net.addLink(s10, h12)
40net.addLink(s10, h13)
41net.addLink(s10, h14)
42net.addLink(s10, d11)
43net.addLink(s10, d12)
44
45# Add leaf switch and hosts in rack 2
46# subnet: 10.0.2.0/24
47s20 = net.addSwitch('s20', dpid='0000000000000012')
48h21 = net.addHost('h21', mac='00:00:10:00:02:21', ip='10.0.2.21/24', defaultRoute='via 10.0.2.1')
49h22 = net.addHost('h22', mac='00:00:10:00:02:22', ip='10.0.2.22/24', defaultRoute='via 10.0.2.1')
50h23 = net.addHost('h23', mac='00:00:10:00:02:23', ip='10.0.2.23/24', defaultRoute='via 10.0.2.1')
51h24 = net.addHost('h24', mac='00:00:10:00:02:24', ip='10.0.2.24/24', defaultRoute='via 10.0.2.1')
52d21 = net.addHost('d21', mac='00:00:10:00:02:b1', ip='10.0.2.221/24', defaultRoute='via 10.0.2.1')
53d22 = net.addHost('d22', mac='00:00:10:00:02:b2', ip='10.0.2.222/24', defaultRoute='via 10.0.2.1')
54net.addLink(s20, h21)
55net.addLink(s20, h22)
56net.addLink(s20, h23)
57net.addLink(s20, h24)
58net.addLink(s20, d21)
59net.addLink(s20, d22)
60
61# Add spine switches and nat
62# subnet: 10.0.0.0/16
63ss1 = net.addSwitch('ss1', dpid='0000000000000021')
64ss2 = net.addSwitch('ss2', dpid='0000000000000022')
65net.addLink(ss1, s10)
66net.addLink(ss1, s20)
67net.addLink(ss2, s10)
68net.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
77net.addController(RemoteController('c1', ip='10.10.108.140'))
78
79# Main
80setLogLevel('info')
81net.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
92CLI(net)
93net.stop()
94