blob: 0c9d074d67143083e01553ee998493b14c29f99c [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 Shi38f4ce92016-08-04 10:01:52 +000027
Junxiao Shi1f481fa2017-01-26 15:14:43 +000028#include "execute-command-fixture.hpp"
29#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_AUTO_TEST_SUITE(TestFaceModule)
38
39BOOST_FIXTURE_TEST_SUITE(ShowCommand, ExecuteCommandFixture)
40
41using ndn::nfd::FaceQueryFilter;
42
43const std::string NORMAL_OUTPUT = std::string(R"TEXT(
44 faceid=256
45 remote=udp4://84.67.35.111:6363
46 local=udp4://79.91.49.215:6363
47counters={in={28975i 28232d 212n 13307258B} out={19525i 30993d 1038n 6231946B}}
48 flags={non-local on-demand point-to-point}
49)TEXT").substr(1);
50
51BOOST_AUTO_TEST_CASE(Normal)
52{
53 this->processInterest = [this] (const Interest& interest) {
54 Name datasetName("/localhost/nfd/faces/query");
55 FaceQueryFilter filter;
56 filter.setFaceId(256);
57 datasetName.append(filter.wireEncode());
58
59 FaceStatus payload;
60 payload.setFaceId(256)
61 .setRemoteUri("udp4://84.67.35.111:6363")
62 .setLocalUri("udp4://79.91.49.215:6363")
63 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
64 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
65 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
66 .setNInInterests(28975)
67 .setNInDatas(28232)
68 .setNInNacks(212)
69 .setNOutInterests(19525)
70 .setNOutDatas(30993)
71 .setNOutNacks(1038)
72 .setNInBytes(13307258)
73 .setNOutBytes(6231946);
74
75 this->sendDataset(datasetName, payload);
76 };
77
78 this->execute("face show 256");
79 BOOST_CHECK_EQUAL(exitCode, 0);
80 BOOST_CHECK(out.is_equal(NORMAL_OUTPUT));
81 BOOST_CHECK(err.is_empty());
82}
83
84BOOST_AUTO_TEST_CASE(NotFound)
85{
86 this->processInterest = [this] (const Interest& interest) {
87 this->sendEmptyDataset(interest.getName());
88 };
89
90 this->execute("face show 256");
91 BOOST_CHECK_EQUAL(exitCode, 3);
92 BOOST_CHECK(out.is_empty());
93 BOOST_CHECK(err.is_equal("Face 256 not found.\n"));
94}
95
96BOOST_AUTO_TEST_CASE(Error)
97{
98 this->processInterest = nullptr; // no response
99
100 this->execute("face show 256");
101 BOOST_CHECK_EQUAL(exitCode, 1);
102 BOOST_CHECK(out.is_empty());
103 BOOST_CHECK(err.is_equal("Error 10060 when fetching face information: Timeout\n"));
104}
105
106BOOST_AUTO_TEST_SUITE_END() // ShowCommand
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000107
108const std::string STATUS_XML = stripXmlSpaces(R"XML(
109 <faces>
110 <face>
111 <faceId>134</faceId>
112 <remoteUri>udp4://233.252.0.4:6363</remoteUri>
113 <localUri>udp4://192.0.2.1:6363</localUri>
114 <faceScope>non-local</faceScope>
115 <facePersistency>permanent</facePersistency>
116 <linkType>multi-access</linkType>
Eric Newberry6d932e82016-11-24 05:05:43 +0000117 <flags/>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000118 <packetCounters>
119 <incomingPackets>
120 <nInterests>22562</nInterests>
121 <nDatas>22031</nDatas>
122 <nNacks>63</nNacks>
123 </incomingPackets>
124 <outgoingPackets>
125 <nInterests>30121</nInterests>
126 <nDatas>20940</nDatas>
127 <nNacks>1218</nNacks>
128 </outgoingPackets>
129 </packetCounters>
130 <byteCounters>
131 <incomingBytes>2522915</incomingBytes>
132 <outgoingBytes>1353592</outgoingBytes>
133 </byteCounters>
134 </face>
135 <face>
136 <faceId>745</faceId>
137 <remoteUri>fd://75</remoteUri>
138 <localUri>unix:///var/run/nfd.sock</localUri>
139 <faceScope>local</faceScope>
140 <facePersistency>on-demand</facePersistency>
141 <linkType>point-to-point</linkType>
Eric Newberry6d932e82016-11-24 05:05:43 +0000142 <flags>
143 <localFieldsEnabled/>
144 </flags>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000145 <packetCounters>
146 <incomingPackets>
147 <nInterests>18998</nInterests>
148 <nDatas>26701</nDatas>
149 <nNacks>147</nNacks>
150 </incomingPackets>
151 <outgoingPackets>
152 <nInterests>34779</nInterests>
153 <nDatas>17028</nDatas>
154 <nNacks>1176</nNacks>
155 </outgoingPackets>
156 </packetCounters>
157 <byteCounters>
158 <incomingBytes>4672308</incomingBytes>
159 <outgoingBytes>8957187</outgoingBytes>
160 </byteCounters>
161 </face>
162 </faces>
163)XML");
164
165const std::string STATUS_TEXT =
166 "Faces:\n"
167 " faceid=134 remote=udp4://233.252.0.4:6363 local=udp4://192.0.2.1:6363"
168 " counters={in={22562i 22031d 63n 2522915B} out={30121i 20940d 1218n 1353592B}}"
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000169 " flags={non-local permanent multi-access}\n"
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000170 " faceid=745 remote=fd://75 local=unix:///var/run/nfd.sock"
171 " counters={in={18998i 26701d 147n 4672308B} out={34779i 17028d 1176n 8957187B}}"
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000172 " flags={local on-demand point-to-point local-fields}\n";
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000173
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000174BOOST_FIXTURE_TEST_CASE(Status, StatusFixture<FaceModule>)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000175{
176 this->fetchStatus();
177 FaceStatus payload1;
178 payload1.setFaceId(134)
179 .setRemoteUri("udp4://233.252.0.4:6363")
180 .setLocalUri("udp4://192.0.2.1:6363")
181 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
182 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT)
183 .setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS)
184 .setNInInterests(22562)
185 .setNInDatas(22031)
186 .setNInNacks(63)
187 .setNOutInterests(30121)
188 .setNOutDatas(20940)
189 .setNOutNacks(1218)
190 .setNInBytes(2522915)
191 .setNOutBytes(1353592);
192 FaceStatus payload2;
193 payload2.setFaceId(745)
194 .setRemoteUri("fd://75")
195 .setLocalUri("unix:///var/run/nfd.sock")
196 .setFaceScope(ndn::nfd::FACE_SCOPE_LOCAL)
197 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
198 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
Eric Newberry6d932e82016-11-24 05:05:43 +0000199 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000200 .setNInInterests(18998)
201 .setNInDatas(26701)
202 .setNInNacks(147)
203 .setNOutInterests(34779)
204 .setNOutDatas(17028)
205 .setNOutNacks(1176)
206 .setNInBytes(4672308)
207 .setNOutBytes(8957187);
208 this->sendDataset("/localhost/nfd/faces/list", payload1, payload2);
209 this->prepareStatusOutput();
210
211 BOOST_CHECK(statusXml.is_equal(STATUS_XML));
212 BOOST_CHECK(statusText.is_equal(STATUS_TEXT));
213}
214
215BOOST_AUTO_TEST_SUITE_END() // TestFaceModule
Junxiao Shi331ade72016-08-19 14:07:19 +0000216BOOST_AUTO_TEST_SUITE_END() // Nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000217
218} // namespace tests
Junxiao Shi331ade72016-08-19 14:07:19 +0000219} // namespace nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000220} // namespace tools
221} // namespace nfd