private Collection<Element> getConfigXML() { ArrayList<Element> config = new ArrayList<Element>(); Element element; element = new Element("source"); element.setText("" + source.getMote().getID()); config.add(element); element = new Element("dest"); element.setText(superDest.getClass().getName()); Collection<Element> destConfig = superDest.getConfigXML(); if (destConfig != null) { element.addContent(destConfig); config.add(element); } return config; }
public void simulationFinishedLoading() { if (delayedConfiguration == null) { return; } super.simulationFinishedLoading(); 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; for (Element edgeElement : edgeConfig) { if (edgeElement.getName().equals("src")) { 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; } } } 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()); 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; } /* Backwards compatibility: se.sics -> org.contikios */ destClassName = destClassName.replaceFirst("^se\\.sics", "org.contikios"); Class<? extends DGRMDestinationRadio> destClass = simulation .getCooja() .tryLoadClass(this, DGRMDestinationRadio.class, destClassName); if (destClass == null) { throw new RuntimeException("Could not load class: " + destClassName); } try { dest = destClass.newInstance(); @SuppressWarnings("unchecked") List<Element> children = edgeElement.getChildren(); dest.setConfigXML(children, simulation); } catch (Exception e) { throw (RuntimeException) new RuntimeException("Unknown class: " + destClassName).initCause(e); } } } } if (source == null || dest == null) { logger.fatal("Failed loading DGRM links, aborting"); return; } else { addEdge(new Edge(source, dest)); } } } requestEdgeAnalysis(); delayedConfiguration = null; }
public RadioConnection createConnections(Radio source) { if (edgesDirty) { analyzeEdges(); } if (edgesDirty) { logger.fatal("Error when analyzing edges, aborting new radio connection"); return new RadioConnection(source); } /* Create new radio connection using edge hash table */ RadioConnection newConn = new RadioConnection(source); DGRMDestinationRadio[] destinations = getPotentialDestinations(source); if (destinations == null || destinations.length == 0) { /* No destinations */ /*logger.info(sendingRadio + ": No dest");*/ return newConn; } /*logger.info(source + ": " + destinations.length + " potential destinations");*/ for (DGRMDestinationRadio dest : destinations) { if (dest.radio == source) { /* Fail: cannot receive our own transmission */ /*logger.info(source + ": Fail, receiver is sender");*/ continue; } int srcc = source.getChannel(); int dstc = dest.radio.getChannel(); int edgeChannel = dest.getChannel(); if (edgeChannel >= 0 && dstc >= 0 && edgeChannel != dstc) { /* Fail: the edge is configured for a different radio channel */ continue; } if (srcc >= 0 && dstc >= 0 && srcc != dstc) { /* Fail: radios are on different (but configured) channels */ newConn.addInterfered(dest.radio); continue; } if (!dest.radio.isRadioOn()) { /* Fail: radio is off */ /*logger.info(source + ": Fail, off");*/ newConn.addInterfered(dest.radio); continue; } if (dest.radio.isInterfered()) { /* Fail: radio is interfered in another connection */ /*logger.info(source + ": Fail, interfered");*/ newConn.addInterfered(dest.radio); continue; } if (dest.radio.isReceiving()) { /* Fail: radio is already actively receiving */ /*logger.info(source + ": Fail, receiving");*/ newConn.addInterfered(dest.radio); /* We will also interfere with the other connection */ dest.radio.interfereAnyReception(); // 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) { conn.addInterfered(dest.radio); ; break; } } } continue; } if (dest.ratio < 1.0 && random.nextDouble() > dest.ratio) { /* Fail: Reception ratio */ /*logger.info(source + ": Fail, randomly");*/ newConn.addInterfered(dest.radio); continue; } /* Success: radio starts receiving */ /*logger.info(source + ": OK: " + dest.radio);*/ newConn.addDestination(dest.radio, dest.delay); } return newConn; }