blob: dfb414dc63f1ad5e109f7ae8343510bacfa13977 [file] [log] [blame]
Gamze Abaka641fc072018-09-04 09:16:27 +00001'''
2 Copyright 2016-present Open Networking Foundation
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16'''
17from mininet.cli import CLI
18from mininet.log import setLogLevel
19from mininet.net import Mininet
20from mininet.topo import Topo
21from mininet.node import RemoteController, UserSwitch
22
23class MinimalTopo( Topo ):
24 "Minimal topology with a single switch and two hosts"
25
26 def build( self ):
27 # Create two hosts.
28 h1 = self.addHost( 'h1' )
29 h2 = self.addHost( 'h2' )
30
31 # Create a switch
32 s1 = self.addSwitch( 's1', cls=UserSwitch)
33
34 # Add links between the switch and each host
35 self.addLink( s1, h1 )
36 self.addLink( s1, h2 )
37
38def runMinimalTopo():
39 "Bootstrap a Mininet network using the Minimal Topology"
40
41 # Create an instance of our topology
42 topo = MinimalTopo()
43
44 # Create a network based on the topology using OVS and controlled by
45 # a remote controller.
46 net = Mininet(
47 topo=topo,
48 controller=lambda name: RemoteController( name, ip='127.0.0.1' ),
49 switch=UserSwitch,
50 autoSetMacs=True )
51
52 # Actually start the network
53 net.start()
54
55 # Drop the user in to a CLI so user can run commands.
56 CLI( net )
57
58 # After the user exits the CLI, shutdown the network.
59 net.stop()
60
61if __name__ == '__main__':
62 # This runs if this file is executed directly
63 setLogLevel( 'info' )
64 runMinimalTopo()
65
66# Allows the file to be imported using `mn --custom <filename> --topo minimal`
67topos = {
68 'minimal': MinimalTopo
69}