/** * 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; }
@Override public RoutingInfo getRoutingInfo() { RoutingInfo top = super.getRoutingInfo(); RoutingInfo ri1 = new RoutingInfo("DelProb =--> " + delProb); RoutingInfo ri = new RoutingInfo("Messages FT-->"); for (Message m : this.getMessageCollection()) { ri.addMoreInfo(new RoutingInfo(String.format("%s : %.6f", m.getId(), m.getProperty(ftStr)))); } top.addMoreInfo(ri1); top.addMoreInfo(ri); return top; }
protected Message getOldestMessage(boolean excludeMsgBeingSent) { Collection<Message> msgCollection = getMessageCollection(); List<Message> messages = new ArrayList<Message>(); messages.addAll(msgCollection); Collections.sort(messages, msgComparator); Message old = null; for (int i = messages.size() - 1; i > 0; i--) { old = messages.get(i); if (excludeMsgBeingSent && isSending(old.getId())) continue; return old; } return old; }
private Connection tryOtherMessages() { Collection<Message> msgCollection = getMessageCollection(); if (msgCollection.size() == 0) return null; if (neighb.size() == 0) return null; List<Message> messages = new ArrayList<Message>(); messages.addAll(msgCollection); Collections.sort(messages, msgComparator); double curFt; double newFt; Connection con = null; for (Message m : messages) { for (DTNHost h : neighb) { if ((this.getDelProb() >= threshold * (((FadToSink) h.getRouter()).getDelProb()))) continue; con = getConOf(h); if (con == null || h.getRouter().hasMessage(m.getId())) continue; curFt = (Double) m.getProperty(ftStr); newFt = 1 - (1 - curFt) * (1 - delProb); Message msg = m.replicate(); msg.updateProperty(ftStr, newFt); if (startTransfer(msg, con) != RCV_OK) continue; m.updateProperty(ftStr, 1 - (1 - curFt) * (1 - ((FadToSink) h.getRouter()).getDelProb())); delProb = (1 - alpha) * delProb + alpha * ((FadToSink) h.getRouter()).getDelProb(); this.lastUpdate = SimClock.getTime(); return con; } } return con; }