35 : m_scheduler(scheduler)
37 , m_routingCalcInterval{confParam.getRoutingCalcInterval()}
38 , m_isRoutingTableCalculating(false)
39 , m_isRouteCalculationScheduled(false)
40 , m_confParam(confParam)
41 , m_hyperbolicState(m_confParam.getHyperbolicState())
44 [
this] (std::shared_ptr<Lsa> lsa,
LsdbUpdate updateType,
45 const auto& namesToAdd,
const auto& namesToRemove) {
46 auto type = lsa->getType();
47 bool updateForOwnAdjacencyLsa = lsa->getOriginRouter() == m_confParam.
getRouterPrefix() &&
49 bool scheduleCalculation =
false;
56 NLSR_LOG_DEBUG(
"No Adj LSA of router itself, routing table can not be calculated :(");
58 clearDryRoutingTable();
62 m_ownAdjLsaExist =
false;
66 m_ownAdjLsaExist =
true;
73 scheduleCalculation =
true;
77 if (scheduleCalculation) {
90 if (m_isRoutingTableCalculating ==
false) {
91 m_isRoutingTableCalculating =
true;
94 calculateLsRoutingTable();
97 calculateLsRoutingTable();
98 calculateHypRoutingTable(
true);
101 calculateHypRoutingTable(
false);
104 m_isRouteCalculationScheduled =
false;
105 m_isRoutingTableCalculating =
false;
113 RoutingTable::calculateLsRoutingTable()
118 NLSR_LOG_DEBUG(
"Adjacency build is scheduled, routing table can not be calculated :(");
124 if (!m_ownAdjLsaExist) {
132 map.createFromAdjLsdb(lsaRange.first, lsaRange.second);
135 size_t nRouters = map.getMapSize();
137 LinkStateRoutingTableCalculator calculator(nRouters);
139 calculator.calculatePath(map, *
this, m_confParam, m_lsdb);
147 RoutingTable::calculateHypRoutingTable(
bool isDryRun)
150 clearDryRoutingTable();
158 map.createFromCoordinateLsdb(lsaRange.first, lsaRange.second);
161 size_t nRouters = map.getMapSize();
163 HyperbolicRoutingCalculator calculator(nRouters, isDryRun, m_confParam.
getRouterPrefix());
165 calculator.calculatePath(map, *
this, m_lsdb, m_confParam.
getAdjacencyList());
177 if (!m_isRouteCalculationScheduled) {
178 NLSR_LOG_DEBUG(
"Scheduling routing table calculation in " << m_routingCalcInterval);
179 m_scheduler.schedule(m_routingCalcInterval, [
this] {
calculate(); });
180 m_isRouteCalculationScheduled =
true;
193 NLSR_LOG_DEBUG(
"Adding " << nh <<
" for destination: " << destRouter);
196 if (rteChk ==
nullptr) {
221 NLSR_LOG_DEBUG(
"Adding " << nh <<
" to dry table for destination: " << destRouter);
231 it->getNexthopList().addNextHop(nh);
237 RoutingTable::clearRoutingTable()
244 RoutingTable::clearDryRoutingTable()
250 template<ndn::encoding::Tag TAG>
254 size_t totalLength = 0;
257 totalLength += it->wireEncode(block);
261 totalLength += it->wireEncode(block);
264 totalLength += block.prependVarNumber(totalLength);
279 ndn::EncodingEstimator estimator;
282 ndn::EncodingBuffer buffer(estimatedSize, 0);
291 RoutingTableStatus::wireDecode(
const ndn::Block& wire)
302 auto val =
m_wire.elements_begin();
304 std::set<ndn::Name> destinations;
308 if (destinations.emplace(entry.getDestination()).second) {
317 if (val !=
m_wire.elements_end()) {
318 NDN_THROW(
Error(
"Unrecognized TLV of type " + ndn::to_string(val->type()) +
" in RoutingTable"));
325 os <<
"Routing Table:\n";
331 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
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)
@ HYPERBOLIC_STATE_DRY_RUN
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Adjacent)