Cooja, DGRM: Change DirectedGraphMedium over to DGRMDestinationRadio and fix RSSI
This commit is contained in:
parent
bed3877984
commit
9b1fb12a3f
|
@ -72,7 +72,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
|
||||||
private boolean edgesDirty = true;
|
private boolean edgesDirty = true;
|
||||||
|
|
||||||
/* Used for optimizing lookup time */
|
/* Used for optimizing lookup time */
|
||||||
private Hashtable<Radio,DestinationRadio[]> edgesTable = new Hashtable<Radio,DestinationRadio[]>();
|
private Hashtable<Radio,DGRMDestinationRadio[]> edgesTable = new Hashtable<Radio,DGRMDestinationRadio[]>();
|
||||||
|
|
||||||
public DirectedGraphMedium() {
|
public DirectedGraphMedium() {
|
||||||
/* Do not initialize radio medium: use only for hash table */
|
/* Do not initialize radio medium: use only for hash table */
|
||||||
|
@ -165,29 +165,23 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
|
||||||
/* Set signal strengths */
|
/* Set signal strengths */
|
||||||
RadioConnection[] conns = getActiveConnections();
|
RadioConnection[] conns = getActiveConnections();
|
||||||
for (RadioConnection conn : conns) {
|
for (RadioConnection conn : conns) {
|
||||||
|
/* When sending RSSI is Strong!
|
||||||
|
* TODO: is this reasonable
|
||||||
|
*/
|
||||||
if (conn.getSource().getCurrentSignalStrength() < SS_STRONG) {
|
if (conn.getSource().getCurrentSignalStrength() < SS_STRONG) {
|
||||||
conn.getSource().setCurrentSignalStrength(SS_STRONG);
|
conn.getSource().setCurrentSignalStrength(SS_STRONG);
|
||||||
}
|
}
|
||||||
for (Radio dstRadio : conn.getDestinations()) {
|
//Maximum reception signal of all possible radios received
|
||||||
if (dstRadio.getCurrentSignalStrength() < SS_STRONG) {
|
DGRMDestinationRadio dstRadios[] = edgesTable.get(conn.getSource());
|
||||||
dstRadio.setCurrentSignalStrength(SS_STRONG);
|
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.
|
* Generates hash table using current edges for efficient lookup.
|
||||||
*/
|
*/
|
||||||
protected void analyzeEdges() {
|
protected void analyzeEdges() {
|
||||||
Hashtable<Radio,ArrayList<DestinationRadio>> listTable =
|
Hashtable<Radio,ArrayList<DGRMDestinationRadio>> listTable =
|
||||||
new Hashtable<Radio,ArrayList<DestinationRadio>>();
|
new Hashtable<Radio,ArrayList<DGRMDestinationRadio>>();
|
||||||
|
|
||||||
/* Fill edge hash table with all edges */
|
/* Fill edge hash table with all edges */
|
||||||
for (Edge edge: getEdges()) {
|
for (Edge edge: getEdges()) {
|
||||||
ArrayList<DestinationRadio> destRadios;
|
ArrayList<DGRMDestinationRadio> destRadios;
|
||||||
if (!listTable.containsKey(edge.source)) {
|
if (!listTable.containsKey(edge.source)) {
|
||||||
destRadios = new ArrayList<DestinationRadio>();
|
destRadios = new ArrayList<DGRMDestinationRadio>();
|
||||||
} else {
|
} else {
|
||||||
destRadios = listTable.get(edge.source);
|
destRadios = listTable.get(edge.source);
|
||||||
}
|
}
|
||||||
|
@ -213,11 +207,11 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert to arrays */
|
/* Convert to arrays */
|
||||||
Hashtable<Radio,DestinationRadio[]> arrTable = new Hashtable<Radio,DestinationRadio[]>();
|
Hashtable<Radio,DGRMDestinationRadio[]> arrTable = new Hashtable<Radio,DGRMDestinationRadio[]>();
|
||||||
Enumeration<Radio> sources = listTable.keys();
|
Enumeration<Radio> sources = listTable.keys();
|
||||||
while (sources.hasMoreElements()) {
|
while (sources.hasMoreElements()) {
|
||||||
Radio source = sources.nextElement();
|
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);
|
arrTable.put(source, arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,7 +226,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
|
||||||
* @param source Source radio
|
* @param source Source radio
|
||||||
* @return All potential destination radios
|
* @return All potential destination radios
|
||||||
*/
|
*/
|
||||||
public DestinationRadio[] getPotentialDestinations(Radio source) {
|
public DGRMDestinationRadio[] getPotentialDestinations(Radio source) {
|
||||||
if (edgesDirty) {
|
if (edgesDirty) {
|
||||||
analyzeEdges();
|
analyzeEdges();
|
||||||
}
|
}
|
||||||
|
@ -250,7 +244,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
|
||||||
|
|
||||||
/* Create new radio connection using edge hash table */
|
/* Create new radio connection using edge hash table */
|
||||||
RadioConnection newConn = new RadioConnection(source);
|
RadioConnection newConn = new RadioConnection(source);
|
||||||
DestinationRadio[] destinations = getPotentialDestinations(source);
|
DGRMDestinationRadio[] destinations = getPotentialDestinations(source);
|
||||||
if (destinations == null || destinations.length == 0) {
|
if (destinations == null || destinations.length == 0) {
|
||||||
/* No destinations */
|
/* No destinations */
|
||||||
/*logger.info(sendingRadio + ": No dest");*/
|
/*logger.info(sendingRadio + ": No dest");*/
|
||||||
|
@ -258,8 +252,8 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*logger.info(source + ": " + destinations.length + " potential destinations");*/
|
/*logger.info(source + ": " + destinations.length + " potential destinations");*/
|
||||||
for (DestinationRadio d: destinations) {
|
for (DGRMDestinationRadio dest: destinations) {
|
||||||
DGRMDestinationRadio dest = (DGRMDestinationRadio) d;
|
|
||||||
if (dest.radio == source) {
|
if (dest.radio == source) {
|
||||||
/* Fail: cannot receive our own transmission */
|
/* Fail: cannot receive our own transmission */
|
||||||
/*logger.info(source + ": Fail, receiver is sender");*/
|
/*logger.info(source + ": Fail, receiver is sender");*/
|
||||||
|
@ -369,7 +363,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
|
||||||
if (element.getName().equals("edge")) {
|
if (element.getName().equals("edge")) {
|
||||||
Collection<Element> edgeConfig = element.getChildren();
|
Collection<Element> edgeConfig = element.getChildren();
|
||||||
Radio source = null;
|
Radio source = null;
|
||||||
DestinationRadio dest = null;
|
DGRMDestinationRadio dest = null;
|
||||||
for (Element edgeElement : edgeConfig) {
|
for (Element edgeElement : edgeConfig) {
|
||||||
if (edgeElement.getName().equals("src")) {
|
if (edgeElement.getName().equals("src")) {
|
||||||
oldConfig = true;
|
oldConfig = true;
|
||||||
|
@ -388,7 +382,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
|
||||||
} else if (oldConfig && edgeElement.getName().equals("ratio")) {
|
} else if (oldConfig && edgeElement.getName().equals("ratio")) {
|
||||||
/* Old config: parse link ratio */
|
/* Old config: parse link ratio */
|
||||||
double ratio = Double.parseDouble(edgeElement.getText());
|
double ratio = Double.parseDouble(edgeElement.getText());
|
||||||
((DGRMDestinationRadio)dest).ratio = ratio;
|
dest.ratio = ratio;
|
||||||
} else if (edgeElement.getName().equals("dest")) {
|
} else if (edgeElement.getName().equals("dest")) {
|
||||||
if (oldConfig) {
|
if (oldConfig) {
|
||||||
/* Old config: create simple destination link */
|
/* Old config: create simple destination link */
|
||||||
|
@ -406,8 +400,8 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
|
||||||
if (destClassName == null || destClassName.isEmpty()) {
|
if (destClassName == null || destClassName.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Class<? extends DestinationRadio> destClass =
|
Class<? extends DGRMDestinationRadio> destClass =
|
||||||
simulation.getGUI().tryLoadClass(this, DestinationRadio.class, destClassName);
|
simulation.getGUI().tryLoadClass(this, DGRMDestinationRadio.class, destClassName);
|
||||||
if (destClass == null) {
|
if (destClass == null) {
|
||||||
throw new RuntimeException("Could not load class: " + destClassName);
|
throw new RuntimeException("Could not load class: " + destClassName);
|
||||||
}
|
}
|
||||||
|
@ -435,9 +429,9 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
|
||||||
|
|
||||||
public static class Edge {
|
public static class Edge {
|
||||||
public Radio source = null;
|
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.source = source;
|
||||||
this.superDest = dest;
|
this.superDest = dest;
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ public class UDGM extends AbstractRadioMedium {
|
||||||
/* Add potential destination */
|
/* Add potential destination */
|
||||||
addEdge(
|
addEdge(
|
||||||
new DirectedGraphMedium.Edge(source,
|
new DirectedGraphMedium.Edge(source,
|
||||||
new DestinationRadio(dest)));
|
new DGRMDestinationRadio(dest)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue