There is probably a better way of doing this, but currently parseCustomFile can modify globals (e.g. TOPOS) as well as instance variables (self.validate) and classes (e.g. MyTopo), which are also in the global name space. Inconveniently enough, lambdas don't seem to be full closures in Python; if they were, this trickiness would be unnecessary. Even so, using execfile() seems like it might be a bit dubious...
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
"""Custom topology example
|
|
|
|
author: Brandon Heller (brandonh@stanford.edu)
|
|
|
|
Two directly connected switches plus a host for each switch:
|
|
|
|
host --- switch --- switch --- host
|
|
|
|
Adding the 'topos' dict with a key/value pair to generate our newly defined
|
|
topology enables one to pass in '--topo=mytopo' from the command line.
|
|
"""
|
|
|
|
from mininet.topo import Topo, Node
|
|
|
|
class MyTopo( Topo ):
|
|
"Simple topology example."
|
|
|
|
def __init__( self, enable_all = True ):
|
|
"Create custom topo."
|
|
|
|
# Add default members to class.
|
|
super( MyTopo, self ).__init__()
|
|
|
|
# Set Node IDs for hosts and switches
|
|
leftHost = 1
|
|
leftSwitch = 2
|
|
rightSwitch = 3
|
|
rightHost = 4
|
|
|
|
# Add nodes
|
|
self._add_node( leftSwitch, Node( is_switch=True ) )
|
|
self._add_node( rightSwitch, Node( is_switch=True ) )
|
|
self._add_node( leftHost, Node( is_switch=False ) )
|
|
self._add_node( rightHost, Node( is_switch=False ) )
|
|
|
|
# Add edges
|
|
self._add_edge( leftHost, leftSwitch )
|
|
self._add_edge( leftSwitch, rightSwitch )
|
|
self._add_edge( rightSwitch, rightHost )
|
|
|
|
# Consider all switches and hosts 'on'
|
|
self.enable_all()
|
|
|
|
|
|
topos = { 'mytopo': MyTopo }
|
|
|
|
# topos = { 'mytopo': ( lambda: MyTopo() ) } |