Browse Source

Definition of data structure and processing required for the caller to update the RTT
associated with the address


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac356@3465 e5f2f494-b856-4b98-b285-d166d9295462

Haidong Wang 14 years ago
parent
commit
cd8167307c

+ 1 - 0
src/lib/nsas/Makefile.am

@@ -15,6 +15,7 @@ libnsas_la_SOURCES += hash_key.cc hash_key.h
 libnsas_la_SOURCES += hash_table.h
 libnsas_la_SOURCES += lru_list.h
 libnsas_la_SOURCES += nameserver_address_store.cc nameserver_address_store.h
+libnsas_la_SOURCES += nameserver_address.h
 libnsas_la_SOURCES += nameserver_entry.cc nameserver_entry.h
 libnsas_la_SOURCES += nsas_entry_compare.h
 libnsas_la_SOURCES += nsas_entry.h

+ 89 - 0
src/lib/nsas/nameserver_address.h

@@ -0,0 +1,89 @@
+// Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+// $Id$
+
+#ifndef __NAMESERVER_ADDRESS_H
+#define __NAMESERVER_ADDRESS_H
+
+#include <boost/shared_ptr.hpp>
+
+#include "asiolink.h"
+#include "nameserver_entry.h"
+
+namespace isc {
+namespace nsas {
+
+/// \brief Nameserver Address
+///
+/// This class implements the object that returned from NSAS when the resolver
+/// request an address for the name server. It contains one IOAddress object
+/// that can be used by resolver. When the resolver get query back from the name
+/// server, it should update the name server's RTT(Round Trip Time) with this 
+/// object.
+
+class NameserverAddress {
+public:
+    /// \brief Constructor
+    ///
+    /// The NameserverAddress object will contain one shared_ptr object that
+    /// pointed to NameserverEntry which contains the address as well as it's 
+    /// corresponding index. The user can update it's RTT with the index later.
+    ///
+    /// \param namerserver A shared_ptr that points to a NameserverEntry object
+    /// the shared_ptr can avoid the NameserverEntry object being dropped while the
+    /// request is processing.
+    /// \param index The address's index in NameserverEntry's addresses vector
+    NameserverAddress(boost::shared_ptr<NameserverEntry>& nameserver, uint32_t index):
+        ns_(nameserver), index_(index)
+    {
+    }
+
+    /// \brief Destructor
+    ///
+    /// Empty destructor.
+    ~NameserverAddress()
+    {}
+
+    /// \brief Return address
+    ///
+    asiolink::IOAddress getAddress() const { 
+        NameserverEntry *ne = ns_.get();
+        assert(ne != NULL);
+        return ne->getAddressAtIndex(index_); 
+    }
+
+    /// \brief Update Round-trip Time
+    ///
+    /// When the user get one request back from the name server, it should
+    /// update the address's RTT.
+    /// \param rtt The new Round-Trip Time
+    void updateRTT(uint32_t rtt) { 
+        NameserverEntry* ne = ns_.get();
+        if(ne) ne->updateAddressRTTAtIndex(rtt, index_); 
+    }
+private:
+    /// \brief Default Constructor
+    ///
+    /// A private default constructor to avoid creating an empty object.
+    NameserverAddress();
+
+    boost::shared_ptr<NameserverEntry> ns_;  ///< Shared-pointer to NameserverEntry object
+    uint32_t index_;                         ///< The address index in NameserverEntry
+};
+
+} // namespace nsas
+} // namespace isc
+
+#endif//__NAMESERVER_ADDRESS_H

+ 16 - 0
src/lib/nsas/nameserver_entry.cc

@@ -143,6 +143,13 @@ void NameserverEntry::getAddresses(AddressVector& addresses, short family) const
         bind1st(AddressSelection(), family));
 }
 
+asiolink::IOAddress NameserverEntry::getAddressAtIndex(uint32_t index) const
+{
+    assert(index < address_.size());
+
+    return address_[index].getAddress();
+}
+
 // Set the address RTT to a specific value
 void NameserverEntry::setAddressRTT(const IOAddress& address, uint32_t rtt) {
 
@@ -154,6 +161,15 @@ void NameserverEntry::setAddressRTT(const IOAddress& address, uint32_t rtt) {
     }
 }
 
+// Update the address's rtt 
+void NameserverEntry::updateAddressRTTAtIndex(uint32_t rtt, uint32_t index) {
+    //make sure it is a valid index
+    if(index >= address_.size()) return;
+
+    //update the rtt
+    address_[index].setRTT(rtt);
+}
+
 // Sets the address to be unreachable
 void NameserverEntry::setAddressUnreachable(const IOAddress& address) {
     setAddressRTT(address, AddressEntry::UNREACHABLE);

+ 13 - 0
src/lib/nsas/nameserver_entry.h

@@ -126,6 +126,11 @@ public:
     virtual void getAddresses(NameserverEntry::AddressVector& addresses,
         short family = 0) const;
 
+    /// \brief Return Address that corresponding to the index
+    ///
+    /// \param index The address index in the address vector
+    virtual asiolink::IOAddress getAddressAtIndex(uint32_t index) const;
+
     /// \brief Update RTT
     ///
     /// Updates the RTT for a particular address
@@ -134,6 +139,12 @@ public:
     /// \param RTT New RTT for the address
     virtual void setAddressRTT(const asiolink::IOAddress& address, uint32_t rtt);
 
+    /// \brief Update RTT of the address that corresponding to the index
+    ///
+    /// \param rtt Round-Trip Time
+    /// \param index The address's index in address vector
+    virtual void updateAddressRTTAtIndex(uint32_t rtt, uint32_t index);
+
     /// \brief Set Address Unreachable
     ///
     /// Sets the specified address to be unreachable
@@ -156,6 +167,8 @@ public:
         return HashKey(name_, classCode_);
     }
 
+    /// \return Hash Key of the Nameserver
+
     /// \return Expiration Time of Data
     ///
     /// Returns the expiration time of addresses for this nameserver.  For

+ 1 - 0
src/lib/nsas/tests/Makefile.am

@@ -23,6 +23,7 @@ run_unittests_SOURCES += hash_key_unittest.cc
 run_unittests_SOURCES += hash_table_unittest.cc
 run_unittests_SOURCES += hash_unittest.cc
 run_unittests_SOURCES += lru_list_unittest.cc
+run_unittests_SOURCES += nameserver_address_unittest.cc
 run_unittests_SOURCES += nameserver_address_store_unittest.cc
 run_unittests_SOURCES += nameserver_entry_unittest.cc
 run_unittests_SOURCES += nsas_entry_compare_unittest.cc

+ 97 - 0
src/lib/nsas/tests/nameserver_address_unittest.cc

@@ -0,0 +1,97 @@
+// Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+// $Id$
+
+#include <gtest/gtest.h>
+
+#include "name.h"
+#include "nameserver_address.h"
+#include "rdata.h"
+#include "rrclass.h"
+#include "rrset.h"
+#include "rrttl.h"
+
+#include "nsas_test.h"
+
+namespace isc {
+namespace nsas {
+
+using namespace dns;
+using namespace rdata;
+
+#define TEST_ADDRESS_INDEX 1
+
+/// \brief NameserverEntry sample class for testing
+class NameserverEntrySample {
+public:
+    NameserverEntrySample():
+        rrv4_(Name("example.org"), RRClass::IN(), RRType::A(), RRTTL(1200))
+    {
+        // Add some sample A records
+        rrv4_.addRdata(ConstRdataPtr(new RdataTest<A>("1.2.3.4")));
+        rrv4_.addRdata(ConstRdataPtr(new RdataTest<A>("5.6.7.8")));
+        rrv4_.addRdata(ConstRdataPtr(new RdataTest<A>("9.10.11.12")));
+
+        ns_.reset(new NameserverEntry(&rrv4_, NULL));
+    }
+
+    // Return the sample NameserverEntry
+    boost::shared_ptr<NameserverEntry>& getNameserverEntry() { return ns_; }
+
+    // Return the IOAddress corresponding to the index in rrv4_
+    asiolink::IOAddress getAddressAtIndex(uint32_t index) { return ns_.get()->getAddressAtIndex(index); }
+
+    // Return the RTT of the address
+    uint32_t getAddressRTTAtIndex(uint32_t index) { 
+        NameserverEntry::AddressVector addresses;
+        ns_.get()->getAddresses(addresses);
+        return addresses[index].getRTT();
+    }
+
+private:
+    BasicRRset rrv4_;                       ///< Standard RRSet - IN, A, lowercase name
+    boost::shared_ptr<NameserverEntry> ns_; ///< Shared_ptr that points to a NameserverEntry object
+};
+
+/// \brief Test Fixture Class
+class NameserverAddressTest : public ::testing::Test {
+protected:
+    // Constructor
+    NameserverAddressTest(): 
+        ns_address_(ns_sample_.getNameserverEntry(), TEST_ADDRESS_INDEX)
+    {
+    }
+
+    NameserverEntrySample ns_sample_;
+    NameserverAddress ns_address_;
+};
+
+// Test that the address is equal to the address in NameserverEntry
+TEST_F(NameserverAddressTest, Address) {
+    EXPECT_TRUE(ns_address_.getAddress().equal( ns_sample_.getAddressAtIndex(TEST_ADDRESS_INDEX)));
+}
+
+// Test that the RTT is updated
+TEST_F(NameserverAddressTest, UpdateRTT) {
+    uint32_t old_rtt = ns_sample_.getAddressRTTAtIndex(TEST_ADDRESS_INDEX);
+    uint32_t new_rtt = old_rtt + 1;
+
+    ns_address_.updateRTT(new_rtt);
+
+    EXPECT_EQ(new_rtt, ns_sample_.getAddressRTTAtIndex(TEST_ADDRESS_INDEX));
+}
+
+} // namespace nsas
+} // namespace isc