blob: eaf1f1a12cf6c0e5a4b961ad04f052f2e305ef67 [file] [log] [blame]
Vince Lehman9a709032014-09-13 16:28:07 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 *
21 **/
22
23#include "test-common.hpp"
24#include "dummy-face.hpp"
25
26#include "route/routing-table-calculator.hpp"
27
28#include "adjacency-list.hpp"
29#include "lsa.hpp"
30#include "lsdb.hpp"
31#include "nlsr.hpp"
32#include "route/map.hpp"
33#include "route/routing-table.hpp"
34
35#include <boost/test/unit_test.hpp>
36
37namespace nlsr {
38namespace test {
39
40using ndn::DummyFace;
41using ndn::shared_ptr;
42using ndn::time::system_clock;
43static const system_clock::TimePoint MAX_TIME = system_clock::TimePoint::max();
44
45class HyperbolicCalculatorFixture : public BaseFixture
46{
47public:
48 HyperbolicCalculatorFixture()
49 : face(ndn::makeDummyFace())
50 , nlsr(g_ioService, g_scheduler, ndn::ref(*face))
51 , routingTable(nlsr.getRoutingTable())
52 , adjacencies(nlsr.getAdjacencyList())
53 , lsdb(nlsr.getLsdb())
54 {
55 setUpTopology();
56 }
57
58 // Triangle topology with routers A, B, C connected
59 void setUpTopology()
60 {
61 INIT_LOGGERS("/tmp", "TRACE");
62
63 Adjacent a(ROUTER_A_NAME, ROUTER_A_FACE, 0, Adjacent::STATUS_ACTIVE, 0, 0);
64 Adjacent b(ROUTER_B_NAME, ROUTER_B_FACE, 0, Adjacent::STATUS_ACTIVE, 0, 0);
65 Adjacent c(ROUTER_C_NAME, ROUTER_C_FACE, 0, Adjacent::STATUS_ACTIVE, 0, 0);
66
67 // Router A
68 adjacencies.insert(b);
69 adjacencies.insert(c);
70
71 AdjLsa adjA(a.getName(), "adjacency", 1, MAX_TIME, 2, adjacencies);
72 lsdb.installAdjLsa(adjA);
73
74 CoordinateLsa coordA(adjA.getOrigRouter(), "coordinate", 1, MAX_TIME, 16.23, 2.97);
75 lsdb.installCoordinateLsa(coordA);
76
77 // Router B
78 a.setFaceId(1);
79 c.setFaceId(2);
80
81 AdjacencyList adjacencyListB;
82 adjacencyListB.insert(a);
83 adjacencyListB.insert(c);
84
85 AdjLsa adjB(b.getName(), "adjacency", 1, MAX_TIME, 2, adjacencyListB);
86 lsdb.installAdjLsa(adjB);
87
88 CoordinateLsa coordB(adjB.getOrigRouter(), "coordinate", 1, MAX_TIME, 16.59, 3.0);
89 lsdb.installCoordinateLsa(coordB);
90
91 // Router C
92 a.setFaceId(1);
93 b.setFaceId(2);
94
95 AdjacencyList adjacencyListC;
96 adjacencyListC.insert(a);
97 adjacencyListC.insert(b);
98
99 AdjLsa adjC(c.getName(), "adjacency", 1, MAX_TIME, 2, adjacencyListC);
100 lsdb.installAdjLsa(adjC);
101
102 CoordinateLsa coordC(adjC.getOrigRouter(), "coordinate", 1, MAX_TIME, 14.11, 2.99);
103 lsdb.installCoordinateLsa(coordC);
104
105 map.createFromAdjLsdb(nlsr);
106 }
107
108public:
109 shared_ptr<DummyFace> face;
110 Nlsr nlsr;
111 Map map;
112
113 RoutingTable& routingTable;
114 AdjacencyList& adjacencies;
115 Lsdb& lsdb;
116
117 static const ndn::Name ROUTER_A_NAME;
118 static const ndn::Name ROUTER_B_NAME;
119 static const ndn::Name ROUTER_C_NAME;
120
121 static const std::string ROUTER_A_FACE;
122 static const std::string ROUTER_B_FACE;
123 static const std::string ROUTER_C_FACE;
124};
125
126const ndn::Name HyperbolicCalculatorFixture::ROUTER_A_NAME = "/ndn/router/a";
127const ndn::Name HyperbolicCalculatorFixture::ROUTER_B_NAME = "/ndn/router/b";
128const ndn::Name HyperbolicCalculatorFixture::ROUTER_C_NAME = "/ndn/router/c";
129
130const std::string HyperbolicCalculatorFixture::ROUTER_A_FACE = "face-a";
131const std::string HyperbolicCalculatorFixture::ROUTER_B_FACE = "face-b";
132const std::string HyperbolicCalculatorFixture::ROUTER_C_FACE = "face-c";
133
134BOOST_FIXTURE_TEST_SUITE(TestHyperbolicRoutingCalculator, HyperbolicCalculatorFixture)
135
136BOOST_AUTO_TEST_CASE(Basic)
137{
138 HyperbolicRoutingCalculator calculator(map.getMapSize(), false, ROUTER_A_NAME);
139 calculator.calculatePaths(map, routingTable, lsdb, adjacencies);
140
141 RoutingTableEntry* entryB = routingTable.findRoutingTableEntry(ROUTER_B_NAME);
142
143 // Router A should be able to get to B through B with cost 0 and to B through
144 // C with cost 2010
145 NexthopList& bHopList = entryB->getNexthopList();
146 BOOST_REQUIRE_EQUAL(bHopList.getNextHops().size(), 2);
147
148 for (std::list<NextHop>::iterator it = bHopList.begin(); it != bHopList.end(); ++it) {
149 std::string faceUri = it->getConnectingFaceUri();
150 uint64_t cost = it->getRouteCostAsAdjustedInteger();
151
152 BOOST_CHECK((faceUri == ROUTER_B_FACE && cost == 0) ||
153 (faceUri == ROUTER_C_FACE && cost == 2010));
154 }
155
156 RoutingTableEntry* entryC = routingTable.findRoutingTableEntry(ROUTER_C_NAME);
157
158 // Router A should be able to get to C through C with cost 0 and to C through
159 // B with cost 2010
160 NexthopList& cHopList = entryC->getNexthopList();
161 BOOST_REQUIRE_EQUAL(cHopList.getNextHops().size(), 2);
162
163 for (std::list<NextHop>::iterator it = cHopList.begin(); it != cHopList.end(); ++it) {
164 std::string faceUri = it->getConnectingFaceUri();
165 uint64_t cost = it->getRouteCostAsAdjustedInteger();
166
167 BOOST_CHECK((faceUri == ROUTER_B_FACE && cost == 2010) ||
168 (faceUri == ROUTER_C_FACE && cost == 0));
169 }
170}
171
172BOOST_AUTO_TEST_SUITE_END()
173
174} //namespace test
175} //namespace nlsr