routing
Class SprayAndWaitRouter

java.lang.Object
  extended by routing.MessageRouter
      extended by routing.ActiveRouter
          extended by routing.SprayAndWaitRouter

public class SprayAndWaitRouter
extends ActiveRouter

Implementation of Spray and wait router as depicted in Spray and Wait: An Efficient Routing Scheme for Intermittently Connected Mobile Networks by Thrasyvoulos Spyropoulus et al.


Field Summary
static java.lang.String BINARY_MODE
          identifier for the binary-mode setting ("binaryMode")
protected  int initialNrofCopies
           
protected  boolean isBinary
           
static java.lang.String MSG_COUNT_PROPERTY
          Message property key
static java.lang.String NROF_COPIES
          identifier for the initial number of copies setting ("nrofCopies")
static java.lang.String SPRAYANDWAIT_NS
          SprayAndWait router's settings name space ("SprayAndWaitRouter")
 
Fields inherited from class routing.ActiveRouter
DELETE_DELIVERED_S, deleteDelivered, RESPONSE_PREFIX, sendingConnections, TTL_CHECK_INTERVAL
 
Fields inherited from class routing.MessageRouter
B_SIZE_S, DENIED_NO_SPACE, DENIED_OLD, DENIED_TTL, DENIED_UNSPECIFIED, MSG_TTL_S, msgTtl, Q_MODE_FIFO, Q_MODE_RANDOM, RCV_OK, SEND_QUEUE_MODE_S, TRY_LATER_BUSY
 
Constructor Summary
  SprayAndWaitRouter(Settings s)
           
protected SprayAndWaitRouter(SprayAndWaitRouter r)
          Copy constructor.
 
Method Summary
 boolean createNewMessage(Message msg)
          Creates a new message to the router.
protected  java.util.List<Message> getMessagesWithCopiesLeft()
          Creates and returns a list of messages this router is currently carrying and still has copies left to distribute (nrof copies > 1).
 Message messageTransferred(java.lang.String id, DTNHost from)
          This method should be called (on the receiving host) after a message was successfully transferred.
 int receiveMessage(Message m, DTNHost from)
          Try to start receiving a message from another host.
 SprayAndWaitRouter replicate()
          Creates a replicate of this router.
protected  void transferDone(Connection con)
          Called just before a transfer is finalized (by ActiveRouter.update()).
 void update()
          Checks out all sending connections to finalize the ready ones and abort those whose connection went down.
 
Methods inherited from class routing.ActiveRouter
addToSendingConnections, canStartTransfer, changedConnection, checkReceiving, dropExpiredMessages, exchangeDeliverableMessages, getConnections, getMessagesForConnected, getOldestMessage, init, isSending, isTransferring, makeRoomForMessage, makeRoomForNewMessage, requestDeliverableMessages, shuffleMessages, startTransfer, transferAborted, tryAllMessages, tryAllMessagesToAllConnections, tryMessagesForConnected, tryMessagesToConnections
 
Methods inherited from class routing.MessageRouter
addApplication, addToMessages, compareByQueueMode, deleteMessage, getApplications, getBufferSize, getFreeBufferSize, getHost, getMessage, getMessageCollection, getNrofMessages, getRoutingInfo, hasMessage, isDeliveredMessage, isIncomingMessage, messageAborted, putToIncomingBuffer, removeFromIncomingBuffer, removeFromMessages, sendMessage, sortByQueueMode, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NROF_COPIES

public static final java.lang.String NROF_COPIES
identifier for the initial number of copies setting ("nrofCopies")

See Also:
Constant Field Values

BINARY_MODE

public static final java.lang.String BINARY_MODE
identifier for the binary-mode setting ("binaryMode")

See Also:
Constant Field Values

SPRAYANDWAIT_NS

public static final java.lang.String SPRAYANDWAIT_NS
SprayAndWait router's settings name space ("SprayAndWaitRouter")

See Also:
Constant Field Values

MSG_COUNT_PROPERTY

public static final java.lang.String MSG_COUNT_PROPERTY
Message property key

See Also:
Constant Field Values

initialNrofCopies

protected int initialNrofCopies

isBinary

protected boolean isBinary
Constructor Detail

SprayAndWaitRouter

public SprayAndWaitRouter(Settings s)

SprayAndWaitRouter

protected SprayAndWaitRouter(SprayAndWaitRouter r)
Copy constructor.

Parameters:
r - The router prototype where setting values are copied from
Method Detail

receiveMessage

public int receiveMessage(Message m,
                          DTNHost from)
Description copied from class: MessageRouter
Try to start receiving a message from another host.

Overrides:
receiveMessage in class ActiveRouter
Parameters:
m - Message to put in the receiving buffer
from - Who the message is from
Returns:
Value zero if the node accepted the message (RCV_OK), value less than zero if node rejected the message (e.g. DENIED_OLD), value bigger than zero if the other node should try later (e.g. TRY_LATER_BUSY).

messageTransferred

public Message messageTransferred(java.lang.String id,
                                  DTNHost from)
Description copied from class: MessageRouter
This method should be called (on the receiving host) after a message was successfully transferred. The transferred message is put to the message buffer unless this host is the final recipient of the message.

Overrides:
messageTransferred in class ActiveRouter
Parameters:
id - Id of the transferred message
from - Host the message was from (previous hop)
Returns:
The message that this host received

createNewMessage

public boolean createNewMessage(Message msg)
Description copied from class: MessageRouter
Creates a new message to the router.

Overrides:
createNewMessage in class ActiveRouter
Parameters:
msg - The message to create
Returns:
True if the creation succeeded, false if not (e.g. the message was too big for the buffer)

update

public void update()
Description copied from class: ActiveRouter
Checks out all sending connections to finalize the ready ones and abort those whose connection went down. Also drops messages whose TTL <= 0 (checking every one simulated minute).

Overrides:
update in class ActiveRouter
See Also:
ActiveRouter.addToSendingConnections(Connection)

getMessagesWithCopiesLeft

protected java.util.List<Message> getMessagesWithCopiesLeft()
Creates and returns a list of messages this router is currently carrying and still has copies left to distribute (nrof copies > 1).

Returns:
A list of messages that have copies left

transferDone

protected void transferDone(Connection con)
Called just before a transfer is finalized (by ActiveRouter.update()). Reduces the number of copies we have left for a message. In binary Spray and Wait, sending host is left with floor(n/2) copies, but in standard mode, nrof copies left is reduced by one.

Overrides:
transferDone in class ActiveRouter
Parameters:
con - The connection whose transfer was finalized

replicate

public SprayAndWaitRouter replicate()
Description copied from class: MessageRouter
Creates a replicate of this router. The replicate has the same settings as this router but empty buffers and routing tables.

Specified by:
replicate in class MessageRouter
Returns:
The replicate