Statistics
| Branch: | Tag: | Revision:

mininet / custom / topo-2sw-2host.py @ 987fd755

History | View | Annotate | Download (1.25 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
14
from mininet.node import Node
15

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

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

    
22
        # Add default members to class.
23
        super( MyTopo, self ).__init__()
24

    
25
        # Set Node IDs for hosts and switches
26
        leftHost = 1
27
        leftSwitch = 2
28
        rightSwitch = 3
29
        rightHost = 4
30

    
31
        # Add nodes
32
        self.addNode( leftSwitch, Node( isSwitch=True ) )
33
        self.addNode( rightSwitch, Node( isSwitch=True ) )
34
        self.addNode( leftHost, Node( isSwitch=False ) )
35
        self.addNode( rightHost, Node( isSwitch=False ) )
36

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

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

    
45

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