blob: 2595e41d2357348594aaad1e5b501cb7461161d2 [file] [log] [blame]
Vince Lehman904c2412014-09-23 19:36:11 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Vince Lehmanc2e51f62015-01-20 15:03:11 -06003 * Copyright (c) 2014-2015, The University of Memphis,
4 * Regents of the University of California,
5 * Arizona Board of Regents.
Vince Lehman904c2412014-09-23 19:36:11 -05006 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Vince Lehman904c2412014-09-23 19:36:11 -050020 **/
21
22#include "test-common.hpp"
23#include "dummy-face.hpp"
24
25#include "nlsr.hpp"
26#include "communication/sync-logic-handler.hpp"
27
28namespace nlsr {
29namespace test {
30
31using ndn::DummyFace;
32using ndn::shared_ptr;
33
34class SyncLogicFixture : public BaseFixture
35{
36public:
37 SyncLogicFixture()
38 : face(ndn::makeDummyFace())
39 , nlsr(g_ioService, g_scheduler, ndn::ref(*face))
Vince Lehmanc11cc202015-01-20 11:41:33 -060040 , sync(nlsr.getSyncLogicHandler())
Vince Lehman904c2412014-09-23 19:36:11 -050041 , CONFIG_NETWORK("/ndn")
42 , CONFIG_SITE("/site")
43 , CONFIG_ROUTER_NAME("/%C1.Router/this-router")
44 {
45 nlsr.getConfParameter().setNetwork(CONFIG_NETWORK);
46 nlsr.getConfParameter().setSiteName(CONFIG_SITE);
47 nlsr.getConfParameter().setRouterName(CONFIG_ROUTER_NAME);
48 nlsr.getConfParameter().buildRouterPrefix();
49 }
50
51 void
52 receiveUpdate(std::string prefix, uint64_t seqNo)
53 {
54 Sync::MissingDataInfo info = {prefix, 0, seqNo};
55
56 std::vector<Sync::MissingDataInfo> updates;
57 updates.push_back(info);
58
59 face->processEvents(ndn::time::milliseconds(1));
60 face->m_sentInterests.clear();
61
62 sync.onNsyncUpdate(updates, NULL);
63
64 face->processEvents(ndn::time::milliseconds(1));
65 }
66
67public:
68 shared_ptr<DummyFace> face;
69 Nlsr nlsr;
Vince Lehmanc11cc202015-01-20 11:41:33 -060070 SyncLogicHandler& sync;
Vince Lehman904c2412014-09-23 19:36:11 -050071
72 const std::string CONFIG_NETWORK;
73 const std::string CONFIG_SITE;
74 const std::string CONFIG_ROUTER_NAME;
75};
76
77BOOST_FIXTURE_TEST_SUITE(TestSyncLogicHandler, SyncLogicFixture)
78
79BOOST_AUTO_TEST_CASE(UpdateForOther)
80{
81 std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
82 CONFIG_SITE + "/%C1.Router/other-router/";
83
84 receiveUpdate(updateName, 1);
85
86 std::vector<ndn::Interest>& interests = face->m_sentInterests;
87 BOOST_REQUIRE_EQUAL(interests.size(), 3);
88
89 std::vector<ndn::Interest>::iterator it = interests.begin();
alvy49b1c0c2014-12-19 13:57:46 -060090 BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + NameLsa::TYPE_STRING + "/");
Vince Lehman904c2412014-09-23 19:36:11 -050091
92 ++it;
alvy49b1c0c2014-12-19 13:57:46 -060093 BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + AdjLsa::TYPE_STRING + "/");
Vince Lehman904c2412014-09-23 19:36:11 -050094
95 ++it;
alvy49b1c0c2014-12-19 13:57:46 -060096 BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + CoordinateLsa::TYPE_STRING + "/");
Vince Lehman904c2412014-09-23 19:36:11 -050097}
98
99BOOST_AUTO_TEST_CASE(NoUpdateForSelf)
100{
101 std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
102 CONFIG_SITE + CONFIG_ROUTER_NAME;
103
104 receiveUpdate(updateName, 1);
105
106 std::vector<ndn::Interest>& interests = face->m_sentInterests;
107 BOOST_CHECK_EQUAL(interests.size(), 0);
108}
109
110BOOST_AUTO_TEST_CASE(MalformedUpdate)
111{
112 std::string updateName = CONFIG_SITE + nlsr.getConfParameter().getLsaPrefix().toUri() +
113 CONFIG_ROUTER_NAME;
114
115 std::vector<ndn::Interest>& interests = face->m_sentInterests;
116 BOOST_CHECK_EQUAL(interests.size(), 0);
117}
118
119BOOST_AUTO_TEST_CASE(SequenceNumber)
120{
121 std::string originRouter = CONFIG_NETWORK + CONFIG_SITE + "/%C1.Router/other-router/";
122
123 Lsdb& lsdb = nlsr.getLsdb();
124
125 // Install Name LSA
126 NamePrefixList nameList;
alvy49b1c0c2014-12-19 13:57:46 -0600127 NameLsa lsa(originRouter, NameLsa::TYPE_STRING, 999, ndn::time::system_clock::TimePoint::max(), nameList);
Vince Lehman904c2412014-09-23 19:36:11 -0500128 lsdb.installNameLsa(lsa);
129
130 // Install Adj LSA
131 AdjacencyList adjList;
alvy49b1c0c2014-12-19 13:57:46 -0600132 AdjLsa adjLsa(originRouter, AdjLsa::TYPE_STRING, 1000, ndn::time::system_clock::TimePoint::max(),
Vince Lehman904c2412014-09-23 19:36:11 -0500133 3 , adjList);
134 lsdb.installAdjLsa(adjLsa);
135
136 // Install Cor LSA
alvy49b1c0c2014-12-19 13:57:46 -0600137 CoordinateLsa corLsa(originRouter, CoordinateLsa::TYPE_STRING, 1000, ndn::time::system_clock::TimePoint::max(),
Vince Lehman904c2412014-09-23 19:36:11 -0500138 0,0);
139 lsdb.installCoordinateLsa(corLsa);
140
141 std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
142 CONFIG_SITE + "/%C1.Router/other-router/";
143
144 // Lower NameLSA sequence number
145 uint64_t lowerSeqNo = static_cast<uint64_t>(998) << 40;
146 receiveUpdate(updateName, lowerSeqNo);
147
148 std::vector<ndn::Interest>& interests = face->m_sentInterests;
149 BOOST_REQUIRE_EQUAL(interests.size(), 0);
150
151 // Same NameLSA sequence number
152 uint64_t sameSeqNo = static_cast<uint64_t>(999) << 40;
153 receiveUpdate(updateName, sameSeqNo);
154
155 interests = face->m_sentInterests;
156 BOOST_REQUIRE_EQUAL(interests.size(), 0);
157
158 // Higher NameLSA sequence number
159 uint64_t higherSeqNo = static_cast<uint64_t>(1000) << 40;
160 receiveUpdate(updateName, higherSeqNo);
161
162 interests = face->m_sentInterests;
163 BOOST_REQUIRE_EQUAL(interests.size(), 1);
164
165 std::vector<ndn::Interest>::iterator it = interests.begin();
166 BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + "name/");
167}
168
Vince Lehmanc11cc202015-01-20 11:41:33 -0600169BOOST_AUTO_TEST_CASE(UpdatePrefix)
170{
171 ndn::Name expectedPrefix = nlsr.getConfParameter().getLsaPrefix();
172 expectedPrefix.append(CONFIG_SITE);
173 expectedPrefix.append(CONFIG_ROUTER_NAME);
174
175 nlsr.initialize();
176
177 BOOST_CHECK_EQUAL(sync.m_updatePrefix, expectedPrefix);
178}
179
Vince Lehman9d097802015-03-16 17:55:59 -0500180BOOST_AUTO_TEST_CASE(CreateSyncSocketOnInitialization) // Bug #2649
181{
182 nlsr.initialize();
183
184 // Make sure an adjacency LSA has not been built yet
185 ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING);
186 AdjLsa* lsa = nlsr.getLsdb().findAdjLsa(key);
187 BOOST_REQUIRE(lsa == nullptr);
188
189 // Publish a routing update before an Adjacency LSA is built
190 BOOST_CHECK_NO_THROW(sync.publishRoutingUpdate());
191}
192
Vince Lehman904c2412014-09-23 19:36:11 -0500193BOOST_AUTO_TEST_SUITE_END()
194
195} // namespace test
196} // namespace nlsr