Merge branch 'test'
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Mon, 20 Feb 2012 18:54:26 +0000 (16:54 -0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Mon, 20 Feb 2012 18:54:26 +0000 (16:54 -0200)
Conflicts:
src/config/configurationreader.cpp
src/config/configurationreader.h
src/host/messagepayload.cpp
src/link/linkstatus.h
src/main.cpp
src/tcp/tcpheader.cpp

18 files changed:
1  2 
src/config/configuration.cpp
src/dns/dnsresolver.h
src/dns/hostaddress.h
src/dns/timetolive.h
src/host/hoststatus.cpp
src/host/messagepayload.cpp
src/host/pinger.h
src/host/pinginterval.h
src/host/pingscheduler.cpp
src/host/pingscheduler.h
src/icmp/icmppacket.h
src/icmp/icmptype.h
src/icmp/icmpv6packet.cpp
src/link/linkstatus.cpp
src/link/linkstatus.h
src/main.cpp
src/tcp/tcpheader.cpp
src/tcp/tcpheader.h

Simple merge
Simple merge
@@@ -17,11 -17,9 +17,11 @@@ in accordance with section (3) of the G
  This exception does not invalidate any other reasons why a work based
  on this file might be covered by the GNU General Public License.
  */
- #ifndef HOSTADDRESS_H_
- #define HOSTADDRESS_H_
+ #ifndef HOST_ADDRESS_H
+ #define HOST_ADDRESS_H
  
 +#include <stdint.h>
 +
  #include <string>
  
  #include "dns/timetolive.h"
@@@ -17,11 -17,9 +17,11 @@@ in accordance with section (3) of the G
  This exception does not invalidate any other reasons why a work based
  on this file might be covered by the GNU General Public License.
  */
- #ifndef TIMETOLIVE_H
- #define TIMETOLIVE_H
+ #ifndef TIME_TO_LIVE_H
+ #define TIME_TO_LIVE_H
  
 +#include <stdint.h>
 +
  #include <boost/asio.hpp>
  
  //-----------------------------------------------------------------------------
@@@ -128,9 -127,10 +127,9 @@@ void HostStatus::analyze_ping_statistic
      {
          LinkAnalyzer->notify_host_up( HostAddress );
      }
 -
 -}
 +} //lint !e1762
  
- void HostStatusAnalyzer::reset_ping_counters()
+ void HostStatus::reset_ping_counters()
  {
      PingsPerformedCount = 0;
      PingsFailedCount = 0;
@@@ -187,26 -196,84 +198,84 @@@ void MessagePayload::append
  }
  
  /**
+  * @brief Retrieve 1 bit from the payload buffer.
+  *
+  * @param byte_index The index of the byte.
+  * @param bit_index The index of bit within the byte. The indexes are as follow:
+  * [0|1|2|3|4|5|6|7], with the index zero being the left most bit within the byte.
+  *
+  * @return The bit value stored at @a bit_index.
+  */
+ bool MessagePayload::decode1(
+         const int byte_index,
+         const int bit_index
+ ) const
+ {
+     const int max_bit_index = 7;
+     BOOST_ASSERT( ( 0 <= byte_index ) && ( byte_index < static_cast<int>(PayloadSizeInBytes) ) );
+     BOOST_ASSERT( ( 0 <= bit_index ) && ( bit_index <= max_bit_index ) );
+     int shift_amount = max_bit_index - bit_index;
+     uint8_t bit_mask = static_cast<uint8_t>( 0x01U << shift_amount );
+     bool value = static_cast<bool>( Payload[ byte_index ] & bit_mask );
+     return value;
+ }
+ /**
+  * @brief Store 1 bit in the payload buffer.
+  *
+  * @param byte_index The index of the byte.
+  * @param bit_index The index of bit within the byte.
+  * @param value The bit value to store at @a bit_index.
+  *
+  * @return void
+  */
+ void MessagePayload::encode1(
+         const int byte_index,
+         const int bit_index,
+         const bool value
+ )
+ {
+     const int max_bit_index = 7;
+     BOOST_ASSERT( ( 0 <= byte_index ) && ( byte_index < static_cast<int>(PayloadSizeInBytes) ) );
+     BOOST_ASSERT( ( 0 <= bit_index ) && ( bit_index <= max_bit_index ) );
+     int shift_amount = max_bit_index - bit_index;
+     uint8_t bit_mask = static_cast<uint8_t>( 0x01U << shift_amount );
+     if ( value )
+     {
+         Payload[ byte_index ] = Payload[ byte_index ] | bit_mask;
+     }
+     else
+     {
+         bit_mask = static_cast<uint8_t>( ~bit_mask );
+         Payload[ byte_index ] = Payload[ byte_index ] & bit_mask;
+     }
+ }
+ /**
   * @brief Retrieve 16 bits from the payload buffer.
   *
-  * @param left_byte the index of the left byte
-  * @param right_byte the index of the right byte
+  * @param left_byte_index The index of the left byte.
+  * @param right_byte_index The index of the right byte.
   *
-  * @return a concatenation of the byte indexed by left_byte with the byte
-  * indexed by right_byte.
+  * @return A concatenation of the byte indexed by @a left_byte_index with the byte
+  * indexed by @a right_byte_index.
   */
  uint16_t MessagePayload::decode16(
-         const int left_byte,
-         const int right_byte
+         const int left_byte_index,
+         const int right_byte_index
  ) const
  {
-     BOOST_ASSERT( ( 0 <= left_byte ) && ( left_byte < static_cast<int>(PayloadSizeInBytes) ) );
-     BOOST_ASSERT( ( 0 <= right_byte ) && ( right_byte < static_cast<int>(PayloadSizeInBytes) ) );
-     BOOST_ASSERT( left_byte < right_byte );
-     BOOST_ASSERT( ( static_cast<size_t>( right_byte - left_byte ) + 1 ) == sizeof(uint16_t) );
+     BOOST_ASSERT( ( 0 <= left_byte_index ) && ( left_byte_index < static_cast<int>(PayloadSizeInBytes) ) );
+     BOOST_ASSERT( ( 0 <= right_byte_index ) && ( right_byte_index < static_cast<int>(PayloadSizeInBytes) ) );
+     BOOST_ASSERT( left_byte_index < right_byte_index );
 -    BOOST_ASSERT( ( ( right_byte_index - left_byte_index ) + 1 ) == sizeof(uint16_t) );
++    BOOST_ASSERT( ( static_cast<size_t>( right_byte_index - left_byte_index ) + 1 ) == sizeof(uint16_t) );
  
-     uint32_t value = static_cast<uint16_t>( Payload[ left_byte ] << 8 );
-     value += static_cast<uint16_t>( Payload[ right_byte ] );
+     uint32_t value = static_cast<uint16_t>( Payload[ left_byte_index ] << 8 );
+     value += static_cast<uint16_t>( Payload[ right_byte_index ] );
  
      BOOST_ASSERT( value <= numeric_limits<uint16_t>::max() );
  
@@@ -229,43 -296,43 +298,43 @@@ void MessagePayload::encode16
          const uint16_t value
  )
  {
-     BOOST_ASSERT( ( 0 <= left_byte ) && ( left_byte < static_cast<int>(PayloadSizeInBytes) ) );
-     BOOST_ASSERT( ( 0 <= right_byte ) && ( right_byte < static_cast<int>(PayloadSizeInBytes) ) );
-     BOOST_ASSERT( left_byte < right_byte );
-     BOOST_ASSERT( ( static_cast<size_t>( right_byte - left_byte ) + 1 ) == sizeof(uint16_t) );
+     BOOST_ASSERT( ( 0 <= left_byte_index ) && ( left_byte_index < static_cast<int>(PayloadSizeInBytes) ) );
+     BOOST_ASSERT( ( 0 <= right_byte_index ) && ( right_byte_index < static_cast<int>(PayloadSizeInBytes) ) );
+     BOOST_ASSERT( left_byte_index < right_byte_index );
 -    BOOST_ASSERT( ( ( right_byte_index - left_byte_index ) + 1 ) == sizeof(uint16_t) );
++    BOOST_ASSERT( ( static_cast<size_t>( right_byte_index - left_byte_index ) + 1 ) == sizeof(uint16_t) );
  
-     Payload[ left_byte ] = static_cast<uint8_t>( value >> 8 );
-     Payload[ right_byte ] = static_cast<uint8_t>( value & 0xFF );
+     Payload[ left_byte_index ] = static_cast<uint8_t>( value >> 8 );
+     Payload[ right_byte_index ] = static_cast<uint8_t>( value & 0xFF );
 -}
 +} //lint !e1762
  
  /**
   * @brief Retrieve 32 bits from the payload buffer.
   *
-  * @param first_byte The index of the first byte out of 4
-  * @param last_byte The index of the last byte out of 4
+  * @param first_byte_index The index of the first byte out of 4.
+  * @param last_byte_index The index of the last byte out of 4.
   *
-  * @return a concatenation of 4 bytes, from the byte indexed by first_byte to
-  * the byte indexed by last_byte.
+  * @return a concatenation of 4 bytes, from the byte indexed by
+  * @a first_byte_index to the byte indexed by @a last_byte_index.
   */
  uint32_t MessagePayload::decode32(
-         const int first_byte,
-         const int last_byte
+         const int first_byte_index,
+         const int last_byte_index
  ) const
  {
-     BOOST_ASSERT( ( 0 <= first_byte ) && ( first_byte < static_cast<int>(PayloadSizeInBytes) ) );
-     BOOST_ASSERT( ( 0 <= last_byte ) && ( last_byte < static_cast<int>(PayloadSizeInBytes) ) );
-     BOOST_ASSERT( first_byte < last_byte );
-     BOOST_ASSERT( ( static_cast<size_t>( last_byte - first_byte ) + 1 ) == sizeof(uint32_t) );
+     BOOST_ASSERT( ( 0 <= first_byte_index ) && ( first_byte_index < static_cast<int>(PayloadSizeInBytes) ) );
+     BOOST_ASSERT( ( 0 <= last_byte_index ) && ( last_byte_index < static_cast<int>(PayloadSizeInBytes) ) );
+     BOOST_ASSERT( first_byte_index < last_byte_index );
 -    BOOST_ASSERT( ( ( last_byte_index - first_byte_index ) + 1 ) == sizeof(uint32_t) );
++    BOOST_ASSERT( ( static_cast<size_t>( last_byte_index - first_byte_index ) + 1 ) == sizeof(uint32_t) );
  
-     int current_byte = first_byte;
+     int current_byte_index = first_byte_index;
  
-     uint64_t value = static_cast<uint32_t>( Payload[ current_byte ] ) << 24;
-     value += static_cast<uint32_t>( Payload[ ++current_byte ] << 16 );
-     value += static_cast<uint32_t>( Payload[ ++current_byte ] << 8 );
-     value += static_cast<uint32_t>( Payload[ ++current_byte ] );
 -    uint64_t value = static_cast<uint32_t>( Payload[ current_byte_index ] << 24 );
++    uint64_t value = static_cast<uint32_t>( Payload[ current_byte_index ] ) << 24;
+     value += static_cast<uint32_t>( Payload[ ++current_byte_index ] << 16 );
+     value += static_cast<uint32_t>( Payload[ ++current_byte_index ] << 8 );
+     value += static_cast<uint32_t>( Payload[ ++current_byte_index ] );
  
      BOOST_ASSERT( value <= numeric_limits<uint32_t>::max() );
-     BOOST_ASSERT( current_byte == last_byte );
+     BOOST_ASSERT( current_byte_index == last_byte_index );
  
      return static_cast<uint32_t>( value );
  }
@@@ -286,20 -353,20 +355,20 @@@ void MessagePayload::encode32
          const uint32_t value
  )
  {
-     BOOST_ASSERT( ( 0 < first_byte ) && ( first_byte < static_cast<int>(PayloadSizeInBytes) ) );
-     BOOST_ASSERT( ( 0 < last_byte ) && ( last_byte < static_cast<int>(PayloadSizeInBytes) ) );
-     BOOST_ASSERT( first_byte < last_byte );
-     BOOST_ASSERT( ( static_cast<size_t>( last_byte - first_byte ) + 1 ) == sizeof(uint32_t) );
+     BOOST_ASSERT( ( 0 <= first_byte_index ) && ( first_byte_index < static_cast<int>(PayloadSizeInBytes) ) );
+     BOOST_ASSERT( ( 0 <= last_byte_index ) && ( last_byte_index < static_cast<int>(PayloadSizeInBytes) ) );
+     BOOST_ASSERT( first_byte_index < last_byte_index );
 -    BOOST_ASSERT( ( ( last_byte_index - first_byte_index ) + 1 ) == sizeof(uint32_t) );
++    BOOST_ASSERT( ( static_cast<size_t>( last_byte_index - first_byte_index ) + 1 ) == sizeof(uint32_t) );
  
-     int current_byte = first_byte;
+     int current_byte_index = first_byte_index;
  
-     Payload[ current_byte ] = static_cast<uint8_t>( ( value >> 24 ) & 0xFF );
-     Payload[ ++current_byte ] = static_cast<uint8_t>( ( value >> 16 ) & 0xFF );
-     Payload[ ++current_byte ] = static_cast<uint8_t>( ( value >> 8 ) & 0xFF );
-     Payload[ ++current_byte  ] = static_cast<uint8_t>( value & 0xFF );
+     Payload[ current_byte_index ] = static_cast<uint8_t>( ( value >> 24 ) & 0xFF );
+     Payload[ ++current_byte_index ] = static_cast<uint8_t>( ( value >> 16 ) & 0xFF );
+     Payload[ ++current_byte_index ] = static_cast<uint8_t>( ( value >> 8 ) & 0xFF );
+     Payload[ ++current_byte_index  ] = static_cast<uint8_t>( value & 0xFF );
  
-     BOOST_ASSERT( current_byte == last_byte );
+     BOOST_ASSERT( current_byte_index == last_byte_index );
 -}
 +} //lint !e1762
  
  /**
   * @brief Read/Extract all the data from the input stream @a is and stores it
Simple merge
Simple merge
Simple merge
@@@ -17,11 -17,9 +17,11 @@@ in accordance with section (3) of the G
  This exception does not invalidate any other reasons why a work based
  on this file might be covered by the GNU General Public License.
  */
- #ifndef PINGSCHEDULER_H
- #define PINGSCHEDULER_H
+ #ifndef PING_SCHEDULER_H
+ #define PING_SCHEDULER_H
  
 +#include <stdint.h>
 +
  #include <string>
  #include <vector>
  
@@@ -105,9 -96,9 +105,9 @@@ private
      /// The list of IPs which are aliases to the host DNS
      DnsResolver IpList;
      /// The port to ping at destination host
 -    int DestinationPort;
 +    uint16_t DestinationPort;
      /// Object responsible to evaluate the status of the host
-     HostStatusAnalyzer HostAnalyzer;
+     HostStatus HostAnalyzer;
      /// Internal boost pinger object
      boost::shared_ptr<Pinger> Ping;
      /// Thread object
Simple merge
@@@ -57,8 -57,8 +57,8 @@@ enum Icmpv6Typ
      Icmpv6Type_MulticastRouterAdvertisement = 151,
      Icmpv6Type_MulticastRouterSolicitation = 152,
      Icmpv6Type_MulticastRouterTermination = 153,
 -    Icmpv6Type_InvalidLast = 255,
 -    Icmpv6Type_Generic
 +    Icmpv6Type_InvalidLast = 254,
 +    Icmpv6Type_Generic = 255
  };
  
- #endif /* ICMP_TYPE_H */
+ #endif // ICMP_TYPE_H
@@@ -151,9 -151,6 +151,7 @@@ bool Icmpv6Packet::match
  
      return ( type_match && identifier_match && seq_num_match && address_match );
  #else
-     // Silence compiler warning
-     (void)source_address;
 +
      return ( type_match && identifier_match && seq_num_match );
  #endif
  }
@@@ -127,9 -127,9 +127,9 @@@ void LinkStatus::notify_host_down( cons
  
      // inserted in the list?
      BOOST_ASSERT( HostsDownList.count( host_address ) == 1 );
 -}
 +} //lint !e1788
  
- void LinkStatusAnalyzer::add_host_up( const string &host_address )
+ void LinkStatus::add_host_up( const string &host_address )
  {
      if ( HostsDownList.count( host_address ) > 0 )
      {
@@@ -53,14 -53,10 +53,14 @@@ public
      void notify_host_down( const std::string &host_address );
  
  private:
 +    //
 +    // Types
 +    //
 +
-     enum LinkStatus
+     enum Status
      {
-         LinkStatus_Up,
-         LinkStatus_Down
+         Status_Up,
+         Status_Down
      };
  
      enum NotificationStatus
          NotificationStatus_Reported
      };
  
+ #ifdef UNDER_TEST
+ public:
 -#else
 -private:
+ #endif
 +    //
 +    // Methods
 +    //
 +
      void add_host_up( const std::string &host_address );
      void add_host_down( const std::string &host_address );
  
  
      bool can_report_link_status() const;
      void set_link_status(
-             const LinkStatusAnalyzer::LinkStatus new_link_status
+             const LinkStatus::Status new_link_status
      );
  
 -private:
 +    //
 +    // Attributes
 +    //
 +
-     /// the maximum amount of hosts which can be down before sound the alarm
+     /// The maximum amount of hosts which can be down before sound the alarm
      const int HostsDownLimit;
-     /// list of hosts down (obvious isn't it?)
+     /// List of hosts down (obvious isn't it?)
      std::set<std::string> HostsDownList;
-     /// interval the link have to be stable in order to consider it is functional
+     /// Interval the link have to be stable in order to consider it is functional
      const int LinkUpIntervalInMin;
-     /// interval the link have to be down in order to consider it is non-functional
+     /// Interval the link have to be down in order to consider it is non-functional
      const int LinkDownIntervalInMin;
-     /// keep track of the actual link status
-     LinkStatusAnalyzer::LinkStatus CurrentLinkStatus;
-     /// indicates if the last link status change was notified
-     LinkStatusAnalyzer::NotificationStatus CurrentNotificationStatus;
-     /// when was the last time the status changed
+     /// Keep track of the actual link status
+     LinkStatus::Status CurrentLinkStatus;
+     /// Indicates if the last link status change was notified
+     LinkStatus::NotificationStatus CurrentNotificationStatus;
+     /// When was the last time the status changed
      boost::posix_time::ptime TimeLinkStatusChanged;
-     /// command used to notify the status of the link
-     StatusNotifierCommand StatusNotifierCmd;
-     /// mutual exclusion variable to avoid data races
+     /// Command used to notify the status of the link
+     StatusNotifierCommandItem StatusNotifierCmd;
+     /// Mutual exclusion variable to avoid data races
      boost::mutex Mutex;
  
  };
diff --cc src/main.cpp
@@@ -104,7 -120,8 +121,8 @@@ void init_pingers
      BOOST_FOREACH( HostItem host, hosts )
      {
          string destination_address = host->get_address();
 -        int destination_port = host->get_port();
 +        uint16_t destination_port = host->get_port();
+         PingProtocol protocol = host->get_ping_protocol();
          int ping_interval_in_sec = host->get_interval_in_sec();
          PingSchedulerItem scheduler(
                  new PingScheduler(
Simple merge
Simple merge