[svn] commit: r3588 - in /branches/trac408/src/lib/nsas: Makefile.am TODO fetchable.h nameserver_entry.h nsas_types.h resolver_interface.h tests/Makefile.am tests/nameserver_entry_unittest.cc tests/nsas_test.h zone_entry.h
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Nov 22 09:55:22 UTC 2010
Author: vorner
Date: Mon Nov 22 09:55:17 2010
New Revision: 3588
Log:
Make nameserver entry test compile
Modified:
branches/trac408/src/lib/nsas/Makefile.am
branches/trac408/src/lib/nsas/TODO
branches/trac408/src/lib/nsas/fetchable.h
branches/trac408/src/lib/nsas/nameserver_entry.h
branches/trac408/src/lib/nsas/nsas_types.h
branches/trac408/src/lib/nsas/resolver_interface.h
branches/trac408/src/lib/nsas/tests/Makefile.am
branches/trac408/src/lib/nsas/tests/nameserver_entry_unittest.cc
branches/trac408/src/lib/nsas/tests/nsas_test.h
branches/trac408/src/lib/nsas/zone_entry.h
Modified: branches/trac408/src/lib/nsas/Makefile.am
==============================================================================
--- branches/trac408/src/lib/nsas/Makefile.am (original)
+++ branches/trac408/src/lib/nsas/Makefile.am Mon Nov 22 09:55:17 2010
@@ -14,12 +14,12 @@
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_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
-libnsas_la_SOURCES += zone_entry.cc zone_entry.h
+#libnsas_la_SOURCES += zone_entry.cc zone_entry.h
libnsas_la_SOURCES += fetchable.h
libnsas_la_SOURCES += address_request_callback.h
libnsas_la_SOURCES += resolver_interface.h
Modified: branches/trac408/src/lib/nsas/TODO
==============================================================================
--- branches/trac408/src/lib/nsas/TODO (original)
+++ branches/trac408/src/lib/nsas/TODO Mon Nov 22 09:55:17 2010
@@ -6,6 +6,7 @@
pointers to zones). This will ensure the zone is not deleted at wrong time.
* There's only one function for adding callbacks, put them together.
* Return if we timed out.
+* When it expires, it should invalidate the zone up above it.
Zone entries:
* They will be nameserver callbacks themself. This ensures that they are not
Modified: branches/trac408/src/lib/nsas/fetchable.h
==============================================================================
--- branches/trac408/src/lib/nsas/fetchable.h (original)
+++ branches/trac408/src/lib/nsas/fetchable.h Mon Nov 22 09:55:17 2010
@@ -37,6 +37,8 @@
enum State {
/// \short No one yet asked for the information.
NOT_ASKED,
+ /// \short The information is too old and should not be used.
+ EXPIRED,
/// \short The information is asked for but it did not arrive.
IN_PROGRESS,
/// \short It is not possible to get the information.
Modified: branches/trac408/src/lib/nsas/nameserver_entry.h
==============================================================================
--- branches/trac408/src/lib/nsas/nameserver_entry.h (original)
+++ branches/trac408/src/lib/nsas/nameserver_entry.h Mon Nov 22 09:55:17 2010
@@ -127,10 +127,17 @@
/// convenient.)
/// \param family The family of address that is requested.
/// else for all addresses.
+ /// \param expired_ok Return addresses even when expired. In that case,
+ /// it will pretend to be READY. This is here to allow getting address
+ /// with TTL 0 from a nameserver that just arrived and triggered
+ /// a callback.
/// \return The state this is currently in. If the TTL expires, it enters
- /// the NOT_ASKED state by itself.
+ /// the EXPIRED state by itself. It may be IN_PROGRESS and still
+ /// return some addresses (when one address family arrived and is
+ /// is returned, but the other is still on the way).
virtual Fetchable::State getAddresses(
- NameserverEntry::AddressVector& addresses, AddressRequest family);
+ NameserverEntry::AddressVector& addresses,
+ AddressRequest family = ANY_OK, bool expired_ok = false);
// TODO Is this one of any use at all?
/// \brief Return Address that corresponding to the index
@@ -206,6 +213,8 @@
/// \short A callback that some information here arrived (or are unavailable).
struct Callback {
virtual void operator()(NameserverEntry* self) = 0;
+ /// \short Virtual destructor, so descendants are properly cleaned up
+ virtual ~ Callback() {}
};
/**
@@ -214,9 +223,9 @@
* Adds a callback for given zone when they are ready or the information
* is found unreachable.
*
- * If it is not in NOT_ASKED state, it does not ask the for the IP address
- * again, it just inserts the callback. It is up to the caller not to
- * insert one callback multiple times.
+ * If it is not in NOT_ASKED or EXPIRED state, it does not ask the for the
+ * IP address again, it just inserts the callback. It is up to the caller
+ * not to insert one callback multiple times.
*
* The callback might be called directly from this function.
*
Modified: branches/trac408/src/lib/nsas/nsas_types.h
==============================================================================
--- branches/trac408/src/lib/nsas/nsas_types.h (original)
+++ branches/trac408/src/lib/nsas/nsas_types.h Mon Nov 22 09:55:17 2010
@@ -17,9 +17,6 @@
#ifndef __NSAS_TYPES_H
#define __NSAS_TYPES_H
-#include <vector>
-#include <asio.h>
-
/// \file nsas_types.h
/// \brief Nameserver Address Store Types
///
@@ -27,9 +24,6 @@
namespace isc {
namespace nsas {
-
-/// \brief Array of nameserver addresses
-typedef std::vector<ip::address> NsasAddress
/// \brief Address requested
enum AddressRequest {
Modified: branches/trac408/src/lib/nsas/resolver_interface.h
==============================================================================
--- branches/trac408/src/lib/nsas/resolver_interface.h (original)
+++ branches/trac408/src/lib/nsas/resolver_interface.h Mon Nov 22 09:55:17 2010
@@ -52,6 +52,8 @@
* \todo Pass some reason.
*/
virtual void failure() = 0;
+ /// \short Virtual destructor, so descendants are cleaned up
+ virtual ~ Callback() {};
};
typedef boost::shared_ptr<Callback> CallbackPtr;
/**
@@ -65,6 +67,8 @@
*/
virtual void resolve(isc::dns::QuestionPtr question,
CallbackPtr callback) = 0;
+ /// \short Virtual destructor, so descendants are properly cleaned up
+ virtual ~ ResolverInterface() {}
};
} // namespace nsas
Modified: branches/trac408/src/lib/nsas/tests/Makefile.am
==============================================================================
--- branches/trac408/src/lib/nsas/tests/Makefile.am (original)
+++ branches/trac408/src/lib/nsas/tests/Makefile.am Mon Nov 22 09:55:17 2010
@@ -24,11 +24,11 @@
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_address_store_unittest.cc
run_unittests_SOURCES += nameserver_entry_unittest.cc
run_unittests_SOURCES += nsas_entry_compare_unittest.cc
run_unittests_SOURCES += nsas_test.h
-run_unittests_SOURCES += zone_entry_unittest.cc
+#run_unittests_SOURCES += zone_entry_unittest.cc
run_unittests_SOURCES += fetchable_unittest.cc
run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
Modified: branches/trac408/src/lib/nsas/tests/nameserver_entry_unittest.cc
==============================================================================
--- branches/trac408/src/lib/nsas/tests/nameserver_entry_unittest.cc (original)
+++ branches/trac408/src/lib/nsas/tests/nameserver_entry_unittest.cc Mon Nov 22 09:55:17 2010
@@ -111,7 +111,7 @@
/// \short Just a really stupid callback counting times called
struct Callback : public NameserverEntry::Callback {
size_t count;
- virtual void operator()(shared_ptr<ZoneEntry>) {
+ virtual void operator()(NameserverEntry*) {
count ++;
}
Callback() : count(0) { }
@@ -220,11 +220,11 @@
EXPECT_EQ(0, av.size());
NameserverEntry::AddressVector av4;
- alpha.getAddresses(av4, AF_INET);
+ alpha.getAddresses(av4, V4_ONLY);
EXPECT_EQ(0, av4.size());
NameserverEntry::AddressVector av6;
- alpha.getAddresses(av6, AF_INET6);
+ alpha.getAddresses(av6, V6_ONLY);
EXPECT_EQ(0, av6.size());
// Initialize with V4 addresses only.
@@ -236,11 +236,11 @@
EXPECT_EQ(rrv4_.getRdataCount(), bv.size());
NameserverEntry::AddressVector bv4;
- beta.getAddresses(bv4, AF_INET);
+ beta.getAddresses(bv4, V4_ONLY);
EXPECT_EQ(rrv4_.getRdataCount(), bv4.size());
NameserverEntry::AddressVector bv6;
- beta.getAddresses(bv6, AF_INET6);
+ beta.getAddresses(bv6, V6_ONLY);
EXPECT_EQ(0, bv6.size());
// Check that the addresses received are unique.
@@ -256,11 +256,11 @@
EXPECT_EQ(rrv6_.getRdataCount(), cv.size());
NameserverEntry::AddressVector cv4;
- gamma.getAddresses(cv4, AF_INET);
+ gamma.getAddresses(cv4, V4_ONLY);
EXPECT_EQ(0, cv4.size());
NameserverEntry::AddressVector cv6;
- gamma.getAddresses(cv6, AF_INET6);
+ gamma.getAddresses(cv6, V6_ONLY);
EXPECT_EQ(rrv6_.getRdataCount(), cv6.size());
SCOPED_TRACE("Checking V6 addresses");
@@ -274,13 +274,13 @@
EXPECT_EQ((rrv4_.getRdataCount() + rrv6_.getRdataCount()), dv.size());
NameserverEntry::AddressVector dv4;
- delta.getAddresses(dv4, AF_INET);
+ delta.getAddresses(dv4, V4_ONLY);
EXPECT_EQ(rrv4_.getRdataCount(), dv4.size());
SCOPED_TRACE("Checking V4 addresses after dual-address family constructor");
CompareAddresses(dv4, rrv4_);
NameserverEntry::AddressVector dv6;
- delta.getAddresses(dv6, AF_INET6);
+ delta.getAddresses(dv6, V6_ONLY);
EXPECT_EQ(rrv6_.getRdataCount(), dv6.size());
SCOPED_TRACE("Checking V6 addresses after dual-address family constructor");
CompareAddresses(dv6, rrv6_);
@@ -288,8 +288,8 @@
// ... and check that the composite of the v4 and v6 addresses is the same
// as that returned by the get without a filter.
NameserverEntry::AddressVector dvcomponent;
- delta.getAddresses(dvcomponent, AF_INET);
- delta.getAddresses(dvcomponent, AF_INET6);
+ delta.getAddresses(dvcomponent, V4_ONLY);
+ delta.getAddresses(dvcomponent, V6_ONLY);
SCOPED_TRACE("Checking V4+V6 addresses same as composite return");
CompareAddressVectors(dv, dvcomponent);
}
@@ -466,70 +466,76 @@
}
// Tests if it asks the IP addresses and calls callbacks when it comes
+// including the right addresses are returned and that they expire
TEST_F(NameserverEntryTest, IPCallbacks) {
shared_ptr<NameserverEntry> entry(new NameserverEntry(EXAMPLE_CO_UK,
RRClass::IN().getCode()));
- Callback callback;
+ shared_ptr<Callback> callback(new Callback);
TestResolver resolver;
- shared_ptr<ZoneEntry> no_zone, zone(new ZoneEntry(EXAMPLE_CO_UK,
- RRClass::IN().getCode()));
-
- // Ensure that we do not add callbacks now
- EXPECT_THROW(entry->ensureHasCallback(no_zone, callback), isc::BadValue);
-
- entry->askIP(resolver, no_zone, callback, entry);
+
+ entry->askIP(resolver, callback, ANY_OK, entry);
// Ensure it becomes IN_PROGRESS
EXPECT_EQ(Fetchable::IN_PROGRESS, entry->getState());
- // Ensure we can ask for IP address only once
- EXPECT_THROW(entry->askIP(resolver, no_zone, callback, entry),
- isc::BadValue);
-
- // Add a callback for a different zone
- entry->ensureHasCallback(zone, callback);
-
// Now, there should be two queries in the resolver
ASSERT_EQ(2, resolver.requests.size());
resolver.asksIPs(Name(EXAMPLE_CO_UK), 0, 1);
+ // Another one might ask
+ entry->askIP(resolver, callback, V4_ONLY, entry);
+ // There should still be only two queries in the resolver
+ ASSERT_EQ(2, resolver.requests.size());
+
+ // Another one, with need of IPv6 address
+ entry->askIP(resolver, callback, V6_ONLY, entry);
+
// Answer one and see that the callbacks are called
- RRsetPtr answer(new RRset(Name(EXAMPLE_CO_UK), RRClass::IN(), RRType::A(),
- RRTTL(100)));
- answer->addRdata(rdata::in::A("192.0.2.1"));
- Message address(Message::RENDER); // Not able to create different one
- address.addRRset(Section::ANSWER(), answer);
- address.addQuestion(resolver[0]);
- resolver.requests[0].second->success(address);
-
- // Both callbacks should be called by now
- EXPECT_EQ(2, callback.count);
+ resolver.answer(0, Name(EXAMPLE_CO_UK), rdata::in::A("192.0.2.1"));
+
+ // Both callbacks that want IPv4 should be called by now
+ EXPECT_EQ(2, callback->count);
// It should contain one IP address
NameserverEntry::AddressVector addresses;
- entry->getAddresses(addresses);
+ // Still in progress, waiting for the other address
+ EXPECT_EQ(Fetchable::IN_PROGRESS, entry->getAddresses(addresses));
EXPECT_EQ(1, addresses.size());
- EXPECT_EQ(Fetchable::READY, entry->getState());
+ // Answer IPv6 address
+ // It is with zero TTL, so it should expire right away
+ resolver.answer(1, Name(EXAMPLE_CO_UK), rdata::in::AAAA("1001:db8::1"), 0);
+ // The other callback should appear
+ EXPECT_EQ(3, callback->count);
+ // It should return the one address. It should be expired, but
+ // we ignore it for now
+ EXPECT_EQ(Fetchable::READY, entry->getAddresses(addresses, V6_ONLY, true));
+ // Another address should appear
+ EXPECT_EQ(2, addresses.size());
+ // But when we do not ignore it, it should not appear
+ EXPECT_EQ(Fetchable::EXPIRED, entry->getAddresses(addresses, V6_ONLY));
+ EXPECT_EQ(2, addresses.size());
}
// Test the callback is called even when the address is unreachable
TEST_F(NameserverEntryTest, IPCallbacksUnreachable) {
shared_ptr<NameserverEntry> entry(new NameserverEntry(EXAMPLE_CO_UK,
RRClass::IN().getCode()));
- Callback callback;
+ shared_ptr<Callback> callback(new Callback);
TestResolver resolver;
- shared_ptr<ZoneEntry> no_zone;
// Ask for its IP
- entry->askIP(resolver, no_zone, callback, entry);
+ entry->askIP(resolver, callback, ANY_OK, entry);
// Check it asks the resolver
ASSERT_EQ(2, resolver.requests.size());
resolver.asksIPs(Name(EXAMPLE_CO_UK), 0, 1);
resolver.requests[0].second->failure();
// It should still wait for the second one
- EXPECT_EQ(0, callback.count);
+ EXPECT_EQ(0, callback->count);
EXPECT_EQ(Fetchable::IN_PROGRESS, entry->getState());
// It should call the callback now and be unrechable
resolver.requests[1].second->failure();
- EXPECT_EQ(1, callback.count);
+ EXPECT_EQ(1, callback->count);
EXPECT_EQ(Fetchable::UNREACHABLE, entry->getState());
+ NameserverEntry::AddressVector addresses;
+ EXPECT_EQ(Fetchable::UNREACHABLE, entry->getAddresses(addresses));
+ EXPECT_EQ(0, addresses.size());
}
} // namespace nsas
Modified: branches/trac408/src/lib/nsas/tests/nsas_test.h
==============================================================================
--- branches/trac408/src/lib/nsas/tests/nsas_test.h (original)
+++ branches/trac408/src/lib/nsas/tests/nsas_test.h Mon Nov 22 09:55:17 2010
@@ -30,6 +30,7 @@
#include <dns/buffer.h>
#include <dns/rdata.h>
#include <dns/rrtype.h>
+#include <dns/rrttl.h>
#include <dns/messagerenderer.h>
#include "../nsas_entry.h"
#include "../resolver_interface.h"
@@ -219,6 +220,10 @@
using namespace std;
+/*
+ * This pretends to be a resolver. It stores the queries and
+ * they can be answered.
+ */
class TestResolver : public isc::nsas::ResolverInterface {
public:
typedef pair<QuestionPtr, CallbackPtr> Request;
@@ -229,7 +234,7 @@
QuestionPtr operator[](size_t index) {
return (requests[index].first);
}
- /**
+ /*
* Looks if the two provided requests in resolver are A and AAAA.
* Sorts them so index1 is A.
*/
@@ -253,6 +258,21 @@
EXPECT_EQ(RRType::A(), (*this)[index1]->getType());
EXPECT_EQ(RRType::AAAA(), (*this)[index2]->getType());
}
+
+ /*
+ * Sends a simple answer to a query.
+ * Provide index of a query and the address to pass.
+ */
+ void answer(size_t index, const Name& name, const rdata::Rdata& rdata,
+ size_t TTL = 100) {
+ RRsetPtr set(new RRset(name, RRClass::IN(),
+ RRType::A(), RRTTL(TTL)));
+ set->addRdata(rdata);
+ Message address(Message::RENDER); // Not able to create different one
+ address.addRRset(Section::ANSWER(), set);
+ address.addQuestion(requests[index].first);
+ requests[index].second->success(address);
+ }
};
} // Empty namespace
Modified: branches/trac408/src/lib/nsas/zone_entry.h
==============================================================================
--- branches/trac408/src/lib/nsas/zone_entry.h (original)
+++ branches/trac408/src/lib/nsas/zone_entry.h Mon Nov 22 09:55:17 2010
@@ -111,6 +111,8 @@
mutable boost::mutex mutex_; ///< Mutex protecting this zone entry
std::string name_; ///< Canonical zone name
uint16_t classCode_; ///< Class code
+ typedef boost::shared_ptr<NameserverEntry> NameserverPtr;
+ typedef std::vector<NameserverPtr> NameserverVector;
NameserverVector nameservers_; ///< Nameservers
time_t expiry_; ///< Expiry time of this entry
std::list<boost::shared_ptr<AddressRequestCallback> > callbacks_;
@@ -118,7 +120,7 @@
// the nameservers (if there's chance there's some info) and calls
// callbacks. If nameserver is given, it is considered new and valid
// even if its TTL is 0.
- void process(boosh::shared_ptr<AddressRequestCallback> callback,
+ void process(boost::shared_ptr<AddressRequestCallback> callback,
bool v4ok, bool v6ok, NameserverEntry* nameserver);
};
More information about the bind10-changes
mailing list