78 FaceQueryFilter filter;
80 filter.setRemoteUri(remoteUri->toString());
83 filter.setLocalUri(localUri->toString());
86 filter.setUriScheme(*uriScheme);
92 ctx.
exitCode =
static_cast<int>(res);
95 for (
const FaceStatus& item : findFace.
getResults()) {
106 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
114 uint64_t faceId = ctx.
args.
get<uint64_t>(
"id");
119 ctx.
exitCode =
static_cast<int>(res);
126 ctx.
err << findFace.getErrorReason() <<
'\n';
129 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
140 case FacePersistency::FACE_PERSISTENCY_NONE:
141 return y != FacePersistency::FACE_PERSISTENCY_NONE;
142 case FacePersistency::FACE_PERSISTENCY_ON_DEMAND:
143 return y == FacePersistency::FACE_PERSISTENCY_PERSISTENT ||
144 y == FacePersistency::FACE_PERSISTENCY_PERMANENT;
145 case FacePersistency::FACE_PERSISTENCY_PERSISTENT:
146 return y == FacePersistency::FACE_PERSISTENCY_PERMANENT;
147 case FacePersistency::FACE_PERSISTENCY_PERMANENT:
150 return static_cast<int>(x) < static_cast<int>(y);
156 auto remoteUri = ctx.
args.
get<FaceUri>(
"remote");
158 auto persistency = ctx.
args.
get<FacePersistency>(
"persistency", FacePersistency::FACE_PERSISTENCY_PERSISTENT);
160 auto congestionMarking = ctx.
args.
getTribool(
"congestion-marking");
161 auto baseCongestionMarkingIntervalMs = ctx.
args.
getOptional<uint64_t>(
"congestion-marking-interval");
162 auto defaultCongestionThreshold = ctx.
args.
getOptional<uint64_t>(
"default-congestion-threshold");
165 FaceUri canonicalRemote;
166 optional<FaceUri> canonicalLocal;
168 auto handleCanonizeError = [&] (
const FaceUri& faceUri,
const std::string& error) {
170 ctx.
err <<
"Error when canonizing '" << faceUri <<
"': " << error <<
'\n';
173 auto printPositiveResult = [&] (
const std::string& actionSummary,
const ControlParameters& resp) {
175 ctx.
out << actionSummary <<
' ' 176 << ia(
"id") << resp.getFaceId()
177 << ia(
"local") << resp.getLocalUri()
178 << ia(
"remote") << resp.getUri()
179 << ia(
"persistency") << resp.getFacePersistency();
183 auto updateFace = [&printPositiveResult] (ControlParameters respParams, ControlParameters resp) {
185 resp.setLocalUri(respParams.getLocalUri())
186 .setUri(respParams.getUri());
187 printPositiveResult(
"face-updated", resp);
190 auto handle409 = [&] (
const ControlResponse& resp) {
191 ControlParameters respParams(resp.getBody());
192 if (respParams.getUri() != canonicalRemote.toString()) {
197 if (mtu && (!respParams.hasMtu() || respParams.getMtu() != *mtu)) {
203 ControlParameters params;
204 params.setFaceId(respParams.getFaceId()).setFacePersistency(persistency);
205 if (!boost::logic::indeterminate(lpReliability)) {
206 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, lpReliability);
208 ctx.
controller.start<ndn::nfd::FaceUpdateCommand>(
210 bind(updateFace, respParams, _1),
214 else if ((!boost::logic::indeterminate(lpReliability) &&
215 lpReliability != respParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) ||
216 (!boost::logic::indeterminate(congestionMarking) &&
217 congestionMarking != respParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) ||
218 baseCongestionMarkingIntervalMs ||
219 defaultCongestionThreshold) {
220 ControlParameters params;
221 params.setFaceId(respParams.getFaceId());
223 if (!boost::logic::indeterminate(lpReliability) &&
224 lpReliability != respParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
225 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, lpReliability);
227 if (!boost::logic::indeterminate(congestionMarking) &&
228 congestionMarking != respParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) {
229 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, congestionMarking);
232 if (baseCongestionMarkingIntervalMs) {
233 params.setBaseCongestionMarkingInterval(time::milliseconds(*baseCongestionMarkingIntervalMs));
236 if (defaultCongestionThreshold) {
237 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
240 ctx.
controller.start<ndn::nfd::FaceUpdateCommand>(
242 bind(updateFace, respParams, _1),
248 printPositiveResult(
"face-exists", respParams);
253 auto doCreateFace = [&] {
254 ControlParameters params;
255 params.setUri(canonicalRemote.toString());
256 if (canonicalLocal) {
257 params.setLocalUri(canonicalLocal->toString());
259 params.setFacePersistency(persistency);
260 if (!boost::logic::indeterminate(lpReliability)) {
261 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, lpReliability);
263 if (!boost::logic::indeterminate(congestionMarking)) {
264 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, congestionMarking);
266 if (baseCongestionMarkingIntervalMs) {
267 params.setBaseCongestionMarkingInterval(time::milliseconds(*baseCongestionMarkingIntervalMs));
269 if (defaultCongestionThreshold) {
270 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
276 ctx.
controller.start<ndn::nfd::FaceCreateCommand>(
278 bind(printPositiveResult,
"face-created", _1),
279 [&] (
const ControlResponse& resp) {
280 if (resp.getCode() == 409 && handle409(resp)) {
289 [&] (
const FaceUri& canonicalUri) {
290 canonicalRemote = canonicalUri;
293 [&] (
const FaceUri& canonicalUri) {
294 canonicalLocal = canonicalUri;
297 bind(handleCanonizeError, *localUri, _1),
304 bind(handleCanonizeError, remoteUri, _1),
307 ctx.
face.processEvents();
313 const boost::any& faceIdOrUri = ctx.
args.at(
"face");
318 ctx.
exitCode =
static_cast<int>(res);
328 ctx.
err <<
"Multiple faces match specified remote FaceUri. Re-run the command with a FaceId:";
333 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
339 ctx.
controller.start<ndn::nfd::FaceDestroyCommand>(
340 ControlParameters().setFaceId(face.getFaceId()),
341 [&] (
const ControlParameters& resp) {
342 ctx.
out <<
"face-destroyed ";
344 ctx.
out << ia(
"id") << face.getFaceId()
345 << ia(
"local") << face.getLocalUri()
346 << ia(
"remote") << face.getRemoteUri()
347 << ia(
"persistency") << face.getFacePersistency();
353 ctx.
face.processEvents();
358 const std::function<
void()>& onSuccess,
359 const Controller::DatasetFailCallback& onFailure,
360 const CommandOptions& options)
362 controller.fetch<ndn::nfd::FaceDataset>(
363 [
this, onSuccess] (
const std::vector<FaceStatus>& result) {
374 for (
const FaceStatus& item : m_status) {
385 os <<
"<faceId>" << item.getFaceId() <<
"</faceId>";
386 os <<
"<remoteUri>" <<
xml::Text{item.getRemoteUri()} <<
"</remoteUri>";
387 os <<
"<localUri>" <<
xml::Text{item.getLocalUri()} <<
"</localUri>";
389 if (item.hasExpirationPeriod()) {
391 <<
"</expirationPeriod>";
393 os <<
"<faceScope>" << item.getFaceScope() <<
"</faceScope>";
394 os <<
"<facePersistency>" << item.getFacePersistency() <<
"</facePersistency>";
395 os <<
"<linkType>" << item.getLinkType() <<
"</linkType>";
397 if (!item.hasBaseCongestionMarkingInterval() && !item.hasDefaultCongestionThreshold()) {
398 os <<
"<congestion/>";
401 os <<
"<congestion>";
402 if (item.hasBaseCongestionMarkingInterval()) {
403 os <<
"<baseMarkingInterval>" <<
xml::formatDuration(item.getBaseCongestionMarkingInterval())
404 <<
"</baseMarkingInterval>";
406 if (item.hasDefaultCongestionThreshold()) {
407 os <<
"<defaultThreshold>" << item.getDefaultCongestionThreshold() <<
"</defaultThreshold>";
409 os <<
"</congestion>";
413 os <<
"<mtu>" << item.getMtu() <<
"</mtu>";
416 if (item.getFlags() == 0) {
421 os <<
xml::Flag{
"localFieldsEnabled", item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)};
422 os <<
xml::Flag{
"lpReliabilityEnabled", item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)};
423 os <<
xml::Flag{
"congestionMarkingEnabled", item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)};
427 os <<
"<packetCounters>";
428 os <<
"<incomingPackets>" 429 <<
"<nInterests>" << item.getNInInterests() <<
"</nInterests>" 430 <<
"<nData>" << item.getNInData() <<
"</nData>" 431 <<
"<nNacks>" << item.getNInNacks() <<
"</nNacks>" 432 <<
"</incomingPackets>";
433 os <<
"<outgoingPackets>" 434 <<
"<nInterests>" << item.getNOutInterests() <<
"</nInterests>" 435 <<
"<nData>" << item.getNOutData() <<
"</nData>" 436 <<
"<nNacks>" << item.getNOutNacks() <<
"</nNacks>" 437 <<
"</outgoingPackets>";
438 os <<
"</packetCounters>";
440 os <<
"<byteCounters>";
441 os <<
"<incomingBytes>" << item.getNInBytes() <<
"</incomingBytes>";
442 os <<
"<outgoingBytes>" << item.getNOutBytes() <<
"</outgoingBytes>";
443 os <<
"</byteCounters>";
452 for (
const FaceStatus& item : m_status) {
464 os << ia(
"faceid") << item.getFaceId();
465 os << ia(
"remote") << item.getRemoteUri();
466 os << ia(
"local") << item.getLocalUri();
468 if (item.hasExpirationPeriod()) {
469 os << ia(
"expires") << text::formatDuration<time::seconds>(item.getExpirationPeriod());
472 if (item.hasBaseCongestionMarkingInterval() || item.hasDefaultCongestionThreshold()) {
473 os << ia(
"congestion") <<
"{";
475 if (item.hasBaseCongestionMarkingInterval()) {
476 os << congestionSep <<
"base-marking-interval=" 477 << text::formatDuration<time::milliseconds>(item.getBaseCongestionMarkingInterval());
479 if (item.hasDefaultCongestionThreshold()) {
480 os << congestionSep <<
"default-threshold=" << item.getDefaultCongestionThreshold() <<
"B";
486 os << ia(
"mtu") << item.getMtu();
491 << item.getNInInterests() <<
"i " 492 << item.getNInData() <<
"d " 493 << item.getNInNacks() <<
"n " 494 << item.getNInBytes() <<
"B} " 496 << item.getNOutInterests() <<
"i " 497 << item.getNOutData() <<
"d " 498 << item.getNOutNacks() <<
"n " 499 << item.getNOutBytes() <<
"B}}";
501 os << ia(
"flags") <<
'{';
503 os << flagSep << item.getFaceScope();
504 os << flagSep << item.getFacePersistency();
505 os << flagSep << item.getLinkType();
506 if (item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)) {
507 os << flagSep <<
"local-fields";
509 if (item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
510 os << flagSep <<
"lp-reliability";
512 if (item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) {
513 os << flagSep <<
"congestion-marking";
523 os << ia(
"reliability") <<
text::OnOff{resp.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)}
524 << ia(
"congestion-marking") <<
text::OnOff{resp.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)};
525 if (resp.hasBaseCongestionMarkingInterval()) {
526 os << ia(
"congestion-marking-interval")
527 << text::formatDuration<time::milliseconds>(resp.getBaseCongestionMarkingInterval());
529 if (resp.hasDefaultCongestionThreshold()) {
530 os << ia(
"default-congestion-threshold") << resp.getDefaultCongestionThreshold() <<
"B";
533 os << ia(
"mtu") << resp.getMtu();
const CommandArguments & args
ndn::nfd::CommandOptions makeCommandOptions() const
Controller::CommandFailCallback makeCommandFailureHandler(const std::string &commandName)
std::ostream & out
output stream
context for command execution
time::nanoseconds getTimeout() const
int exitCode
program exit code
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
print attributes of an item
std::ostream & err
error stream
print different string on first and subsequent usage
print boolean as 'on' or 'off'