blob: 93a6563c9a9b70ac89f98d9c130275f35f5baf18 [file] [log] [blame]
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry84d3adc2017-08-09 23:31:40 -04002/*
Eric Newberryde332452018-01-30 11:45:32 -07003 * Copyright (c) 2014-2018, 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 Shi38f4ce92016-08-04 10:01:52 +000026#include "face-module.hpp"
Junxiao Shi05dd4442017-02-06 22:50:07 +000027#include "find-face.hpp"
Junxiao Shi38f4ce92016-08-04 10:01:52 +000028
29namespace nfd {
30namespace tools {
Junxiao Shi331ade72016-08-19 14:07:19 +000031namespace nfdc {
Junxiao Shi38f4ce92016-08-04 10:01:52 +000032
33void
Junxiao Shi1f481fa2017-01-26 15:14:43 +000034FaceModule::registerCommands(CommandParser& parser)
35{
Junxiao Shi36e54292017-02-17 18:43:16 +000036 CommandDefinition defFaceList("face", "list");
37 defFaceList
38 .setTitle("print face list")
39 .addArg("remote", ArgValueType::FACE_URI, Required::NO, Positional::YES)
40 .addArg("local", ArgValueType::FACE_URI, Required::NO, Positional::NO)
41 .addArg("scheme", ArgValueType::STRING, Required::NO, Positional::NO, "scheme");
42 parser.addCommand(defFaceList, &FaceModule::list);
Davide Pesaventod2147442018-02-19 23:58:17 -050043 parser.addAlias("face", "list", "");
Junxiao Shi36e54292017-02-17 18:43:16 +000044
Junxiao Shi1f481fa2017-01-26 15:14:43 +000045 CommandDefinition defFaceShow("face", "show");
46 defFaceShow
47 .setTitle("show face information")
48 .addArg("id", ArgValueType::UNSIGNED, Required::YES, Positional::YES);
49 parser.addCommand(defFaceShow, &FaceModule::show);
Junxiao Shi1d7fef52017-02-02 05:33:14 +000050
51 CommandDefinition defFaceCreate("face", "create");
52 defFaceCreate
53 .setTitle("create a face")
54 .addArg("remote", ArgValueType::FACE_URI, Required::YES, Positional::YES)
Junxiao Shi0d976922017-04-01 14:35:21 +000055 .addArg("persistency", ArgValueType::FACE_PERSISTENCY, Required::NO, Positional::YES)
Eric Newberry84d3adc2017-08-09 23:31:40 -040056 .addArg("local", ArgValueType::FACE_URI, Required::NO, Positional::NO)
Eric Newberryde332452018-01-30 11:45:32 -070057 .addArg("reliability", ArgValueType::BOOLEAN, Required::NO, Positional::NO)
58 .addArg("congestion-marking", ArgValueType::BOOLEAN, Required::NO, Positional::NO)
59 .addArg("congestion-marking-interval", ArgValueType::UNSIGNED, Required::NO, Positional::NO)
60 .addArg("default-congestion-threshold", ArgValueType::UNSIGNED, Required::NO, Positional::NO);
Junxiao Shi1d7fef52017-02-02 05:33:14 +000061 parser.addCommand(defFaceCreate, &FaceModule::create);
Junxiao Shi05dd4442017-02-06 22:50:07 +000062
63 CommandDefinition defFaceDestroy("face", "destroy");
64 defFaceDestroy
65 .setTitle("destroy a face")
66 .addArg("face", ArgValueType::FACE_ID_OR_URI, Required::YES, Positional::YES);
67 parser.addCommand(defFaceDestroy, &FaceModule::destroy);
Junxiao Shi1f481fa2017-01-26 15:14:43 +000068}
69
70void
Junxiao Shi36e54292017-02-17 18:43:16 +000071FaceModule::list(ExecuteContext& ctx)
72{
73 auto remoteUri = ctx.args.getOptional<FaceUri>("remote");
74 auto localUri = ctx.args.getOptional<FaceUri>("local");
75 auto uriScheme = ctx.args.getOptional<std::string>("scheme");
76
77 FaceQueryFilter filter;
78 if (remoteUri) {
79 filter.setRemoteUri(remoteUri->toString());
80 }
81 if (localUri) {
82 filter.setLocalUri(localUri->toString());
83 }
84 if (uriScheme) {
85 filter.setUriScheme(*uriScheme);
86 }
87
88 FindFace findFace(ctx);
89 FindFace::Code res = findFace.execute(filter, true);
90
91 ctx.exitCode = static_cast<int>(res);
92 switch (res) {
93 case FindFace::Code::OK:
94 for (const FaceStatus& item : findFace.getResults()) {
95 formatItemText(ctx.out, item, false);
96 ctx.out << '\n';
97 }
98 break;
99 case FindFace::Code::ERROR:
100 case FindFace::Code::NOT_FOUND:
101 case FindFace::Code::CANONIZE_ERROR:
102 ctx.err << findFace.getErrorReason() << '\n';
103 break;
104 default:
105 BOOST_ASSERT_MSG(false, "unexpected FindFace result");
106 break;
107 }
108}
109
110void
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000111FaceModule::show(ExecuteContext& ctx)
112{
113 uint64_t faceId = ctx.args.get<uint64_t>("id");
114
Junxiao Shi8f803f22017-02-10 03:04:28 +0000115 FindFace findFace(ctx);
116 FindFace::Code res = findFace.execute(faceId);
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000117
Junxiao Shi8f803f22017-02-10 03:04:28 +0000118 ctx.exitCode = static_cast<int>(res);
119 switch (res) {
120 case FindFace::Code::OK:
121 formatItemText(ctx.out, findFace.getFaceStatus(), true);
122 break;
123 case FindFace::Code::ERROR:
124 case FindFace::Code::NOT_FOUND:
125 ctx.err << findFace.getErrorReason() << '\n';
126 break;
127 default:
128 BOOST_ASSERT_MSG(false, "unexpected FindFace result");
129 break;
130 }
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000131}
132
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000133/** \brief order persistency in NONE < ON_DEMAND < PERSISTENCY < PERMANENT
134 */
135static bool
136persistencyLessThan(FacePersistency x, FacePersistency y)
137{
138 switch (x) {
139 case FacePersistency::FACE_PERSISTENCY_NONE:
140 return y != FacePersistency::FACE_PERSISTENCY_NONE;
141 case FacePersistency::FACE_PERSISTENCY_ON_DEMAND:
142 return y == FacePersistency::FACE_PERSISTENCY_PERSISTENT ||
143 y == FacePersistency::FACE_PERSISTENCY_PERMANENT;
144 case FacePersistency::FACE_PERSISTENCY_PERSISTENT:
145 return y == FacePersistency::FACE_PERSISTENCY_PERMANENT;
146 case FacePersistency::FACE_PERSISTENCY_PERMANENT:
147 return false;
148 }
149 return static_cast<int>(x) < static_cast<int>(y);
150}
151
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000152void
153FaceModule::create(ExecuteContext& ctx)
154{
Junxiao Shi0d976922017-04-01 14:35:21 +0000155 auto remoteUri = ctx.args.get<FaceUri>("remote");
156 auto localUri = ctx.args.getOptional<FaceUri>("local");
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000157 auto persistency = ctx.args.get<FacePersistency>("persistency", FacePersistency::FACE_PERSISTENCY_PERSISTENT);
Eric Newberry84d3adc2017-08-09 23:31:40 -0400158 auto lpReliability = ctx.args.getTribool("reliability");
Eric Newberryde332452018-01-30 11:45:32 -0700159 auto congestionMarking = ctx.args.getTribool("congestion-marking");
160 auto baseCongestionMarkingIntervalMs = ctx.args.getOptional<uint64_t>("congestion-marking-interval");
161 auto defaultCongestionThreshold = ctx.args.getOptional<uint64_t>("default-congestion-threshold");
Eric Newberry84d3adc2017-08-09 23:31:40 -0400162
Junxiao Shi0d976922017-04-01 14:35:21 +0000163 FaceUri canonicalRemote;
164 ndn::optional<FaceUri> canonicalLocal;
165
166 auto handleCanonizeError = [&] (const FaceUri& faceUri, const std::string& error) {
167 ctx.exitCode = 4;
168 ctx.err << "Error when canonizing '" << faceUri << "': " << error << '\n';
169 };
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000170
171 auto printPositiveResult = [&] (const std::string& actionSummary, const ControlParameters& resp) {
172 text::ItemAttributes ia;
173 ctx.out << actionSummary << ' '
174 << ia("id") << resp.getFaceId()
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000175 << ia("local") << resp.getLocalUri()
176 << ia("remote") << resp.getUri()
Eric Newberryde332452018-01-30 11:45:32 -0700177 << ia("persistency") << resp.getFacePersistency();
178 printFaceParams(ctx.out, ia, resp);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000179 };
180
Eric Newberry84d3adc2017-08-09 23:31:40 -0400181 auto updateFace = [&printPositiveResult] (ControlParameters respParams, ControlParameters resp) {
182 // faces/update response does not have FaceUris, copy from faces/create response
183 resp.setLocalUri(respParams.getLocalUri())
184 .setUri(respParams.getUri());
185 printPositiveResult("face-updated", resp);
186 };
187
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000188 auto handle409 = [&] (const ControlResponse& resp) {
189 ControlParameters respParams(resp.getBody());
Junxiao Shi0d976922017-04-01 14:35:21 +0000190 if (respParams.getUri() != canonicalRemote.toString()) {
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000191 // we are conflicting with a different face, which is a general error
192 return false;
193 }
194
195 if (persistencyLessThan(respParams.getFacePersistency(), persistency)) {
196 // need to upgrade persistency
Eric Newberry84d3adc2017-08-09 23:31:40 -0400197 ControlParameters params;
198 params.setFaceId(respParams.getFaceId()).setFacePersistency(persistency);
199 if (!boost::logic::indeterminate(lpReliability)) {
200 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, lpReliability);
201 }
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000202 ctx.controller.start<ndn::nfd::FaceUpdateCommand>(
Eric Newberry84d3adc2017-08-09 23:31:40 -0400203 params,
204 bind(updateFace, respParams, _1),
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000205 ctx.makeCommandFailureHandler("upgrading face persistency"),
206 ctx.makeCommandOptions());
207 }
Eric Newberryde332452018-01-30 11:45:32 -0700208 else if ((!boost::logic::indeterminate(lpReliability) &&
209 lpReliability != respParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) ||
210 (!boost::logic::indeterminate(congestionMarking) &&
211 congestionMarking != respParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) ||
212 baseCongestionMarkingIntervalMs ||
213 defaultCongestionThreshold) {
Eric Newberry84d3adc2017-08-09 23:31:40 -0400214 ControlParameters params;
Eric Newberryde332452018-01-30 11:45:32 -0700215 params.setFaceId(respParams.getFaceId());
216
217 if (!boost::logic::indeterminate(lpReliability) &&
218 lpReliability != respParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
219 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, lpReliability);
220 }
221 if (!boost::logic::indeterminate(congestionMarking) &&
222 congestionMarking != respParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) {
223 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, congestionMarking);
224 }
225
226 if (baseCongestionMarkingIntervalMs) {
227 params.setBaseCongestionMarkingInterval(time::milliseconds(*baseCongestionMarkingIntervalMs));
228 }
229
230 if (defaultCongestionThreshold) {
231 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
232 }
233
Eric Newberry84d3adc2017-08-09 23:31:40 -0400234 ctx.controller.start<ndn::nfd::FaceUpdateCommand>(
235 params,
236 bind(updateFace, respParams, _1),
Eric Newberryde332452018-01-30 11:45:32 -0700237 ctx.makeCommandFailureHandler("updating face"),
Eric Newberry84d3adc2017-08-09 23:31:40 -0400238 ctx.makeCommandOptions());
239 }
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000240 else {
Eric Newberry84d3adc2017-08-09 23:31:40 -0400241 // don't do anything
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000242 printPositiveResult("face-exists", respParams);
243 }
244 return true;
245 };
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000246
Junxiao Shi0d976922017-04-01 14:35:21 +0000247 auto doCreateFace = [&] {
248 ControlParameters params;
249 params.setUri(canonicalRemote.toString());
250 if (canonicalLocal) {
251 params.setLocalUri(canonicalLocal->toString());
252 }
253 params.setFacePersistency(persistency);
Eric Newberry84d3adc2017-08-09 23:31:40 -0400254 if (!boost::logic::indeterminate(lpReliability)) {
255 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, lpReliability);
256 }
Eric Newberryde332452018-01-30 11:45:32 -0700257 if (!boost::logic::indeterminate(congestionMarking)) {
258 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, congestionMarking);
259 }
260 if (baseCongestionMarkingIntervalMs) {
261 params.setBaseCongestionMarkingInterval(time::milliseconds(*baseCongestionMarkingIntervalMs));
262 }
263 if (defaultCongestionThreshold) {
264 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
265 }
Junxiao Shi0d976922017-04-01 14:35:21 +0000266
267 ctx.controller.start<ndn::nfd::FaceCreateCommand>(
268 params,
269 bind(printPositiveResult, "face-created", _1),
270 [&] (const ControlResponse& resp) {
271 if (resp.getCode() == 409 && handle409(resp)) {
272 return;
273 }
274 ctx.makeCommandFailureHandler("creating face")(resp); // invoke general error handler
275 },
276 ctx.makeCommandOptions());
277 };
278
279 remoteUri.canonize(
280 [&] (const FaceUri& canonicalUri) {
281 canonicalRemote = canonicalUri;
282 if (localUri) {
283 localUri->canonize(
284 [&] (const FaceUri& canonicalUri) {
285 canonicalLocal = canonicalUri;
286 doCreateFace();
287 },
288 bind(handleCanonizeError, *localUri, _1),
289 ctx.face.getIoService(), ctx.getTimeout());
290 }
291 else {
292 doCreateFace();
293 }
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000294 },
Junxiao Shi0d976922017-04-01 14:35:21 +0000295 bind(handleCanonizeError, remoteUri, _1),
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000296 ctx.face.getIoService(), ctx.getTimeout());
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000297
298 ctx.face.processEvents();
299}
300
301void
Junxiao Shi05dd4442017-02-06 22:50:07 +0000302FaceModule::destroy(ExecuteContext& ctx)
303{
Junxiao Shi918e5d42017-02-25 03:58:21 +0000304 const boost::any& faceIdOrUri = ctx.args.at("face");
Junxiao Shi05dd4442017-02-06 22:50:07 +0000305
306 FindFace findFace(ctx);
Junxiao Shi918e5d42017-02-25 03:58:21 +0000307 FindFace::Code res = findFace.execute(faceIdOrUri);
Junxiao Shi05dd4442017-02-06 22:50:07 +0000308
309 ctx.exitCode = static_cast<int>(res);
310 switch (res) {
311 case FindFace::Code::OK:
312 break;
313 case FindFace::Code::ERROR:
314 case FindFace::Code::CANONIZE_ERROR:
315 case FindFace::Code::NOT_FOUND:
316 ctx.err << findFace.getErrorReason() << '\n';
317 return;
318 case FindFace::Code::AMBIGUOUS:
319 ctx.err << "Multiple faces match specified remote FaceUri. Re-run the command with a FaceId:";
320 findFace.printDisambiguation(ctx.err, FindFace::DisambiguationStyle::LOCAL_URI);
321 ctx.err << '\n';
322 return;
323 default:
324 BOOST_ASSERT_MSG(false, "unexpected FindFace result");
325 return;
326 }
327
328 const FaceStatus& face = findFace.getFaceStatus();
329
330 ctx.controller.start<ndn::nfd::FaceDestroyCommand>(
331 ControlParameters().setFaceId(face.getFaceId()),
332 [&] (const ControlParameters& resp) {
333 ctx.out << "face-destroyed ";
334 text::ItemAttributes ia;
335 ctx.out << ia("id") << face.getFaceId()
336 << ia("local") << face.getLocalUri()
337 << ia("remote") << face.getRemoteUri()
Eric Newberryde332452018-01-30 11:45:32 -0700338 << ia("persistency") << face.getFacePersistency();
339 printFaceParams(ctx.out, ia, resp);
Junxiao Shi05dd4442017-02-06 22:50:07 +0000340 },
341 ctx.makeCommandFailureHandler("destroying face"),
342 ctx.makeCommandOptions());
343
344 ctx.face.processEvents();
345}
346
347void
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000348FaceModule::fetchStatus(Controller& controller,
349 const function<void()>& onSuccess,
Junxiao Shi29b41282016-08-22 03:47:02 +0000350 const Controller::DatasetFailCallback& onFailure,
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000351 const CommandOptions& options)
352{
353 controller.fetch<ndn::nfd::FaceDataset>(
354 [this, onSuccess] (const std::vector<FaceStatus>& result) {
355 m_status = result;
356 onSuccess();
357 },
358 onFailure, options);
359}
360
361void
362FaceModule::formatStatusXml(std::ostream& os) const
363{
364 os << "<faces>";
365 for (const FaceStatus& item : m_status) {
366 this->formatItemXml(os, item);
367 }
368 os << "</faces>";
369}
370
371void
372FaceModule::formatItemXml(std::ostream& os, const FaceStatus& item) const
373{
374 os << "<face>";
375
376 os << "<faceId>" << item.getFaceId() << "</faceId>";
377 os << "<remoteUri>" << xml::Text{item.getRemoteUri()} << "</remoteUri>";
378 os << "<localUri>" << xml::Text{item.getLocalUri()} << "</localUri>";
379
380 if (item.hasExpirationPeriod()) {
381 os << "<expirationPeriod>" << xml::formatDuration(item.getExpirationPeriod())
382 << "</expirationPeriod>";
383 }
384 os << "<faceScope>" << item.getFaceScope() << "</faceScope>";
385 os << "<facePersistency>" << item.getFacePersistency() << "</facePersistency>";
386 os << "<linkType>" << item.getLinkType() << "</linkType>";
387
Eric Newberryde332452018-01-30 11:45:32 -0700388 if (!item.hasBaseCongestionMarkingInterval() && !item.hasDefaultCongestionThreshold()) {
389 os << "<congestion/>";
390 }
391 else {
392 os << "<congestion>";
393 if (item.hasBaseCongestionMarkingInterval()) {
394 os << "<baseMarkingInterval>" << xml::formatDuration(item.getBaseCongestionMarkingInterval())
395 << "</baseMarkingInterval>";
396 }
397 if (item.hasDefaultCongestionThreshold()) {
398 os << "<defaultThreshold>" << item.getDefaultCongestionThreshold() << "</defaultThreshold>";
399 }
400 os << "</congestion>";
401 }
402
Eric Newberry6d932e82016-11-24 05:05:43 +0000403 if (item.getFlags() == 0) {
404 os << "<flags/>";
405 }
406 else {
407 os << "<flags>";
408 if (item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)) {
409 os << "<localFieldsEnabled/>";
410 }
Eric Newberry84d3adc2017-08-09 23:31:40 -0400411 if (item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
412 os << "<lpReliabilityEnabled/>";
413 }
Eric Newberryde332452018-01-30 11:45:32 -0700414 if (item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) {
415 os << "<congestionMarkingEnabled/>";
416 }
Eric Newberry6d932e82016-11-24 05:05:43 +0000417 os << "</flags>";
418 }
419
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000420 os << "<packetCounters>";
421 os << "<incomingPackets>"
422 << "<nInterests>" << item.getNInInterests() << "</nInterests>"
Junxiao Shif03d4792017-04-06 16:41:22 +0000423 << "<nData>" << item.getNInData() << "</nData>"
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000424 << "<nNacks>" << item.getNInNacks() << "</nNacks>"
425 << "</incomingPackets>";
426 os << "<outgoingPackets>"
427 << "<nInterests>" << item.getNOutInterests() << "</nInterests>"
Junxiao Shif03d4792017-04-06 16:41:22 +0000428 << "<nData>" << item.getNOutData() << "</nData>"
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000429 << "<nNacks>" << item.getNOutNacks() << "</nNacks>"
430 << "</outgoingPackets>";
431 os << "</packetCounters>";
432
433 os << "<byteCounters>";
434 os << "<incomingBytes>" << item.getNInBytes() << "</incomingBytes>";
435 os << "<outgoingBytes>" << item.getNOutBytes() << "</outgoingBytes>";
436 os << "</byteCounters>";
437
438 os << "</face>";
439}
440
441void
442FaceModule::formatStatusText(std::ostream& os) const
443{
444 os << "Faces:\n";
445 for (const FaceStatus& item : m_status) {
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000446 os << " ";
447 formatItemText(os, item, false);
448 os << '\n';
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000449 }
450}
451
452void
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000453FaceModule::formatItemText(std::ostream& os, const FaceStatus& item, bool wantMultiLine)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000454{
Eric Newberryde332452018-01-30 11:45:32 -0700455 text::ItemAttributes ia(wantMultiLine, 10);
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000456
457 os << ia("faceid") << item.getFaceId();
458 os << ia("remote") << item.getRemoteUri();
459 os << ia("local") << item.getLocalUri();
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000460
461 if (item.hasExpirationPeriod()) {
Eric Newberryde332452018-01-30 11:45:32 -0700462 os << ia("expires") << text::formatDuration<time::seconds>(item.getExpirationPeriod());
463 }
464
465 if (item.hasBaseCongestionMarkingInterval() || item.hasDefaultCongestionThreshold()) {
466 os << ia("congestion") << "{";
467 text::Separator congestionSep("", " ");
468 if (item.hasBaseCongestionMarkingInterval()) {
469 os << congestionSep << "base-marking-interval="
470 << text::formatDuration<time::milliseconds>(item.getBaseCongestionMarkingInterval());
471 }
472 if (item.hasDefaultCongestionThreshold()) {
473 os << congestionSep << "default-threshold=" << item.getDefaultCongestionThreshold() << "B";
474 }
475 os << "}";
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000476 }
477
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000478 os << ia("counters")
479 << "{in={"
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000480 << item.getNInInterests() << "i "
Junxiao Shif03d4792017-04-06 16:41:22 +0000481 << item.getNInData() << "d "
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000482 << item.getNInNacks() << "n "
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000483 << item.getNInBytes() << "B} "
484 << "out={"
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000485 << item.getNOutInterests() << "i "
Junxiao Shif03d4792017-04-06 16:41:22 +0000486 << item.getNOutData() << "d "
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000487 << item.getNOutNacks() << "n "
488 << item.getNOutBytes() << "B}}";
489
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000490 os << ia("flags") << '{';
491 text::Separator flagSep("", " ");
492 os << flagSep << item.getFaceScope();
493 os << flagSep << item.getFacePersistency();
494 os << flagSep << item.getLinkType();
Eric Newberry6d932e82016-11-24 05:05:43 +0000495 if (item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)) {
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000496 os << flagSep << "local-fields";
Eric Newberry6d932e82016-11-24 05:05:43 +0000497 }
Eric Newberry84d3adc2017-08-09 23:31:40 -0400498 if (item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
499 os << flagSep << "lp-reliability";
500 }
Eric Newberryde332452018-01-30 11:45:32 -0700501 if (item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) {
502 os << flagSep << "congestion-marking";
503 }
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000504 os << '}';
Eric Newberry6d932e82016-11-24 05:05:43 +0000505
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000506 os << ia.end();
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000507}
508
Eric Newberryde332452018-01-30 11:45:32 -0700509void
510FaceModule::printFaceParams(std::ostream& os, text::ItemAttributes& ia, const ControlParameters& resp)
511{
512 os << ia("reliability") << (resp.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED) ? "on" : "off")
513 << ia("congestion-marking") << (resp.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED) ? "on" : "off");
514 if (resp.hasBaseCongestionMarkingInterval()) {
515 os << ia("congestion-marking-interval")
516 << text::formatDuration<time::milliseconds>(resp.getBaseCongestionMarkingInterval());
517 }
518 if (resp.hasDefaultCongestionThreshold()) {
519 os << ia("default-congestion-threshold") << resp.getDefaultCongestionThreshold() << "B";
520 }
521 os << '\n';
522}
523
Junxiao Shi331ade72016-08-19 14:07:19 +0000524} // namespace nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000525} // namespace tools
526} // namespace nfd