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
This commit is contained in:
fros4943 2007-07-10 12:43:23 +00:00
parent 836eae63cb
commit 88c7e87e82
2 changed files with 43 additions and 7 deletions

View file

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * 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; package se.sics.cooja;
@ -278,6 +278,13 @@ public class Simulation extends Observable implements Runnable {
return myGUI; return myGUI;
} }
/**
* @return Current simulation random seed
*/
public long getRandomSeed() {
return randomSeed;
}
/** /**
* Returns the current simulation config represented by XML elements. This * Returns the current simulation config represented by XML elements. This
* config also includes the current radio medium, all mote types and motes. * config also includes the current radio medium, all mote types and motes.

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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; 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 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 * Visualizes radio traffic in the UDGM. Allows a user to
* change transmission ranges. * change transmission ranges.
@ -327,14 +341,13 @@ public class UDGM extends AbstractRadioMedium {
// Register this radio medium's plugins // Register this radio medium's plugins
simulation.getGUI().registerTemporaryPlugin(VisUDGM.class); simulation.getGUI().registerTemporaryPlugin(VisUDGM.class);
usingRandom = false;
myRadioMedium = this; 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) { public RadioConnection createConnections(Radio sendingRadio) {
Position sendingPosition = sendingRadio.getPosition(); Position sendingPosition = sendingRadio.getPosition();
@ -346,6 +359,11 @@ public class UDGM extends AbstractRadioMedium {
double moteInterferenceRange = INTERFERENCE_RANGE double moteInterferenceRange = INTERFERENCE_RANGE
* (0.01 * (double) sendingRadio.getCurrentOutputPowerIndicator()); * (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 // Loop through all radios
for (int listenNr = 0; listenNr < getRegisteredRadios().size(); listenNr++) { for (int listenNr = 0; listenNr < getRegisteredRadios().size(); listenNr++) {
Radio listeningRadio = getRegisteredRadios().get(listenNr); Radio listeningRadio = getRegisteredRadios().get(listenNr);
@ -467,6 +485,10 @@ public class UDGM extends AbstractRadioMedium {
element.setText(Double.toString(INTERFERENCE_RANGE)); element.setText(Double.toString(INTERFERENCE_RANGE));
config.add(element); config.add(element);
element = new Element("using_random");
element.setText("" + usingRandom);
config.add(element);
return config; return config;
} }
@ -480,6 +502,13 @@ public class UDGM extends AbstractRadioMedium {
if (element.getName().equals("interference_range")) { if (element.getName().equals("interference_range")) {
INTERFERENCE_RANGE = Double.parseDouble(element.getText()); 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; return true;
} }