Add reversed version of the SingleSwitch topology
Possibly useful for adding custom port mappings.
This commit is contained in:
+2
-1
@@ -17,11 +17,12 @@ from mininet.logging_mod import lg, set_loglevel, LEVELS
|
|||||||
from mininet.net import Mininet, init
|
from mininet.net import Mininet, init
|
||||||
from mininet.node import KernelSwitch, Host, Controller, ControllerParams, NOX
|
from mininet.node import KernelSwitch, Host, Controller, ControllerParams, NOX
|
||||||
from mininet.node import RemoteController
|
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
|
# built in topologies, created only when run
|
||||||
TOPO_DEF = 'minimal'
|
TOPO_DEF = 'minimal'
|
||||||
TOPOS = {'minimal' : (lambda: SingleSwitchTopo(k = 2)),
|
TOPOS = {'minimal' : (lambda: SingleSwitchTopo(k = 2)),
|
||||||
|
'reversed' : (lambda: SingleSwitchReversedTopo(k = 2)),
|
||||||
'single4' : (lambda: SingleSwitchTopo(k = 4)),
|
'single4' : (lambda: SingleSwitchTopo(k = 4)),
|
||||||
'single100' : (lambda: SingleSwitchTopo(k = 100)),
|
'single100' : (lambda: SingleSwitchTopo(k = 100)),
|
||||||
'linear2' : (lambda: LinearTopo(k = 2)),
|
'linear2' : (lambda: LinearTopo(k = 2)),
|
||||||
|
|||||||
@@ -334,6 +334,39 @@ class SingleSwitchTopo(Topo):
|
|||||||
self.enable_all()
|
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):
|
class LinearTopo(Topo):
|
||||||
'''Linear topology of k switches, with one host per switch.'''
|
'''Linear topology of k switches, with one host per switch.'''
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user