core
Class DTNHost

java.lang.Object
  extended by core.DTNHost
All Implemented Interfaces:
java.lang.Comparable<DTNHost>

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

A DTN capable host.


Constructor Summary
DTNHost(java.util.List<MessageListener> msgLs, java.util.List<MovementListener> movLs, java.lang.String groupId, java.util.List<NetworkInterface> interf, ModuleCommunicationBus comBus, MovementModel mmProto, MessageRouter mRouterProto)
          Creates a new DTNHost.
 
Method Summary
 int compareTo(DTNHost h)
          Compares two DTNHosts by their addresses.
 void connect(DTNHost h)
          for tests only --- do not use!!!
 void connectionDown(Connection con)
           
 void connectionUp(Connection con)
          Informs the router of this host about state change in a connection object.
 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 the object reference
 void forceConnection(DTNHost anotherHost, java.lang.String interfaceId, boolean up)
          Force a connection event
 int getAddress()
          Returns the network-layer address of this host.
 double getBufferOccupancy()
          Returns the buffer occupancy percentage.
 ModuleCommunicationBus getComBus()
          Returns this hosts's ModuleCommunicationBus
 java.util.List<Connection> getConnections()
          Returns a copy of the list of connections this host has with other hosts
protected  NetworkInterface getInterface(int interfaceNo)
          Find the network interface based on the index
protected  NetworkInterface getInterface(java.lang.String interfacetype)
          Find the network interface based on the interfacetype
 java.util.List<NetworkInterface> getInterfaces()
          Returns the interface objects of the node
 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 traveling 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.
 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.
static void reset()
          Reset the host and its interfaces
 void sendMessage(java.lang.String id, DTNHost to)
          Sends a message from this host to another host
 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(boolean simulateConnections)
          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<MessageListener> msgLs,
               java.util.List<MovementListener> movLs,
               java.lang.String groupId,
               java.util.List<NetworkInterface> interf,
               ModuleCommunicationBus comBus,
               MovementModel mmProto,
               MessageRouter mRouterProto)
Creates a new DTNHost.

Parameters:
msgLs - Message listeners
movLs - Movement listeners
groupId - GroupID of this host
interf - List of NetworkInterfaces for the class
comBus - Module communication bus object
mmProto - Prototype of the movement model of this host
mRouterProto - Prototype of the message router of this host
Method Detail

reset

public static void reset()
Reset the host and its interfaces


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.


getComBus

public ModuleCommunicationBus getComBus()
Returns this hosts's ModuleCommunicationBus

Returns:
this hosts's ModuleCommunicationBus

connectionUp

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

Parameters:
con - The connection object whose state changed

connectionDown

public void connectionDown(Connection con)

getConnections

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

Returns:
a copy of the 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 traveling or null if no path is in use at the moment.

Returns:
The path this node is traveling

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.

getInterfaces

public java.util.List<NetworkInterface> getInterfaces()
Returns the interface objects of the node


getInterface

protected NetworkInterface getInterface(int interfaceNo)
Find the network interface based on the index


getInterface

protected NetworkInterface getInterface(java.lang.String interfacetype)
Find the network interface based on the interfacetype


forceConnection

public void forceConnection(DTNHost anotherHost,
                            java.lang.String interfaceId,
                            boolean up)
Force a connection event


connect

public void connect(DTNHost h)
for tests only --- do not use!!!


update

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

Parameters:
simulateConnections - Should network layer be updated too

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

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 the object reference

Parameters:
otherHost - The other host
Returns:
True if the hosts objects are the same object

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)