From c9adc9ac83c246370abcab75eaa5088796dfec1e Mon Sep 17 00:00:00 2001 From: Jarrod Pas <j.pas@usask.ca> Date: Thu, 20 Jul 2017 15:33:27 -0600 Subject: [PATCH] Finished BUBBLE implementation --- pydyton/core.py | 2 ++ pydyton/routers.py | 39 ++++++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/pydyton/core.py b/pydyton/core.py index ed6c144..cacc49e 100644 --- a/pydyton/core.py +++ b/pydyton/core.py @@ -34,10 +34,12 @@ class Network: self.community_proc = self.community.process(self.env, self) # packet generation + ''' if packets is None: packets = packets['uniform']() self.packets = packets self.packets_proc = self.packets.process(self.env, self) + ''' # create node network if node_factory is None: diff --git a/pydyton/routers.py b/pydyton/routers.py index 2de2e2c..96a4c23 100644 --- a/pydyton/routers.py +++ b/pydyton/routers.py @@ -40,6 +40,8 @@ def bubble(self, packet, state): if len(self.community) == 0: return False + dest = packet.destination + community_of = lambda n: self.network.community[n] same_community = lambda a, b: community_of(a) == community_of(b) @@ -49,24 +51,31 @@ def bubble(self, packet, state): max = lambda a, b: a if a[0] >= b[0] else b max_gp = (-1, None) - max_lp = (-1, None) - for met in self.links: - if met == dest: - # direct transfer - self.send(met, packet) - return True + if same_community(self, dest): + max_lp = (lp_of(self), self) + for met in self.links: + if same_community(met, dest): + max_lp = max((lp_of(met), met), max_lp) - if same_community(self, dest): - pass - - if max_lp[1] is not None and same_community(self, dest): - self.send(max_lp[1], packet) - return True + if max_lp[1] is not self: + self.send(max_lp[1], packet) + return True + else: + max_gp = (-1, None) + max_lp = (-1, None) + for met in self.links: + if same_community(met, dest): + max_lp = max((lp_of(met), met), max_lp) + max_gp = max((gp_of(met), met), max_gp) + + if max_lp[1] is not None: + self.send(max_lp[1], packet) + return True - if max_gp[1] is not None and same_community(met, dest): - self.send(max_gp[1], packet) - return True + if max_gp[1] is not None: + self.send(max_gp[1], packet) + return True return False -- GitLab