blob: e3a15d4275f1a5ef451880f74c37e6ebfb32cc5a [file] [log] [blame]
Shock Jiang30ad8922014-09-04 15:08:52 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California.
4 *
5 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
7 *
8 * NDNS is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
Shock Jiangcde28712014-10-19 21:17:20 -070020#ifndef NDNS_DAEMON_ZONE_HPP
21#define NDNS_DAEMON_ZONE_HPP
Shock Jiang30ad8922014-09-04 15:08:52 -070022
23#include <ndn-cxx/name.hpp>
Shock Jiangfc171d92014-09-26 09:33:40 -070024
Shock Jiang30ad8922014-09-04 15:08:52 -070025#include <iostream>
26
27namespace ndn {
28namespace ndns {
29
30/**
31 * @brief DNS Zone abstraction, which delegates records
32 * @see http://en.wikipedia.org/wiki/DNS_zone
33 * @see http://irl.cs.ucla.edu/data/files/theses/afanasyev-thesis.pdf
34 *
35 * The class is copyable, since it may be assigned to another Zone instance
36 * when resolving Response or Query from database
37 */
38class Zone
39{
40public:
41 Zone();
42
43 /**
44 * @brief create a Zone instance
45 */
46 explicit
Shock Jiangfc171d92014-09-26 09:33:40 -070047 Zone(const Name& name, const time::seconds& ttl = time::seconds(3600));
Shock Jiang30ad8922014-09-04 15:08:52 -070048
Shock Jiangfc171d92014-09-26 09:33:40 -070049 /**
50 * @brief get name of the zone
51 */
Shock Jiang30ad8922014-09-04 15:08:52 -070052 const Name&
53 getName() const
54 {
55 return m_name;
56 }
57
Shock Jiangfc171d92014-09-26 09:33:40 -070058 /**
59 * @brief set name of the zone
60 */
Shock Jiang30ad8922014-09-04 15:08:52 -070061 void
62 setName(const Name& name)
63 {
64 m_name = name;
65 }
66
Shock Jiangfc171d92014-09-26 09:33:40 -070067 /**
68 * @brief get the id when the rr is stored in the database
69 * default value is 0, the database has to guarantee that id is greater than 0.
70 */
71 uint64_t
Shock Jiang30ad8922014-09-04 15:08:52 -070072 getId() const
73 {
74 return m_id;
75 }
76
Shock Jiangfc171d92014-09-26 09:33:40 -070077 /**
78 * @brief set the id when the rr is stored in the database
79 * default value is 0, the database has to guarantee that id is greater than 0.
80 */
Shock Jiang30ad8922014-09-04 15:08:52 -070081 void
Shock Jiangfc171d92014-09-26 09:33:40 -070082 setId(uint64_t id)
Shock Jiang30ad8922014-09-04 15:08:52 -070083 {
84 m_id = id;
85 }
86
Shock Jiangfc171d92014-09-26 09:33:40 -070087 /**
88 * @brief get default ttl of resource record delegated in this zone, measured by seconds.
89 * default 3600 (seconds)
90 */
91 const time::seconds&
92 getTtl() const
93 {
94 return m_ttl;
95 }
96
97 /**
98 * @brief set default ttl of resource record delegated in this zone, measured by seconds.
99 * default 3600 (seconds)
100 */
101 void
102 setTtl(const time::seconds& ttl)
103 {
104 m_ttl = ttl;
105 }
106
107 /**
108 * @brief two zones are equal if they have the same name. Zone's name is unique
109 */
Shock Jiang30ad8922014-09-04 15:08:52 -0700110 bool
111 operator==(const Zone& other) const
112 {
113 return (m_name == other.getName());
114 }
115
Shock Jiangfc171d92014-09-26 09:33:40 -0700116 bool
117 operator!=(const Zone& other) const
118 {
119 return (m_name != other.getName());
120 }
Shock Jiang30ad8922014-09-04 15:08:52 -0700121
Shock Jiangfc171d92014-09-26 09:33:40 -0700122private:
123 uint64_t m_id;
124
Shock Jiang30ad8922014-09-04 15:08:52 -0700125 Name m_name;
Shock Jiangfc171d92014-09-26 09:33:40 -0700126
127 time::seconds m_ttl;
Shock Jiang30ad8922014-09-04 15:08:52 -0700128};
129
130std::ostream&
131operator<<(std::ostream& os, const Zone& zone);
132
133} // namespace ndns
134} // namespace ndn
135
Shock Jiangcde28712014-10-19 21:17:20 -0700136#endif // NDNS_DAEMON_ZONE_HPP