try to restore edges loaded from old simulation configuration
This commit is contained in:
parent
ff42490e7b
commit
5cde978549
|
@ -41,6 +41,7 @@ import org.apache.log4j.Logger;
|
|||
import org.jdom.Element;
|
||||
|
||||
import se.sics.cooja.ClassDescription;
|
||||
import se.sics.cooja.Mote;
|
||||
import se.sics.cooja.RadioConnection;
|
||||
import se.sics.cooja.Simulation;
|
||||
import se.sics.cooja.interfaces.Radio;
|
||||
|
@ -76,6 +77,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
|
|||
public DirectedGraphMedium() {
|
||||
/* Do not initialize radio medium: use only for hash table */
|
||||
super(null);
|
||||
Visualizer.registerVisualizerSkin(DGRMVisualizerSkin.class);
|
||||
}
|
||||
|
||||
public DirectedGraphMedium(Simulation simulation) {
|
||||
|
@ -362,7 +364,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
|
|||
return;
|
||||
}
|
||||
|
||||
boolean warnedOldConfig = false;
|
||||
boolean oldConfig = false;
|
||||
for (Element element : delayedConfiguration) {
|
||||
if (element.getName().equals("edge")) {
|
||||
Collection<Element> edgeConfig = element.getChildren();
|
||||
|
@ -370,16 +372,36 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
|
|||
DestinationRadio dest = null;
|
||||
for (Element edgeElement : edgeConfig) {
|
||||
if (edgeElement.getName().equals("src")) {
|
||||
/* Old version, ignore edge */
|
||||
if (!warnedOldConfig) {
|
||||
logger.fatal("Old simulation config detected: DGRM links will not be imported");
|
||||
warnedOldConfig = true;
|
||||
oldConfig = true;
|
||||
|
||||
/* Old config: lookup source mote */
|
||||
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")) {
|
||||
source = simulation.getMoteWithID(
|
||||
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")) {
|
||||
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();
|
||||
if (destClassName == null || destClassName.isEmpty()) {
|
||||
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 {
|
||||
addEdge(new Edge(source, dest));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue