es.ants.felixgm.trmsim_wsn.network
Class Sensor

java.lang.Object
  extended by es.ants.felixgm.trmsim_wsn.network.Sensor
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
BTRM_Sensor, EigenTrust_Sensor, LFTM_Sensor, PeerTrust_Sensor, PowerTrust_Sensor, TemplateTRM_Sensor

public abstract class Sensor
extends java.lang.Object
implements java.lang.Runnable

This class models a sensor in a Wireless Sensor Network

A subclass of this class, modelling the specific sensors, has to be implemented in order to add a new Trust and Reputation Model

Since:
0.1
Version:
0.4
Author:
Félix Gómez Mármol, Gregorio Martínez Pérez

Field Summary
protected static double _maxDistance
          Maximum distance between two nodes in the network
protected  boolean activeState
          Indicates if this sensor is currently active or in an idle state
protected static boolean collusion
          Indicates if a collusion among malicious sensors is built
protected static boolean dynamic
          Indicates if some sensors will switch off sometimes in order to save energy
protected  int id
          Sensor's identifier
protected static int idCount
          Sensors' identifier counter
protected  java.util.Collection<Link> links
          Outcoming links of this sensor
protected  int numRequests
          Number of service requests provided by this sensor
protected static int numRequestsThreshold
          Number of service requests provided by this sensor after which it goes to sleep
protected  Outcome outcome
          Last outcome of a performed transaction
protected  Service requiredService
          Service requested by the clients
protected  java.util.HashMap<Service,java.lang.Double> servicesGoodness
          Goodness of this sensor related to each provided service
protected  long transmittedDistance
          Total distance travelled by the messages sent from this sensor
protected static TRModel_WSN trmmodelWSN
          Current Trust and Reputation model used by every Sensor
protected  double xPosition
          X coordinate of this sensor
protected  double yPosition
          Y coordinate of this sensor
 
Constructor Summary
Sensor()
          Class Sensor constructor.
Sensor(int id, double x, double y)
          Class Sensor constructor
 
Method Summary
 void addLink(Sensor sensor)
          Adds a link to a given sensor
 void addService(Service service, double goodness)
          Adds a new service to the set of offered services of this sensor
 void addTransmittedDistance(long distance)
          This method increases the total distance travelled by the messages sent from this sensor
 double distance(Sensor sensor)
          Calculates the distance between this sensor and a given one
 boolean equals(Sensor node)
          It indicates if this sensor is equal to a certain one, according to their id
 java.util.Collection<java.util.Vector<Sensor>> findSensors(ISearchCondition searchCondition)
          This method finds the shortest paths from this Sensor to any reachable Sensor satisfying a given condition (inactive or idle sensors are excluded from any path)
 double get_goodness(Service service)
          Gets the goodness of a given service
 int get_numServices()
          Returns the number of services this sensor provides
 Outcome get_outcome()
          Returns the last outcome of a performed transaction
 java.util.Collection<Service> get_services()
          Returns a collection with the services this sensor provides
 long get_transmittedDistance()
          Returns the total distance travelled by the messages sent from this sensor
static TRModel_WSN get_TRModel_WSN()
          Returns Current Trust and Reputation model used by every Sensor
 java.util.Collection<Sensor> getNeighbors()
          Returns all the neighbors of this sensor, i.e., all the sensors reachable from this one, one step forward
 Service getService(java.lang.String service)
          Returns the requested service or null if this sensor does not offer such service
 double getX()
          Returns the X coordenate
 double getY()
          Returns the Y coordenate
 int id()
          Returns sensor's id.
 boolean isActive()
          Indicates if this sensor is active or not
 boolean isNeighbor(Sensor sensor)
          Indicates if a given sensor is neighbor of this one
 boolean offersService(Service service)
          Indicates this sensor offers a certain service or not
protected  boolean offersService(java.lang.String service)
          Indicates if a sensor offers a certain service or not
 void removeAllNeighbors()
          Deletes all the neighbors of this sesnsor
 void removeLink(Sensor sensor)
          Removes the link with a given sensor
 void removeService(Service service)
          Removes a service from the set of offered services by this sensor
abstract  void reset()
          This method resets a Sensor to its initial state
static void resetId()
          Resets the identifier counter to 1
 void run()
          This method uses the current trust and reputation model in order to find the most trustworthy server offering the required service.
 Service serve(Service service, java.util.Vector<Sensor> path)
          This method returns a requested service.
 void set_goodness(Service service, double goodness)
          Sets the goodness of a given service
 void set_requiredService(Service requiredService)
          Update the client required Service.
static void set_TRModel_WSN(TRModel_WSN TRModel_WSN)
          This method sets the current Trust and Reputation model used by every Sensor
 void setActiveState(boolean active_state)
          This method updates the state of this sensor
static void setCollusion(boolean coll)
          Update the collusion value.
static void setDynamic(boolean dyn)
          Update the dynamic value.
static void setMaxDistance(double maxDistance)
          This method sets the maximum distance between two nodes in the network
 java.lang.String toString()
          This method returns a String representation of this sensor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

collusion

protected static boolean collusion
Indicates if a collusion among malicious sensors is built


dynamic

protected static boolean dynamic
Indicates if some sensors will switch off sometimes in order to save energy


idCount

protected static int idCount
Sensors' identifier counter


id

protected int id
Sensor's identifier


_maxDistance

protected static double _maxDistance
Maximum distance between two nodes in the network


xPosition

protected double xPosition
X coordinate of this sensor


yPosition

protected double yPosition
Y coordinate of this sensor


links

protected java.util.Collection<Link> links
Outcoming links of this sensor


servicesGoodness

protected java.util.HashMap<Service,java.lang.Double> servicesGoodness
Goodness of this sensor related to each provided service


requiredService

protected Service requiredService
Service requested by the clients


activeState

protected boolean activeState
Indicates if this sensor is currently active or in an idle state


numRequests

protected int numRequests
Number of service requests provided by this sensor


numRequestsThreshold

protected static final int numRequestsThreshold
Number of service requests provided by this sensor after which it goes to sleep

See Also:
Constant Field Values

trmmodelWSN

protected static TRModel_WSN trmmodelWSN
Current Trust and Reputation model used by every Sensor


outcome

protected Outcome outcome
Last outcome of a performed transaction


transmittedDistance

protected long transmittedDistance
Total distance travelled by the messages sent from this sensor

Constructor Detail

Sensor

public Sensor()
Class Sensor constructor. Creates a new Sensor and locates it randomly


Sensor

public Sensor(int id,
              double x,
              double y)
Class Sensor constructor

Parameters:
id - Sesnor's identifier
x - X coordinate of this sensor
y - Y coordinate of this sensor
Method Detail

run

public void run()

This method uses the current trust and reputation model in order to find the most trustworthy server offering the required service. It requests that service to the server found and punishes or rewards it according to its satisfaction with the received service

Specified by:
run in interface java.lang.Runnable

serve

public Service serve(Service service,
                     java.util.Vector<Sensor> path)
This method returns a requested service. The similarity between the actually offered service and the actually delivered service depends on the goodness of this sensor about this service. If it has a high goodness both services will be very similar (or equal), otherwise it will deliver a very different service than the one requested

Parameters:
service - Requested service
path - Path leading from the client requesting the service to the server providing it
Returns:
A service more or less similar to the requested one, depending on the goodness of this sensor delivering that certain service

addService

public void addService(Service service,
                       double goodness)
Adds a new service to the set of offered services of this sensor

Parameters:
service - The new service to be added
goodness - The goodness when offering that new service

removeService

public void removeService(Service service)
Removes a service from the set of offered services by this sensor

Parameters:
service - Service to be removed from the set of offered services by this sensor

get_goodness

public double get_goodness(Service service)
                    throws java.lang.Exception
Gets the goodness of a given service

Parameters:
service - The service to get its goodness
Returns:
The goodness of the given service
Throws:
java.lang.Exception - If this sensor does not offer the given service

set_goodness

public void set_goodness(Service service,
                         double goodness)
                  throws java.lang.Exception
Sets the goodness of a given service

Parameters:
service - The service to set its goodness
goodness - The goodness to be set
Throws:
java.lang.Exception - If this sensor does not offer the given service

get_numServices

public int get_numServices()
Returns the number of services this sensor provides

Returns:
Number of services

get_services

public java.util.Collection<Service> get_services()
Returns a collection with the services this sensor provides

Returns:
Collection of services.

getService

public Service getService(java.lang.String service)
Returns the requested service or null if this sensor does not offer such service

Parameters:
service - Yhe id of the service to be retrieved
Returns:
The requested service or null if this sensor does not offer such service

findSensors

public java.util.Collection<java.util.Vector<Sensor>> findSensors(ISearchCondition searchCondition)
This method finds the shortest paths from this Sensor to any reachable Sensor satisfying a given condition (inactive or idle sensors are excluded from any path)

Parameters:
searchCondition - Condition to be accomplished by a sensor in order to consider it "reachable"
Returns:
Paths from this Sensor to any reachable sensor satisfying a given condition

offersService

public boolean offersService(Service service)
Indicates this sensor offers a certain service or not

Parameters:
service - The asking service
Returns:
true if this sensor indeed offers the asking service, false otherwise

offersService

protected boolean offersService(java.lang.String service)
Indicates if a sensor offers a certain service or not

Parameters:
service - The asking service's name
Returns:
true if this sensor indeed offers the asking service, false otherwise

getNeighbors

public java.util.Collection<Sensor> getNeighbors()
Returns all the neighbors of this sensor, i.e., all the sensors reachable from this one, one step forward

Returns:
Neighbor sensors of this sensor

removeAllNeighbors

public void removeAllNeighbors()
Deletes all the neighbors of this sesnsor


isNeighbor

public boolean isNeighbor(Sensor sensor)
Indicates if a given sensor is neighbor of this one

Parameters:
sensor - The asking sensor
Returns:
true if the specified sensor is neighbor of this sensor, false otherwise

addLink

public void addLink(Sensor sensor)
Adds a link to a given sensor

Parameters:
sensor - Sensor to link to

removeLink

public void removeLink(Sensor sensor)
Removes the link with a given sensor

Parameters:
sensor - Sensor to remove link with

distance

public double distance(Sensor sensor)
Calculates the distance between this sensor and a given one

Parameters:
sensor - Sensor to calculate the distance from
Returns:
The distance between this sensor and the given one

id

public int id()
Returns sensor's id.

Returns:
Sensor's id

getX

public double getX()
Returns the X coordenate

Returns:
Coordenate X

getY

public double getY()
Returns the Y coordenate

Returns:
Coordenate Y

get_transmittedDistance

public long get_transmittedDistance()
Returns the total distance travelled by the messages sent from this sensor

Returns:
The total distance travelled by the messages sent from this sensor

get_TRModel_WSN

public static TRModel_WSN get_TRModel_WSN()
Returns Current Trust and Reputation model used by every Sensor

Returns:
Current Trust and Reputation model used by every Sensor

get_outcome

public Outcome get_outcome()
Returns the last outcome of a performed transaction

Returns:
The last outcome of a performed transaction

setActiveState

public void setActiveState(boolean active_state)
This method updates the state of this sensor

Parameters:
active_state - New state of this sesnor: true if the new state is active, and false otherwise

setCollusion

public static void setCollusion(boolean coll)
Update the collusion value.

Parameters:
coll - New collusion value.

setDynamic

public static void setDynamic(boolean dyn)
Update the dynamic value.

Parameters:
dyn - New dinamic value.

setMaxDistance

public static void setMaxDistance(double maxDistance)
This method sets the maximum distance between two nodes in the network

Parameters:
maxDistance - Maximum distance between two nodes in the network

set_requiredService

public void set_requiredService(Service requiredService)
Update the client required Service.

Parameters:
requiredService - New service.

set_TRModel_WSN

public static void set_TRModel_WSN(TRModel_WSN TRModel_WSN)
This method sets the current Trust and Reputation model used by every Sensor

Parameters:
TRModel_WSN - New Trust and Reputation model used by every Sensor

isActive

public boolean isActive()
Indicates if this sensor is active or not

Returns:
true if this sesnor is active, false otherwise

addTransmittedDistance

public void addTransmittedDistance(long distance)
This method increases the total distance travelled by the messages sent from this sensor

Parameters:
distance - Amount of distance to be added

resetId

public static void resetId()
Resets the identifier counter to 1


equals

public boolean equals(Sensor node)
It indicates if this sensor is equal to a certain one, according to their id

Parameters:
node - Sensor to check its equality
Returns:
true if this sensor is equal to the specified one, false otherwhise

reset

public abstract void reset()
This method resets a Sensor to its initial state


toString

public java.lang.String toString()
This method returns a String representation of this sensor

Overrides:
toString in class java.lang.Object
Returns:
A String representation of this sensor