blob: 61d2dcccd0b6b4273d80b872c1dd33e259cbd276 [file] [log] [blame]
Masayoshi Kobayashif358ff52013-03-22 00:31:59 +00001#!/usr/bin/python
2
3"""
4Start up a Simple topology
5"""
6from mininet.net import Mininet
7from mininet.node import Controller, RemoteController
8from mininet.log import setLogLevel, info, error, warn, debug
9from mininet.cli import CLI
10from mininet.topo import Topo
11from mininet.util import quietRun
12from mininet.moduledeps import pathCheck
13from mininet.link import Link, TCLink
14
15from sys import exit
16import os.path
17from subprocess import Popen, STDOUT, PIPE
18
19import sys
20
21
22#import argparse
23
24class MyController( Controller ):
25 def __init__( self, name, ip='127.0.0.1', port=6633, **kwargs):
26 """Init.
27 name: name to give controller
28 ip: the IP address where the remote controller is
29 listening
30 port: the port where the remote controller is listening"""
31 Controller.__init__( self, name, ip=ip, port=port, **kwargs )
32
33 def start( self ):
34 "Overridden to do nothing."
35 return
36
37 def stop( self ):
38 "Overridden to do nothing."
39 return
40
41 def checkListening( self ):
42 "Warn if remote controller is not accessible"
43 listening = self.cmd( "echo A | telnet -e A %s %d" %
44 ( self.ip, self.port ) )
45 if 'Unable' in listening:
46 warn( "Unable to contact the remote controller"
47 " at %s:%d\n" % ( self.ip, self.port ) )
48
49class SDNTopo( Topo ):
50 "SDN Topology"
51
52 def __init__( self, *args, **kwargs ):
53 Topo.__init__( self, *args, **kwargs )
Pavlin Radoslavov738648d2013-04-03 19:59:10 +000054 sw1 = self.addSwitch('sw1', dpid='0000000000000101')
55 sw2 = self.addSwitch('sw2', dpid='0000000000000102')
56 sw3 = self.addSwitch('sw3', dpid='0000000000000103')
57 sw4 = self.addSwitch('sw4', dpid='0000000000000104')
58 sw5 = self.addSwitch('sw5', dpid='0000000000000105')
59 sw6 = self.addSwitch('sw6', dpid='0000000000000106')
Masayoshi Kobayashif358ff52013-03-22 00:31:59 +000060
61 host1 = self.addHost( 'host1' )
62 host2 = self.addHost( 'host2' )
63 host3 = self.addHost( 'host3' )
64 host4 = self.addHost( 'host4' )
65 host5 = self.addHost( 'host5' )
66 host6 = self.addHost( 'host6' )
67
68 root1 = self.addHost( 'root1', inNamespace=False )
69 root2 = self.addHost( 'root2', inNamespace=False )
70 root3 = self.addHost( 'root3', inNamespace=False )
71 root4 = self.addHost( 'root4', inNamespace=False )
72 root5 = self.addHost( 'root5', inNamespace=False )
73 root6 = self.addHost( 'root6', inNamespace=False )
74
75
76 self.addLink( host1, sw1 )
77 self.addLink( host2, sw2 )
78 self.addLink( host3, sw3 )
79 self.addLink( host4, sw4 )
80 self.addLink( host5, sw5 )
81 self.addLink( host6, sw6 )
82
83
84 self.addLink( sw1, sw2 )
85 self.addLink( sw1, sw6 )
86 self.addLink( sw2, sw3 )
87 self.addLink( sw3, sw4 )
88 self.addLink( sw3, sw6 )
89 self.addLink( sw4, sw5 )
90 self.addLink( sw5, sw6 )
Pavlin Radoslavov3b8b9bf2013-04-03 01:23:43 +000091 self.addLink( sw4, sw6 )
Masayoshi Kobayashif358ff52013-03-22 00:31:59 +000092
93 self.addLink( root1, host1 )
94 self.addLink( root2, host2 )
95 self.addLink( root3, host3 )
96 self.addLink( root4, host4 )
97 self.addLink( root5, host5 )
98 self.addLink( root6, host6 )
99
100def startsshd( host ):
101 "Start sshd on host"
102 info( '*** Starting sshd\n' )
103 name, intf, ip = host.name, host.defaultIntf(), host.IP()
104 banner = '/tmp/%s.banner' % name
105 host.cmd( 'echo "Welcome to %s at %s" > %s' % ( name, ip, banner ) )
106 host.cmd( '/usr/sbin/sshd -o "Banner %s"' % banner, '-o "UseDNS no"' )
107 info( '***', host.name, 'is running sshd on', intf, 'at', ip, '\n' )
108
109def startsshds ( hosts ):
110 for h in hosts:
111 startsshd( h )
112
113def stopsshd( ):
114 "Stop *all* sshd processes with a custom banner"
115 info( '*** Shutting down stale sshd/Banner processes ',
116 quietRun( "pkill -9 -f Banner" ), '\n' )
117
118def sdnnet(opt):
119# os.system('/home/ubuntu/openflow/controller/controller ptcp: &')
120# os.system('/home/ubuntu/openflow/controller/controller ptcp:7000 &')
121
122 topo = SDNTopo()
123 info( '*** Creating network\n' )
124# net = Mininet( topo=topo, controller=RemoteController )
125 net = Mininet( topo=topo, controller=MyController, link=TCLink)
126# dc = DebugController('c3', ip='127.0.0.1', port=7000)
127# net.addController(dc)
128# net.addController(controller=RemoteController)
129
130 host1, host2, host3, host4, host5, host6 = net.get( 'host1', 'host2', 'host3', 'host4', 'host5', 'host6')
131
132 ## Adding 2nd, 3rd and 4th interface to host1 connected to sw1 (for another BGP peering)
133 sw1 = net.get('sw1')
134 sw2 = net.get('sw2')
135 sw3 = net.get('sw3')
136 sw4 = net.get('sw4')
137 sw5 = net.get('sw5')
138 sw6 = net.get('sw6')
139
140 net.start()
141
142 sw2.attach('tap01_2')
143 sw3.attach('tap01_3')
144 sw4.attach('tap01_4')
145 sw4.attach('tap01_5')
146 sw5.attach('tap01_6')
147 sw6.attach('tap01_7')
148 sw1.attach('tap01_8')
149
150 host1.defaultIntf().setIP('192.168.100.141/16')
151 host2.defaultIntf().setIP('192.168.100.142/16')
152 host3.defaultIntf().setIP('192.168.100.143/16')
153 host4.defaultIntf().setIP('192.168.100.144/16')
154 host5.defaultIntf().setIP('192.168.100.145/16')
155 host6.defaultIntf().setIP('192.168.100.146/16')
156
157 root1, root2, root3, root4, root5, root6 = net.get( 'root1', 'root2', 'root3', 'root4', 'root5', 'root6' )
158 host1.intf('host1-eth1').setIP('1.1.1.1/24')
159 root1.intf('root1-eth0').setIP('1.1.1.2/24')
160
161 host2.intf('host2-eth1') .setIP('1.1.2.1/24')
162 root2.intf('root2-eth0').setIP('1.1.2.2/24')
163
164 host3.intf('host3-eth1') .setIP('1.1.3.1/24')
165 root3.intf('root3-eth0').setIP('1.1.3.2/24')
166
167 host4.intf('host4-eth1') .setIP('1.1.4.1/24')
168 root4.intf('root4-eth0').setIP('1.1.4.2/24')
169
170 host5.intf('host5-eth1') .setIP('1.1.5.1/24')
171 root5.intf('root5-eth0').setIP('1.1.5.2/24')
172
173 host6.intf('host6-eth1') .setIP('1.1.6.1/24')
174 root6.intf('root6-eth0').setIP('1.1.6.2/24')
175
176 hosts = [ host1, host2, host3, host4, host5, host6 ]
177 stopsshd ()
178 startsshds ( hosts )
179
180 if opt=="cli":
181 CLI(net)
182 stopsshd()
183 net.stop()
184
185if __name__ == '__main__':
186 setLogLevel( 'info' )
187 if len(sys.argv) == 1:
188 sdnnet("cli")
189 elif len(sys.argv) == 2 and sys.argv[1] == "-n":
190 sdnnet("nocli")
191 else:
192 print "%s [-n]" % sys.argv[0]