From e51f281a1d610e9b4117f256962b4019e067b60d Mon Sep 17 00:00:00 2001 From: Lukas Holst Date: Mon, 26 Aug 2024 09:18:10 -0400 Subject: [PATCH] added previous node handling to epidemic strat. rdt router bugfix. --- .../scala/dtn/routing/EpidemicRouter.scala | 20 +++++++++++++++++++ .../main/scala/dtn/routing/RdtRouter.scala | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Modules/DTN/shared/src/main/scala/dtn/routing/EpidemicRouter.scala b/Modules/DTN/shared/src/main/scala/dtn/routing/EpidemicRouter.scala index a12169e82..459475571 100644 --- a/Modules/DTN/shared/src/main/scala/dtn/routing/EpidemicRouter.scala +++ b/Modules/DTN/shared/src/main/scala/dtn/routing/EpidemicRouter.scala @@ -6,6 +6,7 @@ import java.util.concurrent.ConcurrentHashMap import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future import scala.jdk.CollectionConverters.* +import dtn.PreviousNodeBlock /* Includes the standalone EpidemicRouter and the extracted EpidemicStrategy for use in other routers. @@ -43,6 +44,7 @@ class EpidemicRouter(ws: WSEroutingClient, monitoringClient: MonitoringClientInt } override def onIncomingBundle(packet: Packet.IncomingBundle): Unit = { + epidemicStrategy.onIncomingBundle(packet) println("received incoming bundle. information not used for routing. ignoring.") } @@ -93,4 +95,22 @@ class EpidemicStrategy { () } } + + def onIncomingBundle(packet: Packet.IncomingBundle): Unit = { + packet.bndl.other_blocks.collectFirst { + case x: PreviousNodeBlock => x + } match { + case None => println("received incoming bundle without previous node block. ignoring") + case Some(previous_node_block) => { + delivered.get(packet.bndl.id) match { + case null => + delivered.put(packet.bndl.id, Set(previous_node_block.previous_node_id.extract_node_name())) + () + case x: Set[String] => + delivered.put(packet.bndl.id, (x + previous_node_block.previous_node_id.extract_node_name())) + () + } + } + } + } } diff --git a/Modules/DTN/shared/src/main/scala/dtn/routing/RdtRouter.scala b/Modules/DTN/shared/src/main/scala/dtn/routing/RdtRouter.scala index dbbc3a659..aa4bb4293 100644 --- a/Modules/DTN/shared/src/main/scala/dtn/routing/RdtRouter.scala +++ b/Modules/DTN/shared/src/main/scala/dtn/routing/RdtRouter.scala @@ -130,7 +130,8 @@ class RdtRouter( println(s"destination nodes: $destination_nodes") // for these destination nodes select the best neighbours to forward this bundle to - var best_neighbours = destination_nodes.flatMap(node => likelihoodState.get_sorted_neighbours(node).take(5)) + var best_neighbours = + destination_nodes.flatMap(node => likelihoodState.get_sorted_neighbours(node).take(topNNeighbours)) println(s"best neighbours: $best_neighbours") // remove previous node and source node from ideal neighbours if available