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();
316 ctx.
exitCode =
static_cast<int>(res);
326 ctx.
err <<
"Multiple faces match specified remote FaceUri. Re-run the command with a FaceId:";
331 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
337 ctx.
controller.start<ndn::nfd::FaceDestroyCommand>(
338 ControlParameters().setFaceId(face.getFaceId()),
339 [&] (
const ControlParameters& resp) {
340 ctx.
out <<
"face-destroyed ";
342 ctx.
out << ia(
"id") << face.getFaceId()
343 << ia(
"local") << face.getLocalUri()
344 << ia(
"remote") << face.getRemoteUri()
345 << ia(
"persistency") << face.getFacePersistency();
351 ctx.
face.processEvents();
356 const std::function<
void()>& onSuccess,
357 const Controller::DatasetFailCallback& onFailure,
358 const CommandOptions& options)
360 controller.fetch<ndn::nfd::FaceDataset>(
361 [
this, onSuccess] (
const std::vector<FaceStatus>& result) {
372 for (
const FaceStatus& item : m_status) {
383 os <<
"<faceId>" << item.getFaceId() <<
"</faceId>";
384 os <<
"<remoteUri>" <<
xml::Text{item.getRemoteUri()} <<
"</remoteUri>";
385 os <<
"<localUri>" <<
xml::Text{item.getLocalUri()} <<
"</localUri>";
387 if (item.hasExpirationPeriod()) {
389 <<
"</expirationPeriod>";
391 os <<
"<faceScope>" << item.getFaceScope() <<
"</faceScope>";
392 os <<
"<facePersistency>" << item.getFacePersistency() <<
"</facePersistency>";
393 os <<
"<linkType>" << item.getLinkType() <<
"</linkType>";
395 if (!item.hasBaseCongestionMarkingInterval() && !item.hasDefaultCongestionThreshold()) {
396 os <<
"<congestion/>";
399 os <<
"<congestion>";
400 if (item.hasBaseCongestionMarkingInterval()) {
401 os <<
"<baseMarkingInterval>" <<
xml::formatDuration(item.getBaseCongestionMarkingInterval())
402 <<
"</baseMarkingInterval>";
404 if (item.hasDefaultCongestionThreshold()) {
405 os <<
"<defaultThreshold>" << item.getDefaultCongestionThreshold() <<
"</defaultThreshold>";
407 os <<
"</congestion>";
411 os <<
"<mtu>" << item.getMtu() <<
"</mtu>";
414 if (item.getFlags() == 0) {
419 os <<
xml::Flag{
"localFieldsEnabled", item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)};
420 os <<
xml::Flag{
"lpReliabilityEnabled", item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)};
421 os <<
xml::Flag{
"congestionMarkingEnabled", item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)};
425 os <<
"<packetCounters>";
426 os <<
"<incomingPackets>" 427 <<
"<nInterests>" << item.getNInInterests() <<
"</nInterests>" 428 <<
"<nData>" << item.getNInData() <<
"</nData>" 429 <<
"<nNacks>" << item.getNInNacks() <<
"</nNacks>" 430 <<
"</incomingPackets>";
431 os <<
"<outgoingPackets>" 432 <<
"<nInterests>" << item.getNOutInterests() <<
"</nInterests>" 433 <<
"<nData>" << item.getNOutData() <<
"</nData>" 434 <<
"<nNacks>" << item.getNOutNacks() <<
"</nNacks>" 435 <<
"</outgoingPackets>";
436 os <<
"</packetCounters>";
438 os <<
"<byteCounters>";
439 os <<
"<incomingBytes>" << item.getNInBytes() <<
"</incomingBytes>";
440 os <<
"<outgoingBytes>" << item.getNOutBytes() <<
"</outgoingBytes>";
441 os <<
"</byteCounters>";
450 for (
const FaceStatus& item : m_status) {
462 os << ia(
"faceid") << item.getFaceId();
463 os << ia(
"remote") << item.getRemoteUri();
464 os << ia(
"local") << item.getLocalUri();
466 if (item.hasExpirationPeriod()) {
467 os << ia(
"expires") << text::formatDuration<time::seconds>(item.getExpirationPeriod());
470 if (item.hasBaseCongestionMarkingInterval() || item.hasDefaultCongestionThreshold()) {
471 os << ia(
"congestion") <<
"{";
473 if (item.hasBaseCongestionMarkingInterval()) {
474 os << congestionSep <<
"base-marking-interval=" 475 << text::formatDuration<time::milliseconds>(item.getBaseCongestionMarkingInterval());
477 if (item.hasDefaultCongestionThreshold()) {
478 os << congestionSep <<
"default-threshold=" << item.getDefaultCongestionThreshold() <<
"B";
484 os << ia(
"mtu") << item.getMtu();
489 << item.getNInInterests() <<
"i " 490 << item.getNInData() <<
"d " 491 << item.getNInNacks() <<
"n " 492 << item.getNInBytes() <<
"B} " 494 << item.getNOutInterests() <<
"i " 495 << item.getNOutData() <<
"d " 496 << item.getNOutNacks() <<
"n " 497 << item.getNOutBytes() <<
"B}}";
499 os << ia(
"flags") <<
'{';
501 os << flagSep << item.getFaceScope();
502 os << flagSep << item.getFacePersistency();
503 os << flagSep << item.getLinkType();
504 if (item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)) {
505 os << flagSep <<
"local-fields";
507 if (item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
508 os << flagSep <<
"lp-reliability";
510 if (item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) {
511 os << flagSep <<
"congestion-marking";
521 os << ia(
"reliability") <<
text::OnOff{resp.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)}
522 << ia(
"congestion-marking") <<
text::OnOff{resp.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)};
523 if (resp.hasBaseCongestionMarkingInterval()) {
524 os << ia(
"congestion-marking-interval")
525 << text::formatDuration<time::milliseconds>(resp.getBaseCongestionMarkingInterval());
527 if (resp.hasDefaultCongestionThreshold()) {
528 os << ia(
"default-congestion-threshold") << resp.getDefaultCongestionThreshold() <<
"B";
531 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'