Commit 606ba69e authored by JINMEI Tatuya's avatar JINMEI Tatuya

[2429] added getMinimum() method for SOA Rdata; needed for TTL-guess handling.

parent 14e57fb2
......@@ -16,6 +16,7 @@
#include <string>
#include <boost/static_assert.hpp>
#include <boost/lexical_cast.hpp>
#include <exceptions/exceptions.h>
......@@ -112,6 +113,16 @@ SOA::getSerial() const {
return (Serial(b.readUint32()));
}
uint32_t
SOA::getMinimum() const {
// Make sure the buffer access is safe.
BOOST_STATIC_ASSERT(sizeof(numdata_) ==
sizeof(uint32_t) * 4 + sizeof(uint32_t));
InputBuffer b(&numdata_[sizeof(uint32_t) * 4], sizeof(uint32_t));
return (b.readUint32());
}
string
SOA::toText() const {
InputBuffer b(numdata_, sizeof(numdata_));
......
......@@ -35,8 +35,12 @@ public:
SOA(const Name& mname, const Name& rname, uint32_t serial,
uint32_t refresh, uint32_t retry, uint32_t expire,
uint32_t minimum);
/// \brief Returns the serial stored in the SOA.
Serial getSerial() const;
/// brief Returns the minimum TTL field value of the SOA.
uint32_t getMinimum() const;
private:
/// Note: this is a prototype version; we may reconsider
/// this representation later.
......
......@@ -32,12 +32,14 @@ using namespace isc::dns::rdata;
namespace {
class Rdata_SOA_Test : public RdataTest {
// there's nothing to specialize
protected:
Rdata_SOA_Test() : rdata_soa(Name("ns.example.com"),
Name("root.example.com"),
2010012601, 3600, 300, 3600000, 1200)
{}
const generic::SOA rdata_soa;
};
const generic::SOA rdata_soa(Name("ns.example.com"), Name("root.example.com"),
2010012601, 3600, 300, 3600000, 1200);
TEST_F(Rdata_SOA_Test, createFromText) {
//TBD
}
......@@ -86,4 +88,13 @@ TEST_F(Rdata_SOA_Test, getSerial) {
EXPECT_EQ(2010012601, rdata_soa.getSerial().getValue());
}
TEST_F(Rdata_SOA_Test, getMinimum) {
EXPECT_EQ(1200, rdata_soa.getMinimum());
// Also check with a very large number (with the MSB being 1).
EXPECT_EQ(2154848336u, generic::SOA(Name("ns.example.com"),
Name("root.example.com"),
0, 0, 0, 0, 0x80706050).getMinimum());
}
}
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