blob: 20d55140ea9dd871cffed8d7bd68da5b61cdb94d [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/face-module.hpp"
Junxiao Shi1d7fef52017-02-02 05:33:14 +000027#include <ndn-cxx/mgmt/nfd/face-query-filter.hpp>
Junxiao Shi38f4ce92016-08-04 10:01:52 +000028
Junxiao Shi1f481fa2017-01-26 15:14:43 +000029#include "execute-command-fixture.hpp"
30#include "status-fixture.hpp"
Junxiao Shi38f4ce92016-08-04 10:01:52 +000031
32namespace nfd {
33namespace tools {
Junxiao Shi331ade72016-08-19 14:07:19 +000034namespace nfdc {
Junxiao Shi38f4ce92016-08-04 10:01:52 +000035namespace tests {
36
Junxiao Shi1d7fef52017-02-02 05:33:14 +000037using ndn::nfd::FaceQueryFilter;
38
Junxiao Shi331ade72016-08-19 14:07:19 +000039BOOST_AUTO_TEST_SUITE(Nfdc)
Junxiao Shi1f481fa2017-01-26 15:14:43 +000040BOOST_AUTO_TEST_SUITE(TestFaceModule)
41
42BOOST_FIXTURE_TEST_SUITE(ShowCommand, ExecuteCommandFixture)
43
Junxiao Shi1f481fa2017-01-26 15:14:43 +000044const std::string NORMAL_OUTPUT = std::string(R"TEXT(
45 faceid=256
46 remote=udp4://84.67.35.111:6363
47 local=udp4://79.91.49.215:6363
48counters={in={28975i 28232d 212n 13307258B} out={19525i 30993d 1038n 6231946B}}
49 flags={non-local on-demand point-to-point}
50)TEXT").substr(1);
51
52BOOST_AUTO_TEST_CASE(Normal)
53{
54 this->processInterest = [this] (const Interest& interest) {
55 Name datasetName("/localhost/nfd/faces/query");
56 FaceQueryFilter filter;
57 filter.setFaceId(256);
58 datasetName.append(filter.wireEncode());
59
60 FaceStatus payload;
61 payload.setFaceId(256)
62 .setRemoteUri("udp4://84.67.35.111:6363")
63 .setLocalUri("udp4://79.91.49.215:6363")
64 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
65 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
66 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
67 .setNInInterests(28975)
68 .setNInDatas(28232)
69 .setNInNacks(212)
70 .setNOutInterests(19525)
71 .setNOutDatas(30993)
72 .setNOutNacks(1038)
73 .setNInBytes(13307258)
74 .setNOutBytes(6231946);
75
76 this->sendDataset(datasetName, payload);
77 };
78
79 this->execute("face show 256");
80 BOOST_CHECK_EQUAL(exitCode, 0);
81 BOOST_CHECK(out.is_equal(NORMAL_OUTPUT));
82 BOOST_CHECK(err.is_empty());
83}
84
85BOOST_AUTO_TEST_CASE(NotFound)
86{
87 this->processInterest = [this] (const Interest& interest) {
88 this->sendEmptyDataset(interest.getName());
89 };
90
91 this->execute("face show 256");
92 BOOST_CHECK_EQUAL(exitCode, 3);
93 BOOST_CHECK(out.is_empty());
94 BOOST_CHECK(err.is_equal("Face 256 not found.\n"));
95}
96
97BOOST_AUTO_TEST_CASE(Error)
98{
99 this->processInterest = nullptr; // no response
100
101 this->execute("face show 256");
102 BOOST_CHECK_EQUAL(exitCode, 1);
103 BOOST_CHECK(out.is_empty());
104 BOOST_CHECK(err.is_equal("Error 10060 when fetching face information: Timeout\n"));
105}
106
107BOOST_AUTO_TEST_SUITE_END() // ShowCommand
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000108
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000109BOOST_FIXTURE_TEST_SUITE(CreateCommand, ExecuteCommandFixture)
110
111BOOST_AUTO_TEST_CASE(Normal)
112{
113 this->processInterest = [this] (const Interest& interest) {
114 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/faces/create");
115 BOOST_REQUIRE(req.hasUri());
116 BOOST_CHECK_EQUAL(req.getUri(), "udp4://159.242.33.78:6363");
117 BOOST_REQUIRE(req.hasFacePersistency());
118 BOOST_CHECK_EQUAL(req.getFacePersistency(), FacePersistency::FACE_PERSISTENCY_PERSISTENT);
119
120 ControlParameters resp;
121 resp.setFaceId(2130)
122 .setUri("udp4://159.242.33.78:6363")
123 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT);
124 this->succeedCommand(resp);
125 };
126
127 this->execute("face create udp://159.242.33.78");
128 BOOST_CHECK_EQUAL(exitCode, 0);
129 BOOST_CHECK(out.is_equal("face-created id=2130 remote=udp4://159.242.33.78:6363 persistency=persistent\n"));
130 BOOST_CHECK(err.is_empty());
131}
132
133BOOST_AUTO_TEST_CASE(Error)
134{
135 this->processInterest = nullptr; // no response
136
137 this->execute("face create udp://159.242.33.78");
138 BOOST_CHECK_EQUAL(exitCode, 1);
139 BOOST_CHECK(out.is_empty());
140 BOOST_CHECK(err.is_equal("Error 10060 when creating face: request timed out\n"));
141}
142
143BOOST_AUTO_TEST_SUITE_END() // CreateCommand
144
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000145const std::string STATUS_XML = stripXmlSpaces(R"XML(
146 <faces>
147 <face>
148 <faceId>134</faceId>
149 <remoteUri>udp4://233.252.0.4:6363</remoteUri>
150 <localUri>udp4://192.0.2.1:6363</localUri>
151 <faceScope>non-local</faceScope>
152 <facePersistency>permanent</facePersistency>
153 <linkType>multi-access</linkType>
Eric Newberry6d932e82016-11-24 05:05:43 +0000154 <flags/>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000155 <packetCounters>
156 <incomingPackets>
157 <nInterests>22562</nInterests>
158 <nDatas>22031</nDatas>
159 <nNacks>63</nNacks>
160 </incomingPackets>
161 <outgoingPackets>
162 <nInterests>30121</nInterests>
163 <nDatas>20940</nDatas>
164 <nNacks>1218</nNacks>
165 </outgoingPackets>
166 </packetCounters>
167 <byteCounters>
168 <incomingBytes>2522915</incomingBytes>
169 <outgoingBytes>1353592</outgoingBytes>
170 </byteCounters>
171 </face>
172 <face>
173 <faceId>745</faceId>
174 <remoteUri>fd://75</remoteUri>
175 <localUri>unix:///var/run/nfd.sock</localUri>
176 <faceScope>local</faceScope>
177 <facePersistency>on-demand</facePersistency>
178 <linkType>point-to-point</linkType>
Eric Newberry6d932e82016-11-24 05:05:43 +0000179 <flags>
180 <localFieldsEnabled/>
181 </flags>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000182 <packetCounters>
183 <incomingPackets>
184 <nInterests>18998</nInterests>
185 <nDatas>26701</nDatas>
186 <nNacks>147</nNacks>
187 </incomingPackets>
188 <outgoingPackets>
189 <nInterests>34779</nInterests>
190 <nDatas>17028</nDatas>
191 <nNacks>1176</nNacks>
192 </outgoingPackets>
193 </packetCounters>
194 <byteCounters>
195 <incomingBytes>4672308</incomingBytes>
196 <outgoingBytes>8957187</outgoingBytes>
197 </byteCounters>
198 </face>
199 </faces>
200)XML");
201
202const std::string STATUS_TEXT =
203 "Faces:\n"
204 " faceid=134 remote=udp4://233.252.0.4:6363 local=udp4://192.0.2.1:6363"
205 " counters={in={22562i 22031d 63n 2522915B} out={30121i 20940d 1218n 1353592B}}"
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000206 " flags={non-local permanent multi-access}\n"
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000207 " faceid=745 remote=fd://75 local=unix:///var/run/nfd.sock"
208 " counters={in={18998i 26701d 147n 4672308B} out={34779i 17028d 1176n 8957187B}}"
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000209 " flags={local on-demand point-to-point local-fields}\n";
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000210
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000211BOOST_FIXTURE_TEST_CASE(Status, StatusFixture<FaceModule>)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000212{
213 this->fetchStatus();
214 FaceStatus payload1;
215 payload1.setFaceId(134)
216 .setRemoteUri("udp4://233.252.0.4:6363")
217 .setLocalUri("udp4://192.0.2.1:6363")
218 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
219 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT)
220 .setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS)
221 .setNInInterests(22562)
222 .setNInDatas(22031)
223 .setNInNacks(63)
224 .setNOutInterests(30121)
225 .setNOutDatas(20940)
226 .setNOutNacks(1218)
227 .setNInBytes(2522915)
228 .setNOutBytes(1353592);
229 FaceStatus payload2;
230 payload2.setFaceId(745)
231 .setRemoteUri("fd://75")
232 .setLocalUri("unix:///var/run/nfd.sock")
233 .setFaceScope(ndn::nfd::FACE_SCOPE_LOCAL)
234 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
235 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
Eric Newberry6d932e82016-11-24 05:05:43 +0000236 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000237 .setNInInterests(18998)
238 .setNInDatas(26701)
239 .setNInNacks(147)
240 .setNOutInterests(34779)
241 .setNOutDatas(17028)
242 .setNOutNacks(1176)
243 .setNInBytes(4672308)
244 .setNOutBytes(8957187);
245 this->sendDataset("/localhost/nfd/faces/list", payload1, payload2);
246 this->prepareStatusOutput();
247
248 BOOST_CHECK(statusXml.is_equal(STATUS_XML));
249 BOOST_CHECK(statusText.is_equal(STATUS_TEXT));
250}
251
252BOOST_AUTO_TEST_SUITE_END() // TestFaceModule
Junxiao Shi331ade72016-08-19 14:07:19 +0000253BOOST_AUTO_TEST_SUITE_END() // Nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000254
255} // namespace tests
Junxiao Shi331ade72016-08-19 14:07:19 +0000256} // namespace nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000257} // namespace tools
258} // namespace nfd