79 FaceQueryFilter filter;
81 filter.setRemoteUri(remoteUri->toString());
84 filter.setLocalUri(localUri->toString());
87 filter.setUriScheme(*uriScheme);
93 ctx.
exitCode =
static_cast<int>(res);
96 for (
const FaceStatus& item : findFace.
getResults()) {
107 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
115 uint64_t faceId = ctx.
args.
get<uint64_t>(
"id");
120 ctx.
exitCode =
static_cast<int>(res);
127 ctx.
err << findFace.getErrorReason() <<
'\n';
130 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
141 case FacePersistency::FACE_PERSISTENCY_NONE:
142 return y != FacePersistency::FACE_PERSISTENCY_NONE;
143 case FacePersistency::FACE_PERSISTENCY_ON_DEMAND:
144 return y == FacePersistency::FACE_PERSISTENCY_PERSISTENT ||
145 y == FacePersistency::FACE_PERSISTENCY_PERMANENT;
146 case FacePersistency::FACE_PERSISTENCY_PERSISTENT:
147 return y == FacePersistency::FACE_PERSISTENCY_PERMANENT;
148 case FacePersistency::FACE_PERSISTENCY_PERMANENT:
151 return static_cast<int>(x) < static_cast<int>(y);
157 auto remoteUri = ctx.
args.
get<FaceUri>(
"remote");
159 auto persistency = ctx.
args.
get<FacePersistency>(
"persistency", FacePersistency::FACE_PERSISTENCY_PERSISTENT);
161 auto congestionMarking = ctx.
args.
getTribool(
"congestion-marking");
162 auto baseCongestionMarkingIntervalMs = ctx.
args.
getOptional<uint64_t>(
"congestion-marking-interval");
163 auto defaultCongestionThreshold = ctx.
args.
getOptional<uint64_t>(
"default-congestion-threshold");
167 optional<uint64_t> mtu;
168 if (mtuArg ==
"auto") {
169 mtu = std::numeric_limits<uint64_t>::max();
174 if (!boost::conversion::try_lexical_convert<int64_t>(*mtuArg, v) || v < 0) {
176 ctx.
err <<
"MTU must either be a non-negative integer or 'auto'\n";
180 mtu =
static_cast<uint64_t
>(v);
183 optional<FaceUri> canonicalRemote;
184 optional<FaceUri> canonicalLocal;
186 auto updateFace = [&] (ControlParameters respParams, ControlParameters resp) {
188 resp.setLocalUri(respParams.getLocalUri())
189 .setUri(respParams.getUri());
193 auto handle409 = [&] (
const ControlResponse& resp) {
194 ControlParameters respParams(resp.getBody());
195 if (respParams.getUri() != canonicalRemote->toString()) {
200 bool isChangingParams =
false;
201 ControlParameters params;
202 params.setFaceId(respParams.getFaceId());
204 if (mtu && (!respParams.hasMtu() || respParams.getMtu() != *mtu)) {
205 isChangingParams =
true;
210 isChangingParams =
true;
211 params.setFacePersistency(persistency);
214 if (!boost::logic::indeterminate(lpReliability) &&
215 lpReliability != respParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
216 isChangingParams =
true;
217 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED,
bool(lpReliability));
220 if (!boost::logic::indeterminate(congestionMarking) &&
221 congestionMarking != respParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) {
222 isChangingParams =
true;
223 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED,
bool(congestionMarking));
226 if (baseCongestionMarkingIntervalMs) {
227 isChangingParams =
true;
228 params.setBaseCongestionMarkingInterval(time::milliseconds(*baseCongestionMarkingIntervalMs));
231 if (defaultCongestionThreshold) {
232 isChangingParams =
true;
233 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
236 if (isChangingParams) {
237 ctx.
controller.start<ndn::nfd::FaceUpdateCommand>(
239 bind(updateFace, respParams, _1),
251 auto doCreateFace = [&] {
252 ControlParameters params;
253 params.setUri(canonicalRemote->toString());
254 if (canonicalLocal) {
255 params.setLocalUri(canonicalLocal->toString());
257 params.setFacePersistency(persistency);
258 if (!boost::logic::indeterminate(lpReliability)) {
259 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED,
bool(lpReliability));
261 if (!boost::logic::indeterminate(congestionMarking)) {
262 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED,
bool(congestionMarking));
264 if (baseCongestionMarkingIntervalMs) {
265 params.setBaseCongestionMarkingInterval(time::milliseconds(*baseCongestionMarkingIntervalMs));
267 if (defaultCongestionThreshold) {
268 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
274 ctx.
controller.start<ndn::nfd::FaceCreateCommand>(
276 [&] (
const ControlParameters& resp) {
279 [&] (
const ControlResponse& resp) {
280 if (resp.getCode() == 409 && handle409(resp)) {
289 std::tie(canonicalRemote, error) =
canonize(ctx, remoteUri);
290 if (canonicalRemote) {
293 std::tie(canonicalLocal, error) =
canonize(ctx, *localUri);
294 if (canonicalLocal) {
301 ctx.
exitCode =
static_cast<int>(canonizationError.first);
302 ctx.
err << canonizationError.second <<
'\n';
312 ctx.
exitCode =
static_cast<int>(canonizationError.first);
313 ctx.
err << canonizationError.second <<
'\n';
316 ctx.
face.processEvents();
325 ctx.
exitCode =
static_cast<int>(res);
335 ctx.
err <<
"Multiple faces match specified remote FaceUri. Re-run the command with a FaceId:";
340 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
346 ctx.
controller.start<ndn::nfd::FaceDestroyCommand>(
347 ControlParameters().setFaceId(face.getFaceId()),
348 [&] (
const ControlParameters& resp) {
350 ctx.
out <<
"face-destroyed ";
352 ctx.
out << ia(
"id") << face.getFaceId()
353 << ia(
"local") << face.getLocalUri()
354 << ia(
"remote") << face.getRemoteUri()
355 << ia(
"persistency") << face.getFacePersistency();
361 ctx.
face.processEvents();
366 const std::function<
void()>& onSuccess,
367 const Controller::DatasetFailCallback& onFailure,
368 const CommandOptions& options)
370 controller.fetch<ndn::nfd::FaceDataset>(
371 [
this, onSuccess] (
const std::vector<FaceStatus>& result) {
382 for (
const FaceStatus& item : m_status) {
393 os <<
"<faceId>" << item.getFaceId() <<
"</faceId>";
394 os <<
"<remoteUri>" <<
xml::Text{item.getRemoteUri()} <<
"</remoteUri>";
395 os <<
"<localUri>" <<
xml::Text{item.getLocalUri()} <<
"</localUri>";
397 if (item.hasExpirationPeriod()) {
399 <<
"</expirationPeriod>";
401 os <<
"<faceScope>" << item.getFaceScope() <<
"</faceScope>";
402 os <<
"<facePersistency>" << item.getFacePersistency() <<
"</facePersistency>";
403 os <<
"<linkType>" << item.getLinkType() <<
"</linkType>";
405 if (!item.hasBaseCongestionMarkingInterval() && !item.hasDefaultCongestionThreshold()) {
406 os <<
"<congestion/>";
409 os <<
"<congestion>";
410 if (item.hasBaseCongestionMarkingInterval()) {
411 os <<
"<baseMarkingInterval>" <<
xml::formatDuration(item.getBaseCongestionMarkingInterval())
412 <<
"</baseMarkingInterval>";
414 if (item.hasDefaultCongestionThreshold()) {
415 os <<
"<defaultThreshold>" << item.getDefaultCongestionThreshold() <<
"</defaultThreshold>";
417 os <<
"</congestion>";
421 os <<
"<mtu>" << item.getMtu() <<
"</mtu>";
424 if (item.getFlags() == 0) {
429 os <<
xml::Flag{
"localFieldsEnabled", item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)};
430 os <<
xml::Flag{
"lpReliabilityEnabled", item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)};
431 os <<
xml::Flag{
"congestionMarkingEnabled", item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)};
435 os <<
"<packetCounters>";
436 os <<
"<incomingPackets>" 437 <<
"<nInterests>" << item.getNInInterests() <<
"</nInterests>" 438 <<
"<nData>" << item.getNInData() <<
"</nData>" 439 <<
"<nNacks>" << item.getNInNacks() <<
"</nNacks>" 440 <<
"</incomingPackets>";
441 os <<
"<outgoingPackets>" 442 <<
"<nInterests>" << item.getNOutInterests() <<
"</nInterests>" 443 <<
"<nData>" << item.getNOutData() <<
"</nData>" 444 <<
"<nNacks>" << item.getNOutNacks() <<
"</nNacks>" 445 <<
"</outgoingPackets>";
446 os <<
"</packetCounters>";
448 os <<
"<byteCounters>";
449 os <<
"<incomingBytes>" << item.getNInBytes() <<
"</incomingBytes>";
450 os <<
"<outgoingBytes>" << item.getNOutBytes() <<
"</outgoingBytes>";
451 os <<
"</byteCounters>";
460 for (
const FaceStatus& item : m_status) {
472 os << ia(
"faceid") << item.getFaceId();
473 os << ia(
"remote") << item.getRemoteUri();
474 os << ia(
"local") << item.getLocalUri();
476 if (item.hasExpirationPeriod()) {
477 os << ia(
"expires") << text::formatDuration<time::seconds>(item.getExpirationPeriod());
480 if (item.hasBaseCongestionMarkingInterval() || item.hasDefaultCongestionThreshold()) {
481 os << ia(
"congestion") <<
"{";
483 if (item.hasBaseCongestionMarkingInterval()) {
484 os << congestionSep <<
"base-marking-interval=" 485 << text::formatDuration<time::milliseconds>(item.getBaseCongestionMarkingInterval());
487 if (item.hasDefaultCongestionThreshold()) {
488 os << congestionSep <<
"default-threshold=" << item.getDefaultCongestionThreshold() <<
"B";
494 os << ia(
"mtu") << item.getMtu();
499 << item.getNInInterests() <<
"i " 500 << item.getNInData() <<
"d " 501 << item.getNInNacks() <<
"n " 502 << item.getNInBytes() <<
"B} " 504 << item.getNOutInterests() <<
"i " 505 << item.getNOutData() <<
"d " 506 << item.getNOutNacks() <<
"n " 507 << item.getNOutBytes() <<
"B}}";
509 os << ia(
"flags") <<
'{';
511 os << flagSep << item.getFaceScope();
512 os << flagSep << item.getFacePersistency();
513 os << flagSep << item.getLinkType();
514 if (item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)) {
515 os << flagSep <<
"local-fields";
517 if (item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
518 os << flagSep <<
"lp-reliability";
520 if (item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) {
521 os << flagSep <<
"congestion-marking";
530 const std::string& actionSummary,
531 const ControlParameters& resp)
534 os << actionSummary <<
' ' 535 << ia(
"id") << resp.getFaceId()
536 << ia(
"local") << resp.getLocalUri()
537 << ia(
"remote") << resp.getUri()
538 << ia(
"persistency") << resp.getFacePersistency();
545 os << ia(
"reliability") <<
text::OnOff{resp.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)}
546 << ia(
"congestion-marking") <<
text::OnOff{resp.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)};
547 if (resp.hasBaseCongestionMarkingInterval()) {
548 os << ia(
"congestion-marking-interval")
549 << text::formatDuration<time::milliseconds>(resp.getBaseCongestionMarkingInterval());
551 if (resp.hasDefaultCongestionThreshold()) {
552 os << ia(
"default-congestion-threshold") << resp.getDefaultCongestionThreshold() <<
"B";
555 os << ia(
"mtu") << resp.getMtu();
const CommandArguments & args
Controller::CommandFailCallback makeCommandFailureHandler(const std::string &commandName)
std::ostream & out
output stream
context for command execution
int exitCode
program exit code
ndn::nfd::CommandOptions makeCommandOptions() const
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'