removed many of the commands being run to maximize startup performance
This commit is contained in:
+11
-10
@@ -32,7 +32,7 @@ class Intf( object ):
|
|||||||
|
|
||||||
"Basic interface object that can configure itself."
|
"Basic interface object that can configure itself."
|
||||||
|
|
||||||
def __init__( self, name, node=None, port=None, link=None, **params ):
|
def __init__( self, name, node=None, port=None, link=None, mac=None, **params ):
|
||||||
"""name: interface name (e.g. h1-eth0)
|
"""name: interface name (e.g. h1-eth0)
|
||||||
node: owning node (where this intf most likely lives)
|
node: owning node (where this intf most likely lives)
|
||||||
link: parent link if we're part of a link
|
link: parent link if we're part of a link
|
||||||
@@ -40,7 +40,10 @@ class Intf( object ):
|
|||||||
self.node = node
|
self.node = node
|
||||||
self.name = name
|
self.name = name
|
||||||
self.link = link
|
self.link = link
|
||||||
self.mac, self.ip, self.prefixLen = None, None, None
|
self.mac = mac
|
||||||
|
self.ip, self.prefixLen = None, None
|
||||||
|
if self.name == 'lo':
|
||||||
|
self.ip = '127.0.0.1'
|
||||||
# Add to node (and move ourselves if necessary )
|
# Add to node (and move ourselves if necessary )
|
||||||
node.addIntf( self, port=port )
|
node.addIntf( self, port=port )
|
||||||
# Save params for future reference
|
# Save params for future reference
|
||||||
@@ -147,7 +150,6 @@ class Intf( object ):
|
|||||||
def updateAddr( self ):
|
def updateAddr( self ):
|
||||||
"instead of updating ip and mac separately, use one ifconfig call to do it simultaneously"
|
"instead of updating ip and mac separately, use one ifconfig call to do it simultaneously"
|
||||||
ifconfig = self.ifconfig()
|
ifconfig = self.ifconfig()
|
||||||
print ifconfig
|
|
||||||
ips = self._ipMatchRegex.findall( ifconfig )
|
ips = self._ipMatchRegex.findall( ifconfig )
|
||||||
macs = self._macMatchRegex.findall( ifconfig )
|
macs = self._macMatchRegex.findall( ifconfig )
|
||||||
self.ip = ips[ 0 ] if ips else None
|
self.ip = ips[ 0 ] if ips else None
|
||||||
@@ -170,7 +172,6 @@ class Intf( object ):
|
|||||||
self.setParam( r, 'setIP', ip=ip )
|
self.setParam( r, 'setIP', ip=ip )
|
||||||
self.setParam( r, 'isUp', up=up )
|
self.setParam( r, 'isUp', up=up )
|
||||||
self.setParam( r, 'ifconfig', ifconfig=ifconfig )
|
self.setParam( r, 'ifconfig', ifconfig=ifconfig )
|
||||||
#should combine these next two operations into one. this is unecessary
|
|
||||||
#self.updateAddr()
|
#self.updateAddr()
|
||||||
#self.updateIP()
|
#self.updateIP()
|
||||||
#self.updateMAC()
|
#self.updateMAC()
|
||||||
@@ -339,7 +340,7 @@ class Link( object ):
|
|||||||
Other types of links could be tunnels, link emulators, etc.."""
|
Other types of links could be tunnels, link emulators, etc.."""
|
||||||
|
|
||||||
def __init__( self, node1, node2, port1=None, port2=None,
|
def __init__( self, node1, node2, port1=None, port2=None,
|
||||||
intfName1=None, intfName2=None,
|
intfName1=None, intfName2=None, addr1=None, addr2=None,
|
||||||
intf=Intf, cls1=None, cls2=None, params1=None,
|
intf=Intf, cls1=None, cls2=None, params1=None,
|
||||||
params2=None ):
|
params2=None ):
|
||||||
"""Create veth link to another node, making two new interfaces.
|
"""Create veth link to another node, making two new interfaces.
|
||||||
@@ -365,7 +366,7 @@ class Link( object ):
|
|||||||
if not intfName2:
|
if not intfName2:
|
||||||
intfName2 = self.intfName( node2, port2 )
|
intfName2 = self.intfName( node2, port2 )
|
||||||
|
|
||||||
self.makeIntfPair( intfName1, intfName2 )
|
self.makeIntfPair( intfName1, intfName2, addr1, addr2 )
|
||||||
|
|
||||||
if not cls1:
|
if not cls1:
|
||||||
cls1 = intf
|
cls1 = intf
|
||||||
@@ -377,9 +378,9 @@ class Link( object ):
|
|||||||
params2 = {}
|
params2 = {}
|
||||||
|
|
||||||
intf1 = cls1( name=intfName1, node=node1, port=port1,
|
intf1 = cls1( name=intfName1, node=node1, port=port1,
|
||||||
link=self, **params1 )
|
link=self, mac=addr1, **params1 )
|
||||||
intf2 = cls2( name=intfName2, node=node2, port=port2,
|
intf2 = cls2( name=intfName2, node=node2, port=port2,
|
||||||
link=self, **params2 )
|
link=self, mac=addr2, **params2 )
|
||||||
|
|
||||||
# All we are is dust in the wind, and our two interfaces
|
# All we are is dust in the wind, and our two interfaces
|
||||||
self.intf1, self.intf2 = intf1, intf2
|
self.intf1, self.intf2 = intf1, intf2
|
||||||
@@ -390,13 +391,13 @@ class Link( object ):
|
|||||||
return node.name + '-eth' + repr( n )
|
return node.name + '-eth' + repr( n )
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def makeIntfPair( cls, intf1, intf2 ):
|
def makeIntfPair( cls, intf1, intf2, addr1=None, addr2=None ):
|
||||||
"""Create pair of interfaces
|
"""Create pair of interfaces
|
||||||
intf1: name of interface 1
|
intf1: name of interface 1
|
||||||
intf2: name of interface 2
|
intf2: name of interface 2
|
||||||
(override this class method [and possibly delete()]
|
(override this class method [and possibly delete()]
|
||||||
to change link type)"""
|
to change link type)"""
|
||||||
makeIntfPair( intf1, intf2 )
|
makeIntfPair( intf1, intf2, addr1, addr2 )
|
||||||
|
|
||||||
def delete( self ):
|
def delete( self ):
|
||||||
"Delete this link"
|
"Delete this link"
|
||||||
|
|||||||
+23
-4
@@ -90,6 +90,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import select
|
import select
|
||||||
import signal
|
import signal
|
||||||
|
import random
|
||||||
import copy
|
import copy
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from itertools import chain, groupby
|
from itertools import chain, groupby
|
||||||
@@ -101,7 +102,7 @@ from mininet.link import Link, Intf
|
|||||||
from mininet.util import quietRun, fixLimits, numCores, ensureRoot
|
from mininet.util import quietRun, fixLimits, numCores, ensureRoot
|
||||||
from mininet.util import macColonHex, ipStr, ipParse, netParse, ipAdd
|
from mininet.util import macColonHex, ipStr, ipParse, netParse, ipAdd
|
||||||
from mininet.term import cleanUpScreens, makeTerms
|
from mininet.term import cleanUpScreens, makeTerms
|
||||||
from multiprocessing.pool import ThreadPool
|
from multiprocessing import Process
|
||||||
|
|
||||||
# Mininet version: should be consistent with README and LICENSE
|
# Mininet version: should be consistent with README and LICENSE
|
||||||
VERSION = "2.1.0+"
|
VERSION = "2.1.0+"
|
||||||
@@ -160,7 +161,7 @@ class Mininet( object ):
|
|||||||
|
|
||||||
self.terms = [] # list of spawned xterm processes
|
self.terms = [] # list of spawned xterm processes
|
||||||
|
|
||||||
self.pool = ThreadPool( 64 )
|
#self.pool = Pool( 64 )
|
||||||
|
|
||||||
Mininet.init() # Initialize Mininet if necessary
|
Mininet.init() # Initialize Mininet if necessary
|
||||||
|
|
||||||
@@ -306,6 +307,21 @@ class Mininet( object ):
|
|||||||
"return (key,value) tuple list for every node in net"
|
"return (key,value) tuple list for every node in net"
|
||||||
return zip( self.keys(), self.values() )
|
return zip( self.keys(), self.values() )
|
||||||
|
|
||||||
|
def generateMac( self ):
|
||||||
|
newMac = True
|
||||||
|
while True:
|
||||||
|
macList = [ 0x00 ]
|
||||||
|
for i in xrange ( 0, 5 ):
|
||||||
|
macList.append( random.randint( 0x00, 0xff ) )
|
||||||
|
mac = ':'.join( map(lambda x: "%02x" % x, macList ) )
|
||||||
|
for node in self.switches + self.hosts:
|
||||||
|
for intf in node.ports:
|
||||||
|
if intf.mac == mac:
|
||||||
|
newMac = False
|
||||||
|
break
|
||||||
|
if newMac:
|
||||||
|
return mac
|
||||||
|
|
||||||
def addLink( self, node1, node2, port1=None, port2=None,
|
def addLink( self, node1, node2, port1=None, port2=None,
|
||||||
cls=None, **params ):
|
cls=None, **params ):
|
||||||
""""Add a link from node1 to node2
|
""""Add a link from node1 to node2
|
||||||
@@ -314,8 +330,12 @@ class Mininet( object ):
|
|||||||
port1: source port
|
port1: source port
|
||||||
port2: dest port
|
port2: dest port
|
||||||
returns: link object"""
|
returns: link object"""
|
||||||
|
mac1 = self.generateMac()
|
||||||
|
mac2 = self.generateMac()
|
||||||
defaults = { 'port1': port1,
|
defaults = { 'port1': port1,
|
||||||
'port2': port2,
|
'port2': port2,
|
||||||
|
'addr1': mac1,
|
||||||
|
'addr2': mac2,
|
||||||
'intf': self.intf }
|
'intf': self.intf }
|
||||||
defaults.update( params )
|
defaults.update( params )
|
||||||
if not cls:
|
if not cls:
|
||||||
@@ -383,8 +403,7 @@ class Mininet( object ):
|
|||||||
params = topo.linkInfo( srcName, dstName )
|
params = topo.linkInfo( srcName, dstName )
|
||||||
srcPort, dstPort = topo.port( srcName, dstName )
|
srcPort, dstPort = topo.port( srcName, dstName )
|
||||||
self.addLink( src, dst, srcPort, dstPort, **params )
|
self.addLink( src, dst, srcPort, dstPort, **params )
|
||||||
#self.pool.apply( self.addLink, ( src, dst, srcPort, dstPort, params, ) )
|
#self.pool.apply_async( self.addLink, ( src, dst, srcPort, dstPort, params ) )
|
||||||
#self.pool.apply_async( self.addLink, args = ( src, dst )+ params, kwds = { 'Port1':srcPort, 'Port2':dstPort } )
|
|
||||||
info( '(%s, %s) ' % ( src.name, dst.name ) )
|
info( '(%s, %s) ' % ( src.name, dst.name ) )
|
||||||
#self.pool.close()
|
#self.pool.close()
|
||||||
#self.pool.join()
|
#self.pool.join()
|
||||||
|
|||||||
+6
-6
@@ -1089,11 +1089,9 @@ class OVSSwitch( Switch ):
|
|||||||
if self.inNamespace:
|
if self.inNamespace:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
'OVS kernel switch does not work in a namespace' )
|
'OVS kernel switch does not work in a namespace' )
|
||||||
# We should probably call config instead, but this
|
|
||||||
# requires some rethinking...
|
|
||||||
self.cmd( 'ifconfig lo up' )
|
|
||||||
# Annoyingly, --if-exists option seems not to work
|
# Annoyingly, --if-exists option seems not to work
|
||||||
self.cmd( 'ovs-vsctl del-br', self )
|
self.sendCmd( 'ovs-vsctl del-br', self )
|
||||||
|
self.waiting = False
|
||||||
int( self.dpid, 16 ) # DPID must be a hex string
|
int( self.dpid, 16 ) # DPID must be a hex string
|
||||||
# Interfaces and controllers
|
# Interfaces and controllers
|
||||||
intfs = ' '.join( '-- add-port %s %s ' % ( self, intf ) +
|
intfs = ' '.join( '-- add-port %s %s ' % ( self, intf ) +
|
||||||
@@ -1114,10 +1112,12 @@ class OVSSwitch( Switch ):
|
|||||||
'-- set-controller %s %s ' % ( self, clist ) )
|
'-- set-controller %s %s ' % ( self, clist ) )
|
||||||
# Construct ovs-vsctl commands for old versions of OVS
|
# Construct ovs-vsctl commands for old versions of OVS
|
||||||
else:
|
else:
|
||||||
self.cmd( 'ovs-vsctl add-br', self )
|
self.sendCmd( 'ovs-vsctl add-br', self )
|
||||||
|
self.waiting = False
|
||||||
for intf in self.intfList():
|
for intf in self.intfList():
|
||||||
if not intf.IP():
|
if not intf.IP():
|
||||||
self.cmd( 'ovs-vsctl add-port', self, intf )
|
self.sendCmd( 'ovs-vsctl add-port', self, intf )
|
||||||
|
self.waiting = False
|
||||||
cmd = ( 'ovs-vsctl set Bridge %s ' % self +
|
cmd = ( 'ovs-vsctl set Bridge %s ' % self +
|
||||||
'other_config:datapath-id=%s ' % self.dpid +
|
'other_config:datapath-id=%s ' % self.dpid +
|
||||||
'-- set-fail-mode %s %s ' % ( self, self.failMode ) +
|
'-- set-fail-mode %s %s ' % ( self, self.failMode ) +
|
||||||
|
|||||||
+5
-1
@@ -147,7 +147,7 @@ isShellBuiltin.builtIns = None
|
|||||||
# live in the root namespace and thus do not have to be
|
# live in the root namespace and thus do not have to be
|
||||||
# explicitly moved.
|
# explicitly moved.
|
||||||
|
|
||||||
def makeIntfPair( intf1, intf2 ):
|
def makeIntfPair( intf1, intf2, addr1=None, addr2=None ):
|
||||||
"""Make a veth pair connecting intf1 and intf2.
|
"""Make a veth pair connecting intf1 and intf2.
|
||||||
intf1: string, interface
|
intf1: string, interface
|
||||||
intf2: string, interface
|
intf2: string, interface
|
||||||
@@ -156,7 +156,11 @@ def makeIntfPair( intf1, intf2 ):
|
|||||||
quietRun( 'ip link del ' + intf1 )
|
quietRun( 'ip link del ' + intf1 )
|
||||||
quietRun( 'ip link del ' + intf2 )
|
quietRun( 'ip link del ' + intf2 )
|
||||||
# Create new pair
|
# Create new pair
|
||||||
|
if addr1 is None and addr2 is None:
|
||||||
cmd = 'ip link add name ' + intf1 + ' type veth peer name ' + intf2
|
cmd = 'ip link add name ' + intf1 + ' type veth peer name ' + intf2
|
||||||
|
else:
|
||||||
|
cmd = ( 'ip link add name ' + intf1 + ' address ' + addr1 +
|
||||||
|
' type veth peer name ' + intf2 + ' address ' + addr2 )
|
||||||
cmdOutput = quietRun( cmd )
|
cmdOutput = quietRun( cmd )
|
||||||
if cmdOutput == '':
|
if cmdOutput == '':
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user