36 class HyperbolicRoutingCalculator
39 HyperbolicRoutingCalculator(
size_t nRouters,
bool isDryRun, ndn::Name thisRouterName)
40 : m_nRouters(nRouters)
41 , m_isDryRun(isDryRun)
42 , m_thisRouterName(thisRouterName)
47 calculatePath(NameMap&
map,
RoutingTable& rt, Lsdb& lsdb, AdjacencyList& adjacencies);
51 getHyperbolicDistance(Lsdb& lsdb, ndn::Name src, ndn::Name dest);
54 addNextHop(
const ndn::Name& destinationRouter,
const ndn::FaceUri& faceUri,
double cost,
RoutingTable& rt);
57 calculateHyperbolicDistance(
double rI,
double rJ,
double deltaTheta);
60 calculateAngularDistance(std::vector<double> angleVectorI,
61 std::vector<double> angleVectorJ);
64 const size_t m_nRouters;
65 const bool m_isDryRun;
66 const ndn::Name m_thisRouterName;
81 std::list<Adjacent> neighbors = adjacencies.
getAdjList();
82 for (
auto adj = neighbors.begin(); adj != neighbors.end(); ++adj) {
86 NLSR_LOG_TRACE(adj->getName() <<
" is inactive; not using it as a nexthop");
90 ndn::Name srcRouterName = adj->getName();
93 if (srcRouterName == m_thisRouterName) {
98 addNextHop(srcRouterName, adj->getFaceUri(), 0, rt);
102 NLSR_LOG_WARN(adj->getName() <<
" does not exist in the router map!");
107 for (
int dest = 0; dest < static_cast<int>(m_nRouters); ++dest) {
109 if (thisRouter && dest != *thisRouter && dest != *src) {
112 if (destRouterName) {
113 double distance = getHyperbolicDistance(lsdb, srcRouterName, *destRouterName);
117 NLSR_LOG_WARN(
"Could not calculate hyperbolic distance from " << srcRouterName
118 <<
" to " << *destRouterName);
121 addNextHop(*destRouterName, adj->getFaceUri(),
distance, rt);
129 HyperbolicRoutingCalculator::getHyperbolicDistance(Lsdb& lsdb, ndn::Name src, ndn::Name dest)
131 NLSR_LOG_TRACE(
"Calculating hyperbolic distance from " << src <<
" to " << dest);
139 if (srcLsa ==
nullptr || destLsa ==
nullptr) {
143 std::vector<double> srcTheta = srcLsa->getTheta();
144 std::vector<double> destTheta = destLsa->getTheta();
146 double srcRadius = srcLsa->getRadius();
147 double destRadius = destLsa->getRadius();
149 double diffTheta = calculateAngularDistance(srcTheta, destTheta);
157 distance = calculateHyperbolicDistance(srcRadius, destRadius, diffTheta);
165 HyperbolicRoutingCalculator::calculateAngularDistance(std::vector<double> angleVectorI,
166 std::vector<double> angleVectorJ)
173 if (angleVectorI.size() != angleVectorJ.size()) {
179 if (angleVectorI.size() > 1) {
180 for (
unsigned int k = 0; k < angleVectorI.size() - 1; k++) {
181 if ((angleVectorI[k] > M_PI && angleVectorI[k] < 0.0) ||
182 (angleVectorJ[k] > M_PI && angleVectorJ[k] < 0.0)) {
189 if (angleVectorI[angleVectorI.size()-1] > 2.*M_PI ||
190 angleVectorI[angleVectorI.size()-1] < 0.0) {
195 if (angleVectorI[angleVectorI.size()-1] > 2.*M_PI ||
196 angleVectorI[angleVectorI.size()-1] < 0.0) {
202 double innerProduct = 0.0;
205 double x0i = std::cos(angleVectorI[0]);
206 double x0j = std::cos(angleVectorJ[0]);
209 double xni = std::sin(angleVectorI[angleVectorI.size() - 1]);
210 double xnj = std::sin(angleVectorJ[angleVectorJ.size() - 1]);
214 for (
unsigned int k = 0; k < angleVectorI.size() - 1; k++) {
215 xni *= std::sin(angleVectorI[k]);
216 xnj *= std::sin(angleVectorJ[k]);
218 innerProduct += (x0i * x0j) + (xni * xnj);
221 if (angleVectorI.size() > 1) {
222 for (
unsigned int m = 1; m < angleVectorI.size(); m++) {
224 double xmi = std::cos(angleVectorI[m]);
225 double xmj = std::cos(angleVectorJ[m]);
226 for (
unsigned int l = 0; l < m; l++) {
227 xmi *= std::sin(angleVectorI[l]);
228 xmj *= std::sin(angleVectorJ[l]);
230 innerProduct += xmi * xmj;
236 return std::acos(innerProduct);
240 HyperbolicRoutingCalculator::calculateHyperbolicDistance(
double rI,
double rJ,
250 if (deltaTheta <= 0.0 || rI <= 0.0 || rJ <= 0.0) {
252 NLSR_LOG_ERROR(
"Please make sure that no two nodes have the exact same HR coordinates");
256 double xij = (1. / zeta) * std::acosh(std::cosh(zeta*rI) * std::cosh(zeta*rJ) -
257 std::sinh(zeta*rI)*std::sinh(zeta*rJ)*std::cos(deltaTheta));
262 HyperbolicRoutingCalculator::addNextHop(
const ndn::Name& dest,
const ndn::FaceUri& faceUri,
266 hop.setHyperbolic(
true);
268 NLSR_LOG_TRACE(
"Calculated " << hop <<
" for destination: " << dest);
271 rt.addNextHopToDryTable(dest, hop);
274 rt.addNextHop(dest, hop);
283 HyperbolicRoutingCalculator calculator(
map.
size(), isDryRun, thisRouterName);
284 calculator.calculatePath(
map, rt, lsdb, adjacencies);
std::list< Adjacent > & getAdjList()
Assigning numbers to router names.
std::optional< ndn::Name > getRouterNameByMappingNo(int32_t mn) const
Find router name by its mapping number.
std::optional< int32_t > getMappingNoByRouterName(const ndn::Name &rtrName) const
Find mapping number of a router name.
size_t size() const
Return number of entries in this container.
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#define INIT_LOGGER(name)
#define NLSR_LOG_ERROR(x)
#define NLSR_LOG_TRACE(x)
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
void calculateHyperbolicRoutingPath(NameMap &map, RoutingTable &rt, Lsdb &lsdb, AdjacencyList &adjacencies, ndn::Name thisRouterName, bool isDryRun)
constexpr double UNKNOWN_RADIUS
constexpr double UNKNOWN_DISTANCE
std::vector< double > distance