core
Class DTNHost

java.lang.Object
  extended by core.DTNHost
All Implemented Interfaces:
java.lang.Comparable<DTNHost>
Direct Known Subclasses:
TestDTNHost

public class DTNHost
extends java.lang.Object
implements java.lang.Comparable<DTNHost>

A DTN capable host.


Constructor Summary
DTNHost(java.util.List<ConnectionListener> conLs, java.util.List<MessageListener> msgLs, java.util.List<MovementListener> movLs, java.lang.String groupId, double transmitRange, int transmitSpeed, MovementModel mmProto, MessageRouter mRouterProto)
          Creates a new DTNHost.
 
Method Summary
 void changedConnection(Connection con)
          Informs the router of this host about state change in a connection object.
 int compareTo(DTNHost h)
          Compares two DTNHosts by their addresses.
 void connect(DTNHost anotherHost)
          Creates a connection to another host (if it is within range)
 void createNewMessage(Message m)
          Creates a new message to this host's router
 void deleteMessage(java.lang.String id, boolean drop)
          Deletes a message from this host
 boolean equals(DTNHost otherHost)
          Checks if a host is the same as this host by comparing their names.
 void forceConnection(DTNHost anotherHost, boolean up)
          Forces this host to connect/disconnect to/from another host.
 int getAddress()
          Returns the network-layer address of this host.
 double getBufferOccupancy()
          Returns the buffer occupancy percentage.
 java.util.List<Connection> getConnections()
          Returns a list of connections this host has with other hosts
 ConnectivityGrid.GridCell getCurCell()
          Return the "current cell" set by the setCurCell method (for cell based connection checking).
 Coord getLocation()
          Returns the current location of this host.
 java.util.Collection<Message> getMessageCollection()
          Returns the messages in a collection.
 int getNrofMessages()
          Returns the number of messages this node is carrying.
 Path getPath()
          Returns the Path this node is currently travelling or null if no path is in use at the moment.
 MessageRouter getRouter()
          Returns the router of this host
 RoutingInfo getRoutingInfo()
          Returns routing info of this host's router.
 double getTransmitRange()
          Returns the transmit range of this host's radio
 int getTransmitSpeed()
          Returns the transmit speed of this host's radio
 boolean isActive()
          Returns true if this node is active (false if not)
 void messageAborted(java.lang.String id, DTNHost from, int bytesRemaining)
          Informs the host that a message transfer was aborted.
 void messageTransferred(java.lang.String id, DTNHost from)
          Informs the host that a message was successfully transferred.
 void move(double timeIncrement)
          Moves the node towards the next waypoint or waits if it is not time to move yet
 int receiveMessage(Message m, DTNHost from)
          Start receiving a message from another host
 boolean requestDeliverableMessages(Connection con)
          Requests for deliverable message from this host to be sent trough a connection.
 void sendMessage(java.lang.String id, DTNHost to)
          Sends a message from this host to another host
 void setCurCell(ConnectivityGrid.GridCell c)
          Sets the "current cell" (for cell based connection checking).
 void setLocation(Coord location)
          Sets the Node's location overriding any location set by movement model
 void setName(java.lang.String name)
          Sets the Node's name overriding the default name (groupId + netAddress)
 java.lang.String toString()
          Returns a string presentation of the host.
 void update()
          Updates node's network layer and router.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DTNHost

public DTNHost(java.util.List<ConnectionListener> conLs,
               java.util.List<MessageListener> msgLs,
               java.util.List<MovementListener> movLs,
               java.lang.String groupId,
               double transmitRange,
               int transmitSpeed,
               MovementModel mmProto,
               MessageRouter mRouterProto)
Creates a new DTNHost.

Parameters:
conLs - Connection listeners
msgLs - Message listeners
groupId - GroupID of this host
transmitRange - Transmit range of the host's radio
transmitSpeed - Transmit speed of the host's radio
mmProto - Prototype of the movement model of this host
mRouterProto - Prototype of the message router of this host
Method Detail

isActive

public boolean isActive()
Returns true if this node is active (false if not)

Returns:
true if this node is active (false if not)

getRouter

public MessageRouter getRouter()
Returns the router of this host

Returns:
the router of this host

getAddress

public int getAddress()
Returns the network-layer address of this host.


getTransmitRange

public double getTransmitRange()
Returns the transmit range of this host's radio

See Also:
NetworkLayer.getTransmitRange()

getTransmitSpeed

public int getTransmitSpeed()
Returns the transmit speed of this host's radio

See Also:
NetworkLayer.getTransmitSpeed()

changedConnection

public void changedConnection(Connection con)
Informs the router of this host about state change in a connection object.

Parameters:
con - The connection object whose state changed

getConnections

public java.util.List<Connection> getConnections()
Returns a list of connections this host has with other hosts

Returns:
a list of connections this host has with other hosts

getLocation

public Coord getLocation()
Returns the current location of this host.

Returns:
The location

getPath

public Path getPath()
Returns the Path this node is currently travelling or null if no path is in use at the moment.

Returns:
The path this node is travelling

getCurCell

public ConnectivityGrid.GridCell getCurCell()
Return the "current cell" set by the setCurCell method (for cell based connection checking).

Returns:
The current cell

setCurCell

public void setCurCell(ConnectivityGrid.GridCell c)
Sets the "current cell" (for cell based connection checking).

Parameters:
c - The cell to set
See Also:
getCurCell()

setLocation

public void setLocation(Coord location)
Sets the Node's location overriding any location set by movement model

Parameters:
location - The location to set

setName

public void setName(java.lang.String name)
Sets the Node's name overriding the default name (groupId + netAddress)

Parameters:
name - The name to set

getMessageCollection

public java.util.Collection<Message> getMessageCollection()
Returns the messages in a collection.

Returns:
Messages in a collection

getNrofMessages

public int getNrofMessages()
Returns the number of messages this node is carrying.

Returns:
How many messages the node is carrying currently.

getBufferOccupancy

public double getBufferOccupancy()
Returns the buffer occupancy percentage. Occupancy is 0 for empty buffer but can be over 100 if a created message is bigger than buffer space that could be freed.

Returns:
Buffer occupancy percentage

getRoutingInfo

public RoutingInfo getRoutingInfo()
Returns routing info of this host's router.

Returns:
The routing info.

update

public void update()
Updates node's network layer and router.


move

public void move(double timeIncrement)
Moves the node towards the next waypoint or waits if it is not time to move yet

Parameters:
timeIncrement - How long time the node moves

connect

public void connect(DTNHost anotherHost)
Creates a connection to another host (if it is within range)

Parameters:
anotherHost -

forceConnection

public void forceConnection(DTNHost anotherHost,
                            boolean up)
Forces this host to connect/disconnect to/from another host. If the connection to set up already exists, or the connection to destroy doesn't exist, nothing happens.

Parameters:
anotherHost - The host to connect to or disconnect from
up - If true, the a new connection is created, if false, existing connection is destroyed.

sendMessage

public void sendMessage(java.lang.String id,
                        DTNHost to)
Sends a message from this host to another host

Parameters:
id - Identifier of the message
to - Host the message should be sent to

receiveMessage

public int receiveMessage(Message m,
                          DTNHost from)
Start receiving a message from another host

Parameters:
m - The message
from - Who the message is from
Returns:
The value returned by MessageRouter.receiveMessage(Message, DTNHost)

requestDeliverableMessages

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

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

messageTransferred

public void messageTransferred(java.lang.String id,
                               DTNHost from)
Informs the host that a message was successfully transferred.

Parameters:
id - Identifier of the message
from - From who the message was from

messageAborted

public void messageAborted(java.lang.String id,
                           DTNHost from,
                           int bytesRemaining)
Informs the host that a message transfer was aborted.

Parameters:
id - Identifier of the message
from - From who the message was from
bytesRemaining - Nrof bytes that were left before the transfer would have been ready; or -1 if the number of bytes is not known

createNewMessage

public void createNewMessage(Message m)
Creates a new message to this host's router

Parameters:
m - The message to create

deleteMessage

public void deleteMessage(java.lang.String id,
                          boolean drop)
Deletes a message from this host

Parameters:
id - Identifier of the message
drop - True if the message is deleted because of "dropping" (e.g. buffer is full) or false if it was deleted for some other reason (e.g. the message got delivered to final destination). This effects the way the removing is reported to the message listeners.

toString

public java.lang.String toString()
Returns a string presentation of the host.

Overrides:
toString in class java.lang.Object
Returns:
Host's name

equals

public boolean equals(DTNHost otherHost)
Checks if a host is the same as this host by comparing their names.

Parameters:
otherHost - The other host
Returns:
True if the hosts had the same name

compareTo

public int compareTo(DTNHost h)
Compares two DTNHosts by their addresses.

Specified by:
compareTo in interface java.lang.Comparable<DTNHost>
See Also:
Comparable.compareTo(Object)