blob: 854523a51a8bb3b9bb8ea212fa4d795643c14f20 [file] [log] [blame]
Shock Jiang30ad8922014-09-04 15:08:52 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento948c50c2020-12-26 21:30:45 -05002/*
3 * Copyright (c) 2014-2020, Regents of the University of California.
Shock Jiang30ad8922014-09-04 15:08:52 -07004 *
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
Davide Pesavento948c50c2020-12-26 21:30:45 -050023#include "common.hpp"
Shock Jiang30ad8922014-09-04 15:08:52 -070024
25namespace ndn {
26namespace ndns {
27
28/**
29 * @brief DNS Zone abstraction, which delegates records
30 * @see http://en.wikipedia.org/wiki/DNS_zone
31 * @see http://irl.cs.ucla.edu/data/files/theses/afanasyev-thesis.pdf
32 *
Davide Pesavento948c50c2020-12-26 21:30:45 -050033 * This class is copyable, since it may be assigned to another Zone instance
34 * when resolving Response or Query from database
Shock Jiang30ad8922014-09-04 15:08:52 -070035 */
36class Zone
37{
38public:
39 Zone();
40
41 /**
42 * @brief create a Zone instance
43 */
44 explicit
Shock Jiangfc171d92014-09-26 09:33:40 -070045 Zone(const Name& name, const time::seconds& ttl = time::seconds(3600));
Shock Jiang30ad8922014-09-04 15:08:52 -070046
Shock Jiangfc171d92014-09-26 09:33:40 -070047 /**
48 * @brief get name of the zone
49 */
Shock Jiang30ad8922014-09-04 15:08:52 -070050 const Name&
51 getName() const
52 {
53 return m_name;
54 }
55
Shock Jiangfc171d92014-09-26 09:33:40 -070056 /**
57 * @brief set name of the zone
58 */
Shock Jiang30ad8922014-09-04 15:08:52 -070059 void
60 setName(const Name& name)
61 {
62 m_name = name;
63 }
64
Shock Jiangfc171d92014-09-26 09:33:40 -070065 /**
66 * @brief get the id when the rr is stored in the database
67 * default value is 0, the database has to guarantee that id is greater than 0.
68 */
69 uint64_t
Shock Jiang30ad8922014-09-04 15:08:52 -070070 getId() const
71 {
72 return m_id;
73 }
74
Shock Jiangfc171d92014-09-26 09:33:40 -070075 /**
76 * @brief set the id when the rr is stored in the database
77 * default value is 0, the database has to guarantee that id is greater than 0.
78 */
Shock Jiang30ad8922014-09-04 15:08:52 -070079 void
Shock Jiangfc171d92014-09-26 09:33:40 -070080 setId(uint64_t id)
Shock Jiang30ad8922014-09-04 15:08:52 -070081 {
82 m_id = id;
83 }
84
Shock Jiangfc171d92014-09-26 09:33:40 -070085 /**
86 * @brief get default ttl of resource record delegated in this zone, measured by seconds.
87 * default 3600 (seconds)
88 */
89 const time::seconds&
90 getTtl() const
91 {
92 return m_ttl;
93 }
94
95 /**
96 * @brief set default ttl of resource record delegated in this zone, measured by seconds.
97 * default 3600 (seconds)
98 */
99 void
100 setTtl(const time::seconds& ttl)
101 {
102 m_ttl = ttl;
103 }
104
105 /**
106 * @brief two zones are equal if they have the same name. Zone's name is unique
107 */
Shock Jiang30ad8922014-09-04 15:08:52 -0700108 bool
109 operator==(const Zone& other) const
110 {
111 return (m_name == other.getName());
112 }
113
Shock Jiangfc171d92014-09-26 09:33:40 -0700114 bool
115 operator!=(const Zone& other) const
116 {
117 return (m_name != other.getName());
118 }
Shock Jiang30ad8922014-09-04 15:08:52 -0700119
Shock Jiangfc171d92014-09-26 09:33:40 -0700120private:
121 uint64_t m_id;
122
Shock Jiang30ad8922014-09-04 15:08:52 -0700123 Name m_name;
Shock Jiangfc171d92014-09-26 09:33:40 -0700124
125 time::seconds m_ttl;
Shock Jiang30ad8922014-09-04 15:08:52 -0700126};
127
128std::ostream&
129operator<<(std::ostream& os, const Zone& zone);
130
131} // namespace ndns
132} // namespace ndn
133
Shock Jiangcde28712014-10-19 21:17:20 -0700134#endif // NDNS_DAEMON_ZONE_HPP