rib-module.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "rib-module.hpp"
27 #include "format-helpers.hpp"
28 
29 namespace nfd {
30 namespace tools {
31 namespace nfdc {
32 
33 void
34 RibModule::fetchStatus(Controller& controller,
35  const function<void()>& onSuccess,
36  const Controller::DatasetFailCallback& onFailure,
37  const CommandOptions& options)
38 {
39  controller.fetch<ndn::nfd::RibDataset>(
40  [this, onSuccess] (const std::vector<RibEntry>& result) {
41  m_status = result;
42  onSuccess();
43  },
44  onFailure, options);
45 }
46 
47 void
48 RibModule::formatStatusXml(std::ostream& os) const
49 {
50  os << "<rib>";
51  for (const RibEntry& item : m_status) {
52  this->formatItemXml(os, item);
53  }
54  os << "</rib>";
55 }
56 
57 void
58 RibModule::formatItemXml(std::ostream& os, const RibEntry& item) const
59 {
60  os << "<ribEntry>";
61 
62  os << "<prefix>" << xml::Text{item.getName().toUri()} << "</prefix>";
63 
64  os << "<routes>";
65  for (const Route& route : item.getRoutes()) {
66  os << "<route>"
67  << "<faceId>" << route.getFaceId() << "</faceId>"
68  << "<origin>" << route.getOrigin() << "</origin>"
69  << "<cost>" << route.getCost() << "</cost>";
70  if (route.getFlags() == ndn::nfd::ROUTE_FLAGS_NONE) {
71  os << "<flags/>";
72  }
73  else {
74  os << "<flags>";
75  if (route.isChildInherit()) {
76  os << "<childInherit/>";
77  }
78  if (route.isRibCapture()) {
79  os << "<ribCapture/>";
80  }
81  os << "</flags>";
82  }
83  if (!route.hasInfiniteExpirationPeriod()) {
84  os << "<expirationPeriod>"
85  << xml::formatDuration(route.getExpirationPeriod())
86  << "</expirationPeriod>";
87  }
88  os << "</route>";
89  }
90  os << "</routes>";
91 
92  os << "</ribEntry>";
93 }
94 
95 void
96 RibModule::formatStatusText(std::ostream& os) const
97 {
98  os << "RIB:\n";
99  for (const RibEntry& item : m_status) {
100  this->formatItemText(os, item);
101  }
102 }
103 
104 void
105 RibModule::formatItemText(std::ostream& os, const RibEntry& item) const
106 {
107  os << " " << item.getName() << " route={";
108 
109  text::Separator sep(", ");
110  for (const Route& route : item.getRoutes()) {
111  os << sep
112  << "faceid=" << route.getFaceId()
113  << " (origin=" << route.getOrigin()
114  << " cost=" << route.getCost();
115  if (!route.hasInfiniteExpirationPeriod()) {
116  os << " expires=" << text::formatDuration(route.getExpirationPeriod());
117  }
118  if (route.isChildInherit()) {
119  os << " ChildInherit";
120  }
121  if (route.isRibCapture()) {
122  os << " RibCapture";
123  }
124  os << ")";
125  }
126 
127  os << "}";
128  os << "\n";
129 }
130 
131 } // namespace nfdc
132 } // namespace tools
133 } // namespace nfd
virtual void formatStatusText(std::ostream &os) const override
format collected status as text
Definition: rib-module.cpp:96
void formatItemText(std::ostream &os, const RibEntry &item) const
format a single status item as text
Definition: rib-module.cpp:105
std::string formatDuration(DURATION d)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
virtual void formatStatusXml(std::ostream &os) const override
format collected status as XML
Definition: rib-module.cpp:48
std::string formatDuration(DURATION d, bool isLong=false)
void formatItemXml(std::ostream &os, const RibEntry &item) const
format a single status item as XML
Definition: rib-module.cpp:58
print different string on first and subsequent usage
virtual void fetchStatus(Controller &controller, const function< void()> &onSuccess, const Controller::DatasetFailCallback &onFailure, const CommandOptions &options) override
collect status from NFD
Definition: rib-module.cpp:34