try to restore edges loaded from old simulation configuration

This commit is contained in:
Fredrik Osterlind 2011-11-01 11:52:34 +01:00
parent ff42490e7b
commit 5cde978549

View file

@ -41,6 +41,7 @@ import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import se.sics.cooja.ClassDescription; import se.sics.cooja.ClassDescription;
import se.sics.cooja.Mote;
import se.sics.cooja.RadioConnection; import se.sics.cooja.RadioConnection;
import se.sics.cooja.Simulation; import se.sics.cooja.Simulation;
import se.sics.cooja.interfaces.Radio; import se.sics.cooja.interfaces.Radio;
@ -76,6 +77,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
public DirectedGraphMedium() { public DirectedGraphMedium() {
/* Do not initialize radio medium: use only for hash table */ /* Do not initialize radio medium: use only for hash table */
super(null); super(null);
Visualizer.registerVisualizerSkin(DGRMVisualizerSkin.class);
} }
public DirectedGraphMedium(Simulation simulation) { public DirectedGraphMedium(Simulation simulation) {
@ -362,7 +364,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
return; return;
} }
boolean warnedOldConfig = false; boolean oldConfig = false;
for (Element element : delayedConfiguration) { for (Element element : delayedConfiguration) {
if (element.getName().equals("edge")) { if (element.getName().equals("edge")) {
Collection<Element> edgeConfig = element.getChildren(); Collection<Element> edgeConfig = element.getChildren();
@ -370,16 +372,36 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
DestinationRadio dest = null; DestinationRadio dest = null;
for (Element edgeElement : edgeConfig) { for (Element edgeElement : edgeConfig) {
if (edgeElement.getName().equals("src")) { if (edgeElement.getName().equals("src")) {
/* Old version, ignore edge */ oldConfig = true;
if (!warnedOldConfig) {
logger.fatal("Old simulation config detected: DGRM links will not be imported"); /* Old config: lookup source mote */
warnedOldConfig = true; for (Mote m: simulation.getMotes()) {
if (m.toString().equals(edgeElement.getText())) {
logger.info("Old config: mapping '" + edgeElement.getText() + "' to node " + m.getID());
source = m.getInterfaces().getRadio();
break;
}
} }
return;
} else if (edgeElement.getName().equals("source")) { } else if (edgeElement.getName().equals("source")) {
source = simulation.getMoteWithID( source = simulation.getMoteWithID(
Integer.parseInt(edgeElement.getText())).getInterfaces().getRadio(); Integer.parseInt(edgeElement.getText())).getInterfaces().getRadio();
} else if (oldConfig && edgeElement.getName().equals("ratio")) {
/* Old config: parse link ratio */
double ratio = Double.parseDouble(edgeElement.getText());
((DGRMDestinationRadio)dest).ratio = ratio;
} else if (edgeElement.getName().equals("dest")) { } else if (edgeElement.getName().equals("dest")) {
if (oldConfig) {
/* Old config: create simple destination link */
Radio destRadio = null;
for (Mote m: simulation.getMotes()) {
if (m.toString().equals(edgeElement.getText())) {
logger.info("Old config: mapping '" + edgeElement.getText() + "' to node " + m.getID());
destRadio = m.getInterfaces().getRadio();
break;
}
}
dest = new DGRMDestinationRadio(destRadio);
} else {
String destClassName = edgeElement.getText().trim(); String destClassName = edgeElement.getText().trim();
if (destClassName == null || destClassName.isEmpty()) { if (destClassName == null || destClassName.isEmpty()) {
continue; continue;
@ -398,11 +420,10 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
} }
} }
} }
if (source == null || dest == null) {
if (!warnedOldConfig) {
logger.fatal("Old simulation config detected: DGRM links will not be imported");
warnedOldConfig = true;
} }
if (source == null || dest == null) {
logger.fatal("Failed loading DGRM links, aborting");
return;
} else { } else {
addEdge(new Edge(source, dest)); addEdge(new Edge(source, dest));
} }