routing
Class MessageRouter

java.lang.Object
  extended by routing.MessageRouter
Direct Known Subclasses:
ActiveRouter, PassiveRouter

public abstract class MessageRouter
extends java.lang.Object

Superclass for message routers.


Field Summary
static java.lang.String B_SIZE
          identifier for the buffer size setting ("bufferSize")
static int DENIED_NO_SPACE
          Receive return value for not enough space in the buffer for the msg
static int DENIED_OLD
          Receive return value for an old (already received) message
static java.lang.String MSG_TTL
          identifier for the message TTL setting ("msgTtl").
protected  int msgTtl
          TTL for all messages
static int RCV_OK
          Receive return value for ok
static int TRY_LATER_BUSY
          Receive return value for busy receiver
 
Constructor Summary
protected MessageRouter(MessageRouter r)
          Copy-constructor.
  MessageRouter(Settings s)
          Constructor.
 
Method Summary
protected  void addToMessages(Message m, boolean newMessage)
          Adds a message to the message buffer and informs message listeners about new message (if requested).
abstract  void changedConnection(Connection con)
          Informs the router about change in connections state.
 boolean createNewMessage(DTNHost to, java.lang.String id, int size, int responseSize)
          Creates a new message to the router.
 void deleteMessage(java.lang.String id, boolean drop)
          Deletes a message in the buffer.
 int getBufferSize()
          Returns the size of the message buffer.
 int getFreeBufferSize()
          Returns the amount of free space in the buffer.
protected  DTNHost getHost()
          Returns the host this router is in
protected  Message getMessage(java.lang.String id)
          Returns a message by ID.
 java.util.Collection<Message> getMessageCollection()
          Returns a reference to the messages of this router in collection
 int getNrofMessages()
          Returns the number of messages this router has
 RoutingInfo getRoutingInfo()
          Returns routing information about this router.
protected  boolean hasMessage(java.lang.String id)
          Checks if this router has a message with certain id buffered.
 void init(DTNHost host, java.util.List<MessageListener> mListeners)
          Initializes the router; i.e.
protected  boolean isDeliveredMessage(java.lang.String id)
          Returns true if a message with given id has been received by this host as the final recipient (at least once).
 void messageAborted(java.lang.String id, DTNHost from)
          This method should be called (on the receiving host) when a message transfer was aborted.
 Message messageTransferred(java.lang.String id, DTNHost from)
          This method should be called (on the receiving host) after a message was successfully transferred.
protected  void putToIncomingBuffer(Message m, DTNHost from)
          Puts a message to incoming messages buffer.
 int receiveMessage(Message m, DTNHost from)
          Try to start receiving a message from another host.
protected  Message removeFromIncomingBuffer(java.lang.String id, DTNHost from)
          Removes and returns a message with a certain ID from the incoming messages buffer or null if such message wasn't found.
abstract  MessageRouter replicate()
          Creates a replicate of this router.
 boolean requestDeliverableMessages(Connection con)
          Requests for deliverable message from this router to be sent trough a connection.
 void sendMessage(java.lang.String id, DTNHost to)
          Start sending a message to another host.
 java.lang.String toString()
          Returns a String presentation of this router
abstract  void update()
          Updates router.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

B_SIZE

public static final java.lang.String B_SIZE
identifier for the buffer size setting ("bufferSize")

See Also:
Constant Field Values

MSG_TTL

public static final java.lang.String MSG_TTL
identifier for the message TTL setting ("msgTtl"). Value is the amount of minutes and must be an integer

See Also:
Constant Field Values

RCV_OK

public static final int RCV_OK
Receive return value for ok

See Also:
Constant Field Values

TRY_LATER_BUSY

public static final int TRY_LATER_BUSY
Receive return value for busy receiver

See Also:
Constant Field Values

DENIED_OLD

public static final int DENIED_OLD
Receive return value for an old (already received) message

See Also:
Constant Field Values

DENIED_NO_SPACE

public static final int DENIED_NO_SPACE
Receive return value for not enough space in the buffer for the msg

See Also:
Constant Field Values

msgTtl

protected int msgTtl
TTL for all messages

Constructor Detail

MessageRouter

public MessageRouter(Settings s)
Constructor. Creates a new message router based on the settings in the given Settings object. Size of the message buffer is read from B_SIZE setting. Default value is Integer.MAX_VALUE.

Parameters:
s - The settings object

MessageRouter

protected MessageRouter(MessageRouter r)
Copy-constructor.

Parameters:
r - Router to copy the settings from.
Method Detail

init

public void init(DTNHost host,
                 java.util.List<MessageListener> mListeners)
Initializes the router; i.e. sets the host this router is in and message listeners that need to be informed about message related events etc.

Parameters:
host - The host this router is in
mListeners - The message listeners

update

public abstract void update()
Updates router. This method should be called (at least once) on every simulation interval to update the status of transfer(s).


changedConnection

public abstract void changedConnection(Connection con)
Informs the router about change in connections state.

Parameters:
con - The connection that changed

getMessage

protected Message getMessage(java.lang.String id)
Returns a message by ID.

Parameters:
id - ID of the message
Returns:
The message

hasMessage

protected boolean hasMessage(java.lang.String id)
Checks if this router has a message with certain id buffered.

Parameters:
id - Identifier of the message
Returns:
True if the router has message with this id, false if not

isDeliveredMessage

protected boolean isDeliveredMessage(java.lang.String id)
Returns true if a message with given id has been received by this host as the final recipient (at least once).

Parameters:
id - ID of the message we're interested
Returns:
true if a message with given id has been received by this host as the final recipient.

getMessageCollection

public java.util.Collection<Message> getMessageCollection()
Returns a reference to the messages of this router in collection

Returns:
a reference to the messages of this router in collection

getNrofMessages

public int getNrofMessages()
Returns the number of messages this router has

Returns:
How many messages this router has

getBufferSize

public int getBufferSize()
Returns the size of the message buffer.

Returns:
The size or Integer.MAX_VALUE if the size isn't defined.

getFreeBufferSize

public int getFreeBufferSize()
Returns the amount of free space in the buffer. May return a negative value if there are more messages in the buffer than should fit there (because of creating new messages).

Returns:
The amount of free space (Integer.MAX_VALUE if the buffer size isn't defined)

getHost

protected DTNHost getHost()
Returns the host this router is in

Returns:
The host object

sendMessage

public void sendMessage(java.lang.String id,
                        DTNHost to)
Start sending a message to another host.

Parameters:
id - Id of the message to send
to - The host to send the message to

requestDeliverableMessages

public boolean requestDeliverableMessages(Connection con)
Requests for deliverable message from this router to be sent trough a connection.

Parameters:
con - The connection to send the messages trough
Returns:
True if this router started a transfer, false if not

receiveMessage

public int receiveMessage(Message m,
                          DTNHost from)
Try to start receiving a message from another host.

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)
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.

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

putToIncomingBuffer

protected void putToIncomingBuffer(Message m,
                                   DTNHost from)
Puts a message to incoming messages buffer. Two messages with the same ID are distinguished by the from host.

Parameters:
m - The message to put
from - Who the message was from (previous hop).

removeFromIncomingBuffer

protected Message removeFromIncomingBuffer(java.lang.String id,
                                           DTNHost from)
Removes and returns a message with a certain ID from the incoming messages buffer or null if such message wasn't found.

Parameters:
id - ID of the message
from - The host that sent this message (previous hop)
Returns:
The found message or null if such message wasn't found

addToMessages

protected void addToMessages(Message m,
                             boolean newMessage)
Adds a message to the message buffer and informs message listeners about new message (if requested).

Parameters:
m - The message to add
newMessage - If true, message listeners are informed about a new message, if false nothing is informed.

messageAborted

public void messageAborted(java.lang.String id,
                           DTNHost from)
This method should be called (on the receiving host) when a message transfer was aborted.

Parameters:
id - Id of the message that was being transferred
from - Host the message was from (previous hop)

createNewMessage

public boolean createNewMessage(DTNHost to,
                                java.lang.String id,
                                int size,
                                int responseSize)
Creates a new message to the router.

Parameters:
to - The host the message is to
id - Identifier of the message (should be unique). A message with non-unique ID will replace an old message with the same ID in this node's buffer and other nodes may reject the message because they have "seen" a message with that ID before.
size - Size of the message (in bytes)
responseSize - Size of the requested response message or 0 if no response is requested
Returns:
True if the creation succeeded, false if not (e.g. the message was too big for the buffer)

deleteMessage

public void deleteMessage(java.lang.String id,
                          boolean drop)
Deletes a message in the buffer.

Parameters:
id - Identifier of the message to delete
drop - If the message is dropped (e.g. because of full buffer) this should be set to true. False value indicates e.g. remove of message because it was delivered to final destination.

getRoutingInfo

public RoutingInfo getRoutingInfo()
Returns routing information about this router.

Returns:
The routing information.

replicate

public abstract MessageRouter replicate()
Creates a replicate of this router. The replicate has the same settings as this router but empty buffers and routing tables.

Returns:
The replicate

toString

public java.lang.String toString()
Returns a String presentation of this router

Overrides:
toString in class java.lang.Object
Returns:
A String presentation of this router