36 : m_scheduler(scheduler)
38 , m_routingCalcInterval{confParam.getRoutingCalcInterval()}
39 , m_isRoutingTableCalculating(false)
40 , m_isRouteCalculationScheduled(false)
41 , m_confParam(confParam)
42 , m_hyperbolicState(m_confParam.getHyperbolicState())
45 [
this] (std::shared_ptr<Lsa> lsa,
LsdbUpdate updateType,
46 const auto& namesToAdd,
const auto& namesToRemove) {
47 auto type = lsa->getType();
48 bool updateForOwnAdjacencyLsa = lsa->getOriginRouter() == m_confParam.
getRouterPrefix() &&
50 bool scheduleCalculation =
false;
57 NLSR_LOG_DEBUG(
"No Adj LSA of router itself, routing table can not be calculated :(");
59 clearDryRoutingTable();
63 m_ownAdjLsaExist =
false;
67 m_ownAdjLsaExist =
true;
74 scheduleCalculation =
true;
78 if (scheduleCalculation) {
91 if (m_isRoutingTableCalculating ==
false) {
92 m_isRoutingTableCalculating =
true;
95 calculateLsRoutingTable();
98 calculateLsRoutingTable();
99 calculateHypRoutingTable(
true);
102 calculateHypRoutingTable(
false);
105 m_isRouteCalculationScheduled =
false;
106 m_isRoutingTableCalculating =
false;
114 RoutingTable::calculateLsRoutingTable()
119 NLSR_LOG_DEBUG(
"Adjacency build is scheduled, routing table can not be calculated :(");
125 if (!m_ownAdjLsaExist) {
143 RoutingTable::calculateHypRoutingTable(
bool isDryRun)
146 clearDryRoutingTable();
169 if (!m_isRouteCalculationScheduled) {
170 NLSR_LOG_DEBUG(
"Scheduling routing table calculation in " << m_routingCalcInterval);
171 m_scheduler.schedule(m_routingCalcInterval, [
this] {
calculate(); });
172 m_isRouteCalculationScheduled =
true;
185 NLSR_LOG_DEBUG(
"Adding " << nh <<
" for destination: " << destRouter);
188 if (rteChk ==
nullptr) {
213 NLSR_LOG_DEBUG(
"Adding " << nh <<
" to dry table for destination: " << destRouter);
223 it->getNexthopList().addNextHop(nh);
229 RoutingTable::clearRoutingTable()
236 RoutingTable::clearDryRoutingTable()
242 template<ndn::encoding::Tag TAG>
246 size_t totalLength = 0;
249 totalLength += it->wireEncode(block);
253 totalLength += it->wireEncode(block);
256 totalLength += block.prependVarNumber(totalLength);
271 ndn::EncodingEstimator estimator;
274 ndn::EncodingBuffer buffer(estimatedSize, 0);
283 RoutingTableStatus::wireDecode(
const ndn::Block& wire)
294 auto val =
m_wire.elements_begin();
296 std::set<ndn::Name> destinations;
300 if (destinations.emplace(entry.getDestination()).second) {
309 if (val !=
m_wire.elements_end()) {
310 NDN_THROW(
Error(
"Unrecognized TLV of type " + ndn::to_string(val->type()) +
" in RoutingTable"));
317 os <<
"Routing Table:\n";
323 os <<
"Dry-Run Hyperbolic Routing Table:\n";
A class to house all the configuration parameters for NLSR.
const ndn::Name & getRouterPrefix() const
AdjacencyList & getAdjacencyList()
std::pair< LsaContainer::index< Lsdb::byType >::type::iterator, LsaContainer::index< Lsdb::byType >::type::iterator > getLsdbIterator() const
AfterLsdbModified onLsdbModified
bool getIsBuildAdjLsaScheduled() const
static NameMap createFromCoordinateLsdb(IteratorType first, IteratorType last)
Create a NameMap populated with router names in Coordinate LSAs.
static NameMap createFromAdjLsdb(IteratorType first, IteratorType last)
Create a NameMap populated with router names in Adjacency LSAs.
Data abstraction for Nexthop.
void addNextHop(const NextHop &nh)
Adds a next hop to the list.
Data abstraction for RouteTableInfo.
const ndn::Name & getDestination() const
NexthopList & getNexthopList()
void calculate()
Calculates a list of next hops for each router in the network.
void scheduleRoutingTableCalculation()
Schedules a calculation event in the event scheduler only if one isn't already scheduled.
AfterRoutingChange afterRoutingChange
void addNextHopToDryTable(const ndn::Name &destRouter, NextHop &nh)
Adds a next hop to a routing table entry in a dry run scenario.
void addNextHop(const ndn::Name &destRouter, NextHop &nh)
Adds a next hop to a routing table entry.
RoutingTable(ndn::Scheduler &scheduler, Lsdb &lsdb, ConfParameter &confParam)
RoutingTableEntry * findRoutingTableEntry(const ndn::Name &destRouter)
Data abstraction for routing table status.
const std::list< RoutingTableEntry > & getDryRoutingTableEntry() const
std::list< RoutingTableEntry > m_dryTable
std::list< RoutingTableEntry > m_rTable
const ndn::Block & wireEncode() const
const std::list< RoutingTableEntry > & getRoutingTableEntry() const
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#define NLSR_LOG_DEBUG(x)
#define INIT_LOGGER(name)
#define NLSR_LOG_TRACE(x)
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
static bool routingTableEntryCompare(RoutingTableEntry &rte, ndn::Name &destRouter)
void calculateHyperbolicRoutingPath(NameMap &map, RoutingTable &rt, Lsdb &lsdb, AdjacencyList &adjacencies, ndn::Name thisRouterName, bool isDryRun)
@ HYPERBOLIC_STATE_DRY_RUN
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Adjacent)
void calculateLinkStateRoutingPath(NameMap &map, RoutingTable &rt, ConfParameter &confParam, const Lsdb &lsdb)