Merge pull request #16 from cmorty/COOJA_DGRM

DGRM-Related Patches
This commit is contained in:
Fredrik Österlind 2012-11-21 02:44:13 -08:00
commit 150cb33b94
8 changed files with 566 additions and 505 deletions

View file

@ -382,6 +382,20 @@ public class Msp802154Radio extends Radio implements CustomDataRadio {
rssiLastCounter = 8;
}
/* This will set the CORR-value of the CC2420
*
* @see se.sics.cooja.interfaces.Radio#setLQI(int)
*/
public void setLQI(int lqi){
radio.setLQI(lqi);
}
public int getLQI(){
return radio.getLQI();
}
public Mote getMote() {
return mote;
}

View file

@ -169,6 +169,25 @@ public abstract class Radio extends MoteInterface {
*/
public abstract int getOutputPowerIndicatorMax();
/**
* Returns the current LQI-value. This might differ from platform to platform
* @return Current LQI value.
*
*
*/
public int getLQI() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
/**
* Sets the LQI. This in not supported by all platforms. Also results may differ
* from platform to platform.
*
* @param lqi The current LQI
*/
public void setLQI(int lqi){
}
/**
* @return Current surrounding signal strength
*/

View file

@ -91,9 +91,11 @@ public class DGRMConfigurator extends VisPlugin {
private final static int IDX_DST = 1;
private final static int IDX_RATIO = 2;
private final static int IDX_SIGNAL = 3;
private final static int IDX_DELAY = 4;
private final static int IDX_LQI = 4;
private final static int IDX_DELAY = 5;
private final static String[] COLUMN_NAMES = new String[] {
"Source", "Destination", "RX Ratio", "RSSI", "Delay"
"Source", "Destination", "RX Ratio", "RSSI","LQI", "Delay"
};
private GUI gui = null;
@ -128,6 +130,10 @@ public class DGRMConfigurator extends VisPlugin {
for (double d=AbstractRadioMedium.SS_STRONG; d >= AbstractRadioMedium.SS_WEAK; d -= 1) {
combo.addItem((int) d);
}
} else if (column == IDX_LQI) {
for (int d = 110; d > 50; d -= 5) {
combo.addItem((int) d);
}
} else if (column == IDX_DELAY) {
for (double d=0; d <= 5; d++) {
combo.addItem(d);
@ -161,6 +167,17 @@ public class DGRMConfigurator extends VisPlugin {
setText(String.format("%1.1f dBm", v));
}
});
graphTable.getColumnModel().getColumn(IDX_LQI).setCellRenderer(new DefaultTableCellRenderer() {
private static final long serialVersionUID = -4669897764928372246L;
public void setValue(Object value) {
if (!(value instanceof Long)) {
setText(value.toString());
return;
}
long v = ((Long) value).longValue();
setText(String.valueOf(v));
}
});
graphTable.getColumnModel().getColumn(IDX_DELAY).setCellRenderer(new DefaultTableCellRenderer() {
private static final long serialVersionUID = -4669897764928372246L;
public void setValue(Object value) {
@ -174,6 +191,7 @@ public class DGRMConfigurator extends VisPlugin {
});
graphTable.getColumnModel().getColumn(IDX_RATIO).setCellEditor(new DefaultCellEditor(combo));
graphTable.getColumnModel().getColumn(IDX_SIGNAL).setCellEditor(new DefaultCellEditor(combo));
graphTable.getColumnModel().getColumn(IDX_LQI).setCellEditor(new DefaultCellEditor(combo));
graphTable.getColumnModel().getColumn(IDX_DELAY).setCellEditor(new DefaultCellEditor(combo));
graphTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
@ -411,6 +429,9 @@ public class DGRMConfigurator extends VisPlugin {
if (column == IDX_SIGNAL) {
return ((DGRMDestinationRadio)edge.superDest).signal;
}
if (column == IDX_LQI) {
return ((DGRMDestinationRadio)edge.superDest).lqi;
}
if (column == IDX_DELAY) {
return ((DGRMDestinationRadio)edge.superDest).delay / Simulation.MILLISECOND;
}
@ -433,7 +454,10 @@ public class DGRMConfigurator extends VisPlugin {
} else if (column == IDX_DELAY) {
((DGRMDestinationRadio)edge.superDest).delay =
((Number)value).longValue() * Simulation.MILLISECOND;
} else {
} else if (column == IDX_LQI) {
((DGRMDestinationRadio)edge.superDest).lqi = ((Number)value).intValue();
}
else {
super.setValueAt(value, row, column);
}
radioMedium.requestEdgeAnalysis();
@ -461,6 +485,9 @@ public class DGRMConfigurator extends VisPlugin {
if (column == IDX_SIGNAL) {
return true;
}
if (column == IDX_LQI) {
return true;
}
if (column == IDX_DELAY) {
return true;
}

View file

@ -117,6 +117,15 @@ public class DGRMVisualizerSkin implements VisualizerSkin {
g.drawString(msg, x - msgWidth/2, y + 2*Visualizer.MOTE_RADIUS + 3);
for (DestinationRadio r: dests) {
double prob = ((DGRMDestinationRadio)r).ratio;
double rssi = ((DGRMDestinationRadio)r).signal;
double pos_rssi = rssi + 100;
int lqi = ((DGRMDestinationRadio)r).lqi;
float red = (float)(1 - prob*pos_rssi/90*lqi/100);
if(red > 1) red = 1;
if(red < 0) red = 0;
float green = (float)(prob*pos_rssi/90*lqi/100);
if(green > 1) green = 1;
if(green < 0) green = 0;
if (prob == 0.0d) {
continue;
}
@ -124,7 +133,8 @@ public class DGRMVisualizerSkin implements VisualizerSkin {
Position pos = r.radio.getPosition();
Point pixel = visualizer.transformPositionToPixel(pos);
msgWidth = fm.stringWidth(msg);
g.setColor(new Color(1-(float)prob, (float)prob, 0.0f));
g.setColor(new Color(red, green, 0.0f));
g.drawString("LQI: " + lqi + " RSSI: " + rssi,(x + pixel.x)/2,(y + pixel.y)/2);
g.drawLine(x, y, pixel.x, pixel.y);
g.setColor(Color.BLACK);
g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 2*Visualizer.MOTE_RADIUS + 3);

View file

@ -223,48 +223,47 @@ public abstract class AbstractRadioMedium extends RadioMedium {
Radio radio = (Radio) obs;
final Radio.RadioEvent event = radio.getLastEvent();
if (event == Radio.RadioEvent.RECEPTION_STARTED ||
event == Radio.RadioEvent.RECEPTION_INTERFERED ||
event == Radio.RadioEvent.RECEPTION_FINISHED ||
event == Radio.RadioEvent.UNKNOWN) {
/* Ignored */
switch (event) {
case RECEPTION_STARTED:
case RECEPTION_INTERFERED:
case RECEPTION_FINISHED:
case UNKNOWN:
return;
}
if (event == Radio.RadioEvent.HW_ON) {
case HW_ON: {
/* Update signal strengths */
updateSignalStrengths();
} else if (event == Radio.RadioEvent.HW_OFF) {
}
break;
case HW_OFF: {
/* Remove any radio connections from this radio */
removeFromActiveConnections(radio);
/* Update signal strengths */
updateSignalStrengths();
} else if (event == Radio.RadioEvent.TRANSMISSION_STARTED) {
}
break;
case TRANSMISSION_STARTED: {
/* Create new radio connection */
if (radio.isReceiving()) {
/* Radio starts transmitting when it should be receiving!
* Ok, but it won't receive the packet */
/*
* Radio starts transmitting when it should be
* receiving! Ok, but it won't receive the packet
*/
radio.interfereAnyReception();
for (RadioConnection conn : activeConnections) {
if (conn.isDestination(radio)) {
conn.addInterfered(radio);
}
}
radio.interfereAnyReception();
}
RadioConnection newConnection = createConnections(radio);
activeConnections.add(newConnection);
for (Radio r : newConnection.getAllDestinations()) {
if (newConnection.getDestinationDelay(r) == 0) {
r.signalReceptionStart();
} else {
/* EXPERIMENTAL: Simulating propagation delay */
final Radio delayedRadio = r;
TimeEvent delayedEvent = new TimeEvent(0) {
@ -272,21 +271,18 @@ public abstract class AbstractRadioMedium extends RadioMedium {
delayedRadio.signalReceptionStart();
}
};
simulation.scheduleEvent(
delayedEvent,
simulation.getSimulationTime() + newConnection.getDestinationDelay(r));
simulation.scheduleEvent(delayedEvent, simulation.getSimulationTime() + newConnection.getDestinationDelay(r));
}
}
/* Update signal strengths */
} /* Update signal strengths */
updateSignalStrengths();
/* Notify observers */
lastConnection = null;
radioMediumObservable.setRadioMediumChangedAndNotify();
} else if (event == Radio.RadioEvent.TRANSMISSION_FINISHED) {
}
break;
case TRANSMISSION_FINISHED: {
/* Remove radio connection */
/* Connection */
@ -311,8 +307,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
delayedRadio.signalReceptionEnd();
}
};
simulation.scheduleEvent(
delayedEvent,
simulation.scheduleEvent(delayedEvent,
simulation.getSimulationTime() + connection.getDestinationDelay(dstRadio));
}
}
@ -327,8 +322,9 @@ public abstract class AbstractRadioMedium extends RadioMedium {
/* Notify observers */
radioMediumObservable.setRadioMediumChangedAndNotify();
} else if (event == Radio.RadioEvent.CUSTOM_DATA_TRANSMITTED) {
}
break;
case CUSTOM_DATA_TRANSMITTED: {
/* Connection */
RadioConnection connection = getActiveConnectionFrom(radio);
@ -346,8 +342,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
for (Radio dstRadio : connection.getAllDestinations()) {
if (!radio.getClass().equals(dstRadio.getClass()) ||
!(radio instanceof CustomDataRadio)) {
if (!radio.getClass().equals(dstRadio.getClass()) || !(radio instanceof CustomDataRadio)) {
/* Radios communicate via radio packets */
continue;
}
@ -364,15 +359,15 @@ public abstract class AbstractRadioMedium extends RadioMedium {
delayedRadio.receiveCustomData(delayedData);
}
};
simulation.scheduleEvent(
delayedEvent,
simulation.scheduleEvent(delayedEvent,
simulation.getSimulationTime() + connection.getDestinationDelay(dstRadio));
}
}
} else if (event == Radio.RadioEvent.PACKET_TRANSMITTED) {
}
break;
case PACKET_TRANSMITTED: {
/* Connection */
RadioConnection connection = getActiveConnectionFrom(radio);
if (connection == null) {
@ -389,8 +384,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
for (Radio dstRadio : connection.getAllDestinations()) {
if (radio.getClass().equals(dstRadio.getClass()) &&
radio instanceof CustomDataRadio) {
if (radio.getClass().equals(dstRadio.getClass()) && radio instanceof CustomDataRadio) {
/* Radios instead communicate via custom data objects */
continue;
}
@ -408,14 +402,14 @@ public abstract class AbstractRadioMedium extends RadioMedium {
delayedRadio.setReceivedPacket(delayedPacket);
}
};
simulation.scheduleEvent(
delayedEvent,
simulation.scheduleEvent(delayedEvent,
simulation.getSimulationTime() + connection.getDestinationDelay(dstRadio));
}
}
} else {
}
break;
default:
logger.fatal("Unsupported radio event: " + event);
}
}

View file

@ -41,6 +41,7 @@ public class DGRMDestinationRadio extends DestinationRadio {
public double ratio = 1.0; /* Link success ratio (per packet). */
public double signal = AbstractRadioMedium.SS_STRONG; /* RSSI */
public long delay = 0; /* EXPERIMENTAL: Propagation delay (us). */
public int lqi = 105;
public DGRMDestinationRadio() {
super();
@ -54,6 +55,7 @@ public class DGRMDestinationRadio extends DestinationRadio {
clone.ratio = this.ratio;
clone.delay = this.delay;
clone.signal = this.signal;
clone.lqi = this.lqi;
return clone;
}
@ -69,6 +71,11 @@ public class DGRMDestinationRadio extends DestinationRadio {
element.setText("" + signal);
config.add(element);
element = new Element("lqi");
element.setText("" + lqi);
config.add(element);
element = new Element("delay");
element.setText("" + delay);
config.add(element);
@ -85,6 +92,8 @@ public class DGRMDestinationRadio extends DestinationRadio {
ratio = Double.parseDouble(element.getText());
} else if (element.getName().equals("signal")) {
signal = Double.parseDouble(element.getText());
} else if (element.getName().equals("lqi")) {
lqi = Integer.parseInt(element.getText());
} else if (element.getName().equals("delay")) {
delay = Long.parseLong(element.getText());
}

View file

@ -34,6 +34,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;
@ -71,7 +72,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
private boolean edgesDirty = true;
/* 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() {
/* Do not initialize radio medium: use only for hash table */
@ -164,45 +165,42 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
/* Set signal strengths */
RadioConnection[] conns = getActiveConnections();
for (RadioConnection conn : conns) {
/* When sending RSSI is Strong!
* TODO: is this reasonable
*/
if (conn.getSource().getCurrentSignalStrength() < SS_STRONG) {
conn.getSource().setCurrentSignalStrength(SS_STRONG);
}
for (Radio dstRadio : conn.getDestinations()) {
if (dstRadio.getCurrentSignalStrength() < SS_STRONG) {
dstRadio.setCurrentSignalStrength(SS_STRONG);
}
//Maximum reception signal of all possible radios received
DGRMDestinationRadio dstRadios[] = getPotentialDestinations(conn.getSource());
if (dstRadios == null) continue;
for (DGRMDestinationRadio dstRadio : dstRadios) {
if (dstRadio.radio.getCurrentSignalStrength() < dstRadio.signal) {
dstRadio.radio.setCurrentSignalStrength(dstRadio.signal);
}
/* We can set this without further checks, as it will only be read
* if a packet is actually received. In that case it is set to the
* correct value */
dstRadio.radio.setLQI(dstRadio.lqi);
}
/* 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();
}
}
}
}
/**
* Generates hash table using current edges for efficient lookup.
*/
protected void analyzeEdges() {
Hashtable<Radio,ArrayList<DestinationRadio>> listTable =
new Hashtable<Radio,ArrayList<DestinationRadio>>();
Hashtable<Radio,ArrayList<DGRMDestinationRadio>> listTable =
new Hashtable<Radio,ArrayList<DGRMDestinationRadio>>();
/* Fill edge hash table with all edges */
for (Edge edge: getEdges()) {
ArrayList<DestinationRadio> destRadios;
ArrayList<DGRMDestinationRadio> destRadios;
if (!listTable.containsKey(edge.source)) {
destRadios = new ArrayList<DestinationRadio>();
destRadios = new ArrayList<DGRMDestinationRadio>();
} else {
destRadios = listTable.get(edge.source);
}
@ -212,11 +210,11 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
}
/* Convert to arrays */
Hashtable<Radio,DestinationRadio[]> arrTable = new Hashtable<Radio,DestinationRadio[]>();
Hashtable<Radio,DGRMDestinationRadio[]> arrTable = new Hashtable<Radio,DGRMDestinationRadio[]>();
Enumeration<Radio> sources = listTable.keys();
while (sources.hasMoreElements()) {
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);
}
@ -231,7 +229,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
* @param source Source radio
* @return All potential destination radios
*/
public DestinationRadio[] getPotentialDestinations(Radio source) {
public DGRMDestinationRadio[] getPotentialDestinations(Radio source) {
if (edgesDirty) {
analyzeEdges();
}
@ -249,7 +247,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
/* Create new radio connection using edge hash table */
RadioConnection newConn = new RadioConnection(source);
DestinationRadio[] destinations = getPotentialDestinations(source);
DGRMDestinationRadio[] destinations = getPotentialDestinations(source);
if (destinations == null || destinations.length == 0) {
/* No destinations */
/*logger.info(sendingRadio + ": No dest");*/
@ -257,20 +255,14 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
}
/*logger.info(source + ": " + destinations.length + " potential destinations");*/
for (DestinationRadio d: destinations) {
DGRMDestinationRadio dest = (DGRMDestinationRadio) d;
for (DGRMDestinationRadio dest: destinations) {
if (dest.radio == source) {
/* Fail: cannot receive our own transmission */
/*logger.info(source + ": Fail, receiver is sender");*/
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 */
@ -279,24 +271,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;
}
@ -307,24 +292,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;
}
@ -358,6 +342,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
delayedConfiguration = configXML;
return true;
}
public void simulationFinishedLoading() {
if (delayedConfiguration == null) {
return;
@ -366,9 +351,10 @@ 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;
DestinationRadio dest = null;
DGRMDestinationRadio dest = null;
for (Element edgeElement : edgeConfig) {
if (edgeElement.getName().equals("src")) {
oldConfig = true;
@ -387,7 +373,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
} else if (oldConfig && edgeElement.getName().equals("ratio")) {
/* Old config: parse link ratio */
double ratio = Double.parseDouble(edgeElement.getText());
((DGRMDestinationRadio)dest).ratio = ratio;
dest.ratio = ratio;
} else if (edgeElement.getName().equals("dest")) {
if (oldConfig) {
/* Old config: create simple destination link */
@ -405,14 +391,16 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
if (destClassName == null || destClassName.isEmpty()) {
continue;
}
Class<? extends DestinationRadio> destClass =
simulation.getGUI().tryLoadClass(this, DestinationRadio.class, destClassName);
Class<? extends DGRMDestinationRadio> destClass =
simulation.getGUI().tryLoadClass(this, DGRMDestinationRadio.class, destClassName);
if (destClass == null) {
throw new RuntimeException("Could not load class: " + destClassName);
}
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);
@ -434,9 +422,9 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
public static class Edge {
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.superDest = dest;
}

View file

@ -112,7 +112,7 @@ public class UDGM extends AbstractRadioMedium {
/* Add potential destination */
addEdge(
new DirectedGraphMedium.Edge(source,
new DestinationRadio(dest)));
new DGRMDestinationRadio(dest)));
}
}
}