77 FaceQueryFilter filter;
79 filter.setRemoteUri(remoteUri->toString());
82 filter.setLocalUri(localUri->toString());
85 filter.setUriScheme(*uriScheme);
91 ctx.
exitCode =
static_cast<int>(res);
94 for (
const FaceStatus& item : findFace.
getResults()) {
105 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
113 uint64_t faceId = ctx.
args.
get<uint64_t>(
"id");
118 ctx.
exitCode =
static_cast<int>(res);
125 ctx.
err << findFace.getErrorReason() <<
'\n';
128 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
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:
149 return static_cast<int>(x) < static_cast<int>(y);
155 auto remoteUri = ctx.
args.
get<FaceUri>(
"remote");
157 auto persistency = ctx.
args.
get<FacePersistency>(
"persistency", FacePersistency::FACE_PERSISTENCY_PERSISTENT);
159 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");
163 FaceUri canonicalRemote;
164 optional<FaceUri> canonicalLocal;
166 auto handleCanonizeError = [&] (
const FaceUri& faceUri,
const std::string& error) {
168 ctx.
err <<
"Error when canonizing '" << faceUri <<
"': " << error <<
'\n';
171 auto printPositiveResult = [&] (
const std::string& actionSummary,
const ControlParameters& resp) {
173 ctx.
out << actionSummary <<
' ' 174 << ia(
"id") << resp.getFaceId()
175 << ia(
"local") << resp.getLocalUri()
176 << ia(
"remote") << resp.getUri()
177 << ia(
"persistency") << resp.getFacePersistency();
181 auto updateFace = [&printPositiveResult] (ControlParameters respParams, ControlParameters resp) {
183 resp.setLocalUri(respParams.getLocalUri())
184 .setUri(respParams.getUri());
185 printPositiveResult(
"face-updated", resp);
188 auto handle409 = [&] (
const ControlResponse& resp) {
189 ControlParameters respParams(resp.getBody());
190 if (respParams.getUri() != canonicalRemote.toString()) {
197 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);
202 ctx.
controller.start<ndn::nfd::FaceUpdateCommand>(
204 bind(updateFace, respParams, _1),
208 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) {
214 ControlParameters params;
215 params.setFaceId(respParams.getFaceId());
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);
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);
226 if (baseCongestionMarkingIntervalMs) {
227 params.setBaseCongestionMarkingInterval(time::milliseconds(*baseCongestionMarkingIntervalMs));
230 if (defaultCongestionThreshold) {
231 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
234 ctx.
controller.start<ndn::nfd::FaceUpdateCommand>(
236 bind(updateFace, respParams, _1),
242 printPositiveResult(
"face-exists", respParams);
247 auto doCreateFace = [&] {
248 ControlParameters params;
249 params.setUri(canonicalRemote.toString());
250 if (canonicalLocal) {
251 params.setLocalUri(canonicalLocal->toString());
253 params.setFacePersistency(persistency);
254 if (!boost::logic::indeterminate(lpReliability)) {
255 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, lpReliability);
257 if (!boost::logic::indeterminate(congestionMarking)) {
258 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, congestionMarking);
260 if (baseCongestionMarkingIntervalMs) {
261 params.setBaseCongestionMarkingInterval(time::milliseconds(*baseCongestionMarkingIntervalMs));
263 if (defaultCongestionThreshold) {
264 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
267 ctx.
controller.start<ndn::nfd::FaceCreateCommand>(
269 bind(printPositiveResult,
"face-created", _1),
270 [&] (
const ControlResponse& resp) {
271 if (resp.getCode() == 409 && handle409(resp)) {
280 [&] (
const FaceUri& canonicalUri) {
281 canonicalRemote = canonicalUri;
284 [&] (
const FaceUri& canonicalUri) {
285 canonicalLocal = canonicalUri;
288 bind(handleCanonizeError, *localUri, _1),
295 bind(handleCanonizeError, remoteUri, _1),
298 ctx.
face.processEvents();
304 const boost::any& faceIdOrUri = ctx.
args.at(
"face");
309 ctx.
exitCode =
static_cast<int>(res);
319 ctx.
err <<
"Multiple faces match specified remote FaceUri. Re-run the command with a FaceId:";
324 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
330 ctx.
controller.start<ndn::nfd::FaceDestroyCommand>(
331 ControlParameters().setFaceId(face.getFaceId()),
332 [&] (
const ControlParameters& resp) {
333 ctx.
out <<
"face-destroyed ";
335 ctx.
out << ia(
"id") << face.getFaceId()
336 << ia(
"local") << face.getLocalUri()
337 << ia(
"remote") << face.getRemoteUri()
338 << ia(
"persistency") << face.getFacePersistency();
344 ctx.
face.processEvents();
349 const std::function<
void()>& onSuccess,
350 const Controller::DatasetFailCallback& onFailure,
351 const CommandOptions& options)
353 controller.fetch<ndn::nfd::FaceDataset>(
354 [
this, onSuccess] (
const std::vector<FaceStatus>& result) {
365 for (
const FaceStatus& item : m_status) {
376 os <<
"<faceId>" << item.getFaceId() <<
"</faceId>";
377 os <<
"<remoteUri>" <<
xml::Text{item.getRemoteUri()} <<
"</remoteUri>";
378 os <<
"<localUri>" <<
xml::Text{item.getLocalUri()} <<
"</localUri>";
380 if (item.hasExpirationPeriod()) {
382 <<
"</expirationPeriod>";
384 os <<
"<faceScope>" << item.getFaceScope() <<
"</faceScope>";
385 os <<
"<facePersistency>" << item.getFacePersistency() <<
"</facePersistency>";
386 os <<
"<linkType>" << item.getLinkType() <<
"</linkType>";
388 if (!item.hasBaseCongestionMarkingInterval() && !item.hasDefaultCongestionThreshold()) {
389 os <<
"<congestion/>";
392 os <<
"<congestion>";
393 if (item.hasBaseCongestionMarkingInterval()) {
394 os <<
"<baseMarkingInterval>" <<
xml::formatDuration(item.getBaseCongestionMarkingInterval())
395 <<
"</baseMarkingInterval>";
397 if (item.hasDefaultCongestionThreshold()) {
398 os <<
"<defaultThreshold>" << item.getDefaultCongestionThreshold() <<
"</defaultThreshold>";
400 os <<
"</congestion>";
403 if (item.getFlags() == 0) {
408 os <<
xml::Flag{
"localFieldsEnabled", item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)};
409 os <<
xml::Flag{
"lpReliabilityEnabled", item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)};
410 os <<
xml::Flag{
"congestionMarkingEnabled", item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)};
414 os <<
"<packetCounters>";
415 os <<
"<incomingPackets>" 416 <<
"<nInterests>" << item.getNInInterests() <<
"</nInterests>" 417 <<
"<nData>" << item.getNInData() <<
"</nData>" 418 <<
"<nNacks>" << item.getNInNacks() <<
"</nNacks>" 419 <<
"</incomingPackets>";
420 os <<
"<outgoingPackets>" 421 <<
"<nInterests>" << item.getNOutInterests() <<
"</nInterests>" 422 <<
"<nData>" << item.getNOutData() <<
"</nData>" 423 <<
"<nNacks>" << item.getNOutNacks() <<
"</nNacks>" 424 <<
"</outgoingPackets>";
425 os <<
"</packetCounters>";
427 os <<
"<byteCounters>";
428 os <<
"<incomingBytes>" << item.getNInBytes() <<
"</incomingBytes>";
429 os <<
"<outgoingBytes>" << item.getNOutBytes() <<
"</outgoingBytes>";
430 os <<
"</byteCounters>";
439 for (
const FaceStatus& item : m_status) {
451 os << ia(
"faceid") << item.getFaceId();
452 os << ia(
"remote") << item.getRemoteUri();
453 os << ia(
"local") << item.getLocalUri();
455 if (item.hasExpirationPeriod()) {
456 os << ia(
"expires") << text::formatDuration<time::seconds>(item.getExpirationPeriod());
459 if (item.hasBaseCongestionMarkingInterval() || item.hasDefaultCongestionThreshold()) {
460 os << ia(
"congestion") <<
"{";
462 if (item.hasBaseCongestionMarkingInterval()) {
463 os << congestionSep <<
"base-marking-interval=" 464 << text::formatDuration<time::milliseconds>(item.getBaseCongestionMarkingInterval());
466 if (item.hasDefaultCongestionThreshold()) {
467 os << congestionSep <<
"default-threshold=" << item.getDefaultCongestionThreshold() <<
"B";
474 << item.getNInInterests() <<
"i " 475 << item.getNInData() <<
"d " 476 << item.getNInNacks() <<
"n " 477 << item.getNInBytes() <<
"B} " 479 << item.getNOutInterests() <<
"i " 480 << item.getNOutData() <<
"d " 481 << item.getNOutNacks() <<
"n " 482 << item.getNOutBytes() <<
"B}}";
484 os << ia(
"flags") <<
'{';
486 os << flagSep << item.getFaceScope();
487 os << flagSep << item.getFacePersistency();
488 os << flagSep << item.getLinkType();
489 if (item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)) {
490 os << flagSep <<
"local-fields";
492 if (item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
493 os << flagSep <<
"lp-reliability";
495 if (item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) {
496 os << flagSep <<
"congestion-marking";
506 os << ia(
"reliability") <<
text::OnOff{resp.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)}
507 << ia(
"congestion-marking") <<
text::OnOff{resp.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)};
508 if (resp.hasBaseCongestionMarkingInterval()) {
509 os << ia(
"congestion-marking-interval")
510 << text::formatDuration<time::milliseconds>(resp.getBaseCongestionMarkingInterval());
512 if (resp.hasDefaultCongestionThreshold()) {
513 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
print boolean as 'on' or 'off'