mininet.node.SWITCH_PORT_BASE specifies first switch port number.
This should be mostly cosmetic, but it causes switches to number their ports consistently with OpenFlow 1.0, which starts at 1. For older versions of OpenFlow, SWITCH_PORT_BASE may be set to zero.
This commit is contained in:
+7
-4
@@ -48,12 +48,11 @@ import select
|
|||||||
from subprocess import Popen, PIPE, STDOUT
|
from subprocess import Popen, PIPE, STDOUT
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from mininet.log import info, error, debug
|
from mininet.log import info, error, warn, debug
|
||||||
from mininet.util import quietRun, makeIntfPair, moveIntf, isShellBuiltin
|
from mininet.util import quietRun, makeIntfPair, moveIntf, isShellBuiltin
|
||||||
from mininet.moduledeps import moduleDeps, OVS_KMOD, OF_KMOD, TUN
|
from mininet.moduledeps import moduleDeps, OVS_KMOD, OF_KMOD, TUN
|
||||||
|
|
||||||
PORT_BASE = 1 # Port numbering to start from. OF > v0.9 is 1-indexed.
|
SWITCH_PORT_BASE = 1 # For OF > 0.9, switch ports start at 1 rather than zero
|
||||||
|
|
||||||
|
|
||||||
class Node( object ):
|
class Node( object ):
|
||||||
"""A virtual network node is simply a shell in a network namespace.
|
"""A virtual network node is simply a shell in a network namespace.
|
||||||
@@ -62,6 +61,8 @@ class Node( object ):
|
|||||||
inToNode = {} # mapping of input fds to nodes
|
inToNode = {} # mapping of input fds to nodes
|
||||||
outToNode = {} # mapping of output fds to nodes
|
outToNode = {} # mapping of output fds to nodes
|
||||||
|
|
||||||
|
portBase = 0 # Nodes always start with eth0/port0, even in OF 1.0
|
||||||
|
|
||||||
def __init__( self, name, inNamespace=True,
|
def __init__( self, name, inNamespace=True,
|
||||||
defaultMAC=None, defaultIP=None, **kwargs ):
|
defaultMAC=None, defaultIP=None, **kwargs ):
|
||||||
"""name: name of node
|
"""name: name of node
|
||||||
@@ -261,7 +262,7 @@ class Node( object ):
|
|||||||
"Return the next port number to allocate."
|
"Return the next port number to allocate."
|
||||||
if len( self.ports ) > 0:
|
if len( self.ports ) > 0:
|
||||||
return max( self.ports.values() ) + 1
|
return max( self.ports.values() ) + 1
|
||||||
return PORT_BASE
|
return self.portBase
|
||||||
|
|
||||||
def addIntf( self, intf, port=None ):
|
def addIntf( self, intf, port=None ):
|
||||||
"""Add an interface.
|
"""Add an interface.
|
||||||
@@ -401,6 +402,8 @@ class Switch( Node ):
|
|||||||
"""A Switch is a Node that is running (or has execed?)
|
"""A Switch is a Node that is running (or has execed?)
|
||||||
an OpenFlow switch."""
|
an OpenFlow switch."""
|
||||||
|
|
||||||
|
portBase = SWITCH_PORT_BASE # 0 for OF < 1.0, 1 for OF >= 1.0
|
||||||
|
|
||||||
def __init__( self, name, opts='', **kwargs):
|
def __init__( self, name, opts='', **kwargs):
|
||||||
Node.__init__( self, name, **kwargs )
|
Node.__init__( self, name, **kwargs )
|
||||||
self.opts = opts
|
self.opts = opts
|
||||||
|
|||||||
+13
-10
@@ -12,7 +12,7 @@ setup for testing, and can even be emulated with the Mininet package.
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
from networkx.classes.graph import Graph
|
from networkx.classes.graph import Graph
|
||||||
|
from mininet.node import SWITCH_PORT_BASE
|
||||||
|
|
||||||
class NodeID(object):
|
class NodeID(object):
|
||||||
'''Topo node identifier.'''
|
'''Topo node identifier.'''
|
||||||
@@ -127,15 +127,18 @@ class Topo(object):
|
|||||||
@param src source switch DPID
|
@param src source switch DPID
|
||||||
@param dst destination switch DPID
|
@param dst destination switch DPID
|
||||||
'''
|
'''
|
||||||
|
src_base = SWITCH_PORT_BASE if self.is_switch(src) else 0
|
||||||
|
dst_base = SWITCH_PORT_BASE if self.is_switch(dst) else 0
|
||||||
if src not in self.ports:
|
if src not in self.ports:
|
||||||
self.ports[src] = {}
|
self.ports[src] = {}
|
||||||
if dst not in self.ports[src]:
|
if dst not in self.ports[src]:
|
||||||
self.ports[src][dst] = len(self.ports[src]) # num outlinks
|
# num outlinks
|
||||||
|
self.ports[src][dst] = len(self.ports[src]) + src_base
|
||||||
if dst not in self.ports:
|
if dst not in self.ports:
|
||||||
self.ports[dst] = {}
|
self.ports[dst] = {}
|
||||||
if src not in self.ports[dst]:
|
if src not in self.ports[dst]:
|
||||||
self.ports[dst][src] = len(self.ports[dst]) # num outlinks
|
# num outlinks
|
||||||
|
self.ports[dst][src] = len(self.ports[dst]) + dst_base
|
||||||
|
|
||||||
def node_enabled(self, dpid):
|
def node_enabled(self, dpid):
|
||||||
'''Is node connected, admin on, powered on, and fault-free?
|
'''Is node connected, admin on, powered on, and fault-free?
|
||||||
@@ -178,6 +181,11 @@ class Topo(object):
|
|||||||
'''
|
'''
|
||||||
return [str(self.id_gen(dpid = dpid)) for dpid in dpids]
|
return [str(self.id_gen(dpid = dpid)) for dpid in dpids]
|
||||||
|
|
||||||
|
def is_switch(self, n):
|
||||||
|
'''Returns true if node is a switch.'''
|
||||||
|
return self.node_info[n].is_switch
|
||||||
|
|
||||||
|
|
||||||
def switches(self, enabled = True):
|
def switches(self, enabled = True):
|
||||||
'''Return switches.
|
'''Return switches.
|
||||||
|
|
||||||
@@ -185,12 +193,7 @@ class Topo(object):
|
|||||||
|
|
||||||
@return dpids list of dpids
|
@return dpids list of dpids
|
||||||
'''
|
'''
|
||||||
|
nodes = [n for n in self.g.nodes() if self.is_switch(n)]
|
||||||
def is_switch(n):
|
|
||||||
'''Returns true if node is a switch.'''
|
|
||||||
return self.node_info[n].is_switch
|
|
||||||
|
|
||||||
nodes = [n for n in self.g.nodes() if is_switch(n)]
|
|
||||||
return self.nodes_enabled(nodes, enabled)
|
return self.nodes_enabled(nodes, enabled)
|
||||||
|
|
||||||
def hosts(self, enabled = True):
|
def hosts(self, enabled = True):
|
||||||
|
|||||||
Reference in New Issue
Block a user