Browse Source

Interface change

ZoneEntry does not get referral data as well, it asks resolver. Updated
the tests as well.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac408@3707 e5f2f494-b856-4b98-b285-d166d9295462
Michal Vaner 14 years ago
parent
commit
91736af329

+ 32 - 17
src/lib/nsas/tests/nsas_test.h

@@ -239,6 +239,9 @@ class TestResolver : public isc::nsas::ResolverInterface {
         // Thrown if the query at the given index does not exist.
         class NoSuchRequest : public std::exception { };
 
+        // Thrown if the answer does not match the query
+        class DifferentRequest : public std::exception { };
+
         QuestionPtr operator[](size_t index) {
             if (index >= requests.size()) {
                 throw NoSuchRequest();
@@ -290,6 +293,18 @@ class TestResolver : public isc::nsas::ResolverInterface {
             set->addRdata(rdata);
             requests[index].second->success(set);
         }
+
+        void provideNS(size_t index, RRsetPtr nameservers) {
+            if (index >= requests.size()) {
+                throw NoSuchRequest();
+            }
+            if (requests[index].first->getName() != nameservers->getName() ||
+                requests[index].first->getType() != RRType::NS())
+            {
+                throw DifferentRequest();
+            }
+            requests[index].second->success(nameservers);
+        }
 };
 
 // String constants.  These should end in a dot.
@@ -299,28 +314,28 @@ static const std::string MIXED_EXAMPLE_CO_UK("EXAmple.co.uk.");
 
 class TestWithRdata : public ::testing::Test {
 protected:
-    typedef boost::shared_ptr<BasicRRset> BasicRRsetPtr;
+    typedef boost::shared_ptr<RRset> RRsetPtr;
     /// \brief Constructor
     ///
     /// Initializes the RRsets used in the tests.  The RRsets themselves have to
     /// be initialized with the basic data on their construction. The Rdata for
     /// them is added in SetUp().
     TestWithRdata() :
-        rrv4_(new BasicRRset(Name(EXAMPLE_CO_UK), RRClass::IN(), RRType::A(),
+        rrv4_(new RRset(Name(EXAMPLE_CO_UK), RRClass::IN(), RRType::A(),
             RRTTL(1200))),
-        rrcase_(new BasicRRset(Name(MIXED_EXAMPLE_CO_UK), RRClass::IN(),
+        rrcase_(new RRset(Name(MIXED_EXAMPLE_CO_UK), RRClass::IN(),
             RRType::A(), RRTTL(1200))),
-        rrch_(new BasicRRset(Name(EXAMPLE_CO_UK), RRClass::CH(), RRType::A(),
+        rrch_(new RRset(Name(EXAMPLE_CO_UK), RRClass::CH(), RRType::A(),
             RRTTL(1200))),
-        rrns_(new BasicRRset(Name(EXAMPLE_CO_UK), RRClass::IN(), RRType::NS(),
+        rrns_(new RRset(Name(EXAMPLE_CO_UK), RRClass::IN(), RRType::NS(),
             RRTTL(1200))),
-        rr_single_(new BasicRRset(Name(EXAMPLE_CO_UK), RRClass::IN(),
+        rr_single_(new RRset(Name(EXAMPLE_CO_UK), RRClass::IN(),
             RRType::NS(), RRTTL(600))),
-        rr_empty_(new BasicRRset(Name(EXAMPLE_CO_UK), RRClass::IN(),
+        rr_empty_(new RRset(Name(EXAMPLE_CO_UK), RRClass::IN(),
             RRType::NS(), RRTTL(600))),
-        rrv6_(new BasicRRset(Name(EXAMPLE_CO_UK), RRClass::IN(),
+        rrv6_(new RRset(Name(EXAMPLE_CO_UK), RRClass::IN(),
             RRType::AAAA(), RRTTL(900))),
-        rrnet_(new BasicRRset(Name(EXAMPLE_NET), RRClass::IN(), RRType::A(),
+        rrnet_(new RRset(Name(EXAMPLE_NET), RRClass::IN(), RRType::A(),
             RRTTL(600))),
         ns_name_("ns.example.net.")
     {}
@@ -360,14 +375,14 @@ protected:
     }
 
     /// \brief Data for the tests
-    BasicRRsetPtr rrv4_;           ///< Standard RRSet - IN, A, lowercase name
-    BasicRRsetPtr rrcase_;         ///< Mixed-case name
-    BasicRRsetPtr rrch_;           ///< Non-IN RRset (Chaos in this case)
-    BasicRRsetPtr rrns_;           ///< NS RRset
-    BasicRRsetPtr rr_single_;      ///< NS RRset with single NS
-    BasicRRsetPtr rr_empty_;       ///< NS RRset without any nameservers
-    BasicRRsetPtr rrv6_;           ///< Standard RRset, IN, AAAA, lowercase name
-    BasicRRsetPtr rrnet_;          ///< example.net A RRset
+    RRsetPtr rrv4_;           ///< Standard RRSet - IN, A, lowercase name
+    RRsetPtr rrcase_;         ///< Mixed-case name
+    RRsetPtr rrch_;           ///< Non-IN RRset (Chaos in this case)
+    RRsetPtr rrns_;           ///< NS RRset
+    RRsetPtr rr_single_;      ///< NS RRset with single NS
+    RRsetPtr rr_empty_;       ///< NS RRset without any nameservers
+    RRsetPtr rrv6_;           ///< Standard RRset, IN, AAAA, lowercase name
+    RRsetPtr rrnet_;          ///< example.net A RRset
     Name ns_name_;  ///< Nameserver name of ns.example.net
 };
 

+ 31 - 44
src/lib/nsas/tests/zone_entry_unittest.cc

@@ -72,13 +72,7 @@ protected:
 class InheritedZoneEntry : public ZoneEntry {
     public:
         InheritedZoneEntry(shared_ptr<ResolverInterface> resolver,
-            const isc::dns::AbstractRRset& authority,
-            shared_ptr<HashTable<NameserverEntry> > nameserver_table,
-            shared_ptr<LruList<NameserverEntry> > nameserver_lru) :
-            ZoneEntry(resolver, authority, nameserver_table, nameserver_lru)
-        { }
-        InheritedZoneEntry(shared_ptr<ResolverInterface> resolver,
-            const std::string& name, uint16_t class_code,
+            const std::string& name, const RRClass& class_code,
             shared_ptr<HashTable<NameserverEntry> > nameserver_table,
             shared_ptr<LruList<NameserverEntry> > nameserver_lru) :
             ZoneEntry(resolver, name, class_code, nameserver_table,
@@ -92,31 +86,20 @@ TEST_F(ZoneEntryTest, DefaultConstructor) {
 
     // Default constructor should not create any RRsets
     InheritedZoneEntry alpha(resolver_, EXAMPLE_CO_UK,
-        RRClass::IN().getCode(), nameserver_table_, nameserver_lru_);
+        RRClass::IN(), nameserver_table_, nameserver_lru_);
     EXPECT_EQ(EXAMPLE_CO_UK, alpha.getName());
     EXPECT_EQ(RRClass::IN(), alpha.getClass());
     EXPECT_TRUE(alpha.nameservers().empty());
 }
 
-/// Tests of constructor from referral data
-/// Disabled, as this one will probably go away soon
-TEST_F(ZoneEntryTest, DISABLED_ReferralConstructor) {
-    InheritedZoneEntry alpha(resolver_, *rr_single_, nameserver_table_,
-        nameserver_lru_);
-    // It should load the name and class from the referral info
-    EXPECT_EQ(EXAMPLE_CO_UK, alpha.getName());
-    EXPECT_EQ(RRClass::IN(), alpha.getClass());
-    EXPECT_EQ(1, alpha.nameservers().size());
-    EXPECT_EQ("ns.example.net.", alpha.nameservers()[0]->getName());
-    // TODO Test with some additional data once NameserverEntry supports them?
-}
-
 // It should answer negatively right away if there are no nameservers
 TEST_F(ZoneEntryTest, CallbackNoNS) {
     shared_ptr<InheritedZoneEntry> zone(new InheritedZoneEntry(resolver_,
-        *rr_empty_, nameserver_table_, nameserver_lru_));
+        EXAMPLE_CO_UK, RRClass::IN(), nameserver_table_, nameserver_lru_));
     // It should accept the callback
     EXPECT_TRUE(zone->addCallback(callback_, ANY_OK, zone));
+    // Ask for the nameservers
+    EXPECT_NO_THROW(resolver_->provideNS(0, rr_empty_));
     // And tell imediatelly that it is unreachable (when it has no nameservers)
     EXPECT_TRUE(callback_->successes_.empty());
     EXPECT_EQ(1, callback_->unreachable_count_);
@@ -127,13 +110,14 @@ TEST_F(ZoneEntryTest, CallbackZeroTTL) {
     // Make it zero TTL, so it expires right away
     rr_single_->setTTL(RRTTL(0));
     shared_ptr<InheritedZoneEntry> zone(new InheritedZoneEntry(resolver_,
-        *rr_single_, nameserver_table_, nameserver_lru_));
+        EXAMPLE_CO_UK, RRClass::IN(), nameserver_table_, nameserver_lru_));
     // It should accept the callback
     EXPECT_TRUE(zone->addCallback(callback_, ANY_OK, zone));
+    EXPECT_NO_THROW(resolver_->provideNS(0, rr_empty_));
     // It should not be answered yet, it should ask for the IP addresses
     EXPECT_TRUE(callback_->successes_.empty());
     EXPECT_EQ(0, callback_->unreachable_count_);
-    resolver_->asksIPs(ns_name_, 0, 1);
+    resolver_->asksIPs(ns_name_, 1, 2);
     // It should reject another one, as it has zero TTL
     EXPECT_FALSE(zone->addCallback(callback_, ANY_OK, zone));
 }
@@ -141,23 +125,24 @@ TEST_F(ZoneEntryTest, CallbackZeroTTL) {
 // Check it answers callbacks when we give it addresses
 TEST_F(ZoneEntryTest, CallbacksAnswered) {
     shared_ptr<InheritedZoneEntry> zone(new InheritedZoneEntry(resolver_,
-        *rr_single_, nameserver_table_, nameserver_lru_));
+        EXAMPLE_CO_UK, RRClass::IN(), nameserver_table_, nameserver_lru_));
     // It should be in NOT_ASKED state
     EXPECT_EQ(Fetchable::NOT_ASKED, zone->getState());
     // It should accept the callback
     EXPECT_TRUE(zone->addCallback(callback_, ANY_OK, zone));
+    EXPECT_NO_THROW(resolver_->provideNS(0, rr_empty_));
     // It should not be answered yet, it should ask for the IP addresses
     EXPECT_TRUE(callback_->successes_.empty());
     EXPECT_EQ(0, callback_->unreachable_count_);
-    resolver_->asksIPs(ns_name_, 0, 1);
+    resolver_->asksIPs(ns_name_, 1, 2);
     // We should be IN_PROGRESS
     EXPECT_EQ(Fetchable::IN_PROGRESS, zone->getState());
     // Give two more callbacks, with different address families
     EXPECT_TRUE(zone->addCallback(callback_, V4_ONLY, zone));
     EXPECT_TRUE(zone->addCallback(callback_, V6_ONLY, zone));
     // Nothing more is asked
-    EXPECT_EQ(2, resolver_->requests.size());
-    EXPECT_NO_THROW(resolver_->answer(0, ns_name_, RRType::A(),
+    EXPECT_EQ(3, resolver_->requests.size());
+    EXPECT_NO_THROW(resolver_->answer(1, ns_name_, RRType::A(),
          rdata::in::A("192.0.2.1")));
     // Two are answered (ANY and V4)
     ASSERT_EQ(2, callback_->successes_.size());
@@ -167,7 +152,7 @@ TEST_F(ZoneEntryTest, CallbacksAnswered) {
     EXPECT_EQ(0, callback_->unreachable_count_);
     // We are still in progress, not everything arrived
     EXPECT_EQ(Fetchable::IN_PROGRESS, zone->getState());
-    EXPECT_NO_THROW(resolver_->answer(1, ns_name_, RRType::AAAA(),
+    EXPECT_NO_THROW(resolver_->answer(2, ns_name_, RRType::AAAA(),
         rdata::in::AAAA("2001:db8::1")));
     // This should answer the third callback
     ASSERT_EQ(3, callback_->successes_.size());
@@ -177,7 +162,7 @@ TEST_F(ZoneEntryTest, CallbacksAnswered) {
     EXPECT_EQ(Fetchable::READY, zone->getState());
     // When we ask something more, it should be answered right away
     EXPECT_TRUE(zone->addCallback(callback_, V4_ONLY, zone));
-    EXPECT_EQ(2, resolver_->requests.size());
+    EXPECT_EQ(3, resolver_->requests.size());
     ASSERT_EQ(4, callback_->successes_.size());
     EXPECT_TRUE(IOAddress("192.0.2.1").equal(callback_->successes_[3]));
     EXPECT_EQ(0, callback_->unreachable_count_);
@@ -186,29 +171,30 @@ TEST_F(ZoneEntryTest, CallbacksAnswered) {
 // Pretend the server can be reached only by IPv4
 TEST_F(ZoneEntryTest, CallbacksAOnly) {
     shared_ptr<InheritedZoneEntry> zone(new InheritedZoneEntry(resolver_,
-        *rr_single_, nameserver_table_, nameserver_lru_));
+        EXAMPLE_CO_UK, RRClass::IN(), nameserver_table_, nameserver_lru_));
     // It should be in NOT_ASKED state
     EXPECT_EQ(Fetchable::NOT_ASKED, zone->getState());
     // It should accept the callback
     EXPECT_TRUE(zone->addCallback(callback_, ANY_OK, zone));
+    EXPECT_NO_THROW(resolver_->provideNS(0, rr_empty_));
     // It should not be answered yet, it should ask for the IP addresses
     EXPECT_TRUE(callback_->successes_.empty());
     EXPECT_EQ(0, callback_->unreachable_count_);
-    resolver_->asksIPs(ns_name_, 0, 1);
+    resolver_->asksIPs(ns_name_, 1, 2);
     // We should be IN_PROGRESS
     EXPECT_EQ(Fetchable::IN_PROGRESS, zone->getState());
     // Give two more callbacks, with different address families
     EXPECT_TRUE(zone->addCallback(callback_, V4_ONLY, zone));
     EXPECT_TRUE(zone->addCallback(callback_, V6_ONLY, zone));
-    ASSERT_GE(resolver_->requests.size(), 2);
-    resolver_->requests[1].second->failure();
+    ASSERT_GE(resolver_->requests.size(), 3);
+    resolver_->requests[2].second->failure();
     // One should be rejected, but two still stay, they have chance
     EXPECT_EQ(0, callback_->successes_.size());
     EXPECT_EQ(1, callback_->unreachable_count_);
     EXPECT_EQ(Fetchable::IN_PROGRESS, zone->getState());
     // Answer the A one and see it answers what can be answered
     ASSERT_EQ(2, callback_->successes_.size());
-    EXPECT_NO_THROW(resolver_->answer(0, ns_name_, RRType::A(),
+    EXPECT_NO_THROW(resolver_->answer(1, ns_name_, RRType::A(),
         rdata::in::A("192.0.2.1")));
     EXPECT_TRUE(IOAddress("192.0.2.1").equal(callback_->successes_[0]));
     EXPECT_TRUE(IOAddress("192.0.2.1").equal(callback_->successes_[1]));
@@ -217,13 +203,13 @@ TEST_F(ZoneEntryTest, CallbacksAOnly) {
     EXPECT_EQ(Fetchable::READY, zone->getState());
     // Try asking something more
     EXPECT_TRUE(zone->addCallback(callback_, V4_ONLY, zone));
-    EXPECT_EQ(2, resolver_->requests.size());
+    EXPECT_EQ(3, resolver_->requests.size());
     ASSERT_EQ(3, callback_->successes_.size());
     EXPECT_TRUE(IOAddress("192.0.2.1").equal(callback_->successes_[2]));
     EXPECT_EQ(1, callback_->unreachable_count_);
 
     EXPECT_TRUE(zone->addCallback(callback_, V6_ONLY, zone));
-    EXPECT_EQ(2, resolver_->requests.size());
+    EXPECT_EQ(3, resolver_->requests.size());
     EXPECT_EQ(3, callback_->successes_.size());
     EXPECT_EQ(2, callback_->unreachable_count_);
 }
@@ -231,26 +217,27 @@ TEST_F(ZoneEntryTest, CallbacksAOnly) {
 // See it tries hard enough to get address and tries both nameservers
 TEST_F(ZoneEntryTest, CallbackTwoNS) {
     shared_ptr<InheritedZoneEntry> zone(new InheritedZoneEntry(resolver_,
-        *rrns_, nameserver_table_, nameserver_lru_));
+        EXAMPLE_CO_UK, RRClass::IN(), nameserver_table_, nameserver_lru_));
     // It should be in NOT_ASKED state
     EXPECT_EQ(Fetchable::NOT_ASKED, zone->getState());
     // It should accept the callback
     EXPECT_TRUE(zone->addCallback(callback_, V4_ONLY, zone));
+    EXPECT_NO_THROW(resolver_->provideNS(0, rr_empty_));
     EXPECT_EQ(Fetchable::IN_PROGRESS, zone->getState());
     // It asks a question (we do not know which nameserver)
     shared_ptr<Name> name;
-    ASSERT_NO_THROW(name.reset(new Name((*resolver_)[0]->getName())));
-    ASSERT_TRUE(resolver_->asksIPs(*name, 0, 1));
-    resolver_->requests[0].second->failure();
+    ASSERT_NO_THROW(name.reset(new Name((*resolver_)[1]->getName())));
+    ASSERT_TRUE(resolver_->asksIPs(*name, 1, 2));
+    resolver_->requests[1].second->failure();
     // Nothing should be answered or failed yet
     EXPECT_EQ(0, callback_->unreachable_count_);
     EXPECT_EQ(0, callback_->successes_.size());
     // It should be still IN_PROGRESS and ask the second nameserver
     // (at last now, if not before)
     EXPECT_EQ(Fetchable::IN_PROGRESS, zone->getState());
-    ASSERT_TRUE(resolver_->asksIPs((*resolver_)[2]->getName(), 2, 3));
+    ASSERT_TRUE(resolver_->asksIPs((*resolver_)[3]->getName(), 3, 4));
     // Fail the second one
-    resolver_->requests[2].second->failure();
+    resolver_->requests[3].second->failure();
     // The callback should be failed now, as there is no chance of getting
     // v4 address
     EXPECT_EQ(1, callback_->unreachable_count_);
@@ -271,7 +258,7 @@ TEST_F(ZoneEntryTest, CallbackTwoNS) {
     EXPECT_EQ(2, callback_->unreachable_count_);
     EXPECT_EQ(0, callback_->successes_.size());
     // Answer the IPv6 one
-    EXPECT_NO_THROW(resolver_->answer(1, (*resolver_)[1]->getName(),
+    EXPECT_NO_THROW(resolver_->answer(2, (*resolver_)[2]->getName(),
         RRType::AAAA(), rdata::in::AAAA("2001:db8::1")));
 
     // Ready, as we have at last some address

+ 0 - 12
src/lib/nsas/zone_entry.cc

@@ -36,18 +36,6 @@ typedef mutex::scoped_lock Lock; // Local lock, nameservers not locked
 typedef shared_ptr<AddressRequestCallback> CallbackPtr;
 }
 
-ZoneEntry::ZoneEntry(shared_ptr<ResolverInterface> resolver,
-    const AbstractRRset& set,
-    shared_ptr<HashTable<NameserverEntry> > nameserver_table,
-    shared_ptr<LruList<NameserverEntry> > nameserver_lru) :
-    classCode_(set.getClass()),
-    resolver_(resolver),
-    nameserver_table_(nameserver_table),
-    nameserver_lru_(nameserver_lru)
-{
-    // TODO get rid of this function
-}
-
 bool
 ZoneEntry::addCallback(CallbackPtr callback,  AddressFamily family,
     shared_ptr<ZoneEntry> self)

+ 7 - 26
src/lib/nsas/zone_entry.h

@@ -51,9 +51,9 @@ class ZoneEntry : public NsasEntry<ZoneEntry>, public Fetchable {
 public:
 
     /**
-     * \brief Constructor where no NS records are supplied
+     * \brief Constructor.
      *
-     * It is here mostly for testing purposes.
+     * It asks the resolver any needed questions to get the nameservers.
      *
      * \param resolver The resolver used to ask for IP addresses
      * \param name Name of the zone
@@ -63,32 +63,13 @@ public:
      *     everything)
      */
     ZoneEntry(boost::shared_ptr<ResolverInterface> resolver,
-        const std::string& name, uint16_t class_code,
+        const std::string& name, const isc::dns::RRClass& class_code,
         boost::shared_ptr<HashTable<NameserverEntry> > nameserver_table,
         boost::shared_ptr<LruList<NameserverEntry> > nameserver_lru) :
-        name_(name), classCode_(class_code), resolver_(resolver),
+        name_(name), class_code_(class_code), resolver_(resolver),
         nameserver_table_(nameserver_table), nameserver_lru_(nameserver_lru)
     {}
 
-    /**
-     * \brief Constructor
-     *
-     * Creates a zone entry object with an RRset representing the nameservers.
-     *
-     * \param resolver The resolver used to ask for IP addresses
-     * \param authority Specifies the name, code and nameservers of this zone.
-     * \param nameserver_table Hash table of existing nameserves and a place
-     *     where new ones will be put.
-     * \param nameserver_lru The lru where the nameservers will be added or
-     *     touched.
-     * \todo This might be completely unneeded if NSAS uses resolver for
-     *     everything.
-     */
-    ZoneEntry(boost::shared_ptr<ResolverInterface> resolver,
-        const isc::dns::AbstractRRset& authority,
-        boost::shared_ptr<HashTable<NameserverEntry> > nameserver_table,
-        boost::shared_ptr<LruList<NameserverEntry> > nameserver_lru);
-
     /// \return Name of the zone
     std::string getName() const {
         return name_;
@@ -96,12 +77,12 @@ public:
 
     /// \return Class of zone
     const isc::dns::RRClass& getClass() const {
-        return classCode_;
+        return class_code_;
     }
 
     /// \return Return Hash Key
     virtual HashKey hashKey() const {
-        return HashKey(name_, classCode_);
+        return HashKey(name_, class_code_);
     }
 
     /**
@@ -137,7 +118,7 @@ protected:
 private:
     mutable boost::mutex    mutex_;     ///< Mutex protecting this zone entry
     std::string     name_;      ///< Canonical zone name
-    isc::dns::RRClass        classCode_; ///< Class code
+    isc::dns::RRClass        class_code_; ///< Class code
     // Internal function that adds a callback (if there's one) and processes
     // the nameservers (if there's chance there's some info) and calls
     // callbacks. If nameserver is given, it is considered new and valid