LCOV - code coverage report
Current view: top level - nsas - address_entry.h (source / functions) Hit Total Coverage
Test: report.info Lines: 14 18 77.8 %
Date: 2012-05-15 Functions: 4 7 57.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 26 38.5 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
       2                 :            : //
       3                 :            : // Permission to use, copy, modify, and/or distribute this software for any
       4                 :            : // purpose with or without fee is hereby granted, provided that the above
       5                 :            : // copyright notice and this permission notice appear in all copies.
       6                 :            : //
       7                 :            : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
       8                 :            : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
       9                 :            : // AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
      10                 :            : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
      11                 :            : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
      12                 :            : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
      13                 :            : // PERFORMANCE OF THIS SOFTWARE.
      14                 :            : 
      15                 :            : #ifndef __ADDRESS_ENTRY_H
      16                 :            : #define __ADDRESS_ENTRY_H
      17                 :            : 
      18                 :            : /// \brief Address Entry
      19                 :            : ///
      20                 :            : /// Lightweight class that couples an address with a RTT and provides some
      21                 :            : /// convenience methods for accessing and updating the information.
      22                 :            : 
      23                 :            : #include <stdint.h>
      24                 :            : #include <asiolink/io_address.h>
      25                 :            : 
      26                 :            : namespace isc {
      27                 :            : namespace nsas {
      28                 :            : 
      29                 :    5882764 : class AddressEntry {
      30                 :            : public:
      31                 :            :     /// Creates an address entry given IOAddress entry and RTT
      32                 :            :     /// This is the only constructor; the default copy constructor and
      33                 :            :     /// assignment operator are valid for this object.
      34                 :            :     ///
      35                 :            :     /// \param address Address object representing this address
      36                 :            :     /// \param rtt Initial round-trip time
      37                 :            :     AddressEntry(const asiolink::IOAddress& address, uint32_t rtt = 0) :
      38                 :        128 :         address_(address), rtt_(rtt), dead_until_(0)
      39                 :            :     {}
      40                 :            : 
      41                 :            :     /// \return Address object
      42                 :            :     const asiolink::IOAddress& getAddress() const {
      43                 :            :         return address_;
      44                 :            :     }
      45                 :            : 
      46                 :            :     /// \return Current round-trip time
      47                 :       2029 :     uint32_t getRTT() {
      48 [ +  + ][ +  - ]:    1228073 :         if(dead_until_ != 0 && time(NULL) >= dead_until_){
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
      49                 :          0 :             dead_until_ = 0;
      50                 :          0 :             rtt_ = 1; //reset the rtt to a small value so it has an opportunity to be updated
      51                 :            :         }
      52                 :            : 
      53                 :       2029 :         return rtt_;
      54                 :            :     }
      55                 :            : 
      56                 :            :     /// Set current RTT
      57                 :            :     ///
      58                 :            :     /// \param rtt New RTT to be associated with this address
      59                 :          0 :     void setRTT(uint32_t rtt) {
      60   [ -  +  -  + ]:      22021 :         if(rtt == UNREACHABLE){
         [ +  - ][ #  # ]
         [ -  + ][ +  + ]
                 [ #  # ]
      61                 :          7 :             dead_until_ = time(NULL) + 5*60;//Cache the unreachable server for 5 minutes (RFC2308 sec7.2)
      62                 :            :         }
      63                 :            : 
      64                 :         45 :         rtt_ = rtt;
      65                 :          0 :     }
      66                 :            : 
      67                 :            :     /// Mark address as unreachable.
      68                 :          2 :     void setUnreachable() {
      69                 :          2 :         setRTT(UNREACHABLE);   // Largest long number is code for unreachable
      70                 :          2 :     }
      71                 :            : 
      72                 :            :     /// Check if address is unreachable
      73                 :            :     ///
      74                 :            :     /// \return true if the address is unreachable, false if not
      75                 :            :     bool isUnreachable() {
      76                 :          4 :         return (getRTT() == UNREACHABLE); // The getRTT() will check the cache time for unreachable server
      77                 :            :     }
      78                 :            : 
      79                 :            :     /// \return true if the object is a V4 address
      80                 :            :     bool isV4() const {
      81                 :          2 :         return (address_.getFamily() == AF_INET);
      82                 :            :     }
      83                 :            : 
      84                 :            :     /// \return true if the object is a V6 address
      85                 :            :     bool isV6() const {
      86                 :          2 :         return (address_.getFamily() == AF_INET6);
      87                 :            :     }
      88                 :            : 
      89                 :            :     // Next element is defined public for testing
      90                 :            :     static const uint32_t UNREACHABLE;  ///< RTT indicating unreachable address
      91                 :            : 
      92                 :            : private:
      93                 :            :     asiolink::IOAddress address_;       ///< Address
      94                 :            :     uint32_t        rtt_;               ///< Round-trip time
      95                 :            :     time_t  dead_until_;                ///< Dead time for unreachable server
      96                 :            : };
      97                 :            : 
      98                 :            : }   // namespace dns
      99                 :            : }   // namespace isc
     100                 :            : 
     101                 :            : 
     102                 :            : #endif // __ADDRESS_ENTRY_H

Generated by: LCOV version 1.9