76 FaceQueryFilter filter;
78 filter.setRemoteUri(remoteUri->toString());
81 filter.setLocalUri(localUri->toString());
84 filter.setUriScheme(*uriScheme);
90 ctx.
exitCode =
static_cast<int>(res);
93 for (
const FaceStatus& item : findFace.
getResults()) {
104 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
112 uint64_t faceId = ctx.
args.
get<uint64_t>(
"id");
117 ctx.
exitCode =
static_cast<int>(res);
124 ctx.
err << findFace.getErrorReason() <<
'\n';
127 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
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:
148 return static_cast<int>(x) < static_cast<int>(y);
154 auto remoteUri = ctx.
args.
get<FaceUri>(
"remote");
156 auto persistency = ctx.
args.
get<FacePersistency>(
"persistency", FacePersistency::FACE_PERSISTENCY_PERSISTENT);
158 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");
162 FaceUri canonicalRemote;
163 ndn::optional<FaceUri> canonicalLocal;
165 auto handleCanonizeError = [&] (
const FaceUri& faceUri,
const std::string& error) {
167 ctx.
err <<
"Error when canonizing '" << faceUri <<
"': " << error <<
'\n';
170 auto printPositiveResult = [&] (
const std::string& actionSummary,
const ControlParameters& resp) {
172 ctx.
out << actionSummary <<
' ' 173 << ia(
"id") << resp.getFaceId()
174 << ia(
"local") << resp.getLocalUri()
175 << ia(
"remote") << resp.getUri()
176 << ia(
"persistency") << resp.getFacePersistency();
180 auto updateFace = [&printPositiveResult] (ControlParameters respParams, ControlParameters resp) {
182 resp.setLocalUri(respParams.getLocalUri())
183 .setUri(respParams.getUri());
184 printPositiveResult(
"face-updated", resp);
187 auto handle409 = [&] (
const ControlResponse& resp) {
188 ControlParameters respParams(resp.getBody());
189 if (respParams.getUri() != canonicalRemote.toString()) {
196 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);
201 ctx.
controller.start<ndn::nfd::FaceUpdateCommand>(
203 bind(updateFace, respParams, _1),
207 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) {
213 ControlParameters params;
214 params.setFaceId(respParams.getFaceId());
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);
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);
225 if (baseCongestionMarkingIntervalMs) {
226 params.setBaseCongestionMarkingInterval(time::milliseconds(*baseCongestionMarkingIntervalMs));
229 if (defaultCongestionThreshold) {
230 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
233 ctx.
controller.start<ndn::nfd::FaceUpdateCommand>(
235 bind(updateFace, respParams, _1),
241 printPositiveResult(
"face-exists", respParams);
246 auto doCreateFace = [&] {
247 ControlParameters params;
248 params.setUri(canonicalRemote.toString());
249 if (canonicalLocal) {
250 params.setLocalUri(canonicalLocal->toString());
252 params.setFacePersistency(persistency);
253 if (!boost::logic::indeterminate(lpReliability)) {
254 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, lpReliability);
256 if (!boost::logic::indeterminate(congestionMarking)) {
257 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, congestionMarking);
259 if (baseCongestionMarkingIntervalMs) {
260 params.setBaseCongestionMarkingInterval(time::milliseconds(*baseCongestionMarkingIntervalMs));
262 if (defaultCongestionThreshold) {
263 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
266 ctx.
controller.start<ndn::nfd::FaceCreateCommand>(
268 bind(printPositiveResult,
"face-created", _1),
269 [&] (
const ControlResponse& resp) {
270 if (resp.getCode() == 409 && handle409(resp)) {
279 [&] (
const FaceUri& canonicalUri) {
280 canonicalRemote = canonicalUri;
283 [&] (
const FaceUri& canonicalUri) {
284 canonicalLocal = canonicalUri;
287 bind(handleCanonizeError, *localUri, _1),
294 bind(handleCanonizeError, remoteUri, _1),
297 ctx.
face.processEvents();
303 const boost::any& faceIdOrUri = ctx.
args.at(
"face");
308 ctx.
exitCode =
static_cast<int>(res);
318 ctx.
err <<
"Multiple faces match specified remote FaceUri. Re-run the command with a FaceId:";
323 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
329 ctx.
controller.start<ndn::nfd::FaceDestroyCommand>(
330 ControlParameters().setFaceId(face.getFaceId()),
331 [&] (
const ControlParameters& resp) {
332 ctx.
out <<
"face-destroyed ";
334 ctx.
out << ia(
"id") << face.getFaceId()
335 << ia(
"local") << face.getLocalUri()
336 << ia(
"remote") << face.getRemoteUri()
337 << ia(
"persistency") << face.getFacePersistency();
343 ctx.
face.processEvents();
348 const function<
void()>& onSuccess,
349 const Controller::DatasetFailCallback& onFailure,
350 const CommandOptions& options)
352 controller.fetch<ndn::nfd::FaceDataset>(
353 [
this, onSuccess] (
const std::vector<FaceStatus>& result) {
364 for (
const FaceStatus& item : m_status) {
375 os <<
"<faceId>" << item.getFaceId() <<
"</faceId>";
376 os <<
"<remoteUri>" <<
xml::Text{item.getRemoteUri()} <<
"</remoteUri>";
377 os <<
"<localUri>" <<
xml::Text{item.getLocalUri()} <<
"</localUri>";
379 if (item.hasExpirationPeriod()) {
381 <<
"</expirationPeriod>";
383 os <<
"<faceScope>" << item.getFaceScope() <<
"</faceScope>";
384 os <<
"<facePersistency>" << item.getFacePersistency() <<
"</facePersistency>";
385 os <<
"<linkType>" << item.getLinkType() <<
"</linkType>";
387 if (!item.hasBaseCongestionMarkingInterval() && !item.hasDefaultCongestionThreshold()) {
388 os <<
"<congestion/>";
391 os <<
"<congestion>";
392 if (item.hasBaseCongestionMarkingInterval()) {
393 os <<
"<baseMarkingInterval>" <<
xml::formatDuration(item.getBaseCongestionMarkingInterval())
394 <<
"</baseMarkingInterval>";
396 if (item.hasDefaultCongestionThreshold()) {
397 os <<
"<defaultThreshold>" << item.getDefaultCongestionThreshold() <<
"</defaultThreshold>";
399 os <<
"</congestion>";
402 if (item.getFlags() == 0) {
407 if (item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)) {
408 os <<
"<localFieldsEnabled/>";
410 if (item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
411 os <<
"<lpReliabilityEnabled/>";
413 if (item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) {
414 os <<
"<congestionMarkingEnabled/>";
419 os <<
"<packetCounters>";
420 os <<
"<incomingPackets>" 421 <<
"<nInterests>" << item.getNInInterests() <<
"</nInterests>" 422 <<
"<nData>" << item.getNInData() <<
"</nData>" 423 <<
"<nNacks>" << item.getNInNacks() <<
"</nNacks>" 424 <<
"</incomingPackets>";
425 os <<
"<outgoingPackets>" 426 <<
"<nInterests>" << item.getNOutInterests() <<
"</nInterests>" 427 <<
"<nData>" << item.getNOutData() <<
"</nData>" 428 <<
"<nNacks>" << item.getNOutNacks() <<
"</nNacks>" 429 <<
"</outgoingPackets>";
430 os <<
"</packetCounters>";
432 os <<
"<byteCounters>";
433 os <<
"<incomingBytes>" << item.getNInBytes() <<
"</incomingBytes>";
434 os <<
"<outgoingBytes>" << item.getNOutBytes() <<
"</outgoingBytes>";
435 os <<
"</byteCounters>";
444 for (
const FaceStatus& item : m_status) {
456 os << ia(
"faceid") << item.getFaceId();
457 os << ia(
"remote") << item.getRemoteUri();
458 os << ia(
"local") << item.getLocalUri();
460 if (item.hasExpirationPeriod()) {
461 os << ia(
"expires") << text::formatDuration<time::seconds>(item.getExpirationPeriod());
464 if (item.hasBaseCongestionMarkingInterval() || item.hasDefaultCongestionThreshold()) {
465 os << ia(
"congestion") <<
"{";
467 if (item.hasBaseCongestionMarkingInterval()) {
468 os << congestionSep <<
"base-marking-interval=" 469 << text::formatDuration<time::milliseconds>(item.getBaseCongestionMarkingInterval());
471 if (item.hasDefaultCongestionThreshold()) {
472 os << congestionSep <<
"default-threshold=" << item.getDefaultCongestionThreshold() <<
"B";
479 << item.getNInInterests() <<
"i " 480 << item.getNInData() <<
"d " 481 << item.getNInNacks() <<
"n " 482 << item.getNInBytes() <<
"B} " 484 << item.getNOutInterests() <<
"i " 485 << item.getNOutData() <<
"d " 486 << item.getNOutNacks() <<
"n " 487 << item.getNOutBytes() <<
"B}}";
489 os << ia(
"flags") <<
'{';
491 os << flagSep << item.getFaceScope();
492 os << flagSep << item.getFacePersistency();
493 os << flagSep << item.getLinkType();
494 if (item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)) {
495 os << flagSep <<
"local-fields";
497 if (item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
498 os << flagSep <<
"lp-reliability";
500 if (item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) {
501 os << flagSep <<
"congestion-marking";
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());
517 if (resp.hasDefaultCongestionThreshold()) {
518 os << ia(
"default-congestion-threshold") << resp.getDefaultCongestionThreshold() <<
"B";
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