From 88c7e87e8262f5685354e25fa0a31b93b8485332 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Tue, 10 Jul 2007 12:43:23 +0000 Subject: [PATCH] added udgm random transmission support. random mode can currently only be activated via simulation configs (.csc) udgm uses the same random seed as the simulation --- .../cooja/java/se/sics/cooja/Simulation.java | 9 +++- .../java/se/sics/cooja/radiomediums/UDGM.java | 41 ++++++++++++++++--- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/Simulation.java b/tools/cooja/java/se/sics/cooja/Simulation.java index ec03fdece..0f5c009f8 100644 --- a/tools/cooja/java/se/sics/cooja/Simulation.java +++ b/tools/cooja/java/se/sics/cooja/Simulation.java @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: Simulation.java,v 1.15 2007/07/04 16:13:17 fros4943 Exp $ + * $Id: Simulation.java,v 1.16 2007/07/10 12:43:23 fros4943 Exp $ */ package se.sics.cooja; @@ -278,6 +278,13 @@ public class Simulation extends Observable implements Runnable { return myGUI; } + /** + * @return Current simulation random seed + */ + public long getRandomSeed() { + return randomSeed; + } + /** * Returns the current simulation config represented by XML elements. This * config also includes the current radio medium, all mote types and motes. diff --git a/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java b/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java index 08431b4a2..4b6be7153 100644 --- a/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java +++ b/tools/cooja/java/se/sics/cooja/radiomediums/UDGM.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: UDGM.java,v 1.4 2007/05/18 15:17:11 fros4943 Exp $ + * $Id: UDGM.java,v 1.5 2007/07/10 12:43:24 fros4943 Exp $ */ package se.sics.cooja.radiomediums; @@ -83,6 +83,20 @@ public class UDGM extends AbstractRadioMedium { public static final double SS_OK_WORST = -30; + public static final double PACKET_SUCCESS_RATIO = 0.95; + + // Maximum ranges (SS indicator 100) + private static double TRANSMITTING_RANGE = 50; + + private static double INTERFERENCE_RANGE = 100; + + private Simulation mySimulation; + + private boolean usingRandom = false; + + private Random random = new Random(); + + /** * Visualizes radio traffic in the UDGM. Allows a user to * change transmission ranges. @@ -327,14 +341,13 @@ public class UDGM extends AbstractRadioMedium { // Register this radio medium's plugins simulation.getGUI().registerTemporaryPlugin(VisUDGM.class); + + usingRandom = false; + myRadioMedium = this; + mySimulation = simulation; } - // Maximum ranges (SS indicator 100) - private static double TRANSMITTING_RANGE = 50; - - private static double INTERFERENCE_RANGE = 100; - public RadioConnection createConnections(Radio sendingRadio) { Position sendingPosition = sendingRadio.getPosition(); @@ -346,6 +359,11 @@ public class UDGM extends AbstractRadioMedium { double moteInterferenceRange = INTERFERENCE_RANGE * (0.01 * (double) sendingRadio.getCurrentOutputPowerIndicator()); + // If in random state, check if transmission fails + if (usingRandom && random.nextDouble() > PACKET_SUCCESS_RATIO) { + return newConnection; + } + // Loop through all radios for (int listenNr = 0; listenNr < getRegisteredRadios().size(); listenNr++) { Radio listeningRadio = getRegisteredRadios().get(listenNr); @@ -467,6 +485,10 @@ public class UDGM extends AbstractRadioMedium { element.setText(Double.toString(INTERFERENCE_RANGE)); config.add(element); + element = new Element("using_random"); + element.setText("" + usingRandom); + config.add(element); + return config; } @@ -480,6 +502,13 @@ public class UDGM extends AbstractRadioMedium { if (element.getName().equals("interference_range")) { INTERFERENCE_RANGE = Double.parseDouble(element.getText()); } + + if (element.getName().equals("using_random")) { + usingRandom = Boolean.parseBoolean(element.getText()); + if (usingRandom) { + random.setSeed(mySimulation.getRandomSeed()); + } + } } return true; }