Commit eeadbac6 authored by Michal Vaner's avatar Michal Vaner

AddressRequestCallback provides NameserverAddress

So the one that gets it might use it to update the rtt.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac408@3805 e5f2f494-b856-4b98-b285-d166d9295462
parent 8b6addc0
......@@ -18,6 +18,7 @@
#define __ADDRESS_REQUEST_CALLBACK_H
#include "asiolink.h"
#include "nameserver_address.h"
namespace isc {
namespace nsas {
......@@ -55,7 +56,7 @@ public:
/// This method is used when an address has been retrieved for the request.
///
/// \param address Address to be used to access the nameserver.
virtual void success(const asiolink::IOAddress& address) = 0;
virtual void success(const NameserverAddress& address) = 0;
/// \brief Unreachable
///
......
......@@ -155,14 +155,13 @@ protected:
class NSASCallback : public AddressRequestCallback {
public:
typedef pair<bool, asiolink::IOAddress> Result;
typedef pair<bool, NameserverAddress> Result;
static vector<Result> results;
virtual void success(const asiolink::IOAddress& address) {
virtual void success(const NameserverAddress& address) {
results.push_back(Result(true, address));
}
virtual void unreachable() {
results.push_back(Result(false,
asiolink::IOAddress("0.0.0.0")));
results.push_back(Result(false, NameserverAddress()));
}
};
......@@ -266,7 +265,7 @@ TEST_F(NameserverAddressStoreTest, emptyLookup) {
EXPECT_EQ(3, NSASCallback::results.size());
BOOST_FOREACH(const NSASCallback::Result& result, NSASCallback::results) {
EXPECT_TRUE(result.first);
EXPECT_EQ("192.0.2.1", result.second.toText());
EXPECT_EQ("192.0.2.1", result.second.getAddress().toText());
}
}
......@@ -368,7 +367,8 @@ TEST_F(NameserverAddressStoreTest, CombinedTest) {
// That should trigger one answer
EXPECT_EQ(1, NSASCallback::results.size());
EXPECT_TRUE(NSASCallback::results[0].first);
EXPECT_EQ("192.0.2.1", NSASCallback::results[0].second.toText());
EXPECT_EQ("192.0.2.1",
NSASCallback::results[0].second.getAddress().toText());
EXPECT_NO_THROW(resolver_->answer(3, name, RRType::AAAA(),
rdata::in::AAAA("2001:bd8::1")));
// And there should be yet another query
......@@ -399,7 +399,7 @@ TEST_F(NameserverAddressStoreTest, CombinedTest) {
EXPECT_EQ(3, NSASCallback::results.size());
BOOST_FOREACH(const NSASCallback::Result& result, NSASCallback::results) {
EXPECT_TRUE(result.first);
EXPECT_EQ("192.0.2.2", result.second.toText());
EXPECT_EQ("192.0.2.2", result.second.getAddress().toText());
}
}
......
......@@ -77,9 +77,9 @@ protected:
struct Callback : public AddressRequestCallback {
Callback() : unreachable_count_(0) {}
size_t unreachable_count_;
vector<IOAddress> successes_;
vector<NameserverAddress> successes_;
virtual void unreachable() { unreachable_count_ ++; }
virtual void success(const IOAddress& address) {
virtual void success(const NameserverAddress& address) {
successes_.push_back(address);
}
};
......@@ -163,8 +163,9 @@ protected:
EXPECT_EQ(success_count, callback_->successes_.size());
for (size_t i = 0; i < callback_->successes_.size(); ++ i) {
EXPECT_TRUE(IOAddress("192.0.2.1").equal(
callback_->successes_[i]) || IOAddress("2001:db8::1").equal(
callback_->successes_[i]));
callback_->successes_[i].getAddress()) ||
IOAddress("2001:db8::1").equal(
callback_->successes_[i].getAddress()));
}
}
};
......@@ -230,7 +231,8 @@ TEST_F(ZoneEntryTest, ChangedNS) {
EXPECT_NO_THROW(resolver_->answer(1, ns_name_, RRType::A(),
rdata::in::A("192.0.2.1")));
ASSERT_EQ(1, callback_->successes_.size());
EXPECT_TRUE(IOAddress("192.0.2.1").equal(callback_->successes_[0]));
EXPECT_TRUE(IOAddress("192.0.2.1").equal(
callback_->successes_[0].getAddress()));
EXPECT_NO_THROW(resolver_->answer(2, ns_name_, RRType::AAAA(),
rdata::in::AAAA("2001:db8::1")));
EXPECT_EQ(1, callback_->successes_.size());
......@@ -252,7 +254,8 @@ TEST_F(ZoneEntryTest, ChangedNS) {
EXPECT_NO_THROW(resolver_->answer(4, different_name, RRType::A(),
rdata::in::A("192.0.2.2")));
ASSERT_EQ(2, callback_->successes_.size());
EXPECT_TRUE(IOAddress("192.0.2.2").equal(callback_->successes_[1]));
EXPECT_TRUE(IOAddress("192.0.2.2").equal(
callback_->successes_[1].getAddress()));
// And now, switch back, as it timed out again
zone->addCallback(callback_, ANY_OK);
......@@ -264,7 +267,8 @@ TEST_F(ZoneEntryTest, ChangedNS) {
EXPECT_EQ(7, resolver_->requests.size());
EXPECT_EQ(Fetchable::READY, zone->getState());
ASSERT_EQ(3, callback_->successes_.size());
EXPECT_TRUE(IOAddress("192.0.2.1").equal(callback_->successes_[0]));
EXPECT_TRUE(IOAddress("192.0.2.1").equal(
callback_->successes_[0].getAddress()));
}
/**
......@@ -299,8 +303,10 @@ TEST_F(ZoneEntryTest, CallbacksAnswered) {
rdata::in::A("192.0.2.1")));
// Two are answered (ANY and V4)
ASSERT_EQ(2, callback_->successes_.size());
EXPECT_TRUE(IOAddress("192.0.2.1").equal(callback_->successes_[0]));
EXPECT_TRUE(IOAddress("192.0.2.1").equal(callback_->successes_[1]));
EXPECT_TRUE(IOAddress("192.0.2.1").equal(
callback_->successes_[0].getAddress()));
EXPECT_TRUE(IOAddress("192.0.2.1").equal(
callback_->successes_[1].getAddress()));
// None are rejected
EXPECT_EQ(0, callback_->unreachable_count_);
// Answer the IPv6 one as well
......@@ -309,14 +315,16 @@ TEST_F(ZoneEntryTest, CallbacksAnswered) {
// This should answer the third callback
EXPECT_EQ(0, callback_->unreachable_count_);
ASSERT_EQ(3, callback_->successes_.size());
EXPECT_TRUE(IOAddress("2001:db8::1").equal(callback_->successes_[2]));
EXPECT_TRUE(IOAddress("2001:db8::1").equal(
callback_->successes_[2].getAddress()));
// It should think it is ready
EXPECT_EQ(Fetchable::READY, zone->getState());
// When we ask something more, it should be answered right away
zone->addCallback(callback_, V4_ONLY);
EXPECT_EQ(3, resolver_->requests.size());
ASSERT_EQ(4, callback_->successes_.size());
EXPECT_TRUE(IOAddress("192.0.2.1").equal(callback_->successes_[3]));
EXPECT_TRUE(IOAddress("192.0.2.1").equal(
callback_->successes_[3].getAddress()));
EXPECT_EQ(0, callback_->unreachable_count_);
}
......@@ -355,8 +363,10 @@ TEST_F(ZoneEntryTest, CallbacksAOnly) {
EXPECT_NO_THROW(resolver_->answer(1, ns_name_, RRType::A(),
rdata::in::A("192.0.2.1")));
ASSERT_EQ(2, callback_->successes_.size());
EXPECT_TRUE(IOAddress("192.0.2.1").equal(callback_->successes_[0]));
EXPECT_TRUE(IOAddress("192.0.2.1").equal(callback_->successes_[1]));
EXPECT_TRUE(IOAddress("192.0.2.1").equal(
callback_->successes_[0].getAddress()));
EXPECT_TRUE(IOAddress("192.0.2.1").equal(
callback_->successes_[1].getAddress()));
EXPECT_EQ(1, callback_->unreachable_count_);
// Everything arriwed, so we are ready
EXPECT_EQ(Fetchable::READY, zone->getState());
......@@ -364,7 +374,8 @@ TEST_F(ZoneEntryTest, CallbacksAOnly) {
zone->addCallback(callback_, V4_ONLY);
EXPECT_EQ(3, resolver_->requests.size());
ASSERT_EQ(3, callback_->successes_.size());
EXPECT_TRUE(IOAddress("192.0.2.1").equal(callback_->successes_[2]));
EXPECT_TRUE(IOAddress("192.0.2.1").equal(
callback_->successes_[2].getAddress()));
EXPECT_EQ(1, callback_->unreachable_count_);
zone->addCallback(callback_, V6_ONLY);
......@@ -425,8 +436,10 @@ TEST_F(ZoneEntryTest, CallbackTwoNS) {
// The other callbacks should be answered now
EXPECT_EQ(2, callback_->unreachable_count_);
ASSERT_EQ(2, callback_->successes_.size());
EXPECT_TRUE(IOAddress("2001:db8::1").equal(callback_->successes_[0]));
EXPECT_TRUE(IOAddress("2001:db8::1").equal(callback_->successes_[1]));
EXPECT_TRUE(IOAddress("2001:db8::1").equal(
callback_->successes_[0].getAddress()));
EXPECT_TRUE(IOAddress("2001:db8::1").equal(
callback_->successes_[1].getAddress()));
}
/**
......@@ -518,7 +531,8 @@ TEST_F(ZoneEntryTest, AddressTimeout) {
rdata::in::A("192.0.2.1"), 0));
// It answers, not rejects
ASSERT_EQ(1, callback_->successes_.size());
EXPECT_TRUE(IOAddress("192.0.2.1").equal(callback_->successes_[0]));
EXPECT_TRUE(IOAddress("192.0.2.1").equal(
callback_->successes_[0].getAddress()));
EXPECT_EQ(0, callback_->unreachable_count_);
// As well with IPv6
EXPECT_NO_THROW(resolver_->answer(2, ns_name_, RRType::AAAA(),
......@@ -534,7 +548,8 @@ TEST_F(ZoneEntryTest, AddressTimeout) {
rdata::in::A("192.0.2.1"), 0));
EXPECT_EQ(0, callback_->unreachable_count_);
ASSERT_EQ(2, callback_->successes_.size());
EXPECT_TRUE(IOAddress("192.0.2.1").equal(callback_->successes_[1]));
EXPECT_TRUE(IOAddress("192.0.2.1").equal(
callback_->successes_[1].getAddress()));
}
/**
......
......@@ -272,12 +272,12 @@ randIndex(size_t count) {
uniform_int<size_t>(0, count - 1))();
}
asiolink::IOAddress
const NameserverAddress&
chooseAddress(const NameserverEntry::AddressVector& addresses) {
// TODO Something little bit more inteligent than just picking random
// one
assert(!addresses.empty()); // Should not be called with empty list
return (addresses[randIndex(addresses.size())].getAddress());
return (addresses[randIndex(addresses.size())]);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment