[svn] commit: r3479 - in /branches/trac408/src/lib/nsas: nameserver_address_store.cc nameserver_address_store.h tests/nameserver_address_store_unittest.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Sat Nov 6 22:15:07 UTC 2010
Author: vorner
Date: Sat Nov 6 22:15:07 2010
New Revision: 3479
Log:
Started work with address store, another test
While working on the internal part, another opportunity for testcase
appeared.
Modified:
branches/trac408/src/lib/nsas/nameserver_address_store.cc
branches/trac408/src/lib/nsas/nameserver_address_store.h
branches/trac408/src/lib/nsas/tests/nameserver_address_store_unittest.cc
Modified: branches/trac408/src/lib/nsas/nameserver_address_store.cc
==============================================================================
--- branches/trac408/src/lib/nsas/nameserver_address_store.cc (original)
+++ branches/trac408/src/lib/nsas/nameserver_address_store.cc Sat Nov 6 22:15:07 2010
@@ -47,12 +47,60 @@
{
}
+namespace {
+
+// Often used types
+typedef shared_ptr<ZoneEntry> ZonePtr;
+typedef shared_ptr<NameserverEntry> NameserverPtr;
+typedef shared_ptr<AddressRequestCallback> CallbackPtr;
+
+// One function to call new on both ZoneEntry and NameserverEntry
+template<class T>
+shared_ptr<T>
+newT(const std::string& zone, uint16_t class_code) {
+ return (shared_ptr<T>(new T(zone, class_code)));
+}
+
+}
+
void
-NameserverAddressStore::lookup(const std::string& , uint16_t ,
- const AbstractRRset& , const vector<AbstractRRset>& ,
- shared_ptr<AddressRequestCallback> )
+NameserverAddressStore::lookup(const std::string& zone, uint16_t class_code,
+ const AbstractRRset& authority, const vector<AbstractRRset>& ,
+ CallbackPtr callback)
{
- // TODO Implement
+ // Try to look up the entry
+ pair<bool, ZonePtr> zone_lookup(
+ zone_hash_.getOrAdd(HashKey(zone, class_code),
+ bind(newT<ZoneEntry>, zone, class_code)));
+ ZonePtr zone_ptr(zone_lookup.second);
+ if (zone_lookup.first) { // New value
+ zone_lru_.add(zone_ptr);
+ // Sanitize the authority section and put the data there
+ if (authority.getClass().getCode() != class_code) {
+ isc_throw(InconsistentZone,
+ "Authority section is for different class, expected: " <<
+ RRClass(class_code).toText() << ", got: " <<
+ authority.getClass().toText());
+ }
+ if (authority.getName() != Name(zone)) {
+ isc_throw(InconsistentZone,
+ "Authority section is for different zone, expected: " <<
+ zone << ", got: " << authority.getName().toText());
+ }
+ if (authority.getType() != RRType::NS()) {
+ isc_throw(NotNS, "Authority section with non-NS RR type: " <<
+ authority.getType().toText());
+ }
+ } else { // Was already here
+ zone_lru_.touch(zone_ptr);
+ // TODO Do we update the TTL and nameservers here?
+ }
+ zone_ptr->addCallback(callback);
+ processZone(zone_ptr);
+}
+
+void NameserverAddressStore::processZone(ZonePtr) {
+
}
} // namespace nsas
Modified: branches/trac408/src/lib/nsas/nameserver_address_store.h
==============================================================================
--- branches/trac408/src/lib/nsas/nameserver_address_store.h (original)
+++ branches/trac408/src/lib/nsas/nameserver_address_store.h Sat Nov 6 22:15:07 2010
@@ -31,6 +31,32 @@
namespace isc {
namespace nsas {
+
+/**
+ * \short Invalid referral information passed.
+ *
+ * This is thrown if the referral passed to NameserverAddressStore::lookup is
+ * wrong. Has subexceptions for specific conditions.
+ */
+struct InvalidReferral : public isc::BadValue {
+ InvalidReferral(const char *file, size_t line, const char *what) :
+ BadValue(file, line, what)
+ { }
+};
+
+/// \short The referral is not for this zone.
+struct InconsistentZone : public InvalidReferral {
+ InconsistentZone(const char *file, size_t line, const char *what) :
+ InvalidReferral(file, line, what)
+ { }
+};
+
+/// \short The authority zone contains something else than NS
+struct NotNS : public InvalidReferral {
+ NotNS(const char *file, size_t line, const char *what) :
+ InvalidReferral(file, line, what)
+ { }
+};
/// \brief Nameserver Address Store
///
@@ -104,6 +130,17 @@
//}@
private:
ResolverInterface& resolver_;
+ /**
+ * \short Find if any callbacks may be called.
+ *
+ * This is called when new callback or new data arrive to a zone. In both
+ * cases this may trigger executing some of the callbacks or additional
+ * lookups.
+ * \param zone Which zone to process
+ * \todo Should this be part of the zone entry possibly?
+ * \todo Pass some of the referral stuff there?
+ */
+ void processZone(boost::shared_ptr<ZoneEntry> zone);
};
} // namespace nsas
Modified: branches/trac408/src/lib/nsas/tests/nameserver_address_store_unittest.cc
==============================================================================
--- branches/trac408/src/lib/nsas/tests/nameserver_address_store_unittest.cc (original)
+++ branches/trac408/src/lib/nsas/tests/nameserver_address_store_unittest.cc Sat Nov 6 22:15:07 2010
@@ -164,6 +164,10 @@
asiolink::IOAddress("0.0.0.0")));
}
};
+
+ boost::shared_ptr<AddressRequestCallback> getCallback() {
+ return (boost::shared_ptr<AddressRequestCallback>(new NSASCallback));
+ }
};
vector<NameserverAddressStoreTest::NSASCallback::Result>
@@ -238,24 +242,21 @@
DerivedNsas nsas(defaultTestResolver, 10, 10);
// Ask it a question
nsas.lookup("example.net.", RRClass::IN().getCode(), *authority_,
- vector<AbstractRRset>(), boost::shared_ptr<AddressRequestCallback>(
- new NSASCallback));
+ vector<AbstractRRset>(), getCallback());
// It should ask for IP addresses for example.com.
ASSERT_EQ(2, defaultTestResolver.requests.size());
asksIPs(Name("example.com."), 0, 1);
// Ask another question for the same zone
nsas.lookup("example.net.", RRClass::IN().getCode(), *authority_,
- vector<AbstractRRset>(), boost::shared_ptr<AddressRequestCallback>(
- new NSASCallback));
+ vector<AbstractRRset>(), getCallback());
// It should ask no more questions now
EXPECT_EQ(2, defaultTestResolver.requests.size());
// Ask another question with different zone but the same nameserver
authority_->setName(Name("example.com."));
nsas.lookup("example.com.", RRClass::IN().getCode(), *authority_,
- vector<AbstractRRset>(), boost::shared_ptr<AddressRequestCallback>(
- new NSASCallback));
+ vector<AbstractRRset>(), getCallback());
// It still should ask nothing
EXPECT_EQ(2, defaultTestResolver.requests.size());
@@ -276,5 +277,27 @@
}
}
+/// \short Test invalid authority section.
+TEST_F(NameserverAddressStoreTest, invalidAuthority) {
+ DerivedNsas nsas(defaultTestResolver, 2, 2);
+ EXPECT_THROW(nsas.lookup("example.net.", RRClass::CH().getCode(),
+ *authority_, vector<AbstractRRset>(), getCallback()),
+ InconsistentZone);
+ EXPECT_EQ(0, defaultTestResolver.requests.size());
+ EXPECT_EQ(0, NSASCallback::results.size());
+ EXPECT_THROW(nsas.lookup("example.com.", RRClass::IN().getCode(),
+ *authority_, vector<AbstractRRset>(), getCallback()),
+ InconsistentZone);
+ EXPECT_EQ(0, defaultTestResolver.requests.size());
+ EXPECT_EQ(0, NSASCallback::results.size());
+ BasicRRset aAuthority(Name("example.net."), RRClass::IN(), RRType::A(),
+ RRTTL(128));
+ EXPECT_THROW(nsas.lookup("example.net.", RRClass::IN().getCode(),
+ aAuthority, vector<AbstractRRset>(),
+ getCallback()), NotNS);
+ EXPECT_EQ(0, defaultTestResolver.requests.size());
+ EXPECT_EQ(0, NSASCallback::results.size());
+}
+
} // namespace nsas
} // namespace isc
More information about the bind10-changes
mailing list