From 9b1fb12a3fd93be7db06dd9e616aec0aa5743937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Tue, 30 Oct 2012 11:42:02 +0100 Subject: [PATCH] Cooja, DGRM: Change DirectedGraphMedium over to DGRMDestinationRadio and fix RSSI --- .../radiomediums/DirectedGraphMedium.java | 60 +++++++++---------- .../java/se/sics/cooja/radiomediums/UDGM.java | 2 +- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/radiomediums/DirectedGraphMedium.java b/tools/cooja/java/se/sics/cooja/radiomediums/DirectedGraphMedium.java index 78d48e50a..0ff5bbce7 100644 --- a/tools/cooja/java/se/sics/cooja/radiomediums/DirectedGraphMedium.java +++ b/tools/cooja/java/se/sics/cooja/radiomediums/DirectedGraphMedium.java @@ -72,7 +72,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium { private boolean edgesDirty = true; /* Used for optimizing lookup time */ - private Hashtable edgesTable = new Hashtable(); + private Hashtable edgesTable = new Hashtable(); public DirectedGraphMedium() { /* Do not initialize radio medium: use only for hash table */ @@ -165,29 +165,23 @@ public class DirectedGraphMedium extends AbstractRadioMedium { /* Set signal strengths */ RadioConnection[] conns = getActiveConnections(); for (RadioConnection conn : conns) { + /* When sending RSSI is Strong! + * TODO: is this reasonable + */ if (conn.getSource().getCurrentSignalStrength() < SS_STRONG) { conn.getSource().setCurrentSignalStrength(SS_STRONG); } - for (Radio dstRadio : conn.getDestinations()) { - if (dstRadio.getCurrentSignalStrength() < SS_STRONG) { - dstRadio.setCurrentSignalStrength(SS_STRONG); + //Maximum reception signal of all possible radios received + DGRMDestinationRadio dstRadios[] = edgesTable.get(conn.getSource()); + if (dstRadios == null) continue; + for (DGRMDestinationRadio dstRadio : dstRadios) { + if (dstRadio.radio.getCurrentSignalStrength() < dstRadio.signal) { + dstRadio.radio.setCurrentSignalStrength(dstRadio.signal); } } } - /* Set signal strength to weak on interfered */ - for (RadioConnection conn : conns) { - for (Radio intfRadio : conn.getInterfered()) { - if (intfRadio.getCurrentSignalStrength() < SS_STRONG) { - intfRadio.setCurrentSignalStrength(SS_STRONG); - } - - if (!intfRadio.isInterfered()) { - /*logger.warn("Radio was not interfered");*/ - intfRadio.interfereAnyReception(); - } - } - } + } @@ -196,14 +190,14 @@ public class DirectedGraphMedium extends AbstractRadioMedium { * Generates hash table using current edges for efficient lookup. */ protected void analyzeEdges() { - Hashtable> listTable = - new Hashtable>(); + Hashtable> listTable = + new Hashtable>(); /* Fill edge hash table with all edges */ for (Edge edge: getEdges()) { - ArrayList destRadios; + ArrayList destRadios; if (!listTable.containsKey(edge.source)) { - destRadios = new ArrayList(); + destRadios = new ArrayList(); } else { destRadios = listTable.get(edge.source); } @@ -213,11 +207,11 @@ public class DirectedGraphMedium extends AbstractRadioMedium { } /* Convert to arrays */ - Hashtable arrTable = new Hashtable(); + Hashtable arrTable = new Hashtable(); Enumeration sources = listTable.keys(); while (sources.hasMoreElements()) { Radio source = sources.nextElement(); - DestinationRadio[] arr = listTable.get(source).toArray(new DestinationRadio[0]); + DGRMDestinationRadio[] arr = listTable.get(source).toArray(new DGRMDestinationRadio[0]); arrTable.put(source, arr); } @@ -232,7 +226,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium { * @param source Source radio * @return All potential destination radios */ - public DestinationRadio[] getPotentialDestinations(Radio source) { + public DGRMDestinationRadio[] getPotentialDestinations(Radio source) { if (edgesDirty) { analyzeEdges(); } @@ -250,7 +244,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium { /* Create new radio connection using edge hash table */ RadioConnection newConn = new RadioConnection(source); - DestinationRadio[] destinations = getPotentialDestinations(source); + DGRMDestinationRadio[] destinations = getPotentialDestinations(source); if (destinations == null || destinations.length == 0) { /* No destinations */ /*logger.info(sendingRadio + ": No dest");*/ @@ -258,8 +252,8 @@ public class DirectedGraphMedium extends AbstractRadioMedium { } /*logger.info(source + ": " + destinations.length + " potential destinations");*/ - for (DestinationRadio d: destinations) { - DGRMDestinationRadio dest = (DGRMDestinationRadio) d; + for (DGRMDestinationRadio dest: destinations) { + if (dest.radio == source) { /* Fail: cannot receive our own transmission */ /*logger.info(source + ": Fail, receiver is sender");*/ @@ -369,7 +363,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium { if (element.getName().equals("edge")) { Collection edgeConfig = element.getChildren(); Radio source = null; - DestinationRadio dest = null; + DGRMDestinationRadio dest = null; for (Element edgeElement : edgeConfig) { if (edgeElement.getName().equals("src")) { oldConfig = true; @@ -388,7 +382,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium { } else if (oldConfig && edgeElement.getName().equals("ratio")) { /* Old config: parse link ratio */ double ratio = Double.parseDouble(edgeElement.getText()); - ((DGRMDestinationRadio)dest).ratio = ratio; + dest.ratio = ratio; } else if (edgeElement.getName().equals("dest")) { if (oldConfig) { /* Old config: create simple destination link */ @@ -406,8 +400,8 @@ public class DirectedGraphMedium extends AbstractRadioMedium { if (destClassName == null || destClassName.isEmpty()) { continue; } - Class destClass = - simulation.getGUI().tryLoadClass(this, DestinationRadio.class, destClassName); + Class destClass = + simulation.getGUI().tryLoadClass(this, DGRMDestinationRadio.class, destClassName); if (destClass == null) { throw new RuntimeException("Could not load class: " + destClassName); } @@ -435,9 +429,9 @@ public class DirectedGraphMedium extends AbstractRadioMedium { public static class Edge { public Radio source = null; - public DestinationRadio superDest = null; + public DGRMDestinationRadio superDest = null; - public Edge(Radio source, DestinationRadio dest) { + public Edge(Radio source, DGRMDestinationRadio dest) { this.source = source; this.superDest = dest; } diff --git a/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java b/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java index 82865c6a4..0e035ab5d 100644 --- a/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java +++ b/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java @@ -113,7 +113,7 @@ public class UDGM extends AbstractRadioMedium { /* Add potential destination */ addEdge( new DirectedGraphMedium.Edge(source, - new DestinationRadio(dest))); + new DGRMDestinationRadio(dest))); } } }