routing
Class EnergyAwareRouter

java.lang.Object
  extended by routing.MessageRouter
      extended by routing.ActiveRouter
          extended by routing.EnergyAwareRouter
All Implemented Interfaces:
ModuleCommunicationListener

public class EnergyAwareRouter
extends ActiveRouter
implements ModuleCommunicationListener

Energy level-aware variant of Epidemic router.


Field Summary
static java.lang.String ENERGY_VALUE_ID
          ModuleCommunicationBus identifier for the "current amount of energy left" variable.
static java.lang.String INIT_ENERGY_S
          Initial units of energy -setting id ("intialEnergy").
static java.lang.String SCAN_ENERGY_S
          Energy usage per scanning -setting id ("scanEnergy").
static java.lang.String TRANSMIT_ENERGY_S
          Energy usage per second when sending -setting id ("transmitEnergy").
static java.lang.String WARMUP_S
          Energy update warmup period -setting id ("energyWarmup").
 
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
protected EnergyAwareRouter(EnergyAwareRouter r)
          Copy constructor.
  EnergyAwareRouter(Settings s)
          Constructor.
 
Method Summary
protected  int checkReceiving(Message m)
          Checks if router "wants" to start receiving message (i.e.
 void moduleValueChanged(java.lang.String key, java.lang.Object newValue)
          Called by the combus is the energy value is changed
protected  void reduceEnergy(double amount)
          Updates the current energy so that the given amount is reduced from it.
protected  void reduceSendingAndScanningEnergy()
          Reduces the energy reserve for the amount that is used by sending data and scanning for the other nodes.
 EnergyAwareRouter replicate()
          Creates a replicate of this router.
protected  void setEnergy(double[] range)
          Sets the current energy level into the given range using uniform random distribution.
 java.lang.String toString()
          Returns a String presentation of this router
 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, createNewMessage, dropExpiredMessages, exchangeDeliverableMessages, getConnections, getMessagesForConnected, getOldestMessage, init, isSending, isTransferring, makeRoomForMessage, makeRoomForNewMessage, messageTransferred, receiveMessage, requestDeliverableMessages, shuffleMessages, startTransfer, transferAborted, transferDone, 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INIT_ENERGY_S

public static final java.lang.String INIT_ENERGY_S
Initial units of energy -setting id ("intialEnergy"). Can be either a single value, or a range of two values. In the latter case, the used value is a uniformly distributed random value between the two values.

See Also:
Constant Field Values

SCAN_ENERGY_S

public static final java.lang.String SCAN_ENERGY_S
Energy usage per scanning -setting id ("scanEnergy").

See Also:
Constant Field Values

TRANSMIT_ENERGY_S

public static final java.lang.String TRANSMIT_ENERGY_S
Energy usage per second when sending -setting id ("transmitEnergy").

See Also:
Constant Field Values

WARMUP_S

public static final java.lang.String WARMUP_S
Energy update warmup period -setting id ("energyWarmup"). Defines the simulation time after which the energy level starts to decrease due to scanning, transmissions, etc. Default value = 0. If value of "-1" is defined, uses the value from the report warmup setting Report.WARMUP_S from the namespace "Report".

See Also:
Constant Field Values

ENERGY_VALUE_ID

public static final java.lang.String ENERGY_VALUE_ID
ModuleCommunicationBus identifier for the "current amount of energy left" variable. Value type: double

See Also:
Constant Field Values
Constructor Detail

EnergyAwareRouter

public EnergyAwareRouter(Settings s)
Constructor. Creates a new message router based on the settings in the given Settings object.

Parameters:
s - The settings object

EnergyAwareRouter

protected EnergyAwareRouter(EnergyAwareRouter r)
Copy constructor.

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

setEnergy

protected void setEnergy(double[] range)
Sets the current energy level into the given range using uniform random distribution.

Parameters:
range - The min and max values of the range, or if only one value is given, that is used as the energy level

checkReceiving

protected int checkReceiving(Message m)
Description copied from class: ActiveRouter
Checks if router "wants" to start receiving message (i.e. router isn't transferring, doesn't have the message and has room for it).

Overrides:
checkReceiving in class ActiveRouter
Parameters:
m - The message to check
Returns:
A return code similar to MessageRouter.receiveMessage(Message, DTNHost), i.e. MessageRouter.RCV_OK if receiving seems to be OK, TRY_LATER_BUSY if router is transferring, DENIED_OLD if the router is already carrying the message or it has been delivered to this router (as final recipient), or DENIED_NO_SPACE if the message does not fit into buffer

reduceEnergy

protected void reduceEnergy(double amount)
Updates the current energy so that the given amount is reduced from it. If the energy level goes below zero, sets the level to zero. Does nothing if the warmup time has not passed.

Parameters:
amount - The amount of energy to reduce

reduceSendingAndScanningEnergy

protected void reduceSendingAndScanningEnergy()
Reduces the energy reserve for the amount that is used by sending data and scanning for the other nodes.


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)

replicate

public EnergyAwareRouter 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

moduleValueChanged

public void moduleValueChanged(java.lang.String key,
                               java.lang.Object newValue)
Called by the combus is the energy value is changed

Specified by:
moduleValueChanged in interface ModuleCommunicationListener
Parameters:
key - The energy ID
newValue - The new energy value

toString

public java.lang.String toString()
Description copied from class: MessageRouter
Returns a String presentation of this router

Overrides:
toString in class MessageRouter
Returns:
A String presentation of this router