es.ants.felixgm.trmsim_wsn.network
Class Network

java.lang.Object
  extended by es.ants.felixgm.trmsim_wsn.network.Network
Direct Known Subclasses:
BTRM_Network, EigenTrust_Network, LFTM_Network, PeerTrust_Network, PowerTrust_Network, TemplateTRM_Network

public abstract class Network
extends java.lang.Object

This class models a P2P, Ad-hoc or Wireless Sensor Network, or even a multi-agent system.

It is composed of several clients requesting services and servers offering services

The constructor Network requires a XML file following the next structure:

    <?xml version="1.0" encoding="UTF-8"?>
    <wsn>
        <client id="1" x="30.5" y="56.2">
            <server id="2"/>
            <server id="3"/>
        </client>
        <client id="7" x="10.3" y="26.4">
            <server id="4"/>
            <server id="6"/>
        </client>
        <server id="2" x="14.8" y="63.7">
            <service id="Relay" goodness="1.0"/>
            <server id="4"/>
            <server id="5"/>
            <client id="1"/>
        </server>
        <server id="3" x="29.7" y="73.7">
            <service id="Relay" goodness="1.0"/>
            <service id="Service 1" goodness="0.05"/>
            <server id="4"/>
        </server>
        <server id="4" x="38.4" y="56.2">
            <service id="Relay" goodness="1.0"/>
            <server id="6"/>
        </server>
        <server id="5" x="95.6" y="36.8">
            <service id="Relay" goodness="1.0"/>
            <service id="Service 1" goodness="0.12"/>
            <server id="6"/>
            <client id="7"/>
        </server>
        <server id="6" x="53.5" y="97.4">
            <service id="Relay" goodness="1.0"/>
            <service id="Service 1" goodness="0.98"/>
            <server id="3"/>
        </server>
    </tacs>
 

This file represents the following network:

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

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

Field Summary
protected  java.util.Collection<Sensor> clients
          The clients requesting services
protected static double maxDistance
          Maximum distance between two nodes in the network
protected  java.util.Collection<Sensor> sensors
          All the sensors composing the network
protected  java.util.Collection<Sensor> servers
          The servers offering services
protected  java.util.Collection<Service> services
          All the services offered by the network
 
Constructor Summary
Network(java.util.Collection<Sensor> clients, java.util.Collection<Sensor> servers, java.util.Collection<Service> services)
          This constructor creates a new Network from a given set of clients, servers and services
Network(int numSensors, double probClients, double rangeFactor, java.util.Collection<java.lang.Double> probServices, java.util.Collection<java.lang.Double> probGoodness, java.util.Collection<Service> services)
          This constructor creates a new random Network using the given parameters
Network(java.lang.String xmlFilePath)
          This method reads a Network from a XML file and builds its corresponding object The XML file given should have this structure
 
Method Summary
 java.util.Collection<Sensor> get_clients()
          This method retrieves the set of clients belonging to this network
static double get_maxDistance()
          This method retrieves the maximum distance between two nodes in this network
 int get_numClients()
          This method retrieves the number of clients belonging to this network
 int get_numSensors()
          This method retrieves the total number of sensors composing this network
 int get_numServers()
          This method retrieves the number of servers belonging to this network
 java.util.Collection<Sensor> get_sensors()
          This method retrieves the set of sensors belonging to this network
 long get_sensorsTransmittedDistance(ISearchCondition searchCondition, Service requiredService)
          Average transmitted distance per sensor of this network
 java.util.Collection<Sensor> get_servers()
          This method retrieves the set of servers belonging to this network
 java.util.Collection<Service> get_services()
          This method retrieves the set of services offered by this network
abstract  Sensor newSensor()
          This method creates a new sensor.
abstract  Sensor newSensor(int id, double x, double y)
          This method creates a new sensor.
 void oscillate(Service service)
          This method turns every benevolent server in the network into malicious and counts the number of swapped servers.
protected  boolean reachesQualifiedService(Sensor sensor, Service requiredService)
          This method checks if a given sensor can reach any client and any benevolent server offering a given service
 void reset()
          This method resets this network to its initial state
 void set_collusion(boolean collusion)
          This method establishes if a collusion is to be formed or not in this network
 void set_dynamic(boolean dynamic)
          This method establishes if the topology of this network is dynamic, because sensors can sleep or not
 void setNewNeighbors(double newRange)
          This methid establishes every sensor's new neighborhood according to a new wireless range
 java.lang.String toString()
          Prints the whole Network, with all the offered services
 void writeToXMLFile(java.lang.String fileName)
          This method writes the current Network into a XML file following this structure
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

maxDistance

protected static final double maxDistance
Maximum distance between two nodes in the network

See Also:
Constant Field Values

clients

protected java.util.Collection<Sensor> clients
The clients requesting services


servers

protected java.util.Collection<Sensor> servers
The servers offering services


sensors

protected java.util.Collection<Sensor> sensors
All the sensors composing the network


services

protected java.util.Collection<Service> services
All the services offered by the network

Constructor Detail

Network

public Network(java.util.Collection<Sensor> clients,
               java.util.Collection<Sensor> servers,
               java.util.Collection<Service> services)
This constructor creates a new Network from a given set of clients, servers and services

Parameters:
clients - The clients requesting services
servers - The servers offering services
services - All the services offered by the network

Network

public Network(int numSensors,
               double probClients,
               double rangeFactor,
               java.util.Collection<java.lang.Double> probServices,
               java.util.Collection<java.lang.Double> probGoodness,
               java.util.Collection<Service> services)
This constructor creates a new random Network using the given parameters

Parameters:
numSensors - Number of sensors composing the network
probClients - Probability of a sensor to act as a client requesting services
rangeFactor - Maximum wireless range of every sensor. It determines the neighborhood of every sensor
probServices - A collection of probabilities of offering a certain service, one per service
probGoodness - A collection of goodnesses about offering a certain service, one per service
services - All the services offered by the generated Network

Network

public Network(java.lang.String xmlFilePath)
        throws java.lang.Exception

This method reads a Network from a XML file and builds its corresponding object

The XML file given should have this structure

Parameters:
xmlFilePath - Path of the XML file describing the Network to create
Throws:
java.lang.Exception - If the XML file given does not have the structure shown before, or if a node links to an undefined node, or if a node links to itself
Method Detail

oscillate

public void oscillate(Service service)
This method turns every benevolent server in the network into malicious and counts the number of swapped servers. Then (when every server is malicious) it randomly selects malicious servers and converts them into benevolent until the number of benevolent servers is equal to the one before calling this method

Parameters:
service - Service over what the oscillation is to be carried out

newSensor

public abstract Sensor newSensor()
This method creates a new sensor. It must be redefined in each subclass according to the requirements of each particular trust and reputation model

Returns:
New created sensor

newSensor

public abstract Sensor newSensor(int id,
                                 double x,
                                 double y)
This method creates a new sensor. It must be redefined in each subclass according to the requirements of each particular trust and reputation model

Parameters:
id - Sensor's identifier
x - X coordinate of the new sensor
y - Y coordinate of the new sensor
Returns:
New created sensor

reset

public void reset()
This method resets this network to its initial state


setNewNeighbors

public void setNewNeighbors(double newRange)
This methid establishes every sensor's new neighborhood according to a new wireless range

Parameters:
newRange - New wireless range determining every sensor's neighbors

writeToXMLFile

public void writeToXMLFile(java.lang.String fileName)
                    throws java.lang.Exception
This method writes the current Network into a XML file following this structure

Parameters:
fileName - Path of the XML file where to write the current Network
Throws:
java.lang.Exception - If there is any problem when writing to the XML file

toString

public java.lang.String toString()
Prints the whole Network, with all the offered services

Overrides:
toString in class java.lang.Object
Returns:
A string with the whole Network, with all the offered services

get_sensorsTransmittedDistance

public long get_sensorsTransmittedDistance(ISearchCondition searchCondition,
                                           Service requiredService)
Average transmitted distance per sensor of this network

Parameters:
searchCondition - Condition to be accomplished by the querying sensors
requiredService - Service requested by the clients
Returns:
Average transmitted distance per sensor of this network

reachesQualifiedService

protected boolean reachesQualifiedService(Sensor sensor,
                                          Service requiredService)
This method checks if a given sensor can reach any client and any benevolent server offering a given service

Parameters:
sensor - Sensor to find out whether it can reach a benevolent server or not
requiredService - Service requested by the clients
Returns:
true if the given sensor can reach any client and any benevolent server offering the given service, false otherwise

get_clients

public java.util.Collection<Sensor> get_clients()
This method retrieves the set of clients belonging to this network

Returns:
The set of clients belonging to this network

get_servers

public java.util.Collection<Sensor> get_servers()
This method retrieves the set of servers belonging to this network

Returns:
The set of servers belonging to this network

get_sensors

public java.util.Collection<Sensor> get_sensors()
This method retrieves the set of sensors belonging to this network

Returns:
The set of sensors belonging to this network

get_services

public java.util.Collection<Service> get_services()
This method retrieves the set of services offered by this network

Returns:
The set of services offered by this network

get_numSensors

public int get_numSensors()
This method retrieves the total number of sensors composing this network

Returns:
The total number of sensors composing this network

get_numClients

public int get_numClients()
This method retrieves the number of clients belonging to this network

Returns:
The number of clients belonging to this network

get_numServers

public int get_numServers()
This method retrieves the number of servers belonging to this network

Returns:
The number of servers belonging to this network

get_maxDistance

public static double get_maxDistance()
This method retrieves the maximum distance between two nodes in this network

Returns:
The maximum distance between two nodes in this network

set_collusion

public void set_collusion(boolean collusion)
This method establishes if a collusion is to be formed or not in this network

Parameters:
collusion - Indicates if a collusion is to be formed or not in this network

set_dynamic

public void set_dynamic(boolean dynamic)
This method establishes if the topology of this network is dynamic, because sensors can sleep or not

Parameters:
dynamic - Indicates if the topology of this network is dynamic, because sensors can sleep or not