blob: 157745e74c30fe10b7eed01a1cd67446180d20f8 [file] [log] [blame]
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -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
20#ifndef NDNS_QUERY_HPP
21#define NDNS_QUERY_HPP
22
23#include "rr.hpp"
24
shockjiang99ad3892014-08-03 14:56:13 -070025
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -070026#include <ndn-cxx/name.hpp>
27
28namespace ndn {
29namespace ndns {
30
31class Query
32{
33public:
34
shockjiang99ad3892014-08-03 14:56:13 -070035 enum QueryType
36 {
37 QUERY_DNS = 1,
38 QUERY_DNS_R,
39 QUERY_KEY,
40 QUERY_UNKNOWN
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -070041 };
42
shockjiang99ad3892014-08-03 14:56:13 -070043 static std::string toString(const QueryType& qType)
shockjianga5ae48c2014-07-27 23:21:41 -070044 {
45 std::string label;
shockjiang99ad3892014-08-03 14:56:13 -070046 switch (qType) {
47 case QUERY_DNS:
48 label = "DNS";
49 break;
50 case QUERY_DNS_R:
51 label = "DNS-R";
52 break;
53 case QUERY_KEY:
54 label = "KEY";
55 break;
56 default:
57 label = "UNKNOWN";
58 break;
59 }
shockjianga5ae48c2014-07-27 23:21:41 -070060 return label;
61
62 }
63
shockjiang99ad3892014-08-03 14:56:13 -070064 static const QueryType toQueryType(const std::string& str)
shockjianga5ae48c2014-07-27 23:21:41 -070065 {
66 QueryType atype;
67 if (str == "DNS") {
68 atype = QUERY_DNS;
shockjiang99ad3892014-08-03 14:56:13 -070069 } else if (str == "DNS-R") {
shockjianga5ae48c2014-07-27 23:21:41 -070070 atype = QUERY_DNS_R;
shockjiang99ad3892014-08-03 14:56:13 -070071 } else if (str == "KEY") {
72 atype = QUERY_KEY;
shockjianga5ae48c2014-07-27 23:21:41 -070073 }
74 else {
shockjiang99ad3892014-08-03 14:56:13 -070075 atype = QUERY_UNKNOWN;
shockjianga5ae48c2014-07-27 23:21:41 -070076 }
77 return atype;
78 }
79
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -070080 Query();
81
82 virtual ~Query();
83
shockjiang99ad3892014-08-03 14:56:13 -070084 const Name& getAuthorityZone() const
85 {
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -070086 return m_authorityZone;
87 }
88
shockjiang99ad3892014-08-03 14:56:13 -070089 void setAuthorityZone(const Name& authorityZone)
90 {
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -070091 m_authorityZone = authorityZone;
92 }
93
shockjiang99ad3892014-08-03 14:56:13 -070094 time::milliseconds getInterestLifetime() const
95 {
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -070096 return m_interestLifetime;
97 }
98
shockjiang99ad3892014-08-03 14:56:13 -070099 void setInterestLifetime(time::milliseconds interestLifetime)
100 {
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700101 m_interestLifetime = interestLifetime;
102 }
103
shockjiang99ad3892014-08-03 14:56:13 -0700104 enum QueryType getQueryType() const
105 {
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700106 return m_queryType;
107 }
108
shockjiang99ad3892014-08-03 14:56:13 -0700109 void setQueryType(enum QueryType queryType)
110 {
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700111 m_queryType = queryType;
112 }
113
shockjiang99ad3892014-08-03 14:56:13 -0700114 const Name& getRrLabel() const
115 {
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700116 return m_rrLabel;
117 }
118
shockjiang99ad3892014-08-03 14:56:13 -0700119 void setRrLabel(const Name& rrLabel)
120 {
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700121 m_rrLabel = rrLabel;
122 }
123
shockjiang99ad3892014-08-03 14:56:13 -0700124 const RR::RRType& getRrType() const
125 {
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700126 return m_rrType;
127 }
128
shockjiang99ad3892014-08-03 14:56:13 -0700129 void setRrType(const RR::RRType& rrType)
130 {
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700131 m_rrType = rrType;
132 }
133
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700134private:
135 template<bool T>
136 size_t
137 wireEncode(EncodingImpl<T> & block) const;
138
139public:
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700140 Interest
shockjianga5ae48c2014-07-27 23:21:41 -0700141 toInterest() const;
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700142
shockjianga5ae48c2014-07-27 23:21:41 -0700143 bool
144 fromInterest(const Name &name, const Interest& interest);
145
146 bool
147 fromInterest(const Interest& interest);
148
shockjiang99ad3892014-08-03 14:56:13 -0700149 const Name& getFowardingHint() const
150 {
151 return m_forwardingHint;
152 }
153
154 void setFowardingHint(const Name& fowardingHint)
155 {
156 m_forwardingHint = fowardingHint;
157 }
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700158
159public:
shockjiang99ad3892014-08-03 14:56:13 -0700160
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700161 Name m_authorityZone;
shockjiang99ad3892014-08-03 14:56:13 -0700162 Name m_forwardingHint;
163
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700164 enum QueryType m_queryType;
165 time::milliseconds m_interestLifetime;
166 Name m_rrLabel;
shockjianga5ae48c2014-07-27 23:21:41 -0700167 enum RR::RRType m_rrType;
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700168
shockjiang99ad3892014-08-03 14:56:13 -0700169
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700170 mutable Block m_wire;
171};
172
shockjianga5ae48c2014-07-27 23:21:41 -0700173inline std::ostream&
174operator<<(std::ostream& os, const Query& query)
175{
shockjiang99ad3892014-08-03 14:56:13 -0700176 os << "Query: authorityZone=" << query.getAuthorityZone().toUri()
177 << " queryType=" << Query::toString(query.getQueryType()) << " rrLabel="
178 << query.getRrLabel().toUri() << " rrType="
179 << RR::toString(query.getRrType());
shockjianga5ae48c2014-07-27 23:21:41 -0700180 return os;
181}
182
Alexander Afanasyev6e3d1ac2014-07-21 12:47:49 -0700183} // namespace ndns
184} // namespace ndn
185
186#endif // NDNS_QUERY_HPP