Cooja, DRGM: Reordered interference checks: e.g. do not interfere if on different channel

This commit is contained in:
Moritz 'Morty' Strübe 2012-10-30 11:42:03 +01:00
parent 3c9e3e1b95
commit 610f6cba14

View File

@ -35,6 +35,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List;
import java.util.Random; import java.util.Random;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -180,12 +181,9 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
} }
} }
} }
} }
/** /**
* Generates hash table using current edges for efficient lookup. * Generates hash table using current edges for efficient lookup.
*/ */
@ -260,12 +258,6 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
continue; continue;
} }
/* Fail if radios are on different (but configured) channels */
if (source.getChannel() >= 0 &&
dest.radio.getChannel() >= 0 &&
source.getChannel() != dest.radio.getChannel()) {
continue;
}
if (!dest.radio.isRadioOn()) { if (!dest.radio.isRadioOn()) {
/* Fail: radio is off */ /* Fail: radio is off */
@ -274,24 +266,17 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
continue; continue;
} }
if (dest.ratio < 1.0 && random.nextDouble() > dest.ratio) { if (dest.radio.isInterfered()) {
/*logger.info(source + ": Fail, randomly");*/ /* Fail: radio is interfered in another connection */
/* TODO Interfere now? */ /*logger.info(source + ": Fail, interfered");*/
newConn.addInterfered(dest.radio); newConn.addInterfered(dest.radio);
continue;
}
dest.radio.interfereAnyReception(); int srcc = source.getChannel();
RadioConnection otherConnection = null; int dstc = dest.radio.getChannel();
for (RadioConnection conn : getActiveConnections()) { if ( srcc >= 0 && dstc >= 0 && srcc != dstc) {
for (Radio dstRadio : conn.getDestinations()) { /* Fail: radios are on different (but configured) channels */
if (dstRadio == dest.radio) {
otherConnection = conn;
break;
}
}
}
if (otherConnection != null) {
otherConnection.addInterfered(dest.radio);
}
continue; continue;
} }
@ -302,24 +287,23 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
/* We will also interfere with the other connection */ /* We will also interfere with the other connection */
dest.radio.interfereAnyReception(); dest.radio.interfereAnyReception();
RadioConnection otherConnection = null;
// Find connection, that is sending to that radio
// and mark the destination as interfered
for (RadioConnection conn : getActiveConnections()) { for (RadioConnection conn : getActiveConnections()) {
for (Radio dstRadio : conn.getDestinations()) { for (Radio dstRadio : conn.getDestinations()) {
if (dstRadio == dest.radio) { if (dstRadio == dest.radio) {
otherConnection = conn; conn.addInterfered(dest.radio);;
break; break;
} }
} }
} }
if (otherConnection != null) {
otherConnection.addInterfered(dest.radio);
}
continue; continue;
} }
if (dest.radio.isInterfered()) { if (dest.ratio < 1.0 && random.nextDouble() > dest.ratio) {
/* Fail: radio is interfered in another connection */ /* Fail: Reception ratio */
/*logger.info(source + ": Fail, interfered");*/ /*logger.info(source + ": Fail, randomly");*/
newConn.addInterfered(dest.radio); newConn.addInterfered(dest.radio);
continue; continue;
} }
@ -353,6 +337,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
delayedConfiguration = configXML; delayedConfiguration = configXML;
return true; return true;
} }
public void simulationFinishedLoading() { public void simulationFinishedLoading() {
if (delayedConfiguration == null) { if (delayedConfiguration == null) {
return; return;
@ -361,6 +346,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
boolean oldConfig = false; boolean oldConfig = false;
for (Element element : delayedConfiguration) { for (Element element : delayedConfiguration) {
if (element.getName().equals("edge")) { if (element.getName().equals("edge")) {
@SuppressWarnings("unchecked")
Collection<Element> edgeConfig = element.getChildren(); Collection<Element> edgeConfig = element.getChildren();
Radio source = null; Radio source = null;
DGRMDestinationRadio dest = null; DGRMDestinationRadio dest = null;
@ -407,7 +393,9 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
} }
try { try {
dest = destClass.newInstance(); dest = destClass.newInstance();
dest.setConfigXML(edgeElement.getChildren(), simulation); @SuppressWarnings("unchecked")
List<Element> children = edgeElement.getChildren();
dest.setConfigXML(children, simulation);
} catch (Exception e) { } catch (Exception e) {
throw (RuntimeException) throw (RuntimeException)
new RuntimeException("Unknown class: " + destClassName).initCause(e); new RuntimeException("Unknown class: " + destClassName).initCause(e);