Move init() into Mininet() and remove calls (since called automatically.)
Note: we should probably rename it "setup()" to avoid confusion.
This commit is contained in:
@@ -19,7 +19,7 @@ import time
|
|||||||
from mininet.clean import cleanup
|
from mininet.clean import cleanup
|
||||||
from mininet.cli import CLI
|
from mininet.cli import CLI
|
||||||
from mininet.log import lg, LEVELS, info, warn
|
from mininet.log import lg, LEVELS, info, warn
|
||||||
from mininet.net import Mininet, init
|
from mininet.net import Mininet
|
||||||
from mininet.node import Host, CPULimitedHost, Controller, OVSController, NOX
|
from mininet.node import Host, CPULimitedHost, Controller, OVSController, NOX
|
||||||
from mininet.node import RemoteController, UserSwitch, OVSKernelSwitch
|
from mininet.node import RemoteController, UserSwitch, OVSKernelSwitch
|
||||||
from mininet.link import Intf, TCIntf
|
from mininet.link import Intf, TCIntf
|
||||||
@@ -27,6 +27,7 @@ from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
|
|||||||
from mininet.topolib import TreeTopo
|
from mininet.topolib import TreeTopo
|
||||||
from mininet.util import makeNumeric, custom
|
from mininet.util import makeNumeric, custom
|
||||||
|
|
||||||
|
|
||||||
def customNode( constructors, argStr ):
|
def customNode( constructors, argStr ):
|
||||||
"Return custom Node constructor based on argStr"
|
"Return custom Node constructor based on argStr"
|
||||||
cname, newargs, kwargs = splitArgs( argStr )
|
cname, newargs, kwargs = splitArgs( argStr )
|
||||||
@@ -47,7 +48,6 @@ def customNode( constructors, argStr ):
|
|||||||
return custom
|
return custom
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# built in topologies, created only when run
|
# built in topologies, created only when run
|
||||||
TOPODEF = 'minimal'
|
TOPODEF = 'minimal'
|
||||||
TOPOS = { 'minimal': lambda: SingleSwitchTopo( k=2 ),
|
TOPOS = { 'minimal': lambda: SingleSwitchTopo( k=2 ),
|
||||||
@@ -229,9 +229,6 @@ class MininetRunner( object ):
|
|||||||
% self.options.verbosity )
|
% self.options.verbosity )
|
||||||
lg.setLogLevel( self.options.verbosity )
|
lg.setLogLevel( self.options.verbosity )
|
||||||
|
|
||||||
# validate environment setup
|
|
||||||
init()
|
|
||||||
|
|
||||||
def begin( self ):
|
def begin( self ):
|
||||||
"Create and run mininet."
|
"Create and run mininet."
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ of switches, this example demonstrates:
|
|||||||
import sys
|
import sys
|
||||||
flush = sys.stdout.flush
|
flush = sys.stdout.flush
|
||||||
|
|
||||||
from mininet.net import init, Mininet
|
from mininet.net import Mininet
|
||||||
# from mininet.node import KernelSwitch
|
# from mininet.node import KernelSwitch
|
||||||
from mininet.node import UserSwitch, OVSKernelSwitch
|
from mininet.node import UserSwitch, OVSKernelSwitch
|
||||||
from mininet.topo import Topo, Node
|
from mininet.topo import Topo, Node
|
||||||
@@ -106,7 +106,6 @@ def linearBandwidthTest( lengths ):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
lg.setLogLevel( 'info' )
|
lg.setLogLevel( 'info' )
|
||||||
init()
|
|
||||||
sizes = [ 1, 10, 20, 40, 60, 80, 100 ]
|
sizes = [ 1, 10, 20, 40, 60, 80, 100 ]
|
||||||
print "*** Running linearBandwidthTest", sizes
|
print "*** Running linearBandwidthTest", sizes
|
||||||
linearBandwidthTest( sizes )
|
linearBandwidthTest( sizes )
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ but it exposes the configuration details and allows customization.
|
|||||||
For most tasks, the higher-level API will be preferable.
|
For most tasks, the higher-level API will be preferable.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from mininet.net import init
|
from mininet.net import Mininet
|
||||||
from mininet.node import Node, OVSKernelSwitch
|
from mininet.node import Node
|
||||||
from mininet.util import createLink
|
from mininet.util import createLink
|
||||||
from mininet.log import setLogLevel, info
|
from mininet.log import setLogLevel, info
|
||||||
|
|
||||||
def scratchNet( cname='controller', cargs='ptcp:' ):
|
def scratchNet( cname='controller', cargs='ptcp:' ):
|
||||||
"Create network from scratch using kernel switch."
|
"Create network from scratch using Open vSwitch."
|
||||||
|
|
||||||
info( "*** Creating nodes\n" )
|
info( "*** Creating nodes\n" )
|
||||||
controller = Node( 'c0', inNamespace=False )
|
controller = Node( 'c0', inNamespace=False )
|
||||||
@@ -53,6 +53,5 @@ def scratchNet( cname='controller', cargs='ptcp:' ):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
setLogLevel( 'info' )
|
setLogLevel( 'info' )
|
||||||
info( '*** Scratch network demo (kernel datapath)\n' )
|
info( '*** Scratch network demo (kernel datapath)\n' )
|
||||||
OVSKernelSwitch.setup()
|
Mininet.init()
|
||||||
init()
|
|
||||||
scratchNet()
|
scratchNet()
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ For most tasks, the higher-level API will be preferable.
|
|||||||
This version uses the user datapath and an explicit control network.
|
This version uses the user datapath and an explicit control network.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from mininet.net import init
|
from mininet.net import Mininet
|
||||||
from mininet.node import Node
|
from mininet.node import Node
|
||||||
from mininet.util import createLink
|
from mininet.util import createLink
|
||||||
from mininet.log import setLogLevel, info
|
from mininet.log import setLogLevel, info
|
||||||
@@ -64,5 +64,5 @@ def scratchNetUser( cname='controller', cargs='ptcp:' ):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
setLogLevel( 'info' )
|
setLogLevel( 'info' )
|
||||||
info( '*** Scratch network demo (user datapath)\n' )
|
info( '*** Scratch network demo (user datapath)\n' )
|
||||||
init()
|
Mininet.init()
|
||||||
scratchNetUser()
|
scratchNetUser()
|
||||||
|
|||||||
+16
-18
@@ -146,7 +146,7 @@ class Mininet( object ):
|
|||||||
|
|
||||||
self.terms = [] # list of spawned xterm processes
|
self.terms = [] # list of spawned xterm processes
|
||||||
|
|
||||||
init() # Initialize Mininet if necessary
|
Mininet.init() # Initialize Mininet if necessary
|
||||||
|
|
||||||
self.built = False
|
self.built = False
|
||||||
if topo and build:
|
if topo and build:
|
||||||
@@ -527,6 +527,21 @@ class Mininet( object ):
|
|||||||
self.stop()
|
self.stop()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
inited = False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def init( cls ):
|
||||||
|
"Initialize Mininet"
|
||||||
|
if cls.inited:
|
||||||
|
return
|
||||||
|
if os.getuid() != 0:
|
||||||
|
# Note: this script must be run as root
|
||||||
|
# Perhaps we should do so automatically!
|
||||||
|
print "*** Mininet must run as root."
|
||||||
|
exit( 1 )
|
||||||
|
fixLimits()
|
||||||
|
cls.inited = True
|
||||||
|
|
||||||
|
|
||||||
class MininetWithControlNet( Mininet ):
|
class MininetWithControlNet( Mininet ):
|
||||||
|
|
||||||
@@ -592,21 +607,4 @@ class MininetWithControlNet( Mininet ):
|
|||||||
exit( 1 )
|
exit( 1 )
|
||||||
info( '\n' )
|
info( '\n' )
|
||||||
|
|
||||||
# pylint thinks inited is unused
|
|
||||||
# pylint: disable-msg=W0612
|
|
||||||
|
|
||||||
def init():
|
|
||||||
"Initialize Mininet."
|
|
||||||
if init.inited:
|
|
||||||
return
|
|
||||||
if os.getuid() != 0:
|
|
||||||
# Note: this script must be run as root
|
|
||||||
# Perhaps we should do so automatically!
|
|
||||||
print "*** Mininet must run as root."
|
|
||||||
exit( 1 )
|
|
||||||
fixLimits()
|
|
||||||
init.inited = True
|
|
||||||
|
|
||||||
init.inited = False
|
|
||||||
|
|
||||||
# pylint: enable-msg=W0612
|
|
||||||
|
|||||||
+4
-4
@@ -499,7 +499,7 @@ class CPULimitedHost( Host ):
|
|||||||
"Set a cgroup parameter and return its value"
|
"Set a cgroup parameter and return its value"
|
||||||
cmd = 'cgset -r %s.%s=%s /%s' % (
|
cmd = 'cgset -r %s.%s=%s /%s' % (
|
||||||
resource, param, value, self.name )
|
resource, param, value, self.name )
|
||||||
out = quietRun( cmd )
|
quietRun( cmd )
|
||||||
nvalue = int( self.cgroupGet( param, resource ) )
|
nvalue = int( self.cgroupGet( param, resource ) )
|
||||||
if nvalue != value:
|
if nvalue != value:
|
||||||
error( '*** error: cgroupSet: %s set to %s instead of %s\n'
|
error( '*** error: cgroupSet: %s set to %s instead of %s\n'
|
||||||
@@ -568,11 +568,11 @@ class CPULimitedHost( Host ):
|
|||||||
# Reset to unlimited
|
# Reset to unlimited
|
||||||
quota = -1
|
quota = -1
|
||||||
# Set cgroup's period and quota
|
# Set cgroup's period and quota
|
||||||
nperiod = self.cgroupSet( pstr, period )
|
self.cgroupSet( pstr, period )
|
||||||
nquota = self.cgroupSet( qstr, quota )
|
self.cgroupSet( qstr, quota )
|
||||||
if sched == 'rt':
|
if sched == 'rt':
|
||||||
# Set RT priority if necessary
|
# Set RT priority if necessary
|
||||||
nchrt = self.chrt( prio=20 )
|
self.chrt( prio=20 )
|
||||||
info( '(%s %d/%dus) ' % ( sched, quota, period ) )
|
info( '(%s %d/%dus) ' % ( sched, quota, period ) )
|
||||||
|
|
||||||
def config( self, cpu=None, sched=None, **params ):
|
def config( self, cpu=None, sched=None, **params ):
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from mininet.net import init, Mininet
|
from mininet.net import Mininet
|
||||||
from mininet.node import Host, Controller, ControllerParams
|
from mininet.node import Host, Controller
|
||||||
from mininet.node import UserSwitch, OVSKernelSwitch
|
from mininet.node import UserSwitch, OVSKernelSwitch
|
||||||
from mininet.topo import SingleSwitchTopo, LinearTopo
|
from mininet.topo import SingleSwitchTopo, LinearTopo
|
||||||
from mininet.log import setLogLevel
|
from mininet.log import setLogLevel
|
||||||
@@ -21,7 +21,6 @@ class testSingleSwitch( unittest.TestCase ):
|
|||||||
|
|
||||||
def testMinimal( self ):
|
def testMinimal( self ):
|
||||||
"Ping test with both datapaths on minimal topology"
|
"Ping test with both datapaths on minimal topology"
|
||||||
init()
|
|
||||||
for switch in SWITCHES.values():
|
for switch in SWITCHES.values():
|
||||||
mn = Mininet( SingleSwitchTopo(), switch, Host, Controller )
|
mn = Mininet( SingleSwitchTopo(), switch, Host, Controller )
|
||||||
dropped = mn.run( mn.ping )
|
dropped = mn.run( mn.ping )
|
||||||
@@ -29,7 +28,6 @@ class testSingleSwitch( unittest.TestCase ):
|
|||||||
|
|
||||||
def testSingle5( self ):
|
def testSingle5( self ):
|
||||||
"Ping test with both datapaths on 5-host single-switch topology"
|
"Ping test with both datapaths on 5-host single-switch topology"
|
||||||
init()
|
|
||||||
for switch in SWITCHES.values():
|
for switch in SWITCHES.values():
|
||||||
mn = Mininet( SingleSwitchTopo( k=5 ), switch, Host, Controller )
|
mn = Mininet( SingleSwitchTopo( k=5 ), switch, Host, Controller )
|
||||||
dropped = mn.run( mn.ping )
|
dropped = mn.run( mn.ping )
|
||||||
@@ -41,7 +39,6 @@ class testLinear( unittest.TestCase ):
|
|||||||
|
|
||||||
def testLinear5( self ):
|
def testLinear5( self ):
|
||||||
"Ping test with both datapaths on a 5-switch topology"
|
"Ping test with both datapaths on a 5-switch topology"
|
||||||
init()
|
|
||||||
for switch in SWITCHES.values():
|
for switch in SWITCHES.values():
|
||||||
mn = Mininet( LinearTopo( k=5 ), switch, Host, Controller )
|
mn = Mininet( LinearTopo( k=5 ), switch, Host, Controller )
|
||||||
dropped = mn.run( mn.ping )
|
dropped = mn.run( mn.ping )
|
||||||
|
|||||||
Reference in New Issue
Block a user