Skip to content
Snippets Groups Projects
Commit 52082ff3 authored by Bob Lantz's avatar Bob Lantz
Browse files

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.
parent b78c9382
No related branches found
No related tags found
No related merge requests found
...@@ -48,12 +48,11 @@ ...@@ -48,12 +48,11 @@
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 ): ...@@ -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 @@ def newPort( self ): ...@@ -261,7 +262,7 @@ def newPort( self ):
"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 ): ...@@ -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
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
''' '''
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 @@ def add_port(self, src, dst): ...@@ -127,15 +127,18 @@ def add_port(self, src, dst):
@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 @@ def nodes_str(self, dpids): ...@@ -178,6 +181,11 @@ def nodes_str(self, dpids):
''' '''
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 @@ def switches(self, enabled = True): ...@@ -185,12 +193,7 @@ def switches(self, enabled = True):
@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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment