From 6d2cd77b5a4791fbe9afa72a05a9f2a27c55eaed Mon Sep 17 00:00:00 2001 From: Brandon Heller Date: Wed, 6 Jan 2010 08:53:01 -0800 Subject: [PATCH] Add reversed version of the SingleSwitch topology Possibly useful for adding custom port mappings. --- bin/mn_run.py | 3 ++- mininet/topo.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/bin/mn_run.py b/bin/mn_run.py index 281adaf..f5e8530 100755 --- a/bin/mn_run.py +++ b/bin/mn_run.py @@ -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)), diff --git a/mininet/topo.py b/mininet/topo.py index 943f71e..79e256a 100644 --- a/mininet/topo.py +++ b/mininet/topo.py @@ -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.'''