Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (1.23 KB)

1
"""Custom topology example
2

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

5
Two directly connected switches plus a host for each switch:
6

7
   host --- switch --- switch --- host
8

9
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

    
13
from mininet.topo import Topo, Node
14

    
15
class MyTopo( Topo ):
16
    "Simple topology example."
17

    
18
    def __init__( self, enable_all = True ):
19
        "Create custom topo."
20

    
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
        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

    
36
        # Add edges
37
        self.add_edge( leftHost, leftSwitch )
38
        self.add_edge( leftSwitch, rightSwitch )
39
        self.add_edge( rightSwitch, rightHost )
40

    
41
        # Consider all switches and hosts 'on'
42
        self.enable_all()
43

    
44

    
45
topos = { 'mytopo': ( lambda: MyTopo() ) }