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