Last active
December 27, 2015 07:09
-
-
Save lantz/7287376 to your computer and use it in GitHub Desktop.
In Mininet (up to 2.1.0 at least) you cannot have multiple Mininet instances running without running into namespace conflicts for the nodes and port conflicts for local controllers. This example demonstrates an easy way to specify a unique prefix for the nodes and a unique port for the controller, thus allowing multiple Mininet instances to coex…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
""" | |
Example of adding a node prefix to avoid namespace conflicts | |
(and changing the controller port to avoid port conflicts.) | |
If we use UserSwitch, then we can run in a Mininet host (!) | |
""" | |
from mininet.net import Mininet | |
from mininet.topo import Topo, LinearTopo | |
from mininet.node import Controller, UserSwitch | |
from mininet.cli import CLI | |
from mininet.log import setLogLevel | |
from sys import argv, exit | |
from functools import partial | |
class PrefixTopoMixin( Topo ): | |
"Mix-in for adding node prefixes" | |
prefix = '' | |
def addNode( self, name, **opts): | |
name = self.prefix + name | |
return super( PrefixTopoMixin, self).addNode( name, **opts ) | |
class PrefixLinearTopo( PrefixTopoMixin, LinearTopo ): | |
"Linear topo with node prefixes" | |
pass | |
try: | |
prefix = argv[ 1 ] | |
port = int( argv[ 2 ] ) | |
except: | |
print 'usage: %s <node-prefix> <controller-port>' % argv[ 0 ] | |
exit( 1 ) | |
setLogLevel( 'info' ) | |
PrefixLinearTopo.prefix = prefix | |
net = Mininet( topo=PrefixLinearTopo( 3 ), switch=UserSwitch, | |
controller=partial( Controller, port=port ) ) | |
net.start() | |
CLI( net ) | |
net.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is just off the top of my head - it could certainly be improved in a variety of ways.