core
Class Connection

java.lang.Object
  extended by core.Connection
Direct Known Subclasses:
CBRConnection, VBRConnection

public abstract class Connection
extends java.lang.Object

A connection between two DTN nodes.


Field Summary
protected  int bytesTransferred
          how many bytes this connection has transferred
protected  NetworkInterface fromInterface
           
protected  DTNHost fromNode
           
protected  DTNHost msgFromNode
           
protected  Message msgOnFly
           
protected  NetworkInterface toInterface
           
protected  DTNHost toNode
           
 
Constructor Summary
Connection(DTNHost fromNode, NetworkInterface fromInterface, DTNHost toNode, NetworkInterface toInterface)
          Creates a new connection between nodes and sets the connection state to "up".
 
Method Summary
 void abortTransfer()
          Aborts the transfer of the currently transferred message.
protected  void clearMsgOnFly()
          Clears the message that is currently being transferred.
 void finalizeTransfer()
          Finalizes the transfer of the currently transferred message.
 Message getMessage()
          Gets the message that this connection is currently transferring.
 NetworkInterface getOtherInterface(NetworkInterface i)
          Returns the interface in the other end of the connection
 DTNHost getOtherNode(DTNHost node)
          Returns the node in the other end of the connection
abstract  int getRemainingByteCount()
          Returns the amount of bytes to be transferred before ongoing transfer is ready or 0 if there's no ongoing transfer or it has finished already
abstract  double getSpeed()
          Gets the current connection speed
 int getTotalBytesTransferred()
          Returns the total amount of bytes this connection has transferred so far (including all transfers).
 boolean isInitiator(DTNHost node)
          Returns true if the given node is the initiator of the connection, false otherwise
abstract  boolean isMessageTransferred()
          Returns true if the current message transfer is done
 boolean isReadyForTransfer()
          Returns true if the connection is ready to transfer a message (connection is up and there is no message being transferred).
 boolean isUp()
          Returns true if the connection is up
 void setUpState(boolean state)
          Sets the state of the connection.
abstract  int startTransfer(DTNHost from, Message m)
          Sets a message that this connection is currently transferring.
 java.lang.String toString()
          Returns a String presentation of the connection.
 void update()
          Calculate the current transmission speed from the information given by the interfaces, and calculate the missing data amount.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

toNode

protected DTNHost toNode

toInterface

protected NetworkInterface toInterface

fromNode

protected DTNHost fromNode

fromInterface

protected NetworkInterface fromInterface

msgFromNode

protected DTNHost msgFromNode

msgOnFly

protected Message msgOnFly

bytesTransferred

protected int bytesTransferred
how many bytes this connection has transferred

Constructor Detail

Connection

public Connection(DTNHost fromNode,
                  NetworkInterface fromInterface,
                  DTNHost toNode,
                  NetworkInterface toInterface)
Creates a new connection between nodes and sets the connection state to "up".

Parameters:
fromNode - The node that initiated the connection
fromInterface - The interface that initiated the connection
toNode - The node in the other side of the connection
toInterface - The interface in the other side of the connection
Method Detail

isUp

public boolean isUp()
Returns true if the connection is up

Returns:
state of the connection

isInitiator

public boolean isInitiator(DTNHost node)
Returns true if the given node is the initiator of the connection, false otherwise

Parameters:
node - The node to check
Returns:
true if the given node is the initiator of the connection

setUpState

public void setUpState(boolean state)
Sets the state of the connection.

Parameters:
state - True if the connection is up, false if not

startTransfer

public abstract int startTransfer(DTNHost from,
                                  Message m)
Sets a message that this connection is currently transferring. If message passing is controlled by external events, this method is not needed (but then e.g. finalizeTransfer() and isMessageTransferred() will not work either). Only a one message at a time can be transferred using one connection.

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

update

public void update()
Calculate the current transmission speed from the information given by the interfaces, and calculate the missing data amount.


abortTransfer

public void abortTransfer()
Aborts the transfer of the currently transferred message.


getRemainingByteCount

public abstract int getRemainingByteCount()
Returns the amount of bytes to be transferred before ongoing transfer is ready or 0 if there's no ongoing transfer or it has finished already

Returns:
the amount of bytes to be transferred

clearMsgOnFly

protected void clearMsgOnFly()
Clears the message that is currently being transferred. Calls to getMessage() will return null after this.


finalizeTransfer

public void finalizeTransfer()
Finalizes the transfer of the currently transferred message. The message that was being transferred can not be retrieved from this connections after calling this method (using getMessage()).


isMessageTransferred

public abstract boolean isMessageTransferred()
Returns true if the current message transfer is done

Returns:
True if the transfer is done, false if not

isReadyForTransfer

public boolean isReadyForTransfer()
Returns true if the connection is ready to transfer a message (connection is up and there is no message being transferred).

Returns:
true if the connection is ready to transfer a message

getMessage

public Message getMessage()
Gets the message that this connection is currently transferring.

Returns:
The message or null if no message is being transferred

getSpeed

public abstract double getSpeed()
Gets the current connection speed


getTotalBytesTransferred

public int getTotalBytesTransferred()
Returns the total amount of bytes this connection has transferred so far (including all transfers).


getOtherNode

public DTNHost getOtherNode(DTNHost node)
Returns the node in the other end of the connection

Parameters:
node - The node in this end of the connection
Returns:
The requested node

getOtherInterface

public NetworkInterface getOtherInterface(NetworkInterface i)
Returns the interface in the other end of the connection

Parameters:
i - The interface in this end of the connection
Returns:
The requested interface

toString

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

Overrides:
toString in class java.lang.Object