Statistics
| Branch: | Tag: | Revision:

mininet / custom / topo-2sw-2host.py @ ae2ede79

History | View | Annotate | Download (1.23 KB)

1 befa1310 Brandon Heller
"""Custom topology example
2 3031d31e Brandon Heller

3 befa1310 Brandon Heller
author: Brandon Heller (brandonh@stanford.edu)
4 3031d31e Brandon Heller

5 befa1310 Brandon Heller
Two directly connected switches plus a host for each switch:
6 3031d31e Brandon Heller

7 befa1310 Brandon Heller
   host --- switch --- switch --- host
8 3031d31e Brandon Heller

9 befa1310 Brandon Heller
Adding the 'topos' dict with a key/value pair to generate our newly defined
10
topology enables one to pass in '--topo=mytopo' from the command line.
11
"""
12 3031d31e Brandon Heller
13 befa1310 Brandon Heller
from mininet.topo import Topo, Node
14 3031d31e Brandon Heller
15 befa1310 Brandon Heller
class MyTopo( Topo ):
16 c3a44400 Bob Lantz
    "Simple topology example."
17 befa1310 Brandon Heller
18
    def __init__( self, enable_all = True ):
19 c3a44400 Bob Lantz
        "Create custom topo."
20 befa1310 Brandon Heller
21
        # Add default members to class.
22
        super( MyTopo, self ).__init__()
23
24
        # Set Node IDs for hosts and switches
25
        leftHost = 1
26
        leftSwitch = 2
27
        rightSwitch = 3
28
        rightHost = 4
29
30
        # Add nodes
31 0b1832dd Brandon Heller
        self.add_node( leftSwitch, Node( is_switch=True ) )
32
        self.add_node( rightSwitch, Node( is_switch=True ) )
33
        self.add_node( leftHost, Node( is_switch=False ) )
34
        self.add_node( rightHost, Node( is_switch=False ) )
35 befa1310 Brandon Heller
36
        # Add edges
37 0b1832dd Brandon Heller
        self.add_edge( leftHost, leftSwitch )
38
        self.add_edge( leftSwitch, rightSwitch )
39
        self.add_edge( rightSwitch, rightHost )
40 befa1310 Brandon Heller
41
        # Consider all switches and hosts 'on'
42
        self.enable_all()
43
44
45 0b1832dd Brandon Heller
topos = { 'mytopo': ( lambda: MyTopo() ) }