29 #include <boost/lexical_cast/try_lexical_convert.hpp>
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");
166 std::optional<uint64_t> mtu;
167 if (mtuArg ==
"auto") {
168 mtu = std::numeric_limits<uint64_t>::max();
173 if (!boost::conversion::try_lexical_convert<int64_t>(*mtuArg, v) || v < 0) {
175 ctx.
err <<
"MTU must either be a non-negative integer or 'auto'\n";
179 mtu =
static_cast<uint64_t
>(v);
182 std::optional<FaceUri> canonicalRemote;
183 std::optional<FaceUri> canonicalLocal;
185 auto updateFace = [&] (ControlParameters respParams, ControlParameters resp) {
187 resp.setLocalUri(respParams.getLocalUri())
188 .setUri(respParams.getUri());
192 auto handle409 = [&] (
const ControlResponse& resp) {
193 ControlParameters respParams(resp.getBody());
194 if (respParams.getUri() != canonicalRemote->toString()) {
199 bool isChangingParams =
false;
200 ControlParameters params;
201 params.setFaceId(respParams.getFaceId());
203 if (mtu && (!respParams.hasMtu() || respParams.getMtu() != *mtu)) {
204 isChangingParams =
true;
209 isChangingParams =
true;
210 params.setFacePersistency(persistency);
213 if (!boost::logic::indeterminate(lpReliability) &&
214 lpReliability != respParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
215 isChangingParams =
true;
216 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED,
bool(lpReliability));
219 if (!boost::logic::indeterminate(congestionMarking) &&
220 congestionMarking != respParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) {
221 isChangingParams =
true;
222 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED,
bool(congestionMarking));
225 if (baseCongestionMarkingIntervalMs) {
226 isChangingParams =
true;
227 params.setBaseCongestionMarkingInterval(time::milliseconds(*baseCongestionMarkingIntervalMs));
230 if (defaultCongestionThreshold) {
231 isChangingParams =
true;
232 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
235 if (isChangingParams) {
236 ctx.
controller.start<ndn::nfd::FaceUpdateCommand>(
238 [=, &updateFace] (
const auto& cp) { updateFace(respParams, cp); },
250 auto doCreateFace = [&] {
251 ControlParameters params;
252 params.setUri(canonicalRemote->toString());
253 if (canonicalLocal) {
254 params.setLocalUri(canonicalLocal->toString());
256 params.setFacePersistency(persistency);
257 if (!boost::logic::indeterminate(lpReliability)) {
258 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED,
bool(lpReliability));
260 if (!boost::logic::indeterminate(congestionMarking)) {
261 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED,
bool(congestionMarking));
263 if (baseCongestionMarkingIntervalMs) {
264 params.setBaseCongestionMarkingInterval(time::milliseconds(*baseCongestionMarkingIntervalMs));
266 if (defaultCongestionThreshold) {
267 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
273 ctx.
controller.start<ndn::nfd::FaceCreateCommand>(
275 [&] (
const ControlParameters& resp) {
278 [&] (
const ControlResponse& resp) {
279 if (resp.getCode() == 409 && handle409(resp)) {
288 std::tie(canonicalRemote, error) =
canonize(ctx, remoteUri);
289 if (canonicalRemote) {
292 std::tie(canonicalLocal, error) =
canonize(ctx, *localUri);
293 if (canonicalLocal) {
300 ctx.
exitCode =
static_cast<int>(canonizationError.first);
301 ctx.
err << canonizationError.second <<
'\n';
311 ctx.
exitCode =
static_cast<int>(canonizationError.first);
312 ctx.
err << canonizationError.second <<
'\n';
315 ctx.
face.processEvents();
324 ctx.
exitCode =
static_cast<int>(res);
334 ctx.
err <<
"Multiple faces match specified remote FaceUri. Re-run the command with a FaceId:";
339 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
345 ctx.
controller.start<ndn::nfd::FaceDestroyCommand>(
346 ControlParameters().setFaceId(face.getFaceId()),
347 [&] (
const ControlParameters& resp) {
349 ctx.
out <<
"face-destroyed ";
351 ctx.
out << ia(
"id") << face.getFaceId()
352 << ia(
"local") << face.getLocalUri()
353 << ia(
"remote") << face.getRemoteUri()
354 << ia(
"persistency") << face.getFacePersistency();
360 ctx.
face.processEvents();
365 const std::function<
void()>& onSuccess,
366 const Controller::DatasetFailCallback& onFailure,
367 const CommandOptions& options)
369 controller.fetch<ndn::nfd::FaceDataset>(
370 [
this, onSuccess] (
const auto& result) {
381 for (
const FaceStatus& item : m_status) {
392 os <<
"<faceId>" << item.getFaceId() <<
"</faceId>";
393 os <<
"<remoteUri>" <<
xml::Text{item.getRemoteUri()} <<
"</remoteUri>";
394 os <<
"<localUri>" <<
xml::Text{item.getLocalUri()} <<
"</localUri>";
396 if (item.hasExpirationPeriod()) {
398 <<
"</expirationPeriod>";
400 os <<
"<faceScope>" << item.getFaceScope() <<
"</faceScope>";
401 os <<
"<facePersistency>" << item.getFacePersistency() <<
"</facePersistency>";
402 os <<
"<linkType>" << item.getLinkType() <<
"</linkType>";
404 if (!item.hasBaseCongestionMarkingInterval() && !item.hasDefaultCongestionThreshold()) {
405 os <<
"<congestion/>";
408 os <<
"<congestion>";
409 if (item.hasBaseCongestionMarkingInterval()) {
410 os <<
"<baseMarkingInterval>" <<
xml::formatDuration(item.getBaseCongestionMarkingInterval())
411 <<
"</baseMarkingInterval>";
413 if (item.hasDefaultCongestionThreshold()) {
414 os <<
"<defaultThreshold>" << item.getDefaultCongestionThreshold() <<
"</defaultThreshold>";
416 os <<
"</congestion>";
420 os <<
"<mtu>" << item.getMtu() <<
"</mtu>";
423 if (item.getFlags() == 0) {
428 os <<
xml::Flag{
"localFieldsEnabled", item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)};
429 os <<
xml::Flag{
"lpReliabilityEnabled", item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)};
430 os <<
xml::Flag{
"congestionMarkingEnabled", item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)};
434 os <<
"<packetCounters>";
435 os <<
"<incomingPackets>"
436 <<
"<nInterests>" << item.getNInInterests() <<
"</nInterests>"
437 <<
"<nData>" << item.getNInData() <<
"</nData>"
438 <<
"<nNacks>" << item.getNInNacks() <<
"</nNacks>"
439 <<
"</incomingPackets>";
440 os <<
"<outgoingPackets>"
441 <<
"<nInterests>" << item.getNOutInterests() <<
"</nInterests>"
442 <<
"<nData>" << item.getNOutData() <<
"</nData>"
443 <<
"<nNacks>" << item.getNOutNacks() <<
"</nNacks>"
444 <<
"</outgoingPackets>";
445 os <<
"</packetCounters>";
447 os <<
"<byteCounters>";
448 os <<
"<incomingBytes>" << item.getNInBytes() <<
"</incomingBytes>";
449 os <<
"<outgoingBytes>" << item.getNOutBytes() <<
"</outgoingBytes>";
450 os <<
"</byteCounters>";
459 for (
const FaceStatus& item : m_status) {
471 os << ia(
"faceid") << item.getFaceId();
472 os << ia(
"remote") << item.getRemoteUri();
473 os << ia(
"local") << item.getLocalUri();
475 if (item.hasExpirationPeriod()) {
476 os << ia(
"expires") << text::formatDuration<time::seconds>(item.getExpirationPeriod());
479 if (item.hasBaseCongestionMarkingInterval() || item.hasDefaultCongestionThreshold()) {
480 os << ia(
"congestion") <<
"{";
482 if (item.hasBaseCongestionMarkingInterval()) {
483 os << congestionSep <<
"base-marking-interval="
484 << text::formatDuration<time::milliseconds>(item.getBaseCongestionMarkingInterval());
486 if (item.hasDefaultCongestionThreshold()) {
487 os << congestionSep <<
"default-threshold=" << item.getDefaultCongestionThreshold() <<
"B";
493 os << ia(
"mtu") << item.getMtu();
498 << item.getNInInterests() <<
"i "
499 << item.getNInData() <<
"d "
500 << item.getNInNacks() <<
"n "
501 << item.getNInBytes() <<
"B} "
503 << item.getNOutInterests() <<
"i "
504 << item.getNOutData() <<
"d "
505 << item.getNOutNacks() <<
"n "
506 << item.getNOutBytes() <<
"B}}";
508 os << ia(
"flags") <<
'{';
510 os << flagSep << item.getFaceScope();
511 os << flagSep << item.getFacePersistency();
512 os << flagSep << item.getLinkType();
513 if (item.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)) {
514 os << flagSep <<
"local-fields";
516 if (item.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)) {
517 os << flagSep <<
"lp-reliability";
519 if (item.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) {
520 os << flagSep <<
"congestion-marking";
529 const std::string& actionSummary,
530 const ControlParameters& resp)
533 os << actionSummary <<
' '
534 << ia(
"id") << resp.getFaceId()
535 << ia(
"local") << resp.getLocalUri()
536 << ia(
"remote") << resp.getUri()
537 << ia(
"persistency") << resp.getFacePersistency();
544 os << ia(
"reliability") <<
text::OnOff{resp.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)}
545 << ia(
"congestion-marking") <<
text::OnOff{resp.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)};
546 if (resp.hasBaseCongestionMarkingInterval()) {
547 os << ia(
"congestion-marking-interval")
548 << text::formatDuration<time::milliseconds>(resp.getBaseCongestionMarkingInterval());
550 if (resp.hasDefaultCongestionThreshold()) {
551 os << ia(
"default-congestion-threshold") << resp.getDefaultCongestionThreshold() <<
"B";
554 os << ia(
"mtu") << resp.getMtu();
Context for command execution.
std::ostream & out
output stream
const CommandArguments & args
int exitCode
program exit code
Controller::CommandFailCallback makeCommandFailureHandler(const std::string &commandName)
ndn::nfd::CommandOptions makeCommandOptions() const
std::ostream & err
error stream
Print attributes of an item.
Print different string on first and subsequent usage.
Print boolean as 'on' or 'off'.