diff --git a/mininet/node.py b/mininet/node.py index b22e9c7de83dd06db33f86f9a639af3e31c924ef..403ed00cda60da46ae2c3991ce60be3b6ffd96ac 100644 --- a/mininet/node.py +++ b/mininet/node.py @@ -48,12 +48,11 @@ from subprocess import Popen, PIPE, STDOUT 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.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 ): """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 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, defaultMAC=None, defaultIP=None, **kwargs ): """name: name of node @@ -261,7 +262,7 @@ def newPort( self ): "Return the next port number to allocate." if len( self.ports ) > 0: return max( self.ports.values() ) + 1 - return PORT_BASE + return self.portBase def addIntf( self, intf, port=None ): """Add an interface. @@ -401,6 +402,8 @@ class Switch( Node ): """A Switch is a Node that is running (or has execed?) an OpenFlow switch.""" + portBase = SWITCH_PORT_BASE # 0 for OF < 1.0, 1 for OF >= 1.0 + def __init__( self, name, opts='', **kwargs): Node.__init__( self, name, **kwargs ) self.opts = opts diff --git a/mininet/topo.py b/mininet/topo.py index 3cb80ae6a9c6eaecd02606a1c0792769a936486d..9547fa129a1ec7e3a646c26a6f63330059c9d53e 100644 --- a/mininet/topo.py +++ b/mininet/topo.py @@ -12,7 +12,7 @@ ''' from networkx.classes.graph import Graph - +from mininet.node import SWITCH_PORT_BASE class NodeID(object): '''Topo node identifier.''' @@ -127,15 +127,18 @@ def add_port(self, src, dst): @param src source 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: 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: 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): '''Is node connected, admin on, powered on, and fault-free? @@ -178,6 +181,11 @@ def nodes_str(self, 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): '''Return switches. @@ -185,12 +193,7 @@ def switches(self, enabled = True): @return dpids list of dpids ''' - - 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)] + nodes = [n for n in self.g.nodes() if self.is_switch(n)] return self.nodes_enabled(nodes, enabled) def hosts(self, enabled = True):