74 FaceQueryFilter filter;
76 filter.setRemoteUri(remoteUri->toString());
79 filter.setLocalUri(localUri->toString());
82 filter.setUriScheme(*uriScheme);
88 ctx.
exitCode =
static_cast<int>(res);
91 for (
const FaceStatus& item : findFace.
getResults()) {
102 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
110 uint64_t faceId = ctx.
args.
get<uint64_t>(
"id");
115 ctx.
exitCode =
static_cast<int>(res);
122 ctx.
err << findFace.getErrorReason() <<
'\n';
125 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
136 case FacePersistency::FACE_PERSISTENCY_NONE:
137 return y != FacePersistency::FACE_PERSISTENCY_NONE;
138 case FacePersistency::FACE_PERSISTENCY_ON_DEMAND:
139 return y == FacePersistency::FACE_PERSISTENCY_PERSISTENT ||
140 y == FacePersistency::FACE_PERSISTENCY_PERMANENT;
141 case FacePersistency::FACE_PERSISTENCY_PERSISTENT:
142 return y == FacePersistency::FACE_PERSISTENCY_PERMANENT;
143 case FacePersistency::FACE_PERSISTENCY_PERMANENT:
146 return static_cast<int>(x) < static_cast<int>(y);
152 auto remoteUri = ctx.
args.
get<FaceUri>(
"remote");
154 auto persistency = ctx.
args.
get<FacePersistency>(
"persistency", FacePersistency::FACE_PERSISTENCY_PERSISTENT);
157 FaceUri canonicalRemote;
158 ndn::optional<FaceUri> canonicalLocal;
160 auto handleCanonizeError = [&] (
const FaceUri& faceUri,
const std::string& error) {
162 ctx.
err <<
"Error when canonizing '" << faceUri <<
"': " << error <<
'\n';
165 auto printPositiveResult = [&] (
const std::string& actionSummary,
const ControlParameters& resp) {
167 ctx.
out << actionSummary <<
' ' 168 << ia(
"id") << resp.getFaceId()
169 << ia(
"local") << resp.getLocalUri()
170 << ia(
"remote") << resp.getUri()
171 << ia(
"persistency") << resp.getFacePersistency()
172 << ia(
"reliability") << (resp.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED) ?
"on" :
"off")
176 auto updateFace = [&printPositiveResult] (ControlParameters respParams, ControlParameters resp) {
178 resp.setLocalUri(respParams.getLocalUri())
179 .setUri(respParams.getUri());
180 printPositiveResult(
"face-updated", resp);
183 auto handle409 = [&] (
const ControlResponse& resp) {
184 ControlParameters respParams(resp.getBody());
185 if (respParams.getUri() != canonicalRemote.toString()) {
192 ControlParameters params;
193 params.setFaceId(respParams.getFaceId()).setFacePersistency(persistency);
194 if (!boost::logic::indeterminate(lpReliability)) {
195 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, lpReliability);
197 ctx.
controller.start<ndn::nfd::FaceUpdateCommand>(
199 bind(updateFace, respParams, _1),
203 else if (lpReliability && !respParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
205 ControlParameters params;
206 params.setFaceId(respParams.getFaceId()).setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED,
true);
207 ctx.
controller.start<ndn::nfd::FaceUpdateCommand>(
209 bind(updateFace, respParams, _1),
213 else if (!lpReliability && respParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
215 ControlParameters params;
216 params.setFaceId(respParams.getFaceId()).setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED,
false);
217 ctx.
controller.start<ndn::nfd::FaceUpdateCommand>(
219 bind(updateFace, respParams, _1),
225 printPositiveResult(
"face-exists", respParams);
230 auto doCreateFace = [&] {
231 ControlParameters params;
232 params.setUri(canonicalRemote.toString());
233 if (canonicalLocal) {
234 params.setLocalUri(canonicalLocal->toString());
236 params.setFacePersistency(persistency);
237 if (!boost::logic::indeterminate(lpReliability)) {
238 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, lpReliability);
241 ctx.
controller.start<ndn::nfd::FaceCreateCommand>(
243 bind(printPositiveResult,
"face-created", _1),
244 [&] (
const ControlResponse& resp) {
245 if (resp.getCode() == 409 && handle409(resp)) {
254 [&] (
const FaceUri& canonicalUri) {
255 canonicalRemote = canonicalUri;
258 [&] (
const FaceUri& canonicalUri) {
259 canonicalLocal = canonicalUri;
262 bind(handleCanonizeError, *localUri, _1),
269 bind(handleCanonizeError, remoteUri, _1),
272 ctx.
face.processEvents();
278 const boost::any& faceIdOrUri = ctx.
args.at(
"face");
283 ctx.
exitCode =
static_cast<int>(res);
293 ctx.
err <<
"Multiple faces match specified remote FaceUri. Re-run the command with a FaceId:";
298 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
304 ctx.
controller.start<ndn::nfd::FaceDestroyCommand>(
305 ControlParameters().setFaceId(face.getFaceId()),
306 [&] (
const ControlParameters& resp) {
307 ctx.
out <<
"face-destroyed ";
309 ctx.
out << ia(
"id") << face.getFaceId()
310 << ia(
"local") << face.getLocalUri()
311 << ia(
"remote") << face.getRemoteUri()
312 << ia(
"persistency") << face.getFacePersistency()
313 << ia(
"reliability") << (resp.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED) ?
"on" :
"off")
319 ctx.
face.processEvents();
324 const function<
void()>& onSuccess,
325 const Controller::DatasetFailCallback& onFailure,
326 const CommandOptions& options)
328 controller.fetch<ndn::nfd::FaceDataset>(
329 [
this, onSuccess] (
const std::vector<FaceStatus>& result) {
340 for (
const FaceStatus& item : m_status) {
351 os <<
"<faceId>" << item.getFaceId() <<
"</faceId>";
352 os <<
"<remoteUri>" <<
xml::Text{item.getRemoteUri()} <<
"</remoteUri>";
353 os <<
"<localUri>" <<
xml::Text{item.getLocalUri()} <<
"</localUri>";
355 if (item.hasExpirationPeriod()) {
357 <<
"</expirationPeriod>";
359 os <<
"<faceScope>" << item.getFaceScope() <<
"</faceScope>";
360 os <<
"<facePersistency>" << item.getFacePersistency() <<
"</facePersistency>";
361 os <<
"<linkType>" << item.getLinkType() <<
"</linkType>";
363 if (item.getFlags() == 0) {
368 if (item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)) {
369 os <<
"<localFieldsEnabled/>";
371 if (item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
372 os <<
"<lpReliabilityEnabled/>";
377 os <<
"<packetCounters>";
378 os <<
"<incomingPackets>" 379 <<
"<nInterests>" << item.getNInInterests() <<
"</nInterests>" 380 <<
"<nData>" << item.getNInData() <<
"</nData>" 381 <<
"<nNacks>" << item.getNInNacks() <<
"</nNacks>" 382 <<
"</incomingPackets>";
383 os <<
"<outgoingPackets>" 384 <<
"<nInterests>" << item.getNOutInterests() <<
"</nInterests>" 385 <<
"<nData>" << item.getNOutData() <<
"</nData>" 386 <<
"<nNacks>" << item.getNOutNacks() <<
"</nNacks>" 387 <<
"</outgoingPackets>";
388 os <<
"</packetCounters>";
390 os <<
"<byteCounters>";
391 os <<
"<incomingBytes>" << item.getNInBytes() <<
"</incomingBytes>";
392 os <<
"<outgoingBytes>" << item.getNOutBytes() <<
"</outgoingBytes>";
393 os <<
"</byteCounters>";
402 for (
const FaceStatus& item : m_status) {
414 os << ia(
"faceid") << item.getFaceId();
415 os << ia(
"remote") << item.getRemoteUri();
416 os << ia(
"local") << item.getLocalUri();
418 if (item.hasExpirationPeriod()) {
424 << item.getNInInterests() <<
"i " 425 << item.getNInData() <<
"d " 426 << item.getNInNacks() <<
"n " 427 << item.getNInBytes() <<
"B} " 429 << item.getNOutInterests() <<
"i " 430 << item.getNOutData() <<
"d " 431 << item.getNOutNacks() <<
"n " 432 << item.getNOutBytes() <<
"B}}";
434 os << ia(
"flags") <<
'{';
436 os << flagSep << item.getFaceScope();
437 os << flagSep << item.getFacePersistency();
438 os << flagSep << item.getLinkType();
439 if (item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)) {
440 os << flagSep <<
"local-fields";
442 if (item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
443 os << flagSep <<
"lp-reliability";
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::string formatDuration(DURATION d, bool isLong=false)
std::ostream & err
error stream
print different string on first and subsequent usage