Add reversed version of the SingleSwitch topology

Possibly useful for adding custom port mappings.
This commit is contained in:
Brandon Heller
2010-01-06 08:53:01 -08:00
parent 80b3dbbd48
commit 6d2cd77b5a
2 changed files with 35 additions and 1 deletions
+2 -1
View File
@@ -17,11 +17,12 @@ from mininet.logging_mod import lg, set_loglevel, LEVELS
from mininet.net import Mininet, init
from mininet.node import KernelSwitch, Host, Controller, ControllerParams, NOX
from mininet.node import RemoteController
from mininet.topo import SingleSwitchTopo, LinearTopo
from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
# built in topologies, created only when run
TOPO_DEF = 'minimal'
TOPOS = {'minimal' : (lambda: SingleSwitchTopo(k = 2)),
'reversed' : (lambda: SingleSwitchReversedTopo(k = 2)),
'single4' : (lambda: SingleSwitchTopo(k = 4)),
'single100' : (lambda: SingleSwitchTopo(k = 100)),
'linear2' : (lambda: LinearTopo(k = 2)),
+33
View File
@@ -334,6 +334,39 @@ class SingleSwitchTopo(Topo):
self.enable_all()
class SingleSwitchReversedTopo(SingleSwitchTopo):
'''Single switch connected to k hosts, with reversed ports.
The lowest-numbered host is connected to the highest-numbered port.
Useful to verify that Mininet properly handles custom port numberings.
'''
def port(self, src, dst):
'''Get port number.
@param src source switch DPID
@param dst destination switch DPID
@return tuple (src_port, dst_port):
src_port: port on source switch leading to the destination switch
dst_port: port on destination switch leading to the source switch
'''
if src == 1:
if dst in range(2, self.k + 2):
dst_index = dst - 2
highest = self.k - 1
return (highest - dst_index, 0)
else:
raise Exception('unexpected dst: %i' % dst)
elif src in range(2, self.k + 2):
if dst == 1:
raise Exception('unexpected dst: %i' % dst)
else:
src_index = src - 2
highest = self.k - 1
return (0, highest - src_index)
class LinearTopo(Topo):
'''Linear topology of k switches, with one host per switch.'''