/** * Visualize node's location, radio ranges and connections * * @param g2 The graphic context to draw to */ private void drawHost(Graphics2D g2) { Coord loc = node.getLocation(); if (drawCoverage && node.isRadioActive()) { ArrayList<NetworkInterface> interfaces = new ArrayList<NetworkInterface>(); interfaces.addAll(node.getInterfaces()); for (NetworkInterface ni : interfaces) { double range = ni.getTransmitRange(); Ellipse2D.Double coverage; coverage = new Ellipse2D.Double( scale(loc.getX() - range), scale(loc.getY() - range), scale(range * 2), scale(range * 2)); // draw the "range" circle g2.setColor(rangeColor); g2.draw(coverage); } } if (drawConnections) { g2.setColor(conColor); Coord c1 = node.getLocation(); ArrayList<Connection> conList = new ArrayList<Connection>(); // create a copy to prevent concurrent modification exceptions conList.addAll(node.getConnections()); for (Connection c : conList) { DTNHost otherNode = c.getOtherNode(node); Coord c2; if (otherNode == null) { continue; /* disconnected before drawn */ } c2 = otherNode.getLocation(); g2.drawLine(scale(c1.getX()), scale(c1.getY()), scale(c2.getX()), scale(c2.getY())); } } /* draw node rectangle */ g2.setColor(hostColor); g2.drawRect(scale(loc.getX() - 1), scale(loc.getY() - 1), scale(2), scale(2)); if (isHighlighted()) { g2.setColor(highlightedNodeColor); g2.fillRect(scale(loc.getX()) - 3, scale(loc.getY()) - 3, 6, 6); } if (drawNodeName) { g2.setColor(hostNameColor); // Draw node's address next to it g2.drawString(node.toString(), scale(loc.getX()), scale(loc.getY())); } }
public void changedConnection(Connection con) { DTNHost other = con.getOtherNode(getHost()); if (con.isUp()) { if (other.getRouter().hello().equals("DTNRouter")) neighb.add(other); else if (other.isSink()) { delProb = (1 - alpha) * delProb + alpha; this.lastUpdate = SimClock.getTime(); } } else if (other.getRouter().hello().equals("DTNRouter")) neighb.remove(other); Collections.sort(neighb, neighbComparator); }
private void timeOutUpdate() { if (SimClock.getTime() - this.lastUpdate < secondsForTimeOut) return; for (Connection con : this.getConnections()) if (con.getOtherNode(getHost()).isSink()) { delProb = (1 - alpha) * delProb + alpha; this.lastUpdate = SimClock.getTime(); return; } delProb = (1 - alpha) * delProb; this.lastUpdate = SimClock.getTime(); }
/** * Creates a snapshot of message availability * * @param hosts The list of tracked hosts in the world */ @Override protected void createSnapshot(List<DTNHost> hosts) { write("[" + (int) getSimTime() + "]"); /* write sim time stamp */ if (this.trackedHosts == null) { this.trackedHosts = selectTrackedHosts(hosts); } for (DTNHost host : hosts) { Set<String> msgIds = null; String idString = ""; if (!this.trackedHosts.contains(host)) { continue; } msgIds = new HashSet<String>(); /* add own messages */ for (Message m : host.getMessageCollection()) { if (!isTracked(m)) { continue; } msgIds.add(m.getId()); } /* add all peer messages */ for (Connection c : host.getConnections()) { DTNHost peer = c.getOtherNode(host); for (Message m : peer.getMessageCollection()) { if (!isTracked(m)) { continue; } msgIds.add(m.getId()); } } for (String id : msgIds) { idString += " " + id; } write(host + idString); } }
protected int startTransfer(Message m, Connection con) { int retVal; if (!con.isReadyForTransfer()) { return TRY_LATER_BUSY; } retVal = con.startTransfer(getHost(), m); DTNHost other = con.getOtherNode(getHost()); if (retVal == DENIED_OLD && other.isSink()) { /* final recipient has already received the msg -> delete it */ this.deleteMessage(m.getId(), false); return retVal; } if (retVal == RCV_OK) { // started transfer addToSendingConnections(con); if (other.isSink() || (((FadToSink) other.getRouter()).getDelProb() > 0.9) && !isSending(m.getId())) this.deleteMessage(m.getId(), false); return retVal; } return retVal; }
private Connection getConOf(DTNHost h) { for (Connection con : getConnections()) if (con.getOtherNode(getHost()).equals(h)) return con; return null; }