46 .
setTitle(
"show routes toward a prefix")
74 auto nexthopIt = ctx.
args.find(
"nexthop");
75 std::set<uint64_t> nexthops;
78 if (nexthopIt != ctx.
args.end()) {
82 ctx.
exitCode =
static_cast<int>(res);
92 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
99 listRoutesImpl(ctx, [&] (
const RibEntry& entry,
const Route& route) {
100 return (nexthops.empty() || nexthops.count(route.getFaceId()) > 0) &&
101 (!origin || route.getOrigin() == *origin);
108 auto prefix = ctx.
args.
get<Name>(
"prefix");
110 listRoutesImpl(ctx, [&] (
const RibEntry& entry,
const Route& route) {
111 return entry.getName() == prefix;
116 RibModule::listRoutesImpl(
ExecuteContext& ctx,
const RoutePredicate& filter)
119 [&] (
const std::vector<RibEntry>& dataset) {
120 bool hasRoute =
false;
121 for (
const RibEntry& entry : dataset) {
122 for (
const Route& route : entry.getRoutes()) {
123 if (filter(entry, route)) {
125 formatRouteText(ctx.
out, entry, route,
true);
133 ctx.
err <<
"Route not found\n";
139 ctx.
face.processEvents();
145 auto prefix = ctx.
args.
get<Name>(
"prefix");
146 const boost::any& nexthop = ctx.
args.at(
"nexthop");
147 auto origin = ctx.
args.
get<RouteOrigin>(
"origin", ndn::nfd::ROUTE_ORIGIN_STATIC);
148 auto cost = ctx.
args.
get<uint64_t>(
"cost", 0);
149 bool wantChildInherit = !ctx.
args.
get<
bool>(
"no-inherit",
false);
150 bool wantCapture = ctx.
args.
get<
bool>(
"capture",
false);
156 ctx.
exitCode =
static_cast<int>(res);
163 ctx.
err << findFace.getErrorReason() <<
'\n';
166 ctx.
err <<
"Multiple faces match specified remote FaceUri. Re-run the command with a FaceId:";
171 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
175 ControlParameters registerParams;
178 .setFaceId(findFace.getFaceId())
181 .setFlags((wantChildInherit ? ndn::nfd::ROUTE_FLAG_CHILD_INHERIT : ndn::nfd::ROUTE_FLAGS_NONE) |
182 (wantCapture ? ndn::nfd::ROUTE_FLAG_CAPTURE : ndn::nfd::ROUTE_FLAGS_NONE));
184 registerParams.setExpirationPeriod(time::milliseconds(*expiresMillis));
187 ctx.
controller.start<ndn::nfd::RibRegisterCommand>(
189 [&] (
const ControlParameters& resp) {
190 ctx.
out <<
"route-add-accepted ";
192 ctx.
out << ia(
"prefix") << resp.getName()
193 << ia(
"nexthop") << resp.getFaceId()
194 << ia(
"origin") << resp.getOrigin()
195 << ia(
"cost") << resp.getCost()
196 << ia(
"flags") <<
static_cast<ndn::nfd::RouteFlags
>(resp.getFlags());
197 if (resp.hasExpirationPeriod()) {
198 ctx.
out << ia(
"expires") << resp.getExpirationPeriod().count() <<
"ms\n";
201 ctx.
out<< ia(
"expires") <<
"never\n";
207 ctx.
face.processEvents();
213 auto prefix = ctx.
args.
get<Name>(
"prefix");
214 const boost::any& nexthop = ctx.
args.at(
"nexthop");
215 auto origin = ctx.
args.
get<RouteOrigin>(
"origin", ndn::nfd::ROUTE_ORIGIN_STATIC);
220 ctx.
exitCode =
static_cast<int>(res);
227 ctx.
err << findFace.getErrorReason() <<
'\n';
230 BOOST_ASSERT_MSG(
false,
"unexpected FindFace result");
234 for (uint64_t faceId : findFace.getFaceIds()) {
235 ControlParameters unregisterParams;
241 ctx.
controller.start<ndn::nfd::RibUnregisterCommand>(
243 [&] (
const ControlParameters& resp) {
244 ctx.
out <<
"route-removed ";
246 ctx.
out << ia(
"prefix") << resp.getName()
247 << ia(
"nexthop") << resp.getFaceId()
248 << ia(
"origin") << resp.getOrigin()
255 ctx.
face.processEvents();
260 const function<
void()>& onSuccess,
261 const Controller::DatasetFailCallback& onFailure,
262 const CommandOptions& options)
264 controller.fetch<ndn::nfd::RibDataset>(
265 [
this, onSuccess] (
const std::vector<RibEntry>& result) {
276 for (
const RibEntry& item : m_status) {
277 this->formatItemXml(os, item);
283 RibModule::formatItemXml(std::ostream& os,
const RibEntry& item)
const 287 os <<
"<prefix>" <<
xml::Text{item.getName().toUri()} <<
"</prefix>";
290 for (
const Route& route : item.getRoutes()) {
292 <<
"<faceId>" << route.getFaceId() <<
"</faceId>" 293 <<
"<origin>" << route.getOrigin() <<
"</origin>" 294 <<
"<cost>" << route.getCost() <<
"</cost>";
295 if (route.getFlags() == ndn::nfd::ROUTE_FLAGS_NONE) {
300 if (route.isChildInherit()) {
301 os <<
"<childInherit/>";
303 if (route.isRibCapture()) {
304 os <<
"<ribCapture/>";
308 if (route.hasExpirationPeriod()) {
309 os <<
"<expirationPeriod>" 311 <<
"</expirationPeriod>";
324 for (
const RibEntry& item : m_status) {
326 formatEntryText(os, item);
332 RibModule::formatEntryText(std::ostream& os,
const RibEntry& entry)
334 os << entry.getName() <<
" routes={";
337 for (
const Route& route : entry.getRoutes()) {
339 formatRouteText(os, entry, route,
false);
346 RibModule::formatRouteText(std::ostream& os,
const RibEntry& entry,
const Route& route,
352 os << ia(
"prefix") << entry.getName();
354 os << ia(
"nexthop") << route.getFaceId();
355 os << ia(
"origin") << route.getOrigin();
356 os << ia(
"cost") << route.getCost();
357 os << ia(
"flags") <<
static_cast<ndn::nfd::RouteFlags
>(route.getFlags());
358 if (route.hasExpirationPeriod()) {
362 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::string formatDuration(DURATION d, bool isLong=false)
std::ostream & err
error stream
print different string on first and subsequent usage