From: Guilherme Maciel Ferreira Date: Mon, 20 Feb 2012 18:54:26 +0000 (-0200) Subject: Merge branch 'test' X-Git-Tag: v1.3~11 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=649bb55c827e8ac0308277441ea9047b286ffa87;p=pingcheck Merge branch 'test' Conflicts: src/config/configurationreader.cpp src/config/configurationreader.h src/host/messagepayload.cpp src/link/linkstatus.h src/main.cpp src/tcp/tcpheader.cpp --- 649bb55c827e8ac0308277441ea9047b286ffa87 diff --cc src/dns/hostaddress.h index 07931a8,f5ad6e2..c1da3bf --- a/src/dns/hostaddress.h +++ b/src/dns/hostaddress.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 HOSTADDRESS_H_ - #define HOSTADDRESS_H_ + #ifndef HOST_ADDRESS_H + #define HOST_ADDRESS_H +#include + #include #include "dns/timetolive.h" diff --cc src/dns/timetolive.h index bc6b1e3,74335c9..cfd5168 --- a/src/dns/timetolive.h +++ b/src/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 + #include //----------------------------------------------------------------------------- diff --cc src/host/hoststatus.cpp index 76bea2f,1b8b934..6749d79 --- a/src/host/hoststatus.cpp +++ b/src/host/hoststatus.cpp @@@ -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; diff --cc src/host/messagepayload.cpp index f2c1eda,77aa56e..01f9d44 --- a/src/host/messagepayload.cpp +++ b/src/host/messagepayload.cpp @@@ -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(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( 0x01U << shift_amount ); + bool value = static_cast( 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(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( 0x01U << shift_amount ); + + if ( value ) + { + Payload[ byte_index ] = Payload[ byte_index ] | bit_mask; + } + else + { + bit_mask = static_cast( ~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(PayloadSizeInBytes) ) ); - BOOST_ASSERT( ( 0 <= right_byte ) && ( right_byte < static_cast(PayloadSizeInBytes) ) ); - BOOST_ASSERT( left_byte < right_byte ); - BOOST_ASSERT( ( static_cast( right_byte - left_byte ) + 1 ) == sizeof(uint16_t) ); + BOOST_ASSERT( ( 0 <= left_byte_index ) && ( left_byte_index < static_cast(PayloadSizeInBytes) ) ); + BOOST_ASSERT( ( 0 <= right_byte_index ) && ( right_byte_index < static_cast(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( right_byte_index - left_byte_index ) + 1 ) == sizeof(uint16_t) ); - uint32_t value = static_cast( Payload[ left_byte ] << 8 ); - value += static_cast( Payload[ right_byte ] ); + uint32_t value = static_cast( Payload[ left_byte_index ] << 8 ); + value += static_cast( Payload[ right_byte_index ] ); BOOST_ASSERT( value <= numeric_limits::max() ); @@@ -229,43 -296,43 +298,43 @@@ void MessagePayload::encode16 const uint16_t value ) { - BOOST_ASSERT( ( 0 <= left_byte ) && ( left_byte < static_cast(PayloadSizeInBytes) ) ); - BOOST_ASSERT( ( 0 <= right_byte ) && ( right_byte < static_cast(PayloadSizeInBytes) ) ); - BOOST_ASSERT( left_byte < right_byte ); - BOOST_ASSERT( ( static_cast( right_byte - left_byte ) + 1 ) == sizeof(uint16_t) ); + BOOST_ASSERT( ( 0 <= left_byte_index ) && ( left_byte_index < static_cast(PayloadSizeInBytes) ) ); + BOOST_ASSERT( ( 0 <= right_byte_index ) && ( right_byte_index < static_cast(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( right_byte_index - left_byte_index ) + 1 ) == sizeof(uint16_t) ); - Payload[ left_byte ] = static_cast( value >> 8 ); - Payload[ right_byte ] = static_cast( value & 0xFF ); + Payload[ left_byte_index ] = static_cast( value >> 8 ); + Payload[ right_byte_index ] = static_cast( 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(PayloadSizeInBytes) ) ); - BOOST_ASSERT( ( 0 <= last_byte ) && ( last_byte < static_cast(PayloadSizeInBytes) ) ); - BOOST_ASSERT( first_byte < last_byte ); - BOOST_ASSERT( ( static_cast( last_byte - first_byte ) + 1 ) == sizeof(uint32_t) ); + BOOST_ASSERT( ( 0 <= first_byte_index ) && ( first_byte_index < static_cast(PayloadSizeInBytes) ) ); + BOOST_ASSERT( ( 0 <= last_byte_index ) && ( last_byte_index < static_cast(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( 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( Payload[ current_byte ] ) << 24; - value += static_cast( Payload[ ++current_byte ] << 16 ); - value += static_cast( Payload[ ++current_byte ] << 8 ); - value += static_cast( Payload[ ++current_byte ] ); - uint64_t value = static_cast( Payload[ current_byte_index ] << 24 ); ++ uint64_t value = static_cast( Payload[ current_byte_index ] ) << 24; + value += static_cast( Payload[ ++current_byte_index ] << 16 ); + value += static_cast( Payload[ ++current_byte_index ] << 8 ); + value += static_cast( Payload[ ++current_byte_index ] ); BOOST_ASSERT( value <= numeric_limits::max() ); - BOOST_ASSERT( current_byte == last_byte ); + BOOST_ASSERT( current_byte_index == last_byte_index ); return static_cast( value ); } @@@ -286,20 -353,20 +355,20 @@@ void MessagePayload::encode32 const uint32_t value ) { - BOOST_ASSERT( ( 0 < first_byte ) && ( first_byte < static_cast(PayloadSizeInBytes) ) ); - BOOST_ASSERT( ( 0 < last_byte ) && ( last_byte < static_cast(PayloadSizeInBytes) ) ); - BOOST_ASSERT( first_byte < last_byte ); - BOOST_ASSERT( ( static_cast( last_byte - first_byte ) + 1 ) == sizeof(uint32_t) ); + BOOST_ASSERT( ( 0 <= first_byte_index ) && ( first_byte_index < static_cast(PayloadSizeInBytes) ) ); + BOOST_ASSERT( ( 0 <= last_byte_index ) && ( last_byte_index < static_cast(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( 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( ( value >> 24 ) & 0xFF ); - Payload[ ++current_byte ] = static_cast( ( value >> 16 ) & 0xFF ); - Payload[ ++current_byte ] = static_cast( ( value >> 8 ) & 0xFF ); - Payload[ ++current_byte ] = static_cast( value & 0xFF ); + Payload[ current_byte_index ] = static_cast( ( value >> 24 ) & 0xFF ); + Payload[ ++current_byte_index ] = static_cast( ( value >> 16 ) & 0xFF ); + Payload[ ++current_byte_index ] = static_cast( ( value >> 8 ) & 0xFF ); + Payload[ ++current_byte_index ] = static_cast( 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 diff --cc src/host/pingscheduler.h index c58605f,b12b8f2..0ff5b1b --- a/src/host/pingscheduler.h +++ b/src/host/pingscheduler.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 PINGSCHEDULER_H - #define PINGSCHEDULER_H + #ifndef PING_SCHEDULER_H + #define PING_SCHEDULER_H +#include + #include #include @@@ -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 Ping; /// Thread object diff --cc src/icmp/icmptype.h index 45be859,53f45f3..162276a --- a/src/icmp/icmptype.h +++ b/src/icmp/icmptype.h @@@ -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 diff --cc src/icmp/icmpv6packet.cpp index fd53884,4f5b928..20d9123 --- a/src/icmp/icmpv6packet.cpp +++ b/src/icmp/icmpv6packet.cpp @@@ -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 } diff --cc src/link/linkstatus.cpp index 81e4880,e63d82a..71ef3bc --- a/src/link/linkstatus.cpp +++ b/src/link/linkstatus.cpp @@@ -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 ) { diff --cc src/link/linkstatus.h index 78aaed2,a8f0ca6..4d47139 --- a/src/link/linkstatus.h +++ b/src/link/linkstatus.h @@@ -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 @@@ -69,10 -65,11 +69,13 @@@ 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 ); @@@ -86,30 -83,27 +89,30 @@@ 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 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 index 7577915,2f7e85d..24496fc --- a/src/main.cpp +++ b/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(