blob: 04c2b5f1674f2beabbd4d327b48a2522a0d41d3c [file] [log] [blame]
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi1f481fa2017-01-26 15:14:43 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Junxiao Shi38f4ce92016-08-04 10:01:52 +00004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
Junxiao Shi331ade72016-08-19 14:07:19 +000026#include "nfdc/rib-module.hpp"
Junxiao Shi38f4ce92016-08-04 10:01:52 +000027
Junxiao Shi918e5d42017-02-25 03:58:21 +000028#include "execute-command-fixture.hpp"
Junxiao Shi1f481fa2017-01-26 15:14:43 +000029#include "status-fixture.hpp"
Junxiao Shi38f4ce92016-08-04 10:01:52 +000030
31namespace nfd {
32namespace tools {
Junxiao Shi331ade72016-08-19 14:07:19 +000033namespace nfdc {
Junxiao Shi38f4ce92016-08-04 10:01:52 +000034namespace tests {
35
Junxiao Shi331ade72016-08-19 14:07:19 +000036BOOST_AUTO_TEST_SUITE(Nfdc)
Junxiao Shi1f481fa2017-01-26 15:14:43 +000037BOOST_FIXTURE_TEST_SUITE(TestRibModule, StatusFixture<RibModule>)
Junxiao Shi38f4ce92016-08-04 10:01:52 +000038
Junxiao Shi918e5d42017-02-25 03:58:21 +000039BOOST_FIXTURE_TEST_SUITE(AddCommand, ExecuteCommandFixture)
40
41BOOST_AUTO_TEST_CASE(NormalByFaceId)
42{
43 this->processInterest = [this] (const Interest& interest) {
44 if (this->respondFaceQuery(interest)) {
45 return;
46 }
47
48 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/rib/register");
49 ndn::nfd::RibRegisterCommand cmd;
50 cmd.validateRequest(req);
51 cmd.applyDefaultsToRequest(req);
52 BOOST_CHECK_EQUAL(req.getName(), "/vxXoEaWeDB");
53 BOOST_CHECK_EQUAL(req.getFaceId(), 10156);
54 BOOST_CHECK_EQUAL(req.getOrigin(), ndn::nfd::ROUTE_ORIGIN_STATIC);
55 BOOST_CHECK_EQUAL(req.getCost(), 0);
56 BOOST_CHECK_EQUAL(req.getFlags(), ndn::nfd::ROUTE_FLAGS_NONE);
57 BOOST_CHECK_EQUAL(req.hasExpirationPeriod(), false);
58
59 this->succeedCommand(req);
60 };
61
62 this->execute("route add /vxXoEaWeDB 10156 no-inherit");
63 BOOST_CHECK_EQUAL(exitCode, 0);
64 BOOST_CHECK(out.is_equal("route-add-accepted prefix=/vxXoEaWeDB nexthop=10156 origin=255 "
65 "cost=0 flags=none expires=never\n"));
66 BOOST_CHECK(err.is_empty());
67}
68
69BOOST_AUTO_TEST_CASE(NormalByFaceUri)
70{
71 this->processInterest = [this] (const Interest& interest) {
72 if (this->respondFaceQuery(interest)) {
73 return;
74 }
75
76 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/rib/register");
77 ndn::nfd::RibRegisterCommand cmd;
78 cmd.validateRequest(req);
79 cmd.applyDefaultsToRequest(req);
80 BOOST_CHECK_EQUAL(req.getName(), "/FLQAsaYnYf");
81 BOOST_CHECK_EQUAL(req.getFaceId(), 2249);
82 BOOST_CHECK_EQUAL(req.getOrigin(), 17591);
83 BOOST_CHECK_EQUAL(req.getCost(), 702);
84 BOOST_CHECK_EQUAL(req.getFlags(), ndn::nfd::ROUTE_FLAG_CHILD_INHERIT |
85 ndn::nfd::ROUTE_FLAG_CAPTURE);
86 BOOST_REQUIRE_EQUAL(req.hasExpirationPeriod(), true);
87 BOOST_REQUIRE_EQUAL(req.getExpirationPeriod(), time::milliseconds(727411987));
88
89 ControlParameters resp = req;
90 resp.setExpirationPeriod(time::milliseconds(727411154)); // server side may change expiration
91 this->succeedCommand(resp);
92 };
93
94 this->execute("route add /FLQAsaYnYf tcp4://32.121.182.82:6363 "
95 "origin 17591 cost 702 capture expires 727411987");
96 BOOST_CHECK_EQUAL(exitCode, 0);
97 BOOST_CHECK(out.is_equal("route-add-accepted prefix=/FLQAsaYnYf nexthop=2249 origin=17591 "
98 "cost=702 flags=child-inherit|capture expires=727411154ms\n"));
99 BOOST_CHECK(err.is_empty());
100}
101
102BOOST_AUTO_TEST_CASE(FaceNotExist)
103{
104 this->processInterest = [this] (const Interest& interest) {
105 BOOST_CHECK(this->respondFaceQuery(interest));
106 };
107
108 this->execute("route add /GJiKDus5i 23728");
109 BOOST_CHECK_EQUAL(exitCode, 3);
110 BOOST_CHECK(out.is_empty());
111 BOOST_CHECK(err.is_equal("Face not found\n"));
112}
113
114BOOST_AUTO_TEST_CASE(Ambiguous)
115{
116 this->processInterest = [this] (const Interest& interest) {
117 BOOST_CHECK(this->respondFaceQuery(interest));
118 };
119
120 this->execute("route add /BQqjjnVsz udp4://225.131.75.231:56363");
121 BOOST_CHECK_EQUAL(exitCode, 5);
122 BOOST_CHECK(out.is_empty());
123 BOOST_CHECK(err.is_equal("Multiple faces match specified remote FaceUri. "
124 "Re-run the command with a FaceId: "
125 "6720 (local=udp4://202.83.168.28:56363), "
126 "31066 (local=udp4://25.90.26.32:56363)\n"));
127}
128
129BOOST_AUTO_TEST_CASE(ErrorCanonization)
130{
131 this->execute("route add /bxJfGsVtDt udp6://32.38.164.64:10445");
132 BOOST_CHECK_EQUAL(exitCode, 4);
133 BOOST_CHECK(out.is_empty());
134 BOOST_CHECK(err.is_equal("Error during remote FaceUri canonization: "
135 "No endpoints match the specified address selector\n"));
136}
137
138BOOST_AUTO_TEST_CASE(ErrorDataset)
139{
140 this->processInterest = nullptr; // no response to dataset or command
141
142 this->execute("route add /q1Qf7go7 udp://159.242.33.78");
143 BOOST_CHECK_EQUAL(exitCode, 1);
144 BOOST_CHECK(out.is_empty());
145 BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout\n"));
146}
147
148BOOST_AUTO_TEST_CASE(ErrorCommand)
149{
150 this->processInterest = [this] (const Interest& interest) {
151 if (this->respondFaceQuery(interest)) {
152 return;
153 }
154
155 MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/rib/register");
156 // no response to command
157 };
158
159 this->execute("route add /bYiMbEuE 10156");
160 BOOST_CHECK_EQUAL(exitCode, 1);
161 BOOST_CHECK(out.is_empty());
162 BOOST_CHECK(err.is_equal("Error 10060 when adding route: request timed out\n"));
163}
164
165BOOST_AUTO_TEST_SUITE_END() // AddCommand
166
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000167const std::string STATUS_XML = stripXmlSpaces(R"XML(
168 <rib>
169 <ribEntry>
170 <prefix>/</prefix>
171 <routes>
172 <route>
173 <faceId>262</faceId>
174 <origin>255</origin>
175 <cost>9</cost>
176 <flags>
177 <ribCapture/>
178 </flags>
179 </route>
180 <route>
181 <faceId>272</faceId>
182 <origin>255</origin>
183 <cost>50</cost>
184 <flags/>
185 </route>
186 <route>
187 <faceId>274</faceId>
188 <origin>255</origin>
189 <cost>78</cost>
190 <flags>
191 <childInherit/>
192 <ribCapture/>
193 </flags>
194 </route>
195 <route>
196 <faceId>276</faceId>
197 <origin>255</origin>
198 <cost>79</cost>
199 <flags>
200 <childInherit/>
201 </flags>
202 <expirationPeriod>PT47S</expirationPeriod>
203 </route>
204 </routes>
205 </ribEntry>
206 <ribEntry>
207 <prefix>/localhost/nfd</prefix>
208 <routes>
209 <route>
210 <faceId>258</faceId>
211 <origin>0</origin>
212 <cost>0</cost>
213 <flags>
214 <childInherit/>
215 </flags>
216 </route>
217 </routes>
218 </ribEntry>
219 </rib>
220)XML");
221
222const std::string STATUS_TEXT =
223 "RIB:\n"
224 " / route={faceid=262 (origin=255 cost=9 RibCapture), faceid=272 (origin=255 cost=50), "
225 "faceid=274 (origin=255 cost=78 ChildInherit RibCapture), "
226 "faceid=276 (origin=255 cost=79 expires=47s ChildInherit)}\n"
227 " /localhost/nfd route={faceid=258 (origin=0 cost=0 ChildInherit)}\n";
228
229BOOST_AUTO_TEST_CASE(Status)
230{
231 this->fetchStatus();
232 RibEntry payload1;
233 payload1.setName("/")
234 .addRoute(Route().setFaceId(262)
235 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
236 .setCost(9)
237 .setFlags(ndn::nfd::ROUTE_FLAG_CAPTURE))
238 .addRoute(Route().setFaceId(272)
239 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
240 .setCost(50)
241 .setFlags(ndn::nfd::ROUTE_FLAGS_NONE))
242 .addRoute(Route().setFaceId(274)
243 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
244 .setCost(78)
245 .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE))
246 .addRoute(Route().setFaceId(276)
247 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
248 .setCost(79)
249 .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT)
250 .setExpirationPeriod(time::milliseconds(47292)));
251 RibEntry payload2;
252 payload2.setName("/localhost/nfd")
253 .addRoute(Route().setFaceId(258)
254 .setOrigin(ndn::nfd::ROUTE_ORIGIN_APP)
255 .setCost(0)
256 .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT));
257 this->sendDataset("/localhost/nfd/rib/list", payload1, payload2);
258 this->prepareStatusOutput();
259
260 BOOST_CHECK(statusXml.is_equal(STATUS_XML));
261 BOOST_CHECK(statusText.is_equal(STATUS_TEXT));
262}
263
264BOOST_AUTO_TEST_SUITE_END() // TestRibModule
Junxiao Shi331ade72016-08-19 14:07:19 +0000265BOOST_AUTO_TEST_SUITE_END() // Nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000266
267} // namespace tests
Junxiao Shi331ade72016-08-19 14:07:19 +0000268} // namespace nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000269} // namespace tools
270} // namespace nfd