27 #include <ndn-cxx/mgmt/nfd/control-response.hpp> 28 #include <ndn-cxx/util/regex.hpp> 37 const ndn::PartialName
RT_DATASET = ndn::PartialName(
"routing-table");
41 ndn::mgmt::Dispatcher& dispatcher,
42 const ndn::Face& face,
43 const ndn::KeyChain& keyChain)
45 , m_dispatcher(dispatcher)
46 , m_routingTableEntries(rt.getRoutingTableEntry())
47 , m_dryRoutingTableEntries(rt.getDryRoutingTableEntry())
49 setDispatcher(m_dispatcher);
53 DatasetInterestHandler::setDispatcher(ndn::mgmt::Dispatcher& dispatcher)
55 dispatcher.addStatusDataset(ADJACENCIES_DATASET,
56 ndn::mgmt::makeAcceptAllAuthorization(),
57 std::bind(&DatasetInterestHandler::publishAdjStatus,
this, _1, _2, _3));
58 dispatcher.addStatusDataset(COORDINATES_DATASET,
59 ndn::mgmt::makeAcceptAllAuthorization(),
60 std::bind(&DatasetInterestHandler::publishCoordinateStatus,
this, _1, _2, _3));
61 dispatcher.addStatusDataset(NAMES_DATASET,
62 ndn::mgmt::makeAcceptAllAuthorization(),
63 std::bind(&DatasetInterestHandler::publishNameStatus,
this, _1, _2, _3));
64 dispatcher.addStatusDataset(RT_DATASET,
65 ndn::mgmt::makeAcceptAllAuthorization(),
66 std::bind(&DatasetInterestHandler::publishRtStatus,
this, _1, _2, _3));
70 DatasetInterestHandler::publishAdjStatus(
const ndn::Name& topPrefix,
const ndn::Interest& interest,
71 ndn::mgmt::StatusDatasetContext& context)
75 auto lsaRange = std::make_pair<std::list<AdjLsa>::const_iterator,
76 std::list<AdjLsa>::const_iterator>(
78 for (
auto lsa = lsaRange.first; lsa != lsaRange.second; lsa++) {
83 for (
const Adjacent& adj : lsa->getAdl().getAdjList()) {
86 tlvAdj.
setUri(adj.getFaceUri().toString());
87 tlvAdj.
setCost(adj.getLinkCost());
97 DatasetInterestHandler::publishCoordinateStatus(
const ndn::Name& topPrefix,
const ndn::Interest& interest,
98 ndn::mgmt::StatusDatasetContext& context)
100 auto lsaRange = std::make_pair<std::list<CoordinateLsa>::const_iterator,
101 std::list<CoordinateLsa>::const_iterator>(
105 for (
auto lsa = lsaRange.first; lsa != lsaRange.second; lsa++) {
114 context.append(wire);
120 DatasetInterestHandler::publishNameStatus(
const ndn::Name& topPrefix,
const ndn::Interest& interest,
121 ndn::mgmt::StatusDatasetContext& context)
123 auto lsaRange = std::make_pair<std::list<NameLsa>::const_iterator, std::list<NameLsa>::const_iterator>(
126 for (
auto lsa = lsaRange.first; lsa != lsaRange.second; lsa++) {
132 for (
const ndn::Name& name : lsa->getNpl().getNames()) {
137 context.append(wire);
143 std::vector<tlv::RoutingTable>
144 DatasetInterestHandler::getTlvRTEntries()
146 std::vector<tlv::RoutingTable> rtable;
147 for (
const auto& rte : m_routingTableEntries) {
149 std::shared_ptr<tlv::Destination> tlvDes =
tlv::makeDes(rte);
151 for (
const auto& nh : rte.getNexthopList().getNextHops()) {
153 tlvNexthop.
setUri(nh.getConnectingFaceUri());
154 tlvNexthop.
setCost(nh.getRouteCost());
157 rtable.push_back(tlvRoutingTable);
159 if (!m_dryRoutingTableEntries.empty()) {
160 for (
const auto& dryRte : m_dryRoutingTableEntries) {
162 std::shared_ptr<tlv::Destination> tlvDes =
tlv::makeDes(dryRte);
164 for (
const auto& nh : dryRte.getNexthopList().getNextHops()) {
166 tlvNexthop.
setUri(nh.getConnectingFaceUri());
167 tlvNexthop.
setCost(nh.getRouteCost());
170 rtable.push_back(tlvRoutingTable);
177 DatasetInterestHandler::publishRtStatus(
const ndn::Name& topPrefix,
const ndn::Interest& interest,
178 ndn::mgmt::StatusDatasetContext& context)
185 const ndn::Block& wire = rtStatus.
wireEncode();
186 context.append(wire);
190 template<> std::list<tlv::AdjacencyLsa>
191 getTlvLsas<tlv::AdjacencyLsa>(
const Lsdb& lsdb)
193 std::list<tlv::AdjacencyLsa> lsas;
195 auto lsaRange = std::make_pair<std::list<AdjLsa>::const_iterator,
196 std::list<AdjLsa>::const_iterator>(
197 lsdb.getAdjLsdb().cbegin(), lsdb.getAdjLsdb().cend());
198 for (
auto lsa = lsaRange.first; lsa != lsaRange.second; lsa++) {
204 for (
const Adjacent& adj : lsa->getAdl().getAdjList()) {
207 tlvAdj.
setUri(adj.getFaceUri().toString());
208 tlvAdj.
setCost(adj.getLinkCost());
211 lsas.push_back(tlvLsa);
218 template<> std::list<tlv::CoordinateLsa>
219 getTlvLsas<tlv::CoordinateLsa>(
const Lsdb& lsdb)
221 std::list<tlv::CoordinateLsa> lsas;
223 auto lsaRange = std::make_pair<std::list<CoordinateLsa>::const_iterator,
224 std::list<CoordinateLsa>::const_iterator>(
225 lsdb.getCoordinateLsdb().cbegin(), lsdb.getCoordinateLsdb().cend());
227 for (
auto lsa = lsaRange.first; lsa != lsaRange.second; lsa++) {
236 lsas.push_back(tlvLsa);
243 template<> std::list<tlv::NameLsa>
244 getTlvLsas<tlv::NameLsa>(
const Lsdb& lsdb)
246 std::list<tlv::NameLsa> lsas;
248 auto lsaRange = std::make_pair<std::list<NameLsa>::const_iterator,
249 std::list<NameLsa>::const_iterator>(
250 lsdb.getNameLsdb().cbegin(), lsdb.getNameLsdb().cend());
251 for (
auto lsa = lsaRange.first; lsa != lsaRange.second; lsa++) {
257 for (
const ndn::Name& name : lsa->getNpl().getNames()) {
261 lsas.push_back(tlvLsa);
NextHop & setUri(const std::string &uri)
Adjacency & setCost(uint64_t cost)
const std::list< NameLsa > & getNameLsdb() const
CoordinateLsa & setHyperbolicAngle(const std::vector< double > &hyperbolicAngle)
size_t wireEncode(ndn::EncodingImpl< TAG > &block) const
Encodes the Adjacent objects and some info using the method in TAG.
Data abstraction for Nexthop.
RoutingTableStatus & addRoutingTable(const RoutingTable &routeTable)
AdjacencyLsa & addAdjacency(const Adjacency &adjacency)
NameLsa & addName(const ndn::Name &name)
size_t wireEncode(ndn::EncodingImpl< TAG > &block) const
Encodes the Name objects and some info using the method in TAG.
const ndn::PartialName COORDINATES_DATASET
#define NLSR_LOG_DEBUG(x)
std::shared_ptr< Destination > makeDes(const RoutingTableEntry &rte)
NameLsa & setLsaInfo(const LsaInfo &lsaInfo)
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
Data abstraction for routing table status.
Data abstraction for CoordinateLsa.
CoordinateLsa & setHyperbolicRadius(double hyperbolicRadius)
#define INIT_LOGGER(name)
const std::list< CoordinateLsa > & getCoordinateLsdb() const
Data abstraction for RouteTableInfo.
Adjacency & setUri(const std::string &uri)
const ndn::PartialName ADJACENCIES_DATASET
size_t wireEncode(ndn::EncodingImpl< TAG > &block) const
Encodes the hyperbolic coordinates and some info using the method in TAG.
size_t wireEncode(ndn::EncodingImpl< TAG > &block) const
std::shared_ptr< LsaInfo > makeLsaInfo(const Lsa &lsa)
RoutingTable & setDestination(const Destination &des)
AdjacencyLsa & setLsaInfo(const LsaInfo &lsaInfo)
Data abstraction for NameLsa.
A neighbor reachable over a Face.
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
Data abstraction for AdjacencyLsa.
const ndn::PartialName NAMES_DATASET
const ndn::PartialName RT_DATASET
DatasetInterestHandler(const Lsdb &lsdb, const RoutingTable &rt, ndn::mgmt::Dispatcher &dispatcher, const ndn::Face &face, const ndn::KeyChain &keyChain)
NextHop & setCost(double cost)
Data abstraction for Adjacency.
const std::list< AdjLsa > & getAdjLsdb() const
Adjacency & setName(const ndn::Name &name)
CoordinateLsa & setLsaInfo(const LsaInfo &lsaInfo)
RoutingTable & addNexthops(const NextHop &nexthop)