blob: 74a3f47f7259622cdcab67f2666d4a71282a48dc [file] [log] [blame]
Vince Lehman09131122014-09-09 17:10:11 -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
Vince Lehman02e32992015-03-11 12:31:20 -050023#include "test-common.hpp"
24#include "dummy-face.hpp"
Vince Lehman09131122014-09-09 17:10:11 -050025
Vince Lehman02e32992015-03-11 12:31:20 -050026#include "nlsr.hpp"
27
28#include <ndn-cxx/management/nfd-face-event-notification.hpp>
29#include <ndn-cxx/util/dummy-client-face.hpp>
Vince Lehman09131122014-09-09 17:10:11 -050030
31namespace nlsr {
32namespace test {
33
34using ndn::DummyFace;
35using ndn::shared_ptr;
36
37BOOST_FIXTURE_TEST_SUITE(TestNlsr, BaseFixture)
38
39BOOST_AUTO_TEST_CASE(HyperbolicOn_ZeroCostNeighbors)
40{
41 shared_ptr<DummyFace> face = ndn::makeDummyFace();
42 Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face));
43
44 // Simulate loading configuration file
45 AdjacencyList& neighbors = nlsr.getAdjacencyList();
46
47 Adjacent neighborA("/ndn/neighborA", "uri://faceA", 25, Adjacent::STATUS_INACTIVE, 0, 0);
48 neighbors.insert(neighborA);
49
50 Adjacent neighborB("/ndn/neighborB", "uri://faceB", 10, Adjacent::STATUS_INACTIVE, 0, 0);
51 neighbors.insert(neighborB);
52
53 Adjacent neighborC("/ndn/neighborC", "uri://faceC", 17, Adjacent::STATUS_INACTIVE, 0, 0);
54 neighbors.insert(neighborC);
55
56 nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON);
57
58 nlsr.initialize();
59
60 std::list<Adjacent> neighborList = neighbors.getAdjList();
61 for (std::list<Adjacent>::iterator it = neighborList.begin(); it != neighborList.end(); ++it) {
62 BOOST_CHECK_EQUAL(it->getLinkCost(), 0);
63 }
64}
65
66BOOST_AUTO_TEST_CASE(HyperbolicOff_LinkStateCost)
67{
68 shared_ptr<DummyFace> face = ndn::makeDummyFace();
69 Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face));
70
71 // Simulate loading configuration file
72 AdjacencyList& neighbors = nlsr.getAdjacencyList();
73
74 Adjacent neighborA("/ndn/neighborA", "uri://faceA", 25, Adjacent::STATUS_INACTIVE, 0, 0);
75 neighbors.insert(neighborA);
76
77 Adjacent neighborB("/ndn/neighborB", "uri://faceB", 10, Adjacent::STATUS_INACTIVE, 0, 0);
78 neighbors.insert(neighborB);
79
80 Adjacent neighborC("/ndn/neighborC", "uri://faceC", 17, Adjacent::STATUS_INACTIVE, 0, 0);
81 neighbors.insert(neighborC);
82
83 nlsr.initialize();
84
85 std::list<Adjacent> neighborList = neighbors.getAdjList();
86 for (std::list<Adjacent>::iterator it = neighborList.begin(); it != neighborList.end(); ++it) {
87 BOOST_CHECK(it->getLinkCost() != 0);
88 }
89}
90
Vince Lehman7b616582014-10-17 16:25:39 -050091BOOST_AUTO_TEST_CASE(SetEventIntervals)
92{
93 shared_ptr<DummyFace> face = ndn::makeDummyFace();
94 Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face));
95
96 // Simulate loading configuration file
97 ConfParameter& conf = nlsr.getConfParameter();
98 conf.setAdjLsaBuildInterval(3);
99 conf.setFirstHelloInterval(6);
100 conf.setRoutingCalcInterval(9);
101
102 nlsr.initialize();
103
Vince Lehman50df6b72015-03-03 12:06:40 -0600104 const Lsdb& lsdb = nlsr.getLsdb();
Vince Lehman7b616582014-10-17 16:25:39 -0500105 const RoutingTable& rt = nlsr.getRoutingTable();
106
Vince Lehman50df6b72015-03-03 12:06:40 -0600107 BOOST_CHECK_EQUAL(lsdb.getAdjLsaBuildInterval(), ndn::time::seconds(3));
Vince Lehman7b616582014-10-17 16:25:39 -0500108 BOOST_CHECK_EQUAL(nlsr.getFirstHelloInterval(), 6);
109 BOOST_CHECK_EQUAL(rt.getRoutingCalcInterval(), ndn::time::seconds(9));
110}
111
Vince Lehman02e32992015-03-11 12:31:20 -0500112BOOST_FIXTURE_TEST_CASE(FaceDestroyEvent, UnitTestTimeFixture)
113{
114 shared_ptr<ndn::util::DummyClientFace> face = ndn::util::makeDummyClientFace(g_ioService);
115 Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face));
116
117 // Simulate loading configuration file
118 ConfParameter& conf = nlsr.getConfParameter();
119 conf.setNetwork("/ndn");
120 conf.setSiteName("/site");
121 conf.setRouterName("/%C1.router/this-router");
122 conf.setAdjLsaBuildInterval(0);
123 conf.setRoutingCalcInterval(0);
124
125 // Add active neighbors
126 AdjacencyList& neighbors = nlsr.getAdjacencyList();
127
128 uint64_t destroyFaceId = 128;
129
130 // Create a neighbor whose Face will be destroyed
131 Adjacent failNeighbor("/ndn/neighborA", "uri://faceA", 10, Adjacent::STATUS_ACTIVE, 0,
132 destroyFaceId);
133 neighbors.insert(failNeighbor);
134
135 // Create an additional neighbor so an adjacency LSA can be built after the face is destroyed
136 Adjacent otherNeighbor("/ndn/neighborB", "uri://faceB", 25, Adjacent::STATUS_ACTIVE, 0, 256);
137 neighbors.insert(otherNeighbor);
138
139 nlsr.initialize();
140
141 // Simulate successful HELLO responses
142 nlsr.getLsdb().scheduleAdjLsaBuild();
143
144 // Run the scheduler to build an adjacency LSA
145 this->advanceClocks(ndn::time::milliseconds(1));
146
147 // Make sure an adjacency LSA was built
148 ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING);
149 AdjLsa* lsa = nlsr.getLsdb().findAdjLsa(key);
150 BOOST_REQUIRE(lsa != nullptr);
151
152 uint32_t lastAdjLsaSeqNo = nlsr.getSequencingManager().getAdjLsaSeq();
153
154 // Make sure the routing table was calculated
155 RoutingTableEntry* rtEntry = nlsr.getRoutingTable().findRoutingTableEntry(failNeighbor.getName());
156 BOOST_REQUIRE(rtEntry != nullptr);
157 BOOST_REQUIRE_EQUAL(rtEntry->getNexthopList().getSize(), 1);
158
159 // Receive FaceEventDestroyed notification
160 ndn::nfd::FaceEventNotification event;
161 event.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
162 .setFaceId(destroyFaceId);
163
164 shared_ptr<ndn::Data> data = make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00");
165 data->setContent(event.wireEncode());
166 nlsr.getKeyChain().sign(*data);
167
168 face->receive(*data);
169
170 // Run the scheduler to build an adjacency LSA
171 this->advanceClocks(ndn::time::milliseconds(1));
172
173 Adjacent updatedNeighbor = neighbors.getAdjacent(failNeighbor.getName());
174
175 BOOST_CHECK_EQUAL(updatedNeighbor.getFaceId(), 0);
176 BOOST_CHECK_EQUAL(updatedNeighbor.getInterestTimedOutNo(),
177 nlsr.getConfParameter().getInterestRetryNumber());
178 BOOST_CHECK_EQUAL(updatedNeighbor.getStatus(), Adjacent::STATUS_INACTIVE);
179 BOOST_CHECK_EQUAL(nlsr.getSequencingManager().getAdjLsaSeq(), lastAdjLsaSeqNo + 1);
180
181 // Make sure the routing table was recalculated
182 rtEntry = nlsr.getRoutingTable().findRoutingTableEntry(failNeighbor.getName());
183 BOOST_CHECK(rtEntry == nullptr);
184}
185
Vince Lehman09131122014-09-09 17:10:11 -0500186BOOST_AUTO_TEST_SUITE_END()
187
188} //namespace test
189} //namespace nlsr