core
Class NetworkInterface

java.lang.Object
  extended by core.NetworkInterface
All Implemented Interfaces:
ModuleCommunicationListener
Direct Known Subclasses:
InterferenceLimitedInterface, SimpleBroadcastInterface

public abstract class NetworkInterface
extends java.lang.Object
implements ModuleCommunicationListener

Network interface of a DTNHost. Takes care of connectivity among hosts.


Field Summary
protected  java.util.List<Connection> connections
           
protected  DTNHost host
           
protected  java.lang.String interfacetype
           
protected  ConnectivityOptimizer optimizer
           
static java.lang.String RANGE_ID
          ModuleCommunicationBus identifier for the "radio range" variable.
static java.lang.String SCAN_INTERVAL_ID
          ModuleCommunicationBus identifier for the "scanning interval" variable.
static java.lang.String SCAN_INTERVAL_S
          scanning interval -setting id ("scanInterval")
static java.lang.String SPEED_ID
          ModuleCommunicationBus identifier for the "transmission speed" variable.
static java.lang.String TRANSMIT_RANGE_S
          transmit range -setting id ("transmitRange")
static java.lang.String TRANSMIT_SPEED_S
          transmit speed -setting id ("transmitSpeed")
protected  double transmitRange
           
protected  int transmitSpeed
           
 
Constructor Summary
NetworkInterface()
          For creating an empty class of a specific type
NetworkInterface(NetworkInterface ni)
          copy constructor
NetworkInterface(Settings s)
          For creating an empty class of a specific type
 
Method Summary
protected  void connect(Connection con, NetworkInterface anotherInterface)
          Connects this host to another host.
abstract  void connect(NetworkInterface anotherInterface)
          Connects the interface to another interface.
abstract  void createConnection(NetworkInterface anotherInterface)
          Creates a connection to another host.
 void destroyConnection(DTNHost anotherHost)
          Disconnect a connection between this and another host.
protected  void disconnect(Connection con, NetworkInterface anotherInterface)
          Disconnects this host from another host.
protected  void ensurePositiveValue(double value, java.lang.String settingName)
          Makes sure that a value is positive
 int getAddress()
          Returns the network interface address.
 java.util.List<Connection> getConnections()
          Returns a list of currently connected connections
 DTNHost getHost()
          Returns the DTNHost of this interface
 java.lang.String getInterfaceType()
          For checking what interface type this interface is
 Coord getLocation()
          Returns the current location of the host of this interface.
 double getTransmitRange()
          Returns the transmit range of this network layer
 int getTransmitSpeed()
          Returns the transmit speed of this network layer
protected  boolean isConnected(NetworkInterface netinterface)
          Returns true if the given NetworkInterface is connected to this host.
 boolean isScanning()
          Checks if this interface is currently in the scanning mode
protected  boolean isWithinRange(NetworkInterface anotherInterface)
          Returns true if another interface is within radio range of this interface and this interface is also within radio range of the another interface.
 void moduleValueChanged(java.lang.String key, java.lang.Object newValue)
          This method is called by the ModuleCommunicationBus when/if someone changes the scanning interval, transmit speed, or range
abstract  NetworkInterface replicate()
          Replication function
static void reset()
          Resets the static fields of the class
 void setClisteners(java.util.List<ConnectionListener> cListeners)
          For setting the connectionListeners
 void setHost(DTNHost host)
          For setting the host - needed when a prototype is copied for several hosts
 java.lang.String toString()
          Returns a string representation of the object.
abstract  void update()
          Updates the state of current connections (ie tears down connections that are out of range, recalculates transmission speeds etc.).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TRANSMIT_RANGE_S

public static final java.lang.String TRANSMIT_RANGE_S
transmit range -setting id ("transmitRange")

See Also:
Constant Field Values

TRANSMIT_SPEED_S

public static final java.lang.String TRANSMIT_SPEED_S
transmit speed -setting id ("transmitSpeed")

See Also:
Constant Field Values

SCAN_INTERVAL_S

public static final java.lang.String SCAN_INTERVAL_S
scanning interval -setting id ("scanInterval")

See Also:
Constant Field Values

SCAN_INTERVAL_ID

public static final java.lang.String SCAN_INTERVAL_ID
ModuleCommunicationBus identifier for the "scanning interval" variable.

See Also:
Constant Field Values

RANGE_ID

public static final java.lang.String RANGE_ID
ModuleCommunicationBus identifier for the "radio range" variable. Value type: double

See Also:
Constant Field Values

SPEED_ID

public static final java.lang.String SPEED_ID
ModuleCommunicationBus identifier for the "transmission speed" variable. Value type: integer

See Also:
Constant Field Values

host

protected DTNHost host

interfacetype

protected java.lang.String interfacetype

connections

protected java.util.List<Connection> connections

transmitRange

protected double transmitRange

transmitSpeed

protected int transmitSpeed

optimizer

protected ConnectivityOptimizer optimizer
Constructor Detail

NetworkInterface

public NetworkInterface(Settings s)
For creating an empty class of a specific type


NetworkInterface

public NetworkInterface()
For creating an empty class of a specific type


NetworkInterface

public NetworkInterface(NetworkInterface ni)
copy constructor

Method Detail

reset

public static void reset()
Resets the static fields of the class


replicate

public abstract NetworkInterface replicate()
Replication function


setHost

public void setHost(DTNHost host)
For setting the host - needed when a prototype is copied for several hosts

Parameters:
host - The host where the network interface is

getInterfaceType

public java.lang.String getInterfaceType()
For checking what interface type this interface is


setClisteners

public void setClisteners(java.util.List<ConnectionListener> cListeners)
For setting the connectionListeners

Parameters:
cListeners - List of connection listeners

getAddress

public int getAddress()
Returns the network interface address.

Returns:
The address (integer)

getTransmitRange

public double getTransmitRange()
Returns the transmit range of this network layer

Returns:
the transmit range

getTransmitSpeed

public int getTransmitSpeed()
Returns the transmit speed of this network layer

Returns:
the transmit speed

getConnections

public java.util.List<Connection> getConnections()
Returns a list of currently connected connections

Returns:
a list of currently connected connections

isScanning

public boolean isScanning()
Checks if this interface is currently in the scanning mode

Returns:
True if the interface is scanning; false if not

connect

public abstract void connect(NetworkInterface anotherInterface)
Connects the interface to another interface. Overload this in a derived class. Check the requirements for the connection to work in the derived class, then call connect(Connection, NetworkInterface) for the actual connection.

Parameters:
anotherInterface - The interface to connect to

connect

protected void connect(Connection con,
                       NetworkInterface anotherInterface)
Connects this host to another host. The derived class should check that all pre-requisites for making a connection are satisfied before actually connecting.

Parameters:
con - The new connection object
anotherInterface - The interface to connect to

disconnect

protected void disconnect(Connection con,
                          NetworkInterface anotherInterface)
Disconnects this host from another host. The derived class should make the decision whether to disconnect or not

Parameters:
con - The connection to tear down

isWithinRange

protected boolean isWithinRange(NetworkInterface anotherInterface)
Returns true if another interface is within radio range of this interface and this interface is also within radio range of the another interface.

Parameters:
anotherInterface - The another interface
Returns:
True if the interface is within range, false if not

isConnected

protected boolean isConnected(NetworkInterface netinterface)
Returns true if the given NetworkInterface is connected to this host.

Parameters:
netinterface - The other NetworkInterface to check
Returns:
True if the two hosts are connected

ensurePositiveValue

protected void ensurePositiveValue(double value,
                                   java.lang.String settingName)
Makes sure that a value is positive

Parameters:
value - Value to check
settingName - Name of the setting (for error's message)
Throws:
SettingsError - if the value was not positive

update

public abstract void update()
Updates the state of current connections (ie tears down connections that are out of range, recalculates transmission speeds etc.).


moduleValueChanged

public void moduleValueChanged(java.lang.String key,
                               java.lang.Object newValue)
This method is called by the ModuleCommunicationBus when/if someone changes the scanning interval, transmit speed, or range

Specified by:
moduleValueChanged in interface ModuleCommunicationListener
Parameters:
key - Identifier of the changed value
newValue - New value for the variable

createConnection

public abstract void createConnection(NetworkInterface anotherInterface)
Creates a connection to another host. This method does not do any checks on whether the other node is in range or active.

Parameters:
anotherInterface - The interface to create the connection to

destroyConnection

public void destroyConnection(DTNHost anotherHost)
Disconnect a connection between this and another host.

Parameters:
anotherHost - The host to disconnect from this host

getHost

public DTNHost getHost()
Returns the DTNHost of this interface


getLocation

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

Returns:
The location

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the object.