43 parser.
addAlias(
"route",
"list",
"");
47 .
setTitle(
"show routes toward a prefix")
75 auto nexthopIt = ctx.
args.find(
"nexthop");
76 std::set<uint64_t> nexthops;
79 if (nexthopIt != ctx.
args.end()) {
83 ctx.
exitCode =
static_cast<int>(res);
93 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
100 listRoutesImpl(ctx, [&] (
const RibEntry& entry,
const Route& route) {
101 return (nexthops.empty() || nexthops.count(route.getFaceId()) > 0) &&
102 (!origin || route.getOrigin() == *origin);
109 auto prefix = ctx.
args.
get<Name>(
"prefix");
111 listRoutesImpl(ctx, [&] (
const RibEntry& entry,
const Route& route) {
112 return entry.getName() == prefix;
117 RibModule::listRoutesImpl(
ExecuteContext& ctx,
const RoutePredicate& filter)
120 [&] (
const std::vector<RibEntry>& dataset) {
121 bool hasRoute =
false;
122 for (
const RibEntry& entry : dataset) {
123 for (
const Route& route : entry.getRoutes()) {
124 if (filter(entry, route)) {
126 formatRouteText(ctx.
out, entry, route,
true);
134 ctx.
err <<
"Route not found\n";
140 ctx.
face.processEvents();
146 auto prefix = ctx.
args.
get<Name>(
"prefix");
147 auto nexthop = ctx.
args.at(
"nexthop");
148 auto origin = ctx.
args.
get<RouteOrigin>(
"origin", ndn::nfd::ROUTE_ORIGIN_STATIC);
149 auto cost = ctx.
args.
get<uint64_t>(
"cost", 0);
150 bool wantChildInherit = !ctx.
args.
get<
bool>(
"no-inherit",
false);
151 bool wantCapture = ctx.
args.
get<
bool>(
"capture",
false);
157 ctx.
exitCode =
static_cast<int>(res);
164 ctx.
err << findFace.getErrorReason() <<
'\n';
167 ctx.
err <<
"Multiple faces match specified remote FaceUri. Re-run the command with a FaceId:";
172 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
176 ControlParameters registerParams;
179 .setFaceId(findFace.getFaceId())
182 .setFlags((wantChildInherit ? ndn::nfd::ROUTE_FLAG_CHILD_INHERIT : ndn::nfd::ROUTE_FLAGS_NONE) |
183 (wantCapture ? ndn::nfd::ROUTE_FLAG_CAPTURE : ndn::nfd::ROUTE_FLAGS_NONE));
185 registerParams.setExpirationPeriod(time::milliseconds(*expiresMillis));
188 ctx.
controller.start<ndn::nfd::RibRegisterCommand>(
190 [&] (
const ControlParameters& resp) {
191 ctx.
out <<
"route-add-accepted ";
193 ctx.
out << ia(
"prefix") << resp.getName()
194 << ia(
"nexthop") << resp.getFaceId()
195 << ia(
"origin") << resp.getOrigin()
196 << ia(
"cost") << resp.getCost()
197 << ia(
"flags") <<
static_cast<ndn::nfd::RouteFlags
>(resp.getFlags());
198 if (resp.hasExpirationPeriod()) {
199 ctx.
out << ia(
"expires") << text::formatDuration<time::milliseconds>(resp.getExpirationPeriod()) <<
"\n";
202 ctx.
out<< ia(
"expires") <<
"never\n";
208 ctx.
face.processEvents();
214 auto prefix = ctx.
args.
get<Name>(
"prefix");
215 auto nexthop = ctx.
args.at(
"nexthop");
216 auto origin = ctx.
args.
get<RouteOrigin>(
"origin", ndn::nfd::ROUTE_ORIGIN_STATIC);
221 ctx.
exitCode =
static_cast<int>(res);
228 ctx.
err << findFace.getErrorReason() <<
'\n';
231 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
235 for (uint64_t faceId : findFace.getFaceIds()) {
236 ControlParameters unregisterParams;
242 ctx.
controller.start<ndn::nfd::RibUnregisterCommand>(
244 [&] (
const ControlParameters& resp) {
245 ctx.
out <<
"route-removed ";
247 ctx.
out << ia(
"prefix") << resp.getName()
248 << ia(
"nexthop") << resp.getFaceId()
249 << ia(
"origin") << resp.getOrigin()
256 ctx.
face.processEvents();
261 const std::function<
void()>& onSuccess,
262 const Controller::DatasetFailCallback& onFailure,
263 const CommandOptions& options)
265 controller.fetch<ndn::nfd::RibDataset>(
266 [
this, onSuccess] (
const std::vector<RibEntry>& result) {
277 for (
const RibEntry& item : m_status) {
278 this->formatItemXml(os, item);
284 RibModule::formatItemXml(std::ostream& os,
const RibEntry& item)
const 288 os <<
"<prefix>" <<
xml::Text{item.getName().toUri()} <<
"</prefix>";
291 for (
const Route& route : item.getRoutes()) {
293 <<
"<faceId>" << route.getFaceId() <<
"</faceId>" 294 <<
"<origin>" << route.getOrigin() <<
"</origin>" 295 <<
"<cost>" << route.getCost() <<
"</cost>";
296 if (route.getFlags() == ndn::nfd::ROUTE_FLAGS_NONE) {
301 if (route.isChildInherit()) {
302 os <<
"<childInherit/>";
304 if (route.isRibCapture()) {
305 os <<
"<ribCapture/>";
309 if (route.hasExpirationPeriod()) {
310 os <<
"<expirationPeriod>" 312 <<
"</expirationPeriod>";
325 for (
const RibEntry& item : m_status) {
327 formatEntryText(os, item);
333 RibModule::formatEntryText(std::ostream& os,
const RibEntry& entry)
335 os << entry.getName() <<
" routes={";
338 for (
const Route& route : entry.getRoutes()) {
340 formatRouteText(os, entry, route,
false);
347 RibModule::formatRouteText(std::ostream& os,
const RibEntry& entry,
const Route& route,
353 os << ia(
"prefix") << entry.getName();
355 os << ia(
"nexthop") << route.getFaceId();
356 os << ia(
"origin") << route.getOrigin();
357 os << ia(
"cost") << route.getCost();
358 os << ia(
"flags") <<
static_cast<ndn::nfd::RouteFlags
>(route.getFlags());
359 if (route.hasExpirationPeriod()) {
360 os << ia(
"expires") << text::formatDuration<time::seconds>(route.getExpirationPeriod());
363 os << ia(
"expires") <<
"never";
const CommandArguments & args
ndn::nfd::CommandOptions makeCommandOptions() const
Controller::CommandFailCallback makeCommandFailureHandler(const std::string &commandName)
std::ostream & out
output stream
context for command execution
int exitCode
program exit code
Controller::DatasetFailCallback makeDatasetFailureHandler(const std::string &datasetName)
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