Wiselib
wiselib.testing/algorithms/tracking/PLTT_passive_nb.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  ** This file is part of the generic algorithm library Wiselib.           **
00003  ** Copyright (C) 2008,2009 by the Wisebed (www.wisebed.eu) project.      **
00004  **                                                                       **
00005  ** The Wiselib is free software: you can redistribute it and/or modify   **
00006  ** it under the terms of the GNU Lesser General Public License as        **
00007  ** published by the Free Software Foundation, either version 3 of the    **
00008  ** License, or (at your option) any later version.                       **
00009  **                                                                       **
00010  ** The Wiselib is distributed in the hope that it will be useful,        **
00011  ** but WITHOUT ANY WARRANTY; without even the implied warranty of        **
00012  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         **
00013  ** GNU Lesser General Public License for more details.                   **
00014  **                                                                       **
00015  ** You should have received a copy of the GNU Lesser General Public      **
00016  ** License along with the Wiselib.                                       **
00017  ** If not, see <http://www.gnu.org/licenses/>.                           **
00018  ***************************************************************************/
00019 
00020 #ifndef __PLTT_PASSIVE_H__
00021 #define __PLTT_PASSIVE_H__
00022 #include "PLTT_config.h"
00023 #include "PLTT_message.h"
00024 namespace wiselib
00025 {
00026    template<   typename Os_P,
00027             typename Node_P,
00028             typename PLTT_Node_P,
00029             typename PLTT_NodeList_P,
00030             typename PLTT_Trace_P,
00031             typename PLTT_TraceList_P,
00032             typename PLTT_Agent_P,
00033             typename PLTT_AgentList_P,
00034             typename PLTT_ReliableAgent_P,
00035             typename PLTT_ReliableAgentList_P,
00036             typename NeighborDiscovery_P,
00037             typename Timer_P,
00038             typename Radio_P,
00039             typename Rand_P,
00040             typename Clock_P,
00041             typename PLTT_PassiveSpreadMetrics_P,
00042             typename PLTT_PassiveTrackingMetrics_P,
00043             typename Debug_P>
00044    class PLTT_PassiveType
00045    {
00046    public:
00047       typedef Os_P Os;
00048       typedef Radio_P Radio;
00049       typedef Rand_P Rand;
00050       typedef typename Rand::rand_t rand_t;
00051       typedef Debug_P Debug;
00052       typedef Node_P Node;
00053       typedef PLTT_Agent_P PLTT_Agent;
00054       typedef PLTT_AgentList_P PLTT_AgentList;
00055       typedef PLTT_ReliableAgent_P PLTT_ReliableAgent;
00056       typedef PLTT_ReliableAgentList_P PLTT_ReliableAgentList;
00057       typedef typename PLTT_ReliableAgentList::iterator PLTT_ReliableAgentListIterator;
00058       typedef typename PLTT_Agent::AgentID AgentID;
00059       typedef typename PLTT_AgentList::iterator PLTT_AgentListIterator;
00060       typedef PLTT_Node_P PLTT_Node;
00061       typedef PLTT_NodeList_P PLTT_NodeList;
00062       typedef typename PLTT_NodeList::iterator PLTT_NodeListIterator;
00063       typedef PLTT_Trace_P PLTT_Trace;
00064       typedef typename PLTT_Trace::PLTT_TraceData PLTT_TraceData;
00065       typedef PLTT_TraceList_P PLTT_TraceList;
00066       typedef typename PLTT_TraceList::iterator PLTT_TraceListIterator;
00067       typedef typename Node::Position Position;
00068       typedef typename Node::Position::CoordinatesNumber CoordinatesNumber;
00069       typedef typename PLTT_Node::PLTT_NodeTarget PLTT_NodeTarget;
00070       typedef typename PLTT_NodeTarget::IntensityNumber IntensityNumber;
00071       typedef typename PLTT_Node::PLTT_NodeTargetList PLTT_NodeTargetList;
00072       typedef typename PLTT_Node::PLTT_NodeTargetListIterator PLTT_NodeTargetListIterator;
00073       typedef NeighborDiscovery_P NeighborDiscovery;
00074       typedef typename NeighborDiscovery::node_info_vector_t NB_node_info_vector;
00075       typedef typename NB_node_info_vector::iterator NB_iterator;
00076       typedef Timer_P Timer;
00077       typedef Clock_P Clock;
00078       typedef PLTT_PassiveSpreadMetrics_P PLTT_PassiveSpreadMetrics;
00079       typedef typename PLTT_PassiveSpreadMetrics::PLTT_PassiveSpreadMetricListIterator PLTT_PassiveSpreadMetricListIterator;
00080       typedef PLTT_PassiveTrackingMetrics_P PLTT_PassiveTrackingMetrics;
00081       typedef typename PLTT_PassiveTrackingMetrics::PLTT_PassiveTrackingMetricListIterator PLTT_PassiveTrackingMetricListIterator;
00082       typedef typename Radio::node_id_t node_id_t;
00083       typedef typename Radio::size_t size_t;
00084       typedef typename Radio::block_data_t block_data_t;
00085       typedef typename Radio::message_id_t message_id_t;
00086       typedef typename Radio::ExtendedData ExtendedData;
00087       typedef typename Timer::millis_t millis_t;
00088       typedef typename Radio::TxPower TxPower;
00089       typedef wiselib::vector_static<Os, Node, 10> NodeList;
00090       typedef typename NodeList::iterator NodeList_Iterator;
00091       typedef PLTT_MessageType<Os, Radio> Message;
00092       typedef PLTT_PassiveType<Os, Node, PLTT_Node, PLTT_NodeList, PLTT_Trace, PLTT_TraceList, PLTT_Agent, PLTT_AgentList, PLTT_ReliableAgent, PLTT_ReliableAgentList, NeighborDiscovery, Timer, Radio, Rand, Clock, PLTT_PassiveSpreadMetrics, PLTT_PassiveTrackingMetrics, Debug> self_type;
00093       // -----------------------------------------------------------------------
00094       PLTT_PassiveType()
00095       :  radio_callback_id_            ( 0 ),
00096          seconds_counter                  ( 1 )
00097 #ifdef PLTT_METRICS
00098          ,messages_received_periodic      ( 0 ),
00099          messages_bytes_received_periodic    ( 0 ),
00100          messages_received                ( 0 ),
00101          messages_bytes_received          ( 0 )
00102 #endif
00103 #ifdef PLTT_PASSIVE_TRACKING_METRICS_LIGHT
00104          ,echo_messages_send           ( 0 ),
00105          echo_bytes_send               ( 0 ),
00106          echo_messages_received           ( 0 ),
00107          echo_bytes_received           ( 0 ),
00108          report_messages_send             ( 0 ),
00109          report_bytes_send                ( 0 ),
00110          report_messages_received         ( 0 ),
00111          report_bytes_received            ( 0 ),
00112          query_messages_send           ( 0 ),
00113          query_bytes_send              ( 0 ),
00114          query_messages_received          ( 0 ),
00115          query_bytes_received             ( 0 ),
00116          echo_messages_send_periodic      ( 0 ),
00117          echo_bytes_send_periodic         ( 0 ),
00118          echo_messages_received_periodic  ( 0 ),
00119          echo_bytes_received_periodic     ( 0 ),
00120          report_messages_send_periodic       ( 0 ),
00121          report_bytes_send_periodic          ( 0 ),
00122          report_messages_received_periodic   ( 0 ),
00123          report_bytes_received_periodic      ( 0 ),
00124          query_messages_send_periodic     ( 0 ),
00125          query_bytes_send_periodic        ( 0 ),
00126          query_messages_received_periodic    ( 0 ),
00127          query_bytes_received_periodic       ( 0 )
00128 #endif
00129 #ifdef PLTT_PASSIVE_SPREAD_METRICS_LIGHT
00130          ,spread_messages_send            ( 0 ),
00131          spread_bytes_send                ( 0 ),
00132          spread_messages_received         ( 0 ),
00133          spread_bytes_received            ( 0 ),
00134          spread_messages_inhibited        ( 0 ),
00135          spread_bytes_inhibited           ( 0 ),
00136          inhibition_messages_send         ( 0 ),
00137          inhibition_bytes_send            ( 0 ),
00138          inhibition_messages_received     ( 0 ),
00139          inhibition_bytes_received        ( 0 ),
00140          inhibition_messages_inhibited       ( 0 ),
00141          inhibition_bytes_inhibited          ( 0 ),
00142          spread_messages_send_periodic       ( 0 ),
00143          spread_bytes_send_periodic          ( 0 ),
00144          spread_messages_received_periodic   ( 0 ),
00145          spread_bytes_received_periodic      ( 0 ),
00146          spread_messages_inhibited_periodic  ( 0 ),
00147          spread_bytes_inhibited_periodic  ( 0 ),
00148          inhibition_messages_send_periodic   ( 0 ),
00149          inhibition_bytes_send_periodic      ( 0 ),
00150          inhibition_messages_received_periodic  ( 0 ),
00151          inhibition_bytes_received_periodic  ( 0 ),
00152          inhibition_messages_inhibited_periodic ( 0 ),
00153          inhibition_bytes_inhibited_periodic ( 0 )
00154 #endif
00155 
00156       {}
00157       // -----------------------------------------------------------------------
00158       ~PLTT_PassiveType()
00159       {}
00160       // -----------------------------------------------------------------------
00161       void enable( void )
00162       {
00163          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_MISC
00164          debug().debug( "PLTT_Passive %x: Boot \n", self.get_node().get_id() );
00165          #endif
00166          radio().enable_radio();
00167          radio_callback_id_ = radio().template reg_recv_callback<self_type, &self_type::receive>( this );
00168          millis_t r = rand()()%2000;
00169          timer().template set_timer<self_type, &self_type::neighbor_discovery_enable_task>( r, this, 0);
00170       }
00171       void neighbor_discovery_enable_task( void* userdata = NULL)
00172       {
00173          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_NEIGHBORHOOD_DISCOVERY
00174          debug().debug( "PLTT_Passive %x: Neighbor discovery enable task \n", self.get_node().get_id() );
00175          #endif
00176          block_data_t buff[Radio::MAX_MESSAGE_LENGTH];
00177          self.get_node().get_position().set_buffer_from( buff );
00178          //uint8_t flags = NeighborDiscovery::NEW_PAYLOAD_BIDI | NeighborDiscovery::DROPPED_NB;
00179          uint8_t flags = NeighborDiscovery::NEW_PAYLOAD_BIDI;
00180          neighbor_discovery().init( radio(), clock(), timer(), debug() );
00181          neighbor_discovery().template reg_event_callback<self_type, &self_type::sync_neighbors>( 2, flags, this );
00182          neighbor_discovery().register_payload_space( 2 );
00183          neighbor_discovery().set_payload( 2, buff, self.get_node().get_position().get_buffer_size() );
00184          //neighbor_discovery().register_debug_callback( 0 );
00185          neighbor_discovery().enable();
00186          timer().template set_timer<self_type, &self_type::neighbor_discovery_unregister_task>( 30000, this, 0);
00187       }
00188       // -----------------------------------------------------------------------
00189       void neighbor_discovery_unregister_task( void* userdata = NULL)
00190       {
00191          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_NEIGHBORHOOD_DISCOVERY
00192          debug().debug( "PLTT_Passive %x: Neighbor discovery unregister task \n", self.get_node().get_id() );
00193          #endif
00194          //filter_neighbors();
00195          neighbor_discovery().unreg_event_callback( 2 );
00196          neighbor_discovery().unregister_payload_space( 2 );
00197          neighbor_discovery().disable();
00198          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_NEIGHBORHOOD_DISCOVERY
00199          print_neighbors();
00200          #endif
00201          update_traces();
00202          debug().debug( "PLTT_Passive %x (%i, %i): NB READY! - Neighbor discovery unregister - size of neighbor list %i vs nb size %i ", self.get_node().get_id(), self.get_node().get_position().get_x(), self.get_node().get_position().get_y(), neighbors.size(), neighbor_discovery().neighborhood.size() );
00203          #ifdef OPT_RELIABLE_TRACKING
00204          cleanup_timer = 0;
00205          timer().template set_timer<self_type, &self_type::reliable_agent_daemon>( reliable_millis_timer, this, 0 );
00206          #endif
00207          #ifdef PLTT_METRICS
00208          timer().template set_timer<self_type, &self_type::print_metrics>( rand()()%metrics_timeout, this, 0 );
00209          #endif
00210          TxPower power;
00211          power.set_dB( 0 );
00212          radio().set_power( power );
00213       }
00214       // -----------------------------------------------------------------------
00215       void disable( void )
00216       {
00217          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_MISC
00218          debug().debug( "PLTT_Passive %x: Disable \n", self.get_node().id );
00219          #endif
00220          radio().unreg_recv_callback( radio_callback_id_ );
00221          radio().disable();
00222       }
00223       // -----------------------------------------------------------------------
00224       void send( node_id_t destination, size_t len, block_data_t *data, message_id_t msg_id )
00225       {
00226          Message message;
00227          message.set_msg_id( msg_id );
00228          message.set_payload( len, data );
00229          radio().send( destination, message.buffer_size(), ( uint8_t* )&message );
00230       }
00231       // -----------------------------------------------------------------------
00232       void receive( node_id_t from, size_t len, block_data_t *data, const ExtendedData& exdata )
00233       {
00234          message_id_t msg_id = *data;
00235          Message *message = ( Message* )data;
00236          #ifdef PLTT_METRICS
00237          messages_received_periodic = messages_received_periodic + 1;
00238          messages_bytes_received_periodic = messages_bytes_received_periodic + len;
00239          messages_received = messages_received + 1;
00240          messages_bytes_received = messages_bytes_received + len;
00241          #endif
00242          //debug().debug("sanity check %x,%i",from, msg_id);
00243 //       #ifdef PLTT_SECURE
00244 //       if ( msg_id == PLTT_SECURE_SPREAD_ID )
00245 //       {
00246 //          #ifdef PLTT_PASSIVE_SPREAD_METRICS
00247 //          #endif
00248 //          //send for decryption
00249 //       }
00250 //       else if ( msg_id == PLTT_SECURE_ENCRYPTION_REPLY )
00251 //       {
00252 //          #ifdef PLTT_PASSIVE_SPREAD_METRICS
00253 //          #endif
00254 //          //prepare_spread_trace
00255 //       }
00256 //       #else
00257          if ( msg_id == PLTT_SPREAD_ID )
00258          {
00259             #ifdef PLTT_PASSIVE_SPREAD_METRICS
00260             passive_spread_metrics.inc_spread_messages_received_of_target( PLTT_Trace( message->payload() ).get_target_id() );
00261             passive_spread_metrics.inc_spread_messages_bytes_received_of_target( PLTT_Trace( message->payload() ).get_target_id(), len );
00262             passive_spread_metrics_periodic.inc_spread_messages_received_of_target( PLTT_Trace( message->payload() ).get_target_id() );
00263             passive_spread_metrics_periodic.inc_spread_messages_bytes_received_of_target( PLTT_Trace( message->payload() ).get_target_id(), len );
00264             #endif
00265             #ifdef PLTT_PASSIVE_SPREAD_METRICS_LIGHT
00266             ++spread_messages_received;
00267             spread_bytes_received = spread_bytes_received + len;
00268             ++spread_messages_received_periodic;
00269             spread_bytes_received_periodic = spread_bytes_received_periodic + len;
00270             #endif
00271             #ifdef ISENSE_PLTT_PASSIVE_DEBUG_SPREAD
00272             debug().debug( "PLTT_Passive %x: Received spread message from %x of link metric %i and size %i \n", self.get_node().get_id(), from, exdata.link_metric(), len );
00273             #endif
00274             prepare_spread_trace( store_trace( PLTT_Trace( message->payload() ) ), exdata );
00275          }
00276 //       #endif
00277          else if ( msg_id == PLTT_INHIBITION_MESSAGE_ID )
00278          {
00279             #ifdef PLTT_PASSIVE_SPREAD_METRICS
00280             #ifndef OPT_TARGET_LIST_AGGREGATION
00281             passive_spread_metrics.inc_inhibition_messages_received_of_target( PLTT_Node( message->payload() ).get_node_target_list()->begin()->get_target_id() );
00282             passive_spread_metrics.inc_inhibition_messages_bytes_received_of_target( PLTT_Node( message->payload() ).get_node_target_list()->begin()->get_target_id(), len );
00283             passive_spread_metrics_periodic.inc_inhibition_messages_received_of_target( PLTT_Node( message->payload() ).get_node_target_list()->begin()->get_target_id() );
00284             passive_spread_metrics_periodic.inc_inhibition_messages_bytes_received_of_target( PLTT_Node( message->payload() ).get_node_target_list()->begin()->get_target_id(), len );
00285             #else
00286             passive_spread_metrics.inc_inhibition_messages_received();
00287             passive_spread_metrics.inc_inhibition_messages_bytes_received( len );
00288             passive_spread_metrics_periodic.inc_inhibition_messages_received();
00289             passive_spread_metrics_periodic.inc_inhibition_messages_bytes_received( len );
00290             #endif
00291             #endif
00292             #ifdef PLTT_PASSIVE_SPREAD_METRICS_LIGHT
00293             ++inhibition_messages_received;
00294             inhibition_bytes_received = inhibition_bytes_received + len;
00295             ++inhibition_messages_received_periodic;
00296             inhibition_bytes_received_periodic = inhibition_bytes_received_periodic + len;
00297             #endif
00298             #ifdef ISENSE_PLTT_PASSIVE_DEBUG_INHIBITION
00299             debug().debug( "PLTT_Passive %x: Received inhibition message from %x of size %i and payload size of %i \n", self.get_node().get_id(), from, len, message->payload_size() );
00300             #endif
00301             inhibit_traces( update_neighbor( PLTT_Node( message->payload() ) ), from );
00302          }
00303          else if ( msg_id == PLTT_TRACK_ECHO_ID )
00304          {
00305             #ifdef PLTT_PASSIVE_TRACKING_METRICS
00306             passive_tracking_metrics.inc_echo_messages_received_of_tracker( from );
00307             passive_tracking_metrics.inc_echo_messages_bytes_received_of_tracker( from, len );
00308             passive_tracking_metrics_periodic.inc_echo_messages_received_of_tracker( from );
00309             passive_tracking_metrics_periodic.inc_echo_messages_bytes_received_of_tracker( from, len );
00310             #endif
00311             #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_ECHO
00312             AgentID aid = read<Os, block_data_t, AgentID>( message->payload() );
00313             debug().debug( "PLTT_Passive %x: Received track echo message %x from %x of size %i and payload size of %i \n", self.get_node().get_id(), aid, from, len, message->payload_size() );
00314             #endif
00315             #ifdef PLTT_PASSIVE_TRACKING_METRICS
00316             passive_tracking_metrics.inc_echo_messages_send_of_tracker( from );
00317             passive_tracking_metrics.inc_echo_messages_bytes_send_of_tracker( from, len );
00318             passive_tracking_metrics_periodic.inc_echo_messages_send_of_tracker( from );
00319             passive_tracking_metrics_periodic.inc_echo_messages_bytes_send_of_tracker( from, len );
00320             #endif
00321             #ifdef PLTT_PASSIVE_TRACKING_METRICS_LIGHT
00322             ++echo_messages_received;
00323             echo_bytes_received = echo_bytes_received + len;
00324             ++echo_messages_send;
00325             echo_bytes_send = echo_bytes_send + len;
00326             ++echo_messages_received_periodic;
00327             echo_bytes_received_periodic = echo_bytes_received_periodic + len;
00328             ++echo_messages_send_periodic;
00329             echo_bytes_send_periodic = echo_bytes_send_periodic + len;
00330             #endif
00331             send( from, message->payload_size(), message->payload(), PLTT_TRACK_ECHO_REPLY_ID );
00332 
00333          }
00334          else if ( msg_id == PLTT_QUERY_ID )
00335          {
00336             #ifdef PLTT_PASSIVE_TRACKING_METRICS
00337             passive_tracking_metrics.inc_query_messages_received_of_tracker( PLTT_Agent( message->payload() ).get_tracker().get_id() );
00338             passive_tracking_metrics.inc_query_messages_bytes_received_of_tracker( PLTT_Agent( message->payload() ).get_tracker().get_id(), len );
00339             passive_tracking_metrics_periodic.inc_query_messages_received_of_tracker( PLTT_Agent( message->payload() ).get_tracker().get_id() );
00340             passive_tracking_metrics_periodic.inc_query_messages_bytes_received_of_tracker( PLTT_Agent( message->payload() ).get_tracker().get_id(), len );
00341             #endif
00342             #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
00343             debug().debug( "PLTT_Passive %x: Received query agent message from %x of size %i and payload size of %i and %i \n", self.get_node().get_id(), from, len, PLTT_Agent( message->payload() ).get_buffer_size() );
00344             #endif
00345             #ifdef OPT_RELIABLE_TRACKING
00346             if ( PLTT_Agent( message->payload() ).get_tracker().get_id() != from )
00347             {
00348                block_data_t buf[Radio::MAX_MESSAGE_LENGTH];
00349                block_data_t* buff = buf;
00350                PLTT_Agent( message->payload() ).set_buffer_from( buff );
00351                send( from, PLTT_Agent( message->payload() ).get_buffer_size(), buff, PLTT_QUERY_ACK_ID );
00352             }
00353             #endif
00354             #ifdef PLTT_PASSIVE_TRACKING_METRICS_LIGHT
00355             ++query_messages_received;
00356             query_bytes_received = query_bytes_received + len;
00357             ++query_messages_received_periodic;
00358             query_bytes_received_periodic = query_bytes_received_periodic + len;
00359             #endif
00360 #ifndef ISENSE_APP
00361             timer().template set_timer<self_type, &self_type::process_query>( 10, this, (void*) store_query_agent( PLTT_Agent( message->payload() ), msg_id ) );
00362 #else
00363             PLTT_Agent agent( message->payload() );
00364             if ( find_reliable_agent( agent, msg_id, from ) == 0 )
00365             {
00366                process_query( (void*) & agent );
00367             }
00368             else
00369             {
00370                #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY_REPORT
00371                debug().debug( "PLTT_Passive %x: Ignored query agent\n" );
00372                #endif
00373             }
00374 #endif
00375          }
00376          else if ( msg_id == PLTT_QUERY_REPORT_ID )
00377          {
00378             #ifdef PLTT_PASSIVE_TRACKING_METRICS
00379             passive_tracking_metrics.inc_report_messages_received_of_tracker( PLTT_Agent( message->payload() ).get_tracker().get_id() );
00380             passive_tracking_metrics.inc_report_messages_bytes_received_of_tracker( PLTT_Agent( message->payload() ).get_tracker().get_id(), len );
00381             passive_tracking_metrics_periodic.inc_report_messages_received_of_tracker( PLTT_Agent( message->payload() ).get_tracker().get_id() );
00382             passive_tracking_metrics_periodic.inc_report_messages_bytes_received_of_tracker( PLTT_Agent( message->payload() ).get_tracker().get_id(), len );
00383             #endif
00384             #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY_REPORT
00385             debug().debug( "PLTT_Passive %x: Received report agent message from %x of size %i and payload size of %i \n", self.get_node().get_id(), from, len, message->payload_size() );
00386             #endif
00387             #ifdef OPT_RELIABLE_TRACKING
00388             block_data_t buf[Radio::MAX_MESSAGE_LENGTH];
00389             block_data_t* buff = buf;
00390             PLTT_Agent( message->payload() ).set_buffer_from( buff );
00391             send( from, PLTT_Agent( message->payload() ).get_buffer_size(), buff, PLTT_QUERY_REPORT_ACK_ID );
00392             #endif
00393             #ifdef PLTT_PASSIVE_TRACKING_METRICS_LIGHT
00394             ++report_messages_received;
00395             report_bytes_received = report_bytes_received + len;
00396             ++report_messages_received_periodic;
00397             report_bytes_received_periodic = report_bytes_received_periodic + len;
00398             #endif
00399 #ifndef ISENSE_APP
00400             timer().template set_timer<self_type, &self_type::process_query_report>( 10, this, (void*) store_report_agent( PLTT_Agent( message->payload() ), msg_id ) );
00401 #else
00402             PLTT_Agent agent( message->payload() );
00403             if ( find_reliable_agent( agent, msg_id, from ) == 0 )
00404             {
00405                process_query_report( (void*) & agent );
00406             }
00407             else
00408             {
00409                #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY_REPORT
00410                debug().debug( "PLTT_Passive %x: Ignored query report agent\n" );
00411                #endif
00412             }
00413 #endif
00414 
00415          }
00416          #ifdef OPT_RELIABLE_TRACKING
00417          else if ( msg_id == PLTT_QUERY_ACK_ID )
00418          {
00419             #ifdef PLTT_PASSIVE_TRACKING_METRICS
00420             //TODO
00421             #endif
00422             #ifdef ISENSE_PLTT_PASSIVE_RELIABLE_TRACKING_DEBUG
00423             debug().debug( "PLTT_Passive %x: Received query agent ack message from %x of size %i and payload size of %i \n", self.get_node().get_id(), from , len, message->payload_size() );
00424             #endif
00425             remove_reliable_agent( PLTT_Agent( message->payload() ) , msg_id , from );
00426          }
00427          else if ( msg_id == PLTT_QUERY_REPORT_ACK_ID )
00428          {
00429             #ifdef PLTT_PASSIVE_TRACKING_METRICS
00430             //TODO
00431             #endif
00432             #ifdef ISENSE_PLTT_PASSIVE_RELIABLE_TRACKING_DEBUG
00433             debug().debug( "PLTT_Passive %x: Received report agent ack message from %x of size %i and payload size of %i \n", self.get_node().get_id(), from , len, message->payload_size() );
00434             #endif
00435             remove_reliable_agent( PLTT_Agent( message->payload() ) , msg_id , from );
00436          }
00437          #endif
00438       }
00439       // -----------------------------------------------------------------------
00440       PLTT_Trace* store_trace( PLTT_Trace t )
00441       {
00442          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_SPREAD
00443          debug().debug( "PLTT_Passive %x: Store trace\n", self.get_node().get_id() );
00444          #endif
00445          PLTT_TraceListIterator traces_iterator = traces.begin();
00446          while ( traces_iterator!=traces.end() )
00447          {
00448             if ( traces_iterator->get_target_id() == t.get_target_id() )
00449             {
00450                #ifdef ISENSE_PLTT_PASSIVE_DEBUG_SPREAD
00451                debug().debug( "PLTT_Passive %x: Store trace - new trace intensity and start time (%i, %i ) vs current (%i, %i, %i) ", self.get_node().get_id(), t.get_intensity(), t.get_start_time(), traces_iterator->get_intensity(), traces_iterator->get_start_time(), traces_iterator->get_inhibited() );
00452                #endif
00453                #ifdef OPT_NON_MERGED_TREE
00454                if   ( traces_iterator->get_intensity() <= t.get_intensity() &&
00455                     t.get_start_time() != traces_iterator->get_start_time() )
00456                #else
00457                if   ( traces_iterator->get_intensity() <= t.get_intensity() )
00458                #endif
00459                {
00460                   *traces_iterator = t;
00461                   traces_iterator->update_path( self.get_node() );
00462                   //self.set_node_target_list( traces );
00463                   return &( *traces_iterator );
00464                }
00465                else
00466                {
00467                   return NULL;
00468                }
00469             }
00470             ++traces_iterator;
00471          }
00472          t.update_path( self.get_node() );
00473          traces.push_back( t );
00474          //self.set_node_target_list( traces );
00475          traces_iterator = traces.end() - 1;
00476          return &( *traces_iterator );
00477       }
00478       // -----------------------------------------------------------------------
00479       void update_traces( void* userdata = NULL )
00480       {
00481          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_MISC
00482          debug().debug( "PLTT_Passive %x: Update Traces trace", self.get_node().get_id() );
00483          #endif
00484          for ( PLTT_TraceListIterator traces_iterator = traces.begin(); traces_iterator != traces.end(); ++traces_iterator )
00485          {
00486             if ( ( seconds_counter % traces_iterator->get_diminish_seconds() == 0) && ( traces_iterator->get_inhibited() != 0 ) )
00487             {
00488                traces_iterator->update_intensity_diminish();
00489                if ( traces_iterator->get_intensity() == 0 )
00490                {
00491                   traces_iterator->set_inhibited();
00492                }
00493                #ifdef IOANNIS_DEMO
00494                else
00495                {
00496 
00497                   if (traces_iterator->get_parent().get_id() != 0x0 )
00498                   {
00499                      debug().debug("%x;%x;%x;%i",self.get_node().get_id(), traces_iterator->get_parent().get_id(), traces_iterator->get_target_id(), traces_iterator->get_intensity() );
00500                   }
00501                }
00502                #endif
00503             }
00504          }
00505          seconds_counter++;
00506          timer().template set_timer<self_type, &self_type::update_traces>( 1000, this, 0 );
00507          //self.set_node_target_list( traces );
00508       }
00509       // -----------------------------------------------------------------------
00510       void print_traces( void* userdata = NULL )
00511       {
00512          debug().debug( "PLTT_Passive %x: Traces start print-out\n", self.get_node().id );
00513          for ( PLTT_TraceListIterator traces_iterator = traces.begin(); traces_iterator != traces.end(); ++traces_iterator )
00514          {
00515             traces_iterator->print_trace( debug() );
00516             debug().debug( "-----------------------------\n");
00517          }
00518          debug().debug( "PLTT_Passive %x: Traces end print-out \n", self.get_node().get_id() );
00519          timer().template set_timer<self_type, &self_type::print_traces>( 11000, this, 0);
00520       }
00521       // -----------------------------------------------------------------------
00522       void prepare_spread_trace( PLTT_Trace* t, const ExtendedData& exdata)
00523       {
00524          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_SPREAD
00525          debug().debug( "PLTT_Passive %x: Prepare Spread Trace\n", self.get_node().get_id() );
00526          #endif
00527          if (t != NULL )
00528          {
00529             NodeList recipient_candidates;
00530             Node rep_point = ( *t ).get_repulsion_point();
00531             for ( PLTT_NodeListIterator neighbors_iterator = neighbors.begin(); neighbors_iterator != neighbors.end(); ++neighbors_iterator )
00532             {
00533                if ( rep_point.get_id() != 0 )
00534                {
00535                   if ( rep_point.get_position().distsq( self.get_node().get_position() ) <= rep_point.get_position().distsq( neighbors_iterator->get_node().get_position() ) )
00536                   {
00537                      recipient_candidates.push_back( neighbors_iterator->get_node() );
00538                   }
00539                }
00540             }
00541             millis_t r = rand()()%300;
00542             //#ifdef OPT_LQI_INHIBITION
00543             //if ( exdata.link_metric() != 0 )
00544             //{
00545             // debug().debug( "PLTT_Passive %x: Prepare Spread - Has lqi of %i\n", self.get_node().get_id(), exdata.link_metric() );
00546             // r = 12800 / exdata.link_metric() + r;
00547             //}
00548             //#endif
00549             if ( recipient_candidates.size() == 0 )
00550             {
00551                #ifdef ISENSE_PLTT_PASSIVE_DEBUG_SPREAD
00552                debug().debug( "PLTT_Passive %x: Prepare Spread - Exited due to 0 element candidate list\n", self.get_node().get_id() );
00553                #endif
00554                t->set_inhibited();
00555                return;
00556             }
00557             else if ( recipient_candidates.size() == 1 )
00558             {
00559                #ifdef ISENSE_PLTT_PASSIVE_DEBUG_SPREAD
00560                debug().debug( "PLTT_Passive %x: Prepare Spread - Candidate list of size 1 - Imposing 1000ms delay\n", self.get_node().get_id() );
00561                #endif
00562                r = r + 1000;
00563             }
00564             #ifdef ISENSE_PLTT_PASSIVE_DEBUG_SPREAD
00565             debug().debug( "PLTT_Passive %x: Prepare Spread - Scheduled inhibition and spread in %i millis \n", self.get_node().get_id(), r );
00566             #endif
00567             timer().template set_timer<self_type, &self_type::send_inhibition> ( r, this, ( void* )t);
00568             timer().template set_timer<self_type, &self_type::spread_trace> ( r + 100, this, ( void* )t );
00569          }
00570          else
00571          {
00572             #ifdef ISENSE_PLTT_PASSIVE_DEBUG_SPREAD
00573             debug().debug( "PLTT_Passive %x: Prepared Spread - Exited due to ignore from store\n", self.get_node().get_id() );
00574             #endif
00575          }
00576       }
00577       // -----------------------------------------------------------------------
00578       void spread_trace( void* userdata )
00579       {
00580          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_SPREAD
00581          debug().debug( "PLTT_Passive %x: Spread Trace\n", self.get_node().get_id() );
00582          #endif
00583          PLTT_Trace* t = ( PLTT_Trace* )userdata;
00584          if ( ( *t ).get_inhibited() == 0 )
00585          {
00586             typedef wiselib::vector_static<Os, Node, 10> NodeList;
00587             typedef typename NodeList::iterator NodeList_Iterator;
00588             NodeList recipient_candidates;
00589             NodeList_Iterator recipient_candidates_iterator;
00590             #ifndef OPT_SPREAD_RANDOM_RECEIVERS
00591             NodeList_Iterator recipient_candidates_iterator_buff;
00592             CoordinatesNumber d = 0;
00593             uint8_t found = 0;
00594             #endif
00595             Node rep_point = ( *t ).get_repulsion_point();
00596             #ifdef ISENSE_PLTT_PASSIVE_DEBUG_SPREAD
00597             debug().debug( "PLTT_Passive %x: Spread Trace - Neighbor list of size %i \n", self.get_node().get_id(), neighbors.size() );
00598             #endif
00599             for ( PLTT_NodeListIterator neighbors_iterator = neighbors.begin(); neighbors_iterator != neighbors.end(); ++neighbors_iterator )
00600             {
00601                if ( rep_point.get_id() != 0 )
00602                {
00603                   if ( rep_point.get_position().distsq( self.get_node().get_position() ) <= rep_point.get_position().distsq( neighbors_iterator->get_node().get_position() ) )
00604                   {
00605                      recipient_candidates.push_back( neighbors_iterator->get_node() );
00606                   }
00607                }
00608             }
00609             #ifdef OPT_SPREAD_RANDOM_RECEIVERS
00610             if ( recipient_candidates.size() !=0 )
00611             {
00612                ( *t ).update_intensity_penalize();
00613                rand_t rand_elem = rand()() % recipient_candidates.size();
00614                node_id_t rand_id = recipient_candidates.at( rand_elem ).get_id();
00615                ( *t ).set_furthest_id( rand_id );
00616                recipient_candidates.erase( recipient_candidates.begin() + rand_elem );
00617                size_t len = ( *t ).get_buffer_size();
00618                block_data_t buf[Radio::MAX_MESSAGE_LENGTH];
00619                block_data_t* buff = buf;
00620                buff = ( *t ).set_buffer_from( buff );
00621                #ifdef PLTT_PASSIVE_SPREAD_METRICS
00622                passive_spread_metrics.inc_spread_messages_send_of_target( ( *t ).get_target_id() );
00623                passive_spread_metrics.inc_spread_messages_bytes_send_of_target( ( *t ).get_target_id(), ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00624                passive_spread_metrics_periodic.inc_spread_messages_send_of_target( ( *t ).get_target_id() );
00625                passive_spread_metrics_periodic.inc_spread_messages_bytes_send_of_target( ( *t ).get_target_id(), ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00626                #endif
00627                #ifdef PLTT_PASSIVE_SPREAD_METRICS_LIGHT
00628                ++spread_messages_send;
00629                spread_bytes_send = spread_bytes_send + ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00630                ++spread_messages_send_periodic;
00631                spread_bytes_send_periodic = spread_bytes_send_periodic + ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00632                #endif
00633                #ifdef ISENSE_PLTT_PASSIVE_DEBUG_SPREAD
00634                debug().debug( "PLTT_Passive %x: Spread Trace - To random1\n", self.get_node().get_id() );
00635                #endif
00636                send((*t).get_furthest_id(), len, (uint8_t*)buff, PLTT_SPREAD_ID );
00637             }
00638             #else
00639             for ( recipient_candidates_iterator = recipient_candidates.begin(); recipient_candidates_iterator != recipient_candidates.end(); ++recipient_candidates_iterator )
00640             {
00641                CoordinatesNumber cand_d = rep_point.get_position().distsq( recipient_candidates_iterator->get_position() );
00642                if (cand_d > d)
00643                {
00644                   d = cand_d;
00645                   recipient_candidates_iterator_buff = recipient_candidates_iterator;
00646                   found = 1;
00647                }
00648             }
00649             if ( found == 1 )
00650             {
00651                ( *t ).update_intensity_penalize();
00652                ( *t ).set_furthest_id( recipient_candidates_iterator_buff->get_id() );
00653                recipient_candidates.erase( recipient_candidates_iterator_buff );
00654                size_t len = ( *t ).get_buffer_size();
00655                block_data_t buf[Radio::MAX_MESSAGE_LENGTH];
00656                block_data_t* buff = buf;
00657                buff = ( *t ).set_buffer_from( buff );
00658                #ifdef PLTT_PASSIVE_SPREAD_METRICS
00659                passive_spread_metrics.inc_spread_messages_send_of_target( ( *t ).get_target_id() );
00660                passive_spread_metrics.inc_spread_messages_bytes_send_of_target( ( *t ).get_target_id(), ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00661                passive_spread_metrics_periodic.inc_spread_messages_send_of_target( ( *t ).get_target_id() );
00662                passive_spread_metrics_periodic.inc_spread_messages_bytes_send_of_target( ( *t ).get_target_id(), ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00663                #endif
00664                #ifdef PLTT_PASSIVE_SPREAD_METRICS_LIGHT
00665                ++spread_messages_send;
00666                spread_bytes_send = spread_bytes_send + ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00667                ++spread_messages_send_periodic;
00668                spread_bytes_send_periodic = spread_bytes_send_periodic + ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00669                #endif
00670                #ifdef ISENSE_PLTT_PASSIVE_DEBUG_SPREAD
00671                debug().debug( "PLTT_Passive %x: Spread Trace - To furthest \n", self.get_node().get_id() );
00672                #endif
00673                send( ( *t ).get_furthest_id(), len, ( uint8_t* )buff, PLTT_SPREAD_ID );
00674             }
00675             #endif
00676             if ( recipient_candidates.size() !=0 )
00677             {
00678                ( *t ).set_random_id( recipient_candidates.at( rand()()% recipient_candidates.size() ).get_id() );
00679                size_t len = ( *t ).get_buffer_size();
00680                block_data_t buf[Radio::MAX_MESSAGE_LENGTH];
00681                block_data_t* buff = buf;
00682                buff = ( *t ).set_buffer_from( buff );
00683                #ifdef PLTT_PASSIVE_SPREAD_METRICS
00684                passive_spread_metrics.inc_spread_messages_send_of_target( ( *t ).get_target_id() );
00685                passive_spread_metrics.inc_spread_messages_bytes_send_of_target( ( *t ).get_target_id(), ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00686                passive_spread_metrics_periodic.inc_spread_messages_send_of_target( ( *t ).get_target_id() );
00687                passive_spread_metrics_periodic.inc_spread_messages_bytes_send_of_target( ( *t ).get_target_id(), ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00688                #endif
00689                #ifdef PLTT_PASSIVE_SPREAD_METRICS_LIGHT
00690                ++spread_messages_send;
00691                spread_bytes_send = spread_bytes_send + ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00692                ++spread_messages_send_periodic;
00693                spread_bytes_send_periodic = spread_bytes_send_periodic + ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00694                #endif
00695                #ifdef ISENSE_PLTT_PASSIVE_DEBUG_SPREAD
00696                debug().debug( "PLTT_Passive %x: Spread Trace - To random2\n", self.get_node().get_id() );
00697                #endif
00698                send((*t).get_random_id(), len, (uint8_t*)buff, PLTT_SPREAD_ID );
00699             }
00700             ( *t ).set_inhibited();
00701          }
00702          else
00703          {
00704             #ifdef ISENSE_PLTT_PASSIVE_DEBUG_SPREAD
00705             debug().debug( "PLTT_Passive %x: Spread Trace - Exited due to inhibition\n", self.get_node().get_id() );
00706             #endif
00707             #ifdef PLTT_PASSIVE_SPREAD_METRICS
00708             passive_spread_metrics.inc_spread_messages_inhibited_of_target( ( *t ).get_target_id() );
00709             passive_spread_metrics.inc_spread_messages_bytes_inhibited_of_target( ( *t ).get_target_id(), ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00710             passive_spread_metrics_periodic.inc_spread_messages_inhibited_of_target( ( *t ).get_target_id() );
00711             passive_spread_metrics_periodic.inc_spread_messages_bytes_inhibited_of_target( ( *t ).get_target_id(), ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00712             #endif
00713             #ifdef PLTT_PASSIVE_SPREAD_METRICS_LIGHT
00714             ++spread_messages_inhibited;
00715             spread_bytes_inhibited = spread_bytes_inhibited + ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00716             ++spread_messages_inhibited_periodic;
00717             spread_bytes_inhibited_periodic = spread_bytes_inhibited_periodic + ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00718             #endif
00719          }
00720       }
00721       // -----------------------------------------------------------------------
00722       void send_inhibition( void* userdata = NULL )
00723       {
00724          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_SPREAD
00725          debug().debug( "PLTT_Passive %x: Entered Send Neighbor Inhibition Discovery Message\n", self.get_node().get_id() );
00726          #endif
00727          PLTT_Trace* t = (PLTT_Trace*)userdata;
00728          if ( ( *t ).get_inhibited() == 0 )
00729          {
00730             #ifdef OPT_TARGET_LIST_AGGREGATION
00731             self.set_node_target_list( traces );
00732             #else
00733             self.set_node_target( traces, ( *t ).get_target_id() );
00734             #endif
00735             size_t len = self.get_buffer_size();
00736             block_data_t buf[Radio::MAX_MESSAGE_LENGTH];
00737             block_data_t* buff = buf;
00738             self.set_buffer_from( buff );
00739             #ifdef PLTT_PASSIVE_SPREAD_METRICS
00740             passive_spread_metrics.inc_inhibition_messages_send_of_target( self.get_node_target_list()->begin()->get_target_id() );
00741             passive_spread_metrics.inc_inhibition_messages_bytes_send_of_target( self.get_node_target_list()->begin()->get_target_id(), self.get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00742             passive_spread_metrics_periodic.inc_inhibition_messages_send_of_target( self.get_node_target_list()->begin()->get_target_id() );
00743             passive_spread_metrics_periodic.inc_inhibition_messages_bytes_send_of_target( self.get_node_target_list()->begin()->get_target_id(), self.get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00744             #endif
00745             #ifdef PLTT_PASSIVE_SPREAD_METRICS_LIGHT
00746             ++inhibition_messages_send;
00747             inhibition_bytes_send = inhibition_bytes_send + self.get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00748             ++inhibition_messages_send_periodic;
00749             inhibition_bytes_send_periodic = inhibition_bytes_send_periodic + self.get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00750             #endif
00751             send( Radio::BROADCAST_ADDRESS, len, (uint8_t*)buff, PLTT_INHIBITION_MESSAGE_ID );
00752          }
00753          else
00754          {
00755             #ifdef ISENSE_PLTT_PASSIVE_DEBUG_SPREAD
00756             debug().debug( "PLTT_Passive %x: Exited Send Neighbor Inhibition Discovery due to inhibition\n", self.get_node().get_id() );
00757             #endif
00758             #ifdef PLTT_PASSIVE_SPREAD_METRICS
00759             passive_spread_metrics.inc_spread_messages_inhibited_of_target( ( *t ).get_target_id() );
00760             passive_spread_metrics.inc_spread_messages_bytes_inhibited_of_target( ( *t ).get_target_id(), ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00761             passive_spread_metrics_periodic.inc_spread_messages_inhibited_of_target( ( *t ).get_target_id() );
00762             passive_spread_metrics_periodic.inc_spread_messages_bytes_inhibited_of_target( ( *t ).get_target_id(), ( *t ).get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00763             passive_spread_metrics.inc_inhibition_messages_inhibited_of_target( ( *t ).get_target_id() );
00764             passive_spread_metrics.inc_inhibition_messages_bytes_inhibited_of_target( ( *t ).get_target_id(), self.get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00765             passive_spread_metrics_periodic.inc_inhibition_messages_inhibited_of_target( ( *t ).get_target_id() );
00766             passive_spread_metrics_periodic.inc_inhibition_messages_bytes_inhibited_of_target( ( *t ).get_target_id(), self.get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00767             #endif
00768             #ifdef PLTT_PASSIVE_SPREAD_METRICS_LIGHT
00769             ++spread_messages_inhibited;
00770             spread_bytes_inhibited = spread_bytes_inhibited + self.get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00771             ++spread_messages_inhibited_periodic;
00772             spread_bytes_inhibited_periodic = spread_bytes_inhibited_periodic + self.get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00773             ++inhibition_messages_inhibited;
00774             inhibition_bytes_inhibited = inhibition_bytes_inhibited + self.get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00775             ++inhibition_messages_inhibited_periodic;
00776             inhibition_bytes_inhibited_periodic = inhibition_bytes_inhibited_periodic + self.get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00777             #endif
00778          }
00779       }
00780       //------------------------------------------------------------------------
00781       PLTT_Node* update_neighbor( PLTT_Node n )
00782       {
00783          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_INHIBITION
00784          debug().debug( "PLTT_Passive %x: Update Neighbor\n", self.get_node().get_id() );
00785          #endif
00786          PLTT_NodeListIterator i = neighbors.begin();
00787          while ( i != neighbors.end() )
00788          {
00789             if ( i->get_node().get_id() == n.get_node().get_id() )
00790             {
00791                *i = n;
00792                return &( *i );
00793             }
00794             ++i;
00795          }
00796          neighbors.push_back( n );
00797          i = neighbors.end() - 1;
00798          return &( *i );
00799 
00800       }
00801 #ifndef ISENSE_APP
00802       // -----------------------------------------------------------------------
00803       PLTT_Agent* store_report_agent( PLTT_Agent _agent, message_id_t msg_id )
00804       {
00805          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY_REPORT
00806          debug().debug( "PLTT_Passive %x: Store report agent\n", self.get_node().get_id() );
00807          #endif
00808          PLTT_AgentListIterator i = report_agents.begin();
00809          while ( i != report_agents.end() )
00810          {
00811             if ( ( i->get_agent_id() == _agent.get_agent_id() ) && ( msg_id == PLTT_QUERY_REPORT_ID ) )
00812             {
00813                return NULL;
00814             }
00815             if ( i->get_tracker().get_id() == _agent.get_tracker().get_id() )
00816             {
00817                *i = _agent;
00818                return &( *i );
00819             }
00820             ++i;
00821          }
00822          report_agents.push_back( _agent );
00823          i = report_agents.end() - 1;
00824          return &( *i );
00825       }
00826       // -----------------------------------------------------------------------
00827       PLTT_Agent* store_query_agent( PLTT_Agent _agent, message_id_t msg_id )
00828       {
00829          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
00830          debug().debug( "PLTT_Passive %x: Store track query\n", self.get_node().get_id() );
00831          #endif
00832          PLTT_AgentListIterator i = query_agents.begin();
00833          while ( i != query_agents.end() )
00834          {
00835             if ( ( i->get_agent_id() == _agent.get_agent_id() ) && ( msg_id == PLTT_QUERY_ID) )
00836             {
00837                return NULL;
00838             }
00839             if ( i->get_tracker().get_id() == _agent.get_tracker().get_id() )
00840 
00841             {
00842                *i = _agent;
00843                return &( *i );
00844             }
00845             ++i;
00846          }
00847          query_agents.push_back( _agent );
00848          i = query_agents.end() - 1;
00849          return &( *i );
00850       }
00851 #endif
00852       // -----------------------------------------------------------------------
00853       void print_neighbors( void* userdata = NULL )
00854       {
00855          debug().debug( "PLTT_Passive %x: Begin neighbors printout\n", self.get_node().get_id() );
00856          self.print( debug() );
00857          for ( PLTT_NodeListIterator i = neighbors.begin(); i != neighbors.end(); ++i )
00858          {
00859             i->print( debug() );
00860          }
00861          debug().debug( "\nPLTT_Passive %x: End neighbors printout\n", self.get_node().get_id() );
00862          //timer().template set_timer<self_type, &self_type::print_neighbors>( 10000, this, 0);
00863       }
00864       // -----------------------------------------------------------------------
00865       void inhibit_traces( PLTT_Node* n, node_id_t nid)
00866       {
00867          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_INHIBITION
00868          debug().debug( "PLTT_Passive %x: Inhibit traces\n", self.get_node().get_id() );
00869          #endif
00870          if ( n != NULL )
00871          {
00872             for ( PLTT_TraceListIterator i = traces.begin(); i != traces.end(); ++i )
00873             {
00874                for (PLTT_NodeTargetListIterator j = n->get_node_target_list()->begin(); j != n->get_node_target_list()->end(); ++j )
00875                {
00876                   #ifdef ISENSE_PLTT_PASSIVE_DEBUG_INHIBITION
00877                   debug().debug(" PLTT_Passive %x: Inhbit traces - Has trace of %i intensity vs %i \n", self.get_node().get_id(), i->get_intensity(), j->get_intensity() );
00878                   #endif
00879                   if ( ( i->get_inhibited() == 0 ) &&
00880                       ( j->get_target_id() == i->get_target_id()  &&
00881                       ( j->get_intensity() >=  i->get_intensity() ) ) )
00882                   {
00883                      #ifdef ISENSE_PLTT_PASSIVE_DEBUG_INHIBITION
00884                      debug().debug(" PLTT_Passive %x: Inhibit traces - Has trace of %i inhibited\n", self.get_node().get_id(), i->get_target_id() );
00885                      #endif
00886                      i->set_inhibited();
00887                      #ifdef OPT_PATH_CORRECTION
00888                      i->update_intensity_penalize();
00889                      i->set_current( n->get_node() );
00890                      i->set_parent( n->get_node() );
00891                      i->set_grandparent( n->get_node() );
00892                      #endif
00893                   }
00894                }
00895             }
00896          }
00897          else
00898          {
00899             #ifdef ISENSE_PLTT_PASSIVE_DEBUG_INHIBITION
00900             debug().debug( "PLTT_Passive %x: Inhibit traces - Exited due to NULL\n", self.get_node().get_id() );
00901             #endif
00902          }
00903          //self.set_node_target_list( traces );
00904       }
00905       // -----------------------------------------------------------------------
00906       PLTT_Trace* find_trace( node_id_t nid )
00907       {
00908          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_MISC
00909          debug().debug( "PLTT_Passive %x: Find trace\n", self.get_node().get_id() );
00910          #endif
00911          for ( PLTT_TraceListIterator i = traces.begin(); i != traces.end(); ++i )
00912          {
00913             #ifdef ISENSE_PLTT_PASSIVE_DEBUG_MISC
00914             debug().debug( "PLTT_Passive %x: Find trace - trace of %x with [c : %x] [p: %x] [g %x]\n", self.get_node().get_id(), i->get_target_id(), i->get_current().get_id(), i->get_parent().get_id(), i->get_grandparent().get_id() );
00915             #endif
00916             if ( nid == i->get_target_id() )
00917             {
00918                return &( *i );
00919             }
00920          }
00921          return NULL;
00922       }
00923       // -----------------------------------------------------------------------
00924       void process_query( void* userdata = NULL)
00925       {
00926          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
00927          debug().debug( "PLTT_Passive %x: Process query\n", self.get_node().get_id() );
00928          #endif
00929          if ( userdata == NULL )
00930          {
00931             return;
00932          }
00933          PLTT_Agent* agent = ( PLTT_Agent* ) userdata;
00934          block_data_t buf[Radio::MAX_MESSAGE_LENGTH];
00935          block_data_t* buff = buf;
00936          PLTT_Trace* trace_of_target = find_trace( agent->get_target().get_id() );
00937          if ( trace_of_target != NULL )
00938          {
00939             #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
00940             debug().debug( "PLTT_Passive %x: Process query - Trace of target %x found with intensity %i vs max_intensity %i !\n", self.get_node().get_id(), agent->get_target().get_id(), trace_of_target->get_intensity(), agent->get_max_intensity() );
00941             #endif
00942             //if ( ( agent->get_max_intensity() - trace_of_target->get_intensity() ) <= trace_of_target->get_spread_penalty() )
00943             if ( ( trace_of_target->get_intensity() * 100 ) / agent->get_max_intensity() >= intensity_detection_threshold )
00944             {
00945                #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
00946                debug().debug( "PLTT_Passive %x: Process query - The target is in the area with intensity %i report back!\n", self.get_node().get_id(), trace_of_target->get_intensity() );
00947                #endif
00948                #ifdef PLTT_AGENT_TRACKING_METRICS
00949                agent->set_aprox_detection( clock().time() );
00950                #endif
00951                agent->set_target( Node( agent->get_target().get_id(), self.get_node().get_position() ) );
00952                agent->set_buffer_from( buff );
00953                PLTT_Trace* trace_of_tracker = find_trace( agent->get_tracker().get_id() );
00954                if ( trace_of_tracker != NULL )
00955                {
00956                   #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
00957                   debug().debug( "PLTT_Passive %x: Process query - Trace of tracker %x found with intensity %i vs max_intensity %i\n", self.get_node().get_id(), agent->get_tracker().get_id(), trace_of_tracker->get_intensity(), agent->get_max_intensity() );
00958                   #endif
00959                   if ( ( ( agent->get_max_intensity() - trace_of_tracker->get_intensity() ) <= trace_of_tracker->get_spread_penalty() ) && ( trace_of_tracker->get_parent().get_id() == self.get_node().get_id() ) )
00960                   {
00961                      #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
00962                      debug().debug( "PLTT_Passive %x: Process query - The tracker is in the area with intensity %i report back to him!\n", self.get_node().get_id(), trace_of_tracker->get_intensity() );
00963                      #endif
00964                      #ifdef PLTT_PASSIVE_TRACKING_METRICS
00965                      passive_tracking_metrics.inc_report_messages_send_of_tracker( agent->get_tracker().get_id() );
00966                      passive_tracking_metrics.inc_report_messages_bytes_send_of_tracker( agent->get_tracker().get_id(), agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00967                      passive_tracking_metrics_periodic.inc_report_messages_send_of_tracker( agent->get_tracker().get_id() );
00968                      passive_tracking_metrics_periodic.inc_report_messages_bytes_send_of_tracker( agent->get_tracker().get_id(), agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00969                      #endif
00970                      #ifdef PLTT_PASSIVE_TRACKING_METRICS_LIGHT
00971                      ++report_messages_send;
00972                      report_bytes_send = report_bytes_send + agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00973                      ++report_messages_send_periodic;
00974                      report_bytes_send_periodic = report_bytes_send_periodic + agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00975                      #endif
00976                      #ifdef OPT_RELIABLE_TRACKING
00977                      store_reliable_agent( *agent, PLTT_QUERY_REPORT_ACK_ID, agent->get_tracker().get_id() );
00978                      agent->update_reliable_agent_id();
00979                      agent->set_buffer_from( buff );
00980                      #endif
00981                      send( agent->get_tracker().get_id(), agent->get_buffer_size(), buff, PLTT_QUERY_REPORT_ID );
00982                      return;
00983                   }
00984 
00985                   #ifdef PLTT_PASSIVE_TRACKING_METRICS
00986                   passive_tracking_metrics.inc_report_messages_send_of_tracker( agent->get_tracker().get_id() );
00987                   passive_tracking_metrics.inc_report_messages_bytes_send_of_tracker( agent->get_tracker().get_id(), agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00988                   passive_tracking_metrics_periodic.inc_report_messages_send_of_tracker( agent->get_tracker().get_id() );
00989                   passive_tracking_metrics_periodic.inc_report_messages_bytes_send_of_tracker( agent->get_tracker().get_id(), agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
00990                   #endif
00991                   #ifdef PLTT_PASSIVE_TRACKING_METRICS_LIGHT
00992                   ++report_messages_send;
00993                   report_bytes_send = report_bytes_send + agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00994                   ++report_messages_send_periodic;
00995                   report_bytes_send_periodic = report_bytes_send_periodic + agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
00996                   #endif
00997                   node_id_t tracker_id = trace_of_tracker->get_parent().get_id();
00998                   if ( tracker_id != 0x0 )
00999                   {
01000                      #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
01001                      debug().debug( "PLTT_Passive %x: Process query - Looking for the tracker following his gradient to recipient %x\n", self.get_node().get_id(), tracker_id );
01002                      #endif
01003                   }
01004                   else
01005                   {
01006                      tracker_id = neighbors.at( rand()() % neighbors.size() ).get_node().get_id();
01007                      #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
01008                      debug().debug( "PLTT_Passive %x: Process query - Looking for the tracker following a non coherent gradient to the unknown  %x\n", self.get_node().get_id(), tracker_id );
01009                      #endif
01010                   }
01011 
01012                   #ifdef OPT_RELIABLE_TRACKING
01013                   store_reliable_agent( *agent, PLTT_QUERY_REPORT_ACK_ID, tracker_id );
01014                   agent->update_reliable_agent_id();
01015                   agent->set_buffer_from( buff );
01016                   #endif
01017                   send( tracker_id, agent->get_buffer_size(), buff, PLTT_QUERY_REPORT_ID );
01018                   return;
01019                }
01020                if ( neighbors.size() != 0 )
01021                {
01022                   node_id_t nn = neighbors.at( rand()() % neighbors.size() ).get_node().get_id();
01023                   #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
01024                   debug().debug( "PLTT_Passive %x: Process query - Looking for the tracker to the unknown %x\n", self.get_node().get_id(), nn );
01025                   #endif
01026                   #ifdef PLTT_PASSIVE_TRACKING_METRICS
01027                   passive_tracking_metrics.inc_report_messages_send_of_tracker( agent->get_tracker().get_id() );
01028                   passive_tracking_metrics.inc_report_messages_bytes_send_of_tracker( agent->get_tracker().get_id(), agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
01029                   passive_tracking_metrics_periodic.inc_report_messages_send_of_tracker( agent->get_tracker().get_id() );
01030                   passive_tracking_metrics_periodic.inc_report_messages_bytes_send_of_tracker( agent->get_tracker().get_id(), agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
01031                   #endif
01032                   #ifdef PLTT_PASSIVE_TRACKING_METRICS_LIGHT
01033                   ++report_messages_send;
01034                   report_bytes_send = report_bytes_send + agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
01035                   ++report_messages_send_periodic;
01036                   report_bytes_send_periodic = report_bytes_send_periodic + agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
01037                   #endif
01038                   #ifdef OPT_RELIABLE_TRACKING
01039                   store_reliable_agent( *agent, PLTT_QUERY_REPORT_ACK_ID, nn );
01040                   agent->update_reliable_agent_id();
01041                   #endif
01042                   send( nn, agent->get_buffer_size(), buff, PLTT_QUERY_REPORT_ID );
01043                   agent->set_buffer_from( buff );
01044                   return;
01045                }
01046                else
01047                {
01048                   #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
01049                   debug().debug( "PLTT_Passive %x: Process query - No neighbors node while looking for tracker %x\n", self.get_node().get_id() );
01050                   #endif
01051                   return;
01052                }
01053             }
01054             else
01055             {
01056                #ifdef PLTT_PASSIVE_TRACKING_METRICS
01057                passive_tracking_metrics.inc_query_messages_send_of_tracker( agent->get_tracker().get_id() );
01058                passive_tracking_metrics.inc_query_messages_bytes_send_of_tracker( agent->get_tracker().get_id(), agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
01059                passive_tracking_metrics_periodic.inc_query_messages_send_of_tracker( agent->get_tracker().get_id() );
01060                passive_tracking_metrics_periodic.inc_query_messages_bytes_send_of_tracker( agent->get_tracker().get_id(), agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
01061                #endif
01062                #ifdef PLTT_PASSIVE_TRACKING_METRICS_LIGHT
01063                ++query_messages_send;
01064                query_bytes_send = query_bytes_send + agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
01065                ++query_messages_send_periodic;
01066                query_bytes_send_periodic = query_bytes_send_periodic + agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
01067                #endif
01068                node_id_t target_id = trace_of_target->get_parent().get_id();
01069                if ( target_id != 0 )
01070                {
01071                   #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
01072                   debug().debug( "PLTT_Passive %x: Process query - Looking for the target following his gradient to recipient %x\n", self.get_node().get_id(), target_id );
01073                   #endif
01074                }
01075                else
01076                {
01077                   target_id = neighbors.at( rand()() % neighbors.size() ).get_node().get_id();
01078                   #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
01079                   debug().debug( "PLTT_Passive %x: Process query - Looking for the target following a non coheret gradient to the unknown %x\n", self.get_node().get_id(), target_id );
01080                   #endif
01081                }
01082                #ifdef OPT_RELIABLE_TRACKING
01083                store_reliable_agent( *agent, PLTT_QUERY_ACK_ID, target_id );
01084                agent->update_reliable_agent_id();
01085                agent->set_buffer_from( buff );
01086                #endif
01087                send( target_id, agent->get_buffer_size(), buff, PLTT_QUERY_ID );
01088                return;
01089             }
01090          }
01091          else
01092          {
01093             if ( neighbors.size() != 0 )
01094             {
01095                node_id_t nn = neighbors.at( rand()() % neighbors.size() ).get_node().get_id();
01096                #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
01097                debug().debug( "PLTT_Passive %x: Process query - Looking for the target to the unknown %x with neighlist size: %i\n", self.get_node().get_id(), nn, neighbors.size() );
01098                #endif
01099                #ifdef PLTT_PASSIVE_TRACKING_METRICS
01100                passive_tracking_metrics.inc_query_messages_send_of_tracker( agent->get_tracker().get_id() );
01101                passive_tracking_metrics.inc_query_messages_bytes_send_of_tracker( agent->get_tracker().get_id(), agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
01102                passive_tracking_metrics_periodic.inc_query_messages_send_of_tracker( agent->get_tracker().get_id() );
01103                passive_tracking_metrics_periodic.inc_query_messages_bytes_send_of_tracker( agent->get_tracker().get_id(), agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
01104                #endif
01105                #ifdef PLTT_PASSIVE_TRACKING_METRICS_LIGHT
01106                ++query_messages_send;
01107                query_bytes_send = query_bytes_send + agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
01108                ++query_messages_send_periodic;
01109                query_bytes_send_periodic = query_bytes_send_periodic + agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
01110                #endif
01111 
01112                #ifdef OPT_RELIABLE_TRACKING
01113                store_reliable_agent( *agent, PLTT_QUERY_ACK_ID, nn );
01114                agent->update_reliable_agent_id();
01115                agent->set_buffer_from( buff );
01116                #endif
01117                send( nn, agent->get_buffer_size(), buff, PLTT_QUERY_ID );
01118             }
01119             else
01120             {
01121                #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
01122                debug().debug( "PLTT_Passive %x: Process query - No neighbors node while looking for target\n", self.get_node().get_id() );
01123                #endif
01124             }
01125          }
01126       }
01127       // -----------------------------------------------------------------------
01128       void process_query_report( void* userdata = NULL )
01129       {
01130          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY_REPORT
01131          debug().debug( "PLTT_Passive %x: Process query report\n", self.get_node().get_id() );
01132          #endif
01133          if ( userdata == NULL )
01134          {
01135             return;
01136          }
01137          PLTT_Agent* agent = ( PLTT_Agent* ) userdata;
01138          //agent->print( debug(), clock() );
01139          block_data_t buf[Radio::MAX_MESSAGE_LENGTH];
01140          block_data_t* buff = buf;
01141          agent->set_buffer_from( buff );
01142          PLTT_Trace* trace_of_tracker = find_trace( agent->get_tracker().get_id() );
01143          if ( trace_of_tracker != NULL )
01144          {
01145             #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY_REPORT
01146             debug().debug( "PLTT_Passive %x: Process query report - Trace of tracker %x found with intensity %i vs max_intensity %i\n", self.get_node().get_id(), agent->get_tracker().get_id(), trace_of_tracker->get_intensity(), agent->get_max_intensity() );
01147             #endif
01148             //if ( ( agent->get_max_intensity() - trace_of_tracker->get_intensity() ) <= trace_of_tracker->get_spread_penalty() )
01149             if ( ( trace_of_tracker->get_intensity() * 100 ) / agent->get_max_intensity() >= intensity_detection_threshold )
01150             {
01151                #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
01152                debug().debug( "PLTT_Passive %x: Process query report - The tracker is in the area with intensity %i report back to him!\n", self.get_node().get_id(), trace_of_tracker->get_intensity() );
01153                #endif
01154                #ifdef PLTT_PASSIVE_TRACKING_METRICS
01155                passive_tracking_metrics.inc_report_messages_send_of_tracker( agent->get_tracker().get_id() );
01156                passive_tracking_metrics.inc_report_messages_bytes_send_of_tracker( agent->get_tracker().get_id(), agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
01157                passive_tracking_metrics_periodic.inc_report_messages_send_of_tracker( agent->get_tracker().get_id() );
01158                passive_tracking_metrics_periodic.inc_report_messages_bytes_send_of_tracker( agent->get_tracker().get_id(), agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
01159                #endif
01160                #ifdef PLTT_PASSIVE_TRACKING_METRICS_LIGHT
01161                ++report_messages_send;
01162                report_bytes_send = report_bytes_send + agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
01163                ++report_messages_send_periodic;
01164                report_bytes_send_periodic = report_bytes_send_periodic + agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
01165                #endif
01166                #ifdef OPT_RELIABLE_TRACKING
01167                store_reliable_agent( *agent, PLTT_QUERY_REPORT_ACK_ID, agent->get_tracker().get_id() );
01168                agent->update_reliable_agent_id();
01169                agent->set_buffer_from( buff );
01170                #endif
01171                send( agent->get_tracker().get_id(), agent->get_buffer_size(), buff, PLTT_QUERY_REPORT_ID );
01172                return;
01173             }
01174             node_id_t tracker_id = trace_of_tracker->get_parent().get_id();
01175             if ( tracker_id != 0 )
01176             {
01177                #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
01178                debug().debug( "PLTT_Passive %x: Process query - Looking for the tracker following his gradient to recipient %x\n", self.get_node().get_id(), tracker_id );
01179                #endif
01180             }
01181             else
01182             {
01183                tracker_id = neighbors.at( rand()() % neighbors.size() ).get_node().get_id();
01184                #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY
01185                debug().debug( "PLTT_Passive %x: Process query - Looking for the tracker following a non coherent gradient to the unknown  %x\n", self.get_node().get_id(), tracker_id );
01186                #endif
01187             }
01188             #ifdef OPT_RELIABLE_TRACKING
01189             store_reliable_agent( *agent, PLTT_QUERY_REPORT_ACK_ID, tracker_id );
01190             agent->update_reliable_agent_id();
01191             agent->set_buffer_from( buff );
01192             #endif
01193             send( tracker_id, agent->get_buffer_size(), buff, PLTT_QUERY_REPORT_ID );
01194             return;
01195          }
01196          if ( neighbors.size() != 0 )
01197          {
01198             node_id_t nn = neighbors.at( rand()() % neighbors.size() ).get_node().get_id();
01199             #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY_REPORT
01200             debug().debug( "PLTT_Passive %x: Process query report - Looking for the tracker to the unknown %x with neighlist size: %i\n", self.get_node().get_id(), nn, neighbors.size() );
01201             #endif
01202             #ifdef PLTT_PASSIVE_TRACKING_METRICS
01203             passive_tracking_metrics.inc_report_messages_send_of_tracker( agent->get_tracker().get_id() );
01204             passive_tracking_metrics.inc_report_messages_bytes_send_of_tracker( agent->get_tracker().get_id(), agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
01205             passive_tracking_metrics_periodic.inc_report_messages_send_of_tracker( agent->get_tracker().get_id() );
01206             passive_tracking_metrics_periodic.inc_report_messages_bytes_send_of_tracker( agent->get_tracker().get_id(), agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t ) );
01207             #endif
01208             #ifdef PLTT_PASSIVE_TRACKING_METRICS_LIGHT
01209             ++report_messages_send;
01210             report_bytes_send = report_bytes_send + agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
01211             ++report_messages_send_periodic;
01212             report_bytes_send_periodic = report_bytes_send_periodic + agent->get_buffer_size() + sizeof( message_id_t ) + sizeof( size_t );
01213             #endif
01214             #ifdef OPT_RELIABLE_TRACKING
01215             store_reliable_agent( *agent, PLTT_QUERY_REPORT_ACK_ID, nn );
01216             agent->update_reliable_agent_id();
01217             agent->set_buffer_from( buff );
01218             #endif
01219             send( nn, agent->get_buffer_size(), buff, PLTT_QUERY_REPORT_ID );
01220          }
01221          else
01222          {
01223             #ifdef ISENSE_PLTT_PASSIVE_DEBUG_TRACK_QUERY_REPORT
01224             debug().debug( "PLTT_Passive %x: Process query report - No neighbors node while looking for tracker\n", self.get_node().get_id() );
01225             #endif
01226          }
01227       }
01228       // -----------------------------------------------------------------------
01229       void sync_neighbors( uint8_t event, node_id_t from, uint8_t len, uint8_t* data )
01230       {
01231          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_NEIGHBORHOOD_DISCOVERY
01232          debug().debug( "PLTT_Passive %x: Sync neighbors\n", self.get_node().get_id() );
01233          #endif
01234          if ( event == NeighborDiscovery::DROPPED_NB )
01235          {
01236             PLTT_NodeListIterator i = neighbors.begin();
01237             while ( i != neighbors.end() )
01238             {
01239                if ( i->get_node().get_id() == from )
01240                {
01241                   neighbors.erase( i );
01242                   return;
01243                }
01244                ++i;
01245             }
01246          }
01247          else if ( event == NeighborDiscovery::NEW_PAYLOAD_BIDI )
01248          {
01249 
01250             PLTT_NodeListIterator i = neighbors.begin();
01251             while ( i != neighbors.end() )
01252             {
01253                if ( i->get_node().get_id() == from )
01254                {
01255                   Position p;
01256                   p.get_from_buffer( data );
01257                   i->get_node().set_position( p );
01258                   return;
01259                }
01260                ++i;
01261             }
01262             Position p;
01263             p.get_from_buffer( data );
01264             Node n = Node( from , p );
01265             neighbors.push_back( PLTT_Node( n ) );
01266          }
01267          //filter_neighbors();
01268       }
01269       void filter_neighbors( void* userdata = NULL )
01270       {
01271          PLTT_NodeList tobefiltered;
01272          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_NEIGHBORHOOD_DISCOVERY
01273          debug().debug( "PLTT_Passive %x: Filter neighbors - size of neighbors vector = %i \n", self.get_node().get_id(), neighbors.size() );
01274          #endif
01275          for ( PLTT_NodeListIterator i = neighbors.begin(); i != neighbors.end(); ++i )
01276          {
01277             #ifdef ISENSE_PLTT_PASSIVE_DEBUG_NEIGHBORHOOD_DISCOVERY
01278             debug().debug( "PLTT_Passive %x: Filter neighbors - Inside loop size %x has %i stab \n", self.get_node().get_id(), i->get_node().get_id(), neighbor_discovery().get_nb_stability( i->get_node().get_id() ) );
01279             #endif
01280             if  ( neighbor_discovery().get_nb_stability( i->get_node().get_id() ) >= 50 )
01281             {
01282                tobefiltered.push_back( *i );
01283             }
01284          }
01285          #ifdef ISENSE_PLTT_PASSIVE_DEBUG_NEIGHBORHOOD_DISCOVERY
01286          debug().debug( "PLTT_Passive %x: Sync neighbors - size of filter vector = %i \n", self.get_node().get_id(), tobefiltered.size() );
01287          #endif
01288          for ( PLTT_NodeListIterator z = tobefiltered.begin(); z != tobefiltered.end(); ++z )
01289          {
01290             for (PLTT_NodeListIterator j = neighbors.begin(); j != neighbors.end(); ++j )
01291             {
01292                if ( j->get_node().get_id() == z->get_node().get_id() )
01293                {
01294                   neighbors.erase( j );
01295                   break;
01296                }
01297             }
01298          }
01299       }
01300       // -----------------------------------------------------------------------
01301 #ifdef OPT_RELIABLE_TRACKING
01302       // -----------------------------------------------------------------------
01303       void store_reliable_agent( PLTT_Agent agent, uint8_t msg_id, node_id_t receiver)
01304       {
01305          #ifdef ISENSE_PLTT_PASSIVE_RELIABLE_TRACKING_DEBUG
01306          debug().debug( "PLTT_Passive %x: Store reliable agent from %x and with messageid %i and agentid %x \n", self.get_node().get_id(), receiver, msg_id, agent.get_agent_id() );
01307          #endif
01308          PLTT_ReliableAgent ra( agent, receiver, reliable_agent_exp_time, reliable_agent_rec_time, msg_id );
01309 //       PLTT_ReliableAgentListIterator i = reliable_agents.begin();
01310 //       while ( i != reliable_agents.end() )
01311 //       {
01312 //          if ( /*( i->get_message_id() == ra.get_message_id() ) &&*/
01313 //              ( i->get_agent().get_reliable_agent_id() == ra.get_agent().get_reliable_agent_id() ) &&
01314 //              ( i->get_receiver() == ra.get_receiver() ) &&
01315 //              (i->get_agent().get_agent_id() == ra.get_agent().get_agent_id() ) )
01316 //          {
01317 //             return;
01318 //          }
01319 //          ++i;
01320 //       }
01321          reliable_agents.push_back( ra );
01322       }
01323       // -----------------------------------------------------------------------
01324       uint8_t find_reliable_agent( PLTT_Agent agent, uint8_t msg_id , node_id_t receiver )
01325       {
01326          #ifdef ISENSE_PLTT_PASSIVE_RELIABLE_TRACKING_DEBUG
01327          debug().debug( "PLTT_Passive %x: Find reliable agent from %x and with messageid %i and agentid %x \n", self.get_node().get_id(), receiver, msg_id, agent.get_agent_id() );
01328          #endif
01329          PLTT_ReliableAgent ra( agent, receiver, reliable_agent_exp_time, reliable_agent_rec_time, msg_id );
01330          PLTT_ReliableAgentListIterator i = reliable_agents.begin();
01331          while ( i != reliable_agents.end() )
01332          {
01333             if ( /*( i->get_message_id() == ra.get_message_id() ) &&*/
01334                 ( i->get_agent().get_reliable_agent_id() == ra.get_agent().get_reliable_agent_id() ) &&
01335                 ( i->get_receiver() == ra.get_receiver() ) &&
01336                 (i->get_agent().get_agent_id() == ra.get_agent().get_agent_id() ) )
01337             {
01338                return 1;
01339             }
01340             ++i;
01341          }
01342          return 0;
01343       }
01344       // -----------------------------------------------------------------------
01345       void remove_reliable_agent( PLTT_Agent agent, uint8_t msg_id , node_id_t receiver )
01346       {
01347          #ifdef ISENSE_PLTT_PASSIVE_RELIABLE_TRACKING_DEBUG
01348          debug().debug( "PLTT_Passive %x: remove reliable agent from %x and with messageid %i and agentid %x \n", self.get_node().get_id(), receiver, msg_id, agent.get_agent_id() );
01349          #endif
01350          PLTT_ReliableAgent ra( agent, receiver, reliable_agent_exp_time, reliable_agent_rec_time, msg_id );
01351          PLTT_ReliableAgentListIterator i = reliable_agents.begin();
01352          while ( i != reliable_agents.end() )
01353          {
01354             if ( /*( i->get_message_id() == ra.get_message_id() ) &&*/
01355                 ( i->get_agent().get_reliable_agent_id() == ra.get_agent().get_reliable_agent_id() - 1 ) &&
01356                 ( i->get_receiver() == ra.get_receiver() ) &&
01357                 (i->get_agent().get_agent_id() == ra.get_agent().get_agent_id() ) )
01358             {
01359                reliable_agents.erase( i );
01360                return;
01361             }
01362             ++i;
01363          }
01364       }
01365       // -----------------------------------------------------------------------
01366       void reliable_agent_daemon( void* userdata = NULL )
01367       {
01368          cleanup_timer  = cleanup_timer + reliable_millis_timer;
01369          if ( cleanup_timer > 300000 )
01370          {
01371             reliable_agents.clear();
01372             cleanup_timer = 0;
01373             //cleanup_reliable_agents.clear();
01374          }
01375          for ( PLTT_ReliableAgentListIterator i = reliable_agents.begin(); i != reliable_agents.end(); ++i )
01376          {
01377             #ifdef ISENSE_PLTT_PASSIVE_RELIABLE_TRACKING_DEBUG
01378             //debug().debug("PLTT_Passive %x: Reliable Agent Daemon : Agent %x - exp_timer=%i, rec_timer=%i \n", self.get_node().get_id(), i->get_agent().get_agent_id(), i->get_exp_time(), i->get_rec_time() );
01379             #endif
01380             if (i->get_exp_time() != 0 )
01381             {
01382                i->set_rec_time( i->get_rec_time() - reliable_millis_timer );
01383                i->set_exp_time( i->get_exp_time() - reliable_millis_timer );
01384                #ifdef ISENSE_PLTT_PASSIVE_RELIABLE_TRACKING_DEBUG
01385                //debug().debug("PLTT_Passive %x: Reliable Agent Daemon : Agent %x - exp_timer=%i, rec_timer=%i \n", self.get_node().get_id(), i->get_agent().get_agent_id(), i->get_exp_time(), i->get_rec_time() );
01386                #endif
01387                if ( i->get_exp_time() == 0 )
01388                {
01389                   #ifdef ISENSE_PLTT_PASSIVE_RELIABLE_TRACKING_DEBUG
01390                   //debug().debug( "PLTT_Passive %x: Reliable Agent Daemon : Agent %x expired - preping remove \n", self.get_node().get_id(), i->get_agent().get_agent_id() );
01391                   #endif
01392                   //cleanup_reliable_agents.push_back( *i );
01393                }
01394                if ( i->get_rec_time() == 0 )
01395                {
01396 
01397                   i->set_rec_time( reliable_agent_rec_time );
01398                   block_data_t buf[Radio::MAX_MESSAGE_LENGTH];
01399                   block_data_t* buff = buf;
01400                   i->get_agent().set_buffer_from( buff );
01401                   if ( i->get_message_id() == PLTT_QUERY_ACK_ID )
01402                   {
01403                      #ifdef ISENSE_PLTT_PASSIVE_RELIABLE_TRACKING_DEBUG
01404                      debug().debug( "PLTT_Passive %x: Reliable Agent Daemon : Agent %i resend QUERY! \n", self.get_node().get_id(), i->get_agent().get_agent_id() );
01405                      #endif
01406                      send( i->get_receiver(), i->get_agent().get_buffer_size(), buff, PLTT_QUERY_ID );
01407                   }
01408                   else
01409                   {
01410                      #ifdef ISENSE_PLTT_PASSIVE_RELIABLE_TRACKING_DEBUG
01411                      debug().debug( "PLTT_Passive %x: Reliable Agent Daemon : Agent %i resend REPORT REPORT! \n", self.get_node().get_id(), i->get_agent().get_agent_id() );
01412                      #endif
01413                      send( i->get_receiver(), i->get_agent().get_buffer_size(), buff, PLTT_QUERY_REPORT_ID );
01414                   }
01415                }
01416             }
01417          }
01418          #ifdef ISENSE_PLTT_PASSIVE_RELIABLE_TRACKING_DEBUG
01419          //debug().debug( "PLTT_Passive %x: Reliable Agent Daemon : B4 looped cleanup - Cleanup list sizeof %i and Reliable agent list sizeof %i \n", self.get_node().get_id(), cleanup_reliable_agents.size(), reliable_agents.size() );
01420          #endif
01421 //       for ( PLTT_ReliableAgentListIterator i = cleanup_reliable_agents.begin(); i != cleanup_reliable_agents.end(); ++i )
01422 //       {
01423 //          PLTT_ReliableAgentListIterator j = reliable_agents.begin();
01424 //          while  ( j != reliable_agents.end()  )
01425 //          {
01426 //             if ( ( j->get_receiver() == i->get_receiver() ) &&
01427 //                 //( j->get_message_id() == i->get_message_id() ) &&
01428 //                 ( j->get_agent().get_agent_id() == i->get_agent().get_agent_id() ) &&
01429 //                 ( j->get_agent().get_reliable_agent_id() == i->get_agent().get_reliable_agent_id() ) )
01430 //             {
01431 //                #ifdef ISENSE_PLTT_PASSIVE_RELIABLE_TRACKING_DEBUG
01432 //                debug().debug( "PLTT_Passive %x: Reliable Agent Daemon : Removing and breaking! \n", self.get_node().get_id(), i->get_agent().get_agent_id() );
01433 //                #endif
01434 //                reliable_agents.erase( j );
01435 //                j = reliable_agents.end();
01436 //             }
01437 //             if ( j != reliable_agents.end() ){ ++j; }
01438 //          }
01439 //       }
01440          #ifdef ISENSE_PLTT_PASSIVE_RELIABLE_TRACKING_DEBUG
01441          //debug().debug( "PLTT_Passive %x: Reliable Agent Daemon : AFTER looped cleanup - Cleanup list sizeof %i and Reliable agent list sizeof %i \n", self.get_node().get_id(), cleanup_reliable_agents.size(), reliable_agents.size() );
01442          #endif
01443          //cleanup_reliable_agents.clear();
01444          timer().template set_timer<self_type, &self_type::reliable_agent_daemon>( reliable_millis_timer, this, 0 );
01445       }
01446       // -----------------------------------------------------------------------
01447 #endif
01448       void init( Radio& radio, Timer& timer, Debug& debug, Rand& rand, Clock& clock, NeighborDiscovery& neighbor_discovery )
01449       {
01450          radio_ = &radio;
01451          timer_ = &timer;
01452          debug_ = &debug;
01453          rand_ = &rand;
01454          clock_ = &clock;
01455          neighbor_discovery_ = &neighbor_discovery;
01456       }
01457       // -----------------------------------------------------------------------
01458       void print_metrics( void* userdata = NULL )
01459       {
01460          uint32_t secs = clock().seconds( clock().time() );
01461          secs = secs;
01462 #ifdef PLTT_PASSIVE_SPREAD_METRICS
01463 
01464          for ( PLTT_PassiveSpreadMetricListIterator i = passive_spread_metrics.get_passive_spread_metric_list()->begin(); i != passive_spread_metrics.get_passive_spread_metric_list()->end(); ++i )
01465          {
01466             #ifndef OPT_TARGET_LIST_AGGREGATION
01467             debug().debug(" SMTN\t%x\t%i\t%x\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i ", self.get_node().get_id(), secs, i->get_target_id(), i->get_spread_messages_send(), i->get_spread_messages_bytes_send(), i->get_spread_messages_received(), i->get_spread_messages_bytes_received(), i->get_spread_messages_inhibited(), i->get_spread_messages_bytes_inhibited(), i->get_inhibition_messages_send(), i->get_inhibition_messages_bytes_send(), i->get_inhibition_messages_received(), i->get_inhibition_messages_bytes_received(), i->get_inhibition_messages_inhibited(), i->get_inhibition_messages_bytes_inhibited() );
01468             #else
01469             debug().debug(" SMTN\t%x\t%i\t%x\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i ", self.get_node().get_id(), secs, i->get_target_id(), i->get_spread_messages_send(), i->get_spread_messages_bytes_send(), i->get_spread_messages_received(), i->get_spread_messages_bytes_received(), i->get_spread_messages_inhibited(), i->get_spread_messages_bytes_inhibited(), i->get_inhibition_messages_send(), i->get_inhibition_messages_bytes_send(), i->get_inhibition_messages_inhibited(), i->get_inhibition_messages_bytes_inhibited() );
01470             #endif
01471          }
01472          debug().debug(" SMRN\t%x\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i ",
01473                   self.get_node().get_id(),
01474                   secs,
01475                   passive_spread_metrics.get_spread_messages_send(), passive_spread_metrics.get_spread_messages_bytes_send(),
01476                   passive_spread_metrics.get_inhibition_messages_send(), passive_spread_metrics.get_inhibition_messages_bytes_send(),
01477                   passive_spread_metrics.get_spread_messages_received(), passive_spread_metrics.get_spread_messages_bytes_received(),
01478                   passive_spread_metrics.get_inhibition_messages_received(), passive_spread_metrics.get_inhibition_messages_bytes_received(),
01479                   passive_spread_metrics.get_spread_messages_inhibited(), passive_spread_metrics.get_spread_messages_bytes_inhibited(),
01480                   passive_spread_metrics.get_inhibition_messages_inhibited(), passive_spread_metrics.get_inhibition_messages_bytes_inhibited(),
01481                   messages_received, messages_bytes_received );
01482          for ( PLTT_PassiveSpreadMetricListIterator i = passive_spread_metrics_periodic.get_passive_spread_metric_list()->begin(); i != passive_spread_metrics_periodic.get_passive_spread_metric_list()->end(); ++i )
01483          {
01484             #ifndef OPT_TARGET_LIST_AGGREGATION
01485             debug().debug(" SMTP\t%x\t%i\t%x\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i ", self.get_node().get_id(), secs, i->get_target_id(), i->get_spread_messages_send(), i->get_spread_messages_bytes_send(), i->get_spread_messages_received(), i->get_spread_messages_bytes_received(), i->get_spread_messages_inhibited(), i->get_spread_messages_bytes_inhibited(), i->get_inhibition_messages_send(), i->get_inhibition_messages_bytes_send(), i->get_inhibition_messages_received(), i->get_inhibition_messages_bytes_received(), i->get_inhibition_messages_inhibited(), i->get_inhibition_messages_bytes_inhibited() );
01486             #else
01487             debug().debug(" SMTP\t%x\t%i\t%x\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i ", self.get_node().get_id(), secs, i->get_target_id(), i->get_spread_messages_send(), i->get_spread_messages_bytes_send(), i->get_spread_messages_received(), i->get_spread_messages_bytes_received(), i->get_spread_messages_inhibited(), i->get_spread_messages_bytes_inhibited(), i->get_inhibition_messages_send(), i->get_inhibition_messages_bytes_send(), i->get_inhibition_messages_inhibited(), i->get_inhibition_messages_bytes_inhibited() );
01488             #endif
01489          }
01490          debug().debug(" SMRP\t%x\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t\%i\t%i\t%i\t%i\t%i\t%i ",
01491                   self.get_node().get_id(),
01492                   secs,
01493                   passive_spread_metrics_periodic.get_spread_messages_send(), passive_spread_metrics_periodic.get_spread_messages_bytes_send(),
01494                   passive_spread_metrics_periodic.get_inhibition_messages_send(), passive_spread_metrics_periodic.get_inhibition_messages_bytes_send(),
01495                   passive_spread_metrics_periodic.get_spread_messages_received(), passive_spread_metrics_periodic.get_spread_messages_bytes_received(),
01496                   passive_spread_metrics_periodic.get_inhibition_messages_received(), passive_spread_metrics_periodic.get_inhibition_messages_bytes_received(),
01497                   passive_spread_metrics_periodic.get_spread_messages_inhibited(), passive_spread_metrics_periodic.get_spread_messages_bytes_inhibited(),
01498                   passive_spread_metrics_periodic.get_inhibition_messages_inhibited(), passive_spread_metrics_periodic.get_inhibition_messages_bytes_inhibited(),
01499                   messages_received_periodic, messages_bytes_received_periodic );
01500                   passive_spread_metrics_periodic.reset();
01501 #endif
01502 #ifdef PLTT_PASSIVE_SPREAD_METRICS_LIGHT
01503                   debug().debug(" SMRN\t%x\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i ",
01504                            self.get_node().get_id(),
01505                            secs,
01506                            spread_messages_send, spread_bytes_send,
01507                            inhibition_messages_send, inhibition_bytes_send,
01508                            spread_messages_received, spread_bytes_received,
01509                            inhibition_messages_received, inhibition_bytes_received,
01510                            spread_messages_inhibited, spread_bytes_inhibited,
01511                            inhibition_messages_inhibited, inhibition_bytes_inhibited,
01512                            messages_received, messages_bytes_received );
01513                   debug().debug(" SMRP\t%x\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i ",
01514                            self.get_node().get_id(),
01515                            secs,
01516                            spread_messages_send_periodic, spread_bytes_send_periodic,
01517                            inhibition_messages_send_periodic, inhibition_bytes_send_periodic,
01518                            spread_messages_received_periodic, spread_bytes_received_periodic,
01519                            inhibition_messages_received_periodic, inhibition_bytes_received_periodic,
01520                            spread_messages_inhibited_periodic, spread_bytes_inhibited_periodic,
01521                            inhibition_messages_inhibited_periodic, inhibition_bytes_inhibited_periodic,
01522                            messages_received_periodic, messages_bytes_received_periodic);
01523          spread_messages_send_periodic = 0;
01524          spread_bytes_send_periodic = 0;
01525          spread_messages_received_periodic = 0;
01526          spread_bytes_received_periodic = 0;
01527          spread_messages_inhibited_periodic = 0;
01528          spread_bytes_inhibited_periodic = 0;
01529          inhibition_messages_send_periodic = 0;
01530          inhibition_bytes_send_periodic = 0;
01531          inhibition_messages_received_periodic = 0;
01532          inhibition_bytes_received_periodic = 0;
01533          inhibition_messages_inhibited_periodic = 0;
01534          inhibition_bytes_inhibited_periodic = 0;
01535 #endif
01536 #ifdef PLTT_PASSIVE_TRACKING_METRICS
01537          for ( PLTT_PassiveTrackingMetricListIterator i = passive_tracking_metrics.get_passive_tracking_metric_list()->begin(); i != passive_tracking_metrics.get_passive_tracking_metric_list()->end(); ++i )
01538          {
01539             debug().debug(" TMTN\t%x\t%i\t%x\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i ", self.get_node().get_id(), secs, i->get_tracker_id(), i->get_echo_messages_send(), i->get_echo_messages_bytes_send(), i->get_echo_messages_received(), i->get_echo_messages_bytes_received(), i->get_report_messages_send(), i->get_report_messages_bytes_send(), i->get_report_messages_received(), i->get_report_messages_bytes_received(), i->get_query_messages_send(), i->get_query_messages_bytes_send(), i->get_query_messages_received(), i->get_query_messages_bytes_received() );
01540          }
01541          debug().debug( " TMRN\t%x\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i ",
01542                   self.get_node().get_id(),
01543                   secs,
01544                   passive_tracking_metrics.get_echo_messages_send(), passive_tracking_metrics.get_echo_messages_bytes_send(),
01545                   passive_tracking_metrics.get_report_messages_send(), passive_tracking_metrics.get_report_messages_bytes_send(),
01546                   passive_tracking_metrics.get_query_messages_send(), passive_tracking_metrics.get_query_messages_bytes_send(),
01547                   passive_tracking_metrics.get_echo_messages_received(), passive_tracking_metrics.get_echo_messages_bytes_received(),
01548                   passive_tracking_metrics.get_report_messages_received(), passive_tracking_metrics.get_report_messages_bytes_received(),
01549                   passive_tracking_metrics.get_query_messages_received(), passive_tracking_metrics.get_query_messages_bytes_received(),
01550                   messages_received, messages_bytes_received );
01551          for ( PLTT_PassiveTrackingMetricListIterator i = passive_tracking_metrics_periodic.get_passive_tracking_metric_list()->begin(); i != passive_tracking_metrics_periodic.get_passive_tracking_metric_list()->end(); ++i )
01552          {
01553             debug().debug(" TMTP\t%x\t%i\t%x\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i ", self.get_node().get_id(), secs, i->get_tracker_id(), i->get_echo_messages_send(), i->get_echo_messages_bytes_send(), i->get_echo_messages_received(), i->get_echo_messages_bytes_received(), i->get_report_messages_send(), i->get_report_messages_bytes_send(), i->get_report_messages_received(), i->get_report_messages_bytes_received(), i->get_query_messages_send(), i->get_query_messages_bytes_send(), i->get_query_messages_received(), i->get_query_messages_bytes_received() );
01554          }
01555          debug().debug( " TMRP\t%x\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i ",
01556                   self.get_node().get_id(),
01557                   secs,
01558                   passive_tracking_metrics_periodic.get_echo_messages_send(), passive_tracking_metrics_periodic.get_echo_messages_bytes_send(),
01559                   passive_tracking_metrics_periodic.get_report_messages_send(), passive_tracking_metrics_periodic.get_report_messages_bytes_send(),
01560                   passive_tracking_metrics_periodic.get_query_messages_send(), passive_tracking_metrics_periodic.get_query_messages_bytes_send(),
01561                   passive_tracking_metrics_periodic.get_echo_messages_received(), passive_tracking_metrics_periodic.get_echo_messages_bytes_received(),
01562                   passive_tracking_metrics_periodic.get_report_messages_received(), passive_tracking_metrics_periodic.get_report_messages_bytes_received(),
01563                   passive_tracking_metrics_periodic.get_query_messages_received(), passive_tracking_metrics_periodic.get_query_messages_bytes_received(),
01564                   messages_received_periodic, messages_bytes_received_periodic );
01565                   passive_tracking_metrics_periodic.reset();
01566 #endif
01567 #ifdef PLTT_PASSIVE_TRACKING_METRICS_LIGHT
01568                   debug().debug( " TMRN\t%x\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i ",
01569                            self.get_node().get_id(),
01570                            secs,
01571                            echo_messages_send, echo_bytes_send,
01572                            report_messages_send, report_bytes_send,
01573                            query_messages_send, query_bytes_send,
01574                            echo_messages_received, echo_bytes_received,
01575                            report_messages_received, report_bytes_received,
01576                            query_messages_received, query_bytes_received,
01577                            messages_received, messages_bytes_received );
01578                   debug().debug( " TMRP\t%x\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i ",
01579                            self.get_node().get_id(),
01580                            secs,
01581                            echo_messages_send_periodic, echo_bytes_send_periodic,
01582                            report_messages_send_periodic, report_bytes_send_periodic,
01583                            query_messages_send_periodic, query_bytes_send_periodic,
01584                            echo_messages_received_periodic, echo_bytes_received_periodic,
01585                            report_messages_received_periodic, report_bytes_received_periodic,
01586                            query_messages_received_periodic, query_bytes_received_periodic,
01587                            messages_received_periodic, messages_bytes_received_periodic );
01588       echo_messages_send_periodic = 0;
01589       echo_bytes_send_periodic = 0;
01590       echo_messages_received_periodic = 0;
01591       echo_bytes_received_periodic = 0;
01592       report_messages_send_periodic = 0;
01593       report_bytes_send_periodic = 0;
01594       report_messages_received_periodic = 0;
01595       report_bytes_received_periodic = 0;
01596       query_messages_send_periodic = 0;
01597       query_bytes_send_periodic = 0;
01598       query_messages_received_periodic = 0;
01599       query_bytes_received_periodic = 0;
01600 #endif
01601 #ifdef PLTT_METRICS
01602       messages_received_periodic = 0;
01603       messages_bytes_received_periodic = 0;
01604       timer().template set_timer<self_type, &self_type::print_metrics>( metrics_timeout, this, userdata );
01605 #endif
01606       }
01607       // -----------------------------------------------------------------------
01608       PLTT_NodeList* get_neighbors()
01609       {
01610          return &neighbors;
01611       }
01612       PLTT_TraceList* get_traces()
01613       {
01614          return &traces;
01615       }
01616       PLTT_Node* get_self()
01617       {
01618          return &self;
01619       }
01620       void set_self( PLTT_Node _n )
01621       {
01622          self = _n;
01623       }
01624 #ifdef PLTT_METRICS
01625       void set_metrics_timeout( millis_t _t )
01626       {
01627          metrics_timeout = _t;
01628       }
01629 #endif
01630 #ifdef OPT_RELIABLE_TRACKING
01631       void set_reliable_agent_exp_time( millis_t _t )
01632       {
01633          reliable_agent_exp_time = _t;
01634       }
01635       void set_reliable_agent_rec_time( millis_t _t )
01636       {
01637          reliable_agent_rec_time = _t;
01638       }
01639       void set_reliable_millis_counter( millis_t _t )
01640       {
01641          reliable_millis_timer = _t;
01642       }
01643 #endif
01644       void set_intensity_detection_threshold( IntensityNumber value )
01645       {
01646          intensity_detection_threshold = value;
01647       }
01648    private:
01649       Radio& radio()
01650       {
01651          return *radio_;
01652       }
01653       Timer& timer()
01654       {
01655          return *timer_;
01656       }
01657       Debug& debug()
01658       {
01659          return *debug_;
01660       }
01661       Rand& rand()
01662       {
01663          return *rand_;
01664       }
01665       Clock& clock()
01666       {
01667          return *clock_;
01668       }
01669       NeighborDiscovery& neighbor_discovery()
01670       {
01671          return *neighbor_discovery_;
01672       }
01673       Radio * radio_;
01674       Timer * timer_;
01675       Debug * debug_;
01676       Rand * rand_;
01677       Clock * clock_;
01678       NeighborDiscovery * neighbor_discovery_;
01679       enum MessageIds
01680       {
01681          PLTT_SPREAD_ID = 11,
01682          PLTT_INHIBITION_MESSAGE_ID = 21,
01683          PLTT_QUERY_ID = 31,
01684          PLTT_QUERY_REPORT_ID = 41,
01685          PLTT_TRACK_ECHO_ID = 51,
01686          PLTT_TRACK_ECHO_REPLY_ID = 61
01687 #ifdef OPT_RELIABLE_TRACKING
01688          ,PLTT_QUERY_ACK_ID = 71,
01689          PLTT_QUERY_REPORT_ACK_ID = 81
01690 #endif
01691       };
01692       uint32_t radio_callback_id_;
01693       uint32_t seconds_counter;
01694       PLTT_NodeList neighbors;
01695       PLTT_TraceList traces;
01696 #ifndef ISENSE_APP
01697       PLTT_AgentList report_agents;
01698       PLTT_AgentList query_agents;
01699 #endif
01700 #ifdef OPT_RELIABLE_TRACKING
01701       PLTT_ReliableAgentList reliable_agents;
01702       //PLTT_ReliableAgentList cleanup_reliable_agents;
01703       millis_t reliable_agent_exp_time;
01704       millis_t reliable_agent_rec_time;
01705       millis_t reliable_millis_timer;
01706       uint32_t cleanup_timer;
01707 #endif
01708       PLTT_Node self;
01709       IntensityNumber intensity_detection_threshold;
01710 #ifdef PLTT_PASSIVE_SPREAD_METRICS
01711       PLTT_PassiveSpreadMetrics passive_spread_metrics;
01712       PLTT_PassiveSpreadMetrics passive_spread_metrics_periodic;
01713 #endif
01714 #ifdef PLTT_PASSIVE_TRACKING_METRICS
01715       PLTT_PassiveTrackingMetrics passive_tracking_metrics;
01716       PLTT_PassiveTrackingMetrics passive_tracking_metrics_periodic;
01717 #endif
01718 #ifdef PLTT_METRICS
01719       uint32_t messages_received_periodic;
01720       uint32_t messages_bytes_received_periodic;
01721       uint32_t messages_received;
01722       uint32_t messages_bytes_received;
01723       millis_t metrics_timeout;
01724 #endif
01725 #ifdef PLTT_PASSIVE_TRACKING_METRICS_LIGHT
01726       uint32_t echo_messages_send;
01727       uint32_t echo_bytes_send;
01728       uint32_t echo_messages_received;
01729       uint32_t echo_bytes_received;
01730       uint32_t report_messages_send;
01731       uint32_t report_bytes_send;
01732       uint32_t report_messages_received;
01733       uint32_t report_bytes_received;
01734       uint32_t query_messages_send;
01735       uint32_t query_bytes_send;
01736       uint32_t query_messages_received;
01737       uint32_t query_bytes_received;
01738       uint32_t echo_messages_send_periodic;
01739       uint32_t echo_bytes_send_periodic;
01740       uint32_t echo_messages_received_periodic;
01741       uint32_t echo_bytes_received_periodic;
01742       uint32_t report_messages_send_periodic;
01743       uint32_t report_bytes_send_periodic;
01744       uint32_t report_messages_received_periodic;
01745       uint32_t report_bytes_received_periodic;
01746       uint32_t query_messages_send_periodic;
01747       uint32_t query_bytes_send_periodic;
01748       uint32_t query_messages_received_periodic;
01749       uint32_t query_bytes_received_periodic;
01750 #endif
01751 #ifdef PLTT_PASSIVE_SPREAD_METRICS_LIGHT
01752       uint32_t spread_messages_send;
01753       uint32_t spread_bytes_send;
01754       uint32_t spread_messages_received;
01755       uint32_t spread_bytes_received;
01756       uint32_t spread_messages_inhibited;
01757       uint32_t spread_bytes_inhibited;
01758       uint32_t inhibition_messages_send;
01759       uint32_t inhibition_bytes_send;
01760       uint32_t inhibition_messages_received;
01761       uint32_t inhibition_bytes_received;
01762       uint32_t inhibition_messages_inhibited;
01763       uint32_t inhibition_bytes_inhibited;
01764       uint32_t spread_messages_send_periodic;
01765       uint32_t spread_bytes_send_periodic;
01766       uint32_t spread_messages_received_periodic;
01767       uint32_t spread_bytes_received_periodic;
01768       uint32_t spread_messages_inhibited_periodic;
01769       uint32_t spread_bytes_inhibited_periodic;
01770       uint32_t inhibition_messages_send_periodic;
01771       uint32_t inhibition_bytes_send_periodic;
01772       uint32_t inhibition_messages_received_periodic;
01773       uint32_t inhibition_bytes_received_periodic;
01774       uint32_t inhibition_messages_inhibited_periodic;
01775       uint32_t inhibition_bytes_inhibited_periodic;
01776 #endif
01777       };
01778 }
01779 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines