blob: 560b2233a45483c02341b50be54b3ff02298e78f [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);
43
Junxiao Shi1f481fa2017-01-26 15:14:43 +000044 CommandDefinition defFaceShow("face", "show");
45 defFaceShow
46 .setTitle("show face information")
47 .addArg("id", ArgValueType::UNSIGNED, Required::YES, Positional::YES);
48 parser.addCommand(defFaceShow, &FaceModule::show);
Junxiao Shi1d7fef52017-02-02 05:33:14 +000049
50 CommandDefinition defFaceCreate("face", "create");
51 defFaceCreate
52 .setTitle("create a face")
53 .addArg("remote", ArgValueType::FACE_URI, Required::YES, Positional::YES)
Junxiao Shi0d976922017-04-01 14:35:21 +000054 .addArg("persistency", ArgValueType::FACE_PERSISTENCY, Required::NO, Positional::YES)
Eric Newberry84d3adc2017-08-09 23:31:40 -040055 .addArg("local", ArgValueType::FACE_URI, Required::NO, Positional::NO)
Eric Newberryde332452018-01-30 11:45:32 -070056 .addArg("reliability", ArgValueType::BOOLEAN, Required::NO, Positional::NO)
57 .addArg("congestion-marking", ArgValueType::BOOLEAN, Required::NO, Positional::NO)
58 .addArg("congestion-marking-interval", ArgValueType::UNSIGNED, Required::NO, Positional::NO)
59 .addArg("default-congestion-threshold", ArgValueType::UNSIGNED, Required::NO, Positional::NO);
Junxiao Shi1d7fef52017-02-02 05:33:14 +000060 parser.addCommand(defFaceCreate, &FaceModule::create);
Junxiao Shi05dd4442017-02-06 22:50:07 +000061
62 CommandDefinition defFaceDestroy("face", "destroy");
63 defFaceDestroy
64 .setTitle("destroy a face")
65 .addArg("face", ArgValueType::FACE_ID_OR_URI, Required::YES, Positional::YES);
66 parser.addCommand(defFaceDestroy, &FaceModule::destroy);
Junxiao Shi1f481fa2017-01-26 15:14:43 +000067}
68
69void
Junxiao Shi36e54292017-02-17 18:43:16 +000070FaceModule::list(ExecuteContext& ctx)
71{
72 auto remoteUri = ctx.args.getOptional<FaceUri>("remote");
73 auto localUri = ctx.args.getOptional<FaceUri>("local");
74 auto uriScheme = ctx.args.getOptional<std::string>("scheme");
75
76 FaceQueryFilter filter;
77 if (remoteUri) {
78 filter.setRemoteUri(remoteUri->toString());
79 }
80 if (localUri) {
81 filter.setLocalUri(localUri->toString());
82 }
83 if (uriScheme) {
84 filter.setUriScheme(*uriScheme);
85 }
86
87 FindFace findFace(ctx);
88 FindFace::Code res = findFace.execute(filter, true);
89
90 ctx.exitCode = static_cast<int>(res);
91 switch (res) {
92 case FindFace::Code::OK:
93 for (const FaceStatus& item : findFace.getResults()) {
94 formatItemText(ctx.out, item, false);
95 ctx.out << '\n';
96 }
97 break;
98 case FindFace::Code::ERROR:
99 case FindFace::Code::NOT_FOUND:
100 case FindFace::Code::CANONIZE_ERROR:
101 ctx.err << findFace.getErrorReason() << '\n';
102 break;
103 default:
104 BOOST_ASSERT_MSG(false, "unexpected FindFace result");
105 break;
106 }
107}
108
109void
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000110FaceModule::show(ExecuteContext& ctx)
111{
112 uint64_t faceId = ctx.args.get<uint64_t>("id");
113
Junxiao Shi8f803f22017-02-10 03:04:28 +0000114 FindFace findFace(ctx);
115 FindFace::Code res = findFace.execute(faceId);
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000116
Junxiao Shi8f803f22017-02-10 03:04:28 +0000117 ctx.exitCode = static_cast<int>(res);
118 switch (res) {
119 case FindFace::Code::OK:
120 formatItemText(ctx.out, findFace.getFaceStatus(), true);
121 break;
122 case FindFace::Code::ERROR:
123 case FindFace::Code::NOT_FOUND:
124 ctx.err << findFace.getErrorReason() << '\n';
125 break;
126 default:
127 BOOST_ASSERT_MSG(false, "unexpected FindFace result");
128 break;
129 }
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000130}
131
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000132/** \brief order persistency in NONE < ON_DEMAND < PERSISTENCY < PERMANENT
133 */
134static bool
135persistencyLessThan(FacePersistency x, FacePersistency y)
136{
137 switch (x) {
138 case FacePersistency::FACE_PERSISTENCY_NONE:
139 return y != FacePersistency::FACE_PERSISTENCY_NONE;
140 case FacePersistency::FACE_PERSISTENCY_ON_DEMAND:
141 return y == FacePersistency::FACE_PERSISTENCY_PERSISTENT ||
142 y == FacePersistency::FACE_PERSISTENCY_PERMANENT;
143 case FacePersistency::FACE_PERSISTENCY_PERSISTENT:
144 return y == FacePersistency::FACE_PERSISTENCY_PERMANENT;
145 case FacePersistency::FACE_PERSISTENCY_PERMANENT:
146 return false;
147 }
148 return static_cast<int>(x) < static_cast<int>(y);
149}
150
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000151void
152FaceModule::create(ExecuteContext& ctx)
153{
Junxiao Shi0d976922017-04-01 14:35:21 +0000154 auto remoteUri = ctx.args.get<FaceUri>("remote");
155 auto localUri = ctx.args.getOptional<FaceUri>("local");
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000156 auto persistency = ctx.args.get<FacePersistency>("persistency", FacePersistency::FACE_PERSISTENCY_PERSISTENT);
Eric Newberry84d3adc2017-08-09 23:31:40 -0400157 auto lpReliability = ctx.args.getTribool("reliability");
Eric Newberryde332452018-01-30 11:45:32 -0700158 auto congestionMarking = ctx.args.getTribool("congestion-marking");
159 auto baseCongestionMarkingIntervalMs = ctx.args.getOptional<uint64_t>("congestion-marking-interval");
160 auto defaultCongestionThreshold = ctx.args.getOptional<uint64_t>("default-congestion-threshold");
Eric Newberry84d3adc2017-08-09 23:31:40 -0400161
Junxiao Shi0d976922017-04-01 14:35:21 +0000162 FaceUri canonicalRemote;
163 ndn::optional<FaceUri> canonicalLocal;
164
165 auto handleCanonizeError = [&] (const FaceUri& faceUri, const std::string& error) {
166 ctx.exitCode = 4;
167 ctx.err << "Error when canonizing '" << faceUri << "': " << error << '\n';
168 };
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000169
170 auto printPositiveResult = [&] (const std::string& actionSummary, const ControlParameters& resp) {
171 text::ItemAttributes ia;
172 ctx.out << actionSummary << ' '
173 << ia("id") << resp.getFaceId()
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000174 << ia("local") << resp.getLocalUri()
175 << ia("remote") << resp.getUri()
Eric Newberryde332452018-01-30 11:45:32 -0700176 << ia("persistency") << resp.getFacePersistency();
177 printFaceParams(ctx.out, ia, resp);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000178 };
179
Eric Newberry84d3adc2017-08-09 23:31:40 -0400180 auto updateFace = [&printPositiveResult] (ControlParameters respParams, ControlParameters resp) {
181 // faces/update response does not have FaceUris, copy from faces/create response
182 resp.setLocalUri(respParams.getLocalUri())
183 .setUri(respParams.getUri());
184 printPositiveResult("face-updated", resp);
185 };
186
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000187 auto handle409 = [&] (const ControlResponse& resp) {
188 ControlParameters respParams(resp.getBody());
Junxiao Shi0d976922017-04-01 14:35:21 +0000189 if (respParams.getUri() != canonicalRemote.toString()) {
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000190 // we are conflicting with a different face, which is a general error
191 return false;
192 }
193
194 if (persistencyLessThan(respParams.getFacePersistency(), persistency)) {
195 // need to upgrade persistency
Eric Newberry84d3adc2017-08-09 23:31:40 -0400196 ControlParameters params;
197 params.setFaceId(respParams.getFaceId()).setFacePersistency(persistency);
198 if (!boost::logic::indeterminate(lpReliability)) {
199 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, lpReliability);
200 }
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000201 ctx.controller.start<ndn::nfd::FaceUpdateCommand>(
Eric Newberry84d3adc2017-08-09 23:31:40 -0400202 params,
203 bind(updateFace, respParams, _1),
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000204 ctx.makeCommandFailureHandler("upgrading face persistency"),
205 ctx.makeCommandOptions());
206 }
Eric Newberryde332452018-01-30 11:45:32 -0700207 else if ((!boost::logic::indeterminate(lpReliability) &&
208 lpReliability != respParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) ||
209 (!boost::logic::indeterminate(congestionMarking) &&
210 congestionMarking != respParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) ||
211 baseCongestionMarkingIntervalMs ||
212 defaultCongestionThreshold) {
Eric Newberry84d3adc2017-08-09 23:31:40 -0400213 ControlParameters params;
Eric Newberryde332452018-01-30 11:45:32 -0700214 params.setFaceId(respParams.getFaceId());
215
216 if (!boost::logic::indeterminate(lpReliability) &&
217 lpReliability != respParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
218 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, lpReliability);
219 }
220 if (!boost::logic::indeterminate(congestionMarking) &&
221 congestionMarking != respParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) {
222 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, congestionMarking);
223 }
224
225 if (baseCongestionMarkingIntervalMs) {
226 params.setBaseCongestionMarkingInterval(time::milliseconds(*baseCongestionMarkingIntervalMs));
227 }
228
229 if (defaultCongestionThreshold) {
230 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
231 }
232
Eric Newberry84d3adc2017-08-09 23:31:40 -0400233 ctx.controller.start<ndn::nfd::FaceUpdateCommand>(
234 params,
235 bind(updateFace, respParams, _1),
Eric Newberryde332452018-01-30 11:45:32 -0700236 ctx.makeCommandFailureHandler("updating face"),
Eric Newberry84d3adc2017-08-09 23:31:40 -0400237 ctx.makeCommandOptions());
238 }
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000239 else {
Eric Newberry84d3adc2017-08-09 23:31:40 -0400240 // don't do anything
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000241 printPositiveResult("face-exists", respParams);
242 }
243 return true;
244 };
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000245
Junxiao Shi0d976922017-04-01 14:35:21 +0000246 auto doCreateFace = [&] {
247 ControlParameters params;
248 params.setUri(canonicalRemote.toString());
249 if (canonicalLocal) {
250 params.setLocalUri(canonicalLocal->toString());
251 }
252 params.setFacePersistency(persistency);
Eric Newberry84d3adc2017-08-09 23:31:40 -0400253 if (!boost::logic::indeterminate(lpReliability)) {
254 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, lpReliability);
255 }
Eric Newberryde332452018-01-30 11:45:32 -0700256 if (!boost::logic::indeterminate(congestionMarking)) {
257 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, congestionMarking);
258 }
259 if (baseCongestionMarkingIntervalMs) {
260 params.setBaseCongestionMarkingInterval(time::milliseconds(*baseCongestionMarkingIntervalMs));
261 }
262 if (defaultCongestionThreshold) {
263 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
264 }
Junxiao Shi0d976922017-04-01 14:35:21 +0000265
266 ctx.controller.start<ndn::nfd::FaceCreateCommand>(
267 params,
268 bind(printPositiveResult, "face-created", _1),
269 [&] (const ControlResponse& resp) {
270 if (resp.getCode() == 409 && handle409(resp)) {
271 return;
272 }
273 ctx.makeCommandFailureHandler("creating face")(resp); // invoke general error handler
274 },
275 ctx.makeCommandOptions());
276 };
277
278 remoteUri.canonize(
279 [&] (const FaceUri& canonicalUri) {
280 canonicalRemote = canonicalUri;
281 if (localUri) {
282 localUri->canonize(
283 [&] (const FaceUri& canonicalUri) {
284 canonicalLocal = canonicalUri;
285 doCreateFace();
286 },
287 bind(handleCanonizeError, *localUri, _1),
288 ctx.face.getIoService(), ctx.getTimeout());
289 }
290 else {
291 doCreateFace();
292 }
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000293 },
Junxiao Shi0d976922017-04-01 14:35:21 +0000294 bind(handleCanonizeError, remoteUri, _1),
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000295 ctx.face.getIoService(), ctx.getTimeout());
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000296
297 ctx.face.processEvents();
298}
299
300void
Junxiao Shi05dd4442017-02-06 22:50:07 +0000301FaceModule::destroy(ExecuteContext& ctx)
302{
Junxiao Shi918e5d42017-02-25 03:58:21 +0000303 const boost::any& faceIdOrUri = ctx.args.at("face");
Junxiao Shi05dd4442017-02-06 22:50:07 +0000304
305 FindFace findFace(ctx);
Junxiao Shi918e5d42017-02-25 03:58:21 +0000306 FindFace::Code res = findFace.execute(faceIdOrUri);
Junxiao Shi05dd4442017-02-06 22:50:07 +0000307
308 ctx.exitCode = static_cast<int>(res);
309 switch (res) {
310 case FindFace::Code::OK:
311 break;
312 case FindFace::Code::ERROR:
313 case FindFace::Code::CANONIZE_ERROR:
314 case FindFace::Code::NOT_FOUND:
315 ctx.err << findFace.getErrorReason() << '\n';
316 return;
317 case FindFace::Code::AMBIGUOUS:
318 ctx.err << "Multiple faces match specified remote FaceUri. Re-run the command with a FaceId:";
319 findFace.printDisambiguation(ctx.err, FindFace::DisambiguationStyle::LOCAL_URI);
320 ctx.err << '\n';
321 return;
322 default:
323 BOOST_ASSERT_MSG(false, "unexpected FindFace result");
324 return;
325 }
326
327 const FaceStatus& face = findFace.getFaceStatus();
328
329 ctx.controller.start<ndn::nfd::FaceDestroyCommand>(
330 ControlParameters().setFaceId(face.getFaceId()),
331 [&] (const ControlParameters& resp) {
332 ctx.out << "face-destroyed ";
333 text::ItemAttributes ia;
334 ctx.out << ia("id") << face.getFaceId()
335 << ia("local") << face.getLocalUri()
336 << ia("remote") << face.getRemoteUri()
Eric Newberryde332452018-01-30 11:45:32 -0700337 << ia("persistency") << face.getFacePersistency();
338 printFaceParams(ctx.out, ia, resp);
Junxiao Shi05dd4442017-02-06 22:50:07 +0000339 },
340 ctx.makeCommandFailureHandler("destroying face"),
341 ctx.makeCommandOptions());
342
343 ctx.face.processEvents();
344}
345
346void
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000347FaceModule::fetchStatus(Controller& controller,
348 const function<void()>& onSuccess,
Junxiao Shi29b41282016-08-22 03:47:02 +0000349 const Controller::DatasetFailCallback& onFailure,
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000350 const CommandOptions& options)
351{
352 controller.fetch<ndn::nfd::FaceDataset>(
353 [this, onSuccess] (const std::vector<FaceStatus>& result) {
354 m_status = result;
355 onSuccess();
356 },
357 onFailure, options);
358}
359
360void
361FaceModule::formatStatusXml(std::ostream& os) const
362{
363 os << "<faces>";
364 for (const FaceStatus& item : m_status) {
365 this->formatItemXml(os, item);
366 }
367 os << "</faces>";
368}
369
370void
371FaceModule::formatItemXml(std::ostream& os, const FaceStatus& item) const
372{
373 os << "<face>";
374
375 os << "<faceId>" << item.getFaceId() << "</faceId>";
376 os << "<remoteUri>" << xml::Text{item.getRemoteUri()} << "</remoteUri>";
377 os << "<localUri>" << xml::Text{item.getLocalUri()} << "</localUri>";
378
379 if (item.hasExpirationPeriod()) {
380 os << "<expirationPeriod>" << xml::formatDuration(item.getExpirationPeriod())
381 << "</expirationPeriod>";
382 }
383 os << "<faceScope>" << item.getFaceScope() << "</faceScope>";
384 os << "<facePersistency>" << item.getFacePersistency() << "</facePersistency>";
385 os << "<linkType>" << item.getLinkType() << "</linkType>";
386
Eric Newberryde332452018-01-30 11:45:32 -0700387 if (!item.hasBaseCongestionMarkingInterval() && !item.hasDefaultCongestionThreshold()) {
388 os << "<congestion/>";
389 }
390 else {
391 os << "<congestion>";
392 if (item.hasBaseCongestionMarkingInterval()) {
393 os << "<baseMarkingInterval>" << xml::formatDuration(item.getBaseCongestionMarkingInterval())
394 << "</baseMarkingInterval>";
395 }
396 if (item.hasDefaultCongestionThreshold()) {
397 os << "<defaultThreshold>" << item.getDefaultCongestionThreshold() << "</defaultThreshold>";
398 }
399 os << "</congestion>";
400 }
401
Eric Newberry6d932e82016-11-24 05:05:43 +0000402 if (item.getFlags() == 0) {
403 os << "<flags/>";
404 }
405 else {
406 os << "<flags>";
407 if (item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)) {
408 os << "<localFieldsEnabled/>";
409 }
Eric Newberry84d3adc2017-08-09 23:31:40 -0400410 if (item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
411 os << "<lpReliabilityEnabled/>";
412 }
Eric Newberryde332452018-01-30 11:45:32 -0700413 if (item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) {
414 os << "<congestionMarkingEnabled/>";
415 }
Eric Newberry6d932e82016-11-24 05:05:43 +0000416 os << "</flags>";
417 }
418
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000419 os << "<packetCounters>";
420 os << "<incomingPackets>"
421 << "<nInterests>" << item.getNInInterests() << "</nInterests>"
Junxiao Shif03d4792017-04-06 16:41:22 +0000422 << "<nData>" << item.getNInData() << "</nData>"
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000423 << "<nNacks>" << item.getNInNacks() << "</nNacks>"
424 << "</incomingPackets>";
425 os << "<outgoingPackets>"
426 << "<nInterests>" << item.getNOutInterests() << "</nInterests>"
Junxiao Shif03d4792017-04-06 16:41:22 +0000427 << "<nData>" << item.getNOutData() << "</nData>"
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000428 << "<nNacks>" << item.getNOutNacks() << "</nNacks>"
429 << "</outgoingPackets>";
430 os << "</packetCounters>";
431
432 os << "<byteCounters>";
433 os << "<incomingBytes>" << item.getNInBytes() << "</incomingBytes>";
434 os << "<outgoingBytes>" << item.getNOutBytes() << "</outgoingBytes>";
435 os << "</byteCounters>";
436
437 os << "</face>";
438}
439
440void
441FaceModule::formatStatusText(std::ostream& os) const
442{
443 os << "Faces:\n";
444 for (const FaceStatus& item : m_status) {
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000445 os << " ";
446 formatItemText(os, item, false);
447 os << '\n';
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000448 }
449}
450
451void
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000452FaceModule::formatItemText(std::ostream& os, const FaceStatus& item, bool wantMultiLine)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000453{
Eric Newberryde332452018-01-30 11:45:32 -0700454 text::ItemAttributes ia(wantMultiLine, 10);
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000455
456 os << ia("faceid") << item.getFaceId();
457 os << ia("remote") << item.getRemoteUri();
458 os << ia("local") << item.getLocalUri();
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000459
460 if (item.hasExpirationPeriod()) {
Eric Newberryde332452018-01-30 11:45:32 -0700461 os << ia("expires") << text::formatDuration<time::seconds>(item.getExpirationPeriod());
462 }
463
464 if (item.hasBaseCongestionMarkingInterval() || item.hasDefaultCongestionThreshold()) {
465 os << ia("congestion") << "{";
466 text::Separator congestionSep("", " ");
467 if (item.hasBaseCongestionMarkingInterval()) {
468 os << congestionSep << "base-marking-interval="
469 << text::formatDuration<time::milliseconds>(item.getBaseCongestionMarkingInterval());
470 }
471 if (item.hasDefaultCongestionThreshold()) {
472 os << congestionSep << "default-threshold=" << item.getDefaultCongestionThreshold() << "B";
473 }
474 os << "}";
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000475 }
476
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000477 os << ia("counters")
478 << "{in={"
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000479 << item.getNInInterests() << "i "
Junxiao Shif03d4792017-04-06 16:41:22 +0000480 << item.getNInData() << "d "
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000481 << item.getNInNacks() << "n "
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000482 << item.getNInBytes() << "B} "
483 << "out={"
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000484 << item.getNOutInterests() << "i "
Junxiao Shif03d4792017-04-06 16:41:22 +0000485 << item.getNOutData() << "d "
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000486 << item.getNOutNacks() << "n "
487 << item.getNOutBytes() << "B}}";
488
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000489 os << ia("flags") << '{';
490 text::Separator flagSep("", " ");
491 os << flagSep << item.getFaceScope();
492 os << flagSep << item.getFacePersistency();
493 os << flagSep << item.getLinkType();
Eric Newberry6d932e82016-11-24 05:05:43 +0000494 if (item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)) {
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000495 os << flagSep << "local-fields";
Eric Newberry6d932e82016-11-24 05:05:43 +0000496 }
Eric Newberry84d3adc2017-08-09 23:31:40 -0400497 if (item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
498 os << flagSep << "lp-reliability";
499 }
Eric Newberryde332452018-01-30 11:45:32 -0700500 if (item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) {
501 os << flagSep << "congestion-marking";
502 }
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000503 os << '}';
Eric Newberry6d932e82016-11-24 05:05:43 +0000504
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000505 os << ia.end();
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000506}
507
Eric Newberryde332452018-01-30 11:45:32 -0700508void
509FaceModule::printFaceParams(std::ostream& os, text::ItemAttributes& ia, const ControlParameters& resp)
510{
511 os << ia("reliability") << (resp.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED) ? "on" : "off")
512 << ia("congestion-marking") << (resp.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED) ? "on" : "off");
513 if (resp.hasBaseCongestionMarkingInterval()) {
514 os << ia("congestion-marking-interval")
515 << text::formatDuration<time::milliseconds>(resp.getBaseCongestionMarkingInterval());
516 }
517 if (resp.hasDefaultCongestionThreshold()) {
518 os << ia("default-congestion-threshold") << resp.getDefaultCongestionThreshold() << "B";
519 }
520 os << '\n';
521}
522
Junxiao Shi331ade72016-08-19 14:07:19 +0000523} // namespace nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000524} // namespace tools
525} // namespace nfd