zone: add TTL
Change-Id: I20b2b9647081e9b235414351ff03747601fd1ff3
diff --git a/src/zone.cpp b/src/zone.cpp
index 7d0a7d5..6f859a4 100644
--- a/src/zone.cpp
+++ b/src/zone.cpp
@@ -24,12 +24,14 @@
Zone::Zone()
: m_id(0)
+ , m_ttl(3600)
{
}
-Zone::Zone(const Name& name)
+Zone::Zone(const Name& name, const time::seconds& ttl)
: m_id(0)
, m_name(name)
+ , m_ttl(ttl)
{
}
diff --git a/src/zone.hpp b/src/zone.hpp
index 4f490da..4eab6a9 100644
--- a/src/zone.hpp
+++ b/src/zone.hpp
@@ -21,6 +21,7 @@
#define NDNS_ZONE_HPP
#include <ndn-cxx/name.hpp>
+
#include <iostream>
namespace ndn {
@@ -43,50 +44,87 @@
* @brief create a Zone instance
*/
explicit
- Zone(const Name& name);
+ Zone(const Name& name, const time::seconds& ttl = time::seconds(3600));
+ /**
+ * @brief get name of the zone
+ */
const Name&
getName() const
{
return m_name;
}
+ /**
+ * @brief set name of the zone
+ */
void
setName(const Name& name)
{
m_name = name;
}
- uint32_t
+ /**
+ * @brief get the id when the rr is stored in the database
+ * default value is 0, the database has to guarantee that id is greater than 0.
+ */
+ uint64_t
getId() const
{
return m_id;
}
+ /**
+ * @brief set the id when the rr is stored in the database
+ * default value is 0, the database has to guarantee that id is greater than 0.
+ */
void
- setId(uint32_t id)
+ setId(uint64_t id)
{
m_id = id;
}
+ /**
+ * @brief get default ttl of resource record delegated in this zone, measured by seconds.
+ * default 3600 (seconds)
+ */
+ const time::seconds&
+ getTtl() const
+ {
+ return m_ttl;
+ }
+
+ /**
+ * @brief set default ttl of resource record delegated in this zone, measured by seconds.
+ * default 3600 (seconds)
+ */
+ void
+ setTtl(const time::seconds& ttl)
+ {
+ m_ttl = ttl;
+ }
+
+ /**
+ * @brief two zones are equal if they have the same name. Zone's name is unique
+ */
bool
operator==(const Zone& other) const
{
return (m_name == other.getName());
}
-private:
- /**
- * @brief the id when the rr is stored in the database
- * default value is 0, the database has to guarantee that id is greater than 0.
- */
- uint32_t m_id;
+ bool
+ operator!=(const Zone& other) const
+ {
+ return (m_name != other.getName());
+ }
- /**
- * @brief the zone's name, which means all its
- * delegated subzones or labels are under this namespace
- */
+private:
+ uint64_t m_id;
+
Name m_name;
+
+ time::seconds m_ttl;
};
std::ostream&
diff --git a/tests/unit/zone.cpp b/tests/unit/zone.cpp
index 3acc4ec..0a26e76 100644
--- a/tests/unit/zone.cpp
+++ b/tests/unit/zone.cpp
@@ -35,15 +35,17 @@
Zone zone1;
zone1.setName(zoneName);
zone1.setId(2);
+ zone1.setTtl(time::seconds(4000));
- Zone zone2(zoneName);
- Zone zone3("/net/ndnsim");
-
- BOOST_CHECK_EQUAL(zone1, zone2);
- BOOST_CHECK_EQUAL(zone3, zone2);
- BOOST_CHECK_EQUAL(zone2.getName(), zone3.getName());
BOOST_CHECK_EQUAL(zone1.getId(), 2);
BOOST_CHECK_EQUAL(zone1.getName(), zoneName);
+ BOOST_CHECK_EQUAL(zone1.getTtl(), time::seconds(4000));
+
+ Zone zone2(zoneName);
+ BOOST_CHECK_EQUAL(zone1, zone2);
+ BOOST_CHECK_EQUAL(zone2.getName(), zone1.getName());
+
+ BOOST_CHECK_NE(zone1, Zone("/net/ndnsim2"));
}
BOOST_AUTO_TEST_SUITE_END()