コード例 #1
0
ファイル: FadToSink.java プロジェクト: KhMassri/ONENC
  public boolean createNewMessage(Message msg) {
    makeRoomForNewMessage(msg.getSize());

    msg.setTtl(this.msgTtl);
    msg.addProperty(ftStr, new Double(0));
    return super.createNewMessage(msg);
  }
コード例 #2
0
  /**
   * Sets a message that this connection is currently transferring. If message passing is controlled
   * by external events, this method is not needed (but then e.g. {@link #finalizeTransfer()} and
   * {@link #isMessageTransferred()} will not work either). Only a one message at a time can be
   * transferred using one connection.
   *
   * @param from The host sending the message
   * @param m The message
   * @return The value returned by {@link MessageRouter#receiveMessage(Message, DTNHost)}
   */
  public int startTransfer(DTNHost from, Message m) {
    assert this.msgOnFly == null
        : "Already transferring "
            + this.msgOnFly
            + " from "
            + this.msgFromNode
            + " to "
            + this.getOtherNode(this.msgFromNode)
            + ". Can't "
            + "start transfer of "
            + m
            + " from "
            + from;

    this.msgFromNode = from;
    Message newMessage = m.replicate();
    int retVal = getOtherNode(from).receiveMessage(newMessage, from);

    if (retVal == MessageRouter.RCV_OK) {
      this.msgOnFly = newMessage;
      this.msgsize = m.getSize();
      this.msgsent = 0;
    }

    return retVal;
  }
コード例 #3
0
ファイル: FadToSink.java プロジェクト: KhMassri/ONENC
  protected int checkReceiving(Message m) {
    if (m.getProperty(ftStr) == null) return super.checkReceiving(m);

    Message old = this.getOldestMessage(true);
    if (old == null) return super.checkReceiving(m);
    if ((Double) old.getProperty(ftStr) < (Double) m.getProperty(ftStr))
      return MessageRouter.DENIED_NO_SPACE;

    return super.checkReceiving(m);
  }
コード例 #4
0
ファイル: FadToSink.java プロジェクト: KhMassri/ONENC
    public int compare(Message m1, Message m2) {
      // delivery probability of tuple1's message with tuple1's connection
      double p1 = (Double) m1.getProperty(ftStr);
      double p2 = (Double) m2.getProperty(ftStr);

      if (p1 > p2) {
        return 1;
      } else if (p1 < p2) {
        return -1;
      } else return 0;
    }
コード例 #5
0
ファイル: FadToSink.java プロジェクト: KhMassri/ONENC
  @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;
  }
コード例 #6
0
ファイル: FadToSink.java プロジェクト: KhMassri/ONENC
  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;
  }
コード例 #7
0
  /**
   * 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);
    }
  }
コード例 #8
0
ファイル: FadToSink.java プロジェクト: KhMassri/ONENC
  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;
  }
コード例 #9
0
ファイル: FadToSink.java プロジェクト: KhMassri/ONENC
  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;
  }
コード例 #10
0
ファイル: FadToSink.java プロジェクト: KhMassri/ONENC
 public Message messageTransferred(String id, DTNHost from) {
   Message m = super.messageTransferred(id, from);
   if (m.getProperty(ftStr) == null) m.addProperty(ftStr, new Double(0));
   return m;
 }