blob: c7c64b7ba5b07354598c265ed688f4b8a2288388 [file] [log] [blame]
Vince Lehmancae33b62015-06-05 09:21:30 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, The University of Memphis,
4 * Regents of the University of California,
5 * Arizona Board of Regents.
6 *
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/>.
20 **/
21
22#include "nlsr.hpp"
23#include "test-common.hpp"
24
25#include <ndn-cxx/util/dummy-client-face.hpp>
26
27namespace nlsr {
28namespace test {
29
30class NamePrefixTableFixture : public UnitTestTimeFixture
31{
32public:
33 NamePrefixTableFixture()
34 : face(ndn::util::makeDummyClientFace(g_ioService))
35 , nlsr(g_ioService, g_scheduler, ndn::ref(*face))
36 , lsdb(nlsr.getLsdb())
37 , npt(nlsr.getNamePrefixTable())
38 {
39 INIT_LOGGERS("/tmp", "DEBUG");
40 }
41
42public:
43 shared_ptr<ndn::util::DummyClientFace> face;
44 Nlsr nlsr;
45
46 Lsdb& lsdb;
47 NamePrefixTable& npt;
48};
49
50BOOST_AUTO_TEST_SUITE(TestNamePrefixTable)
51
52BOOST_FIXTURE_TEST_CASE(Bupt, NamePrefixTableFixture)
53{
54 ConfParameter& conf = nlsr.getConfParameter();
55 conf.setNetwork("/ndn");
56 conf.setSiteName("/router");
57 conf.setRouterName("/a");
58 conf.buildRouterPrefix();
59
60 RoutingTable& routingTable = nlsr.getRoutingTable();
61 routingTable.setRoutingCalcInterval(0);
62
63 NamePrefixTable& npt = nlsr.getNamePrefixTable();
64
65 Adjacent thisRouter(conf.getRouterPrefix(), "udp://face", 0, Adjacent::STATUS_ACTIVE, 0, 0);
66
67 ndn::Name buptRouterName("/ndn/cn/edu/bupt/%C1.Router/bupthub");
68 Adjacent bupt(buptRouterName, "udp://bupt", 0, Adjacent::STATUS_ACTIVE, 0, 0);
69
70 // This router's Adjacency LSA
71 nlsr.getAdjacencyList().insert(bupt);
72 AdjLsa thisRouterAdjLsa(thisRouter.getName(),
73 AdjLsa::TYPE_STRING,
74 1,
75 ndn::time::system_clock::now() + ndn::time::seconds::max(),
76 2,
77 nlsr.getAdjacencyList());
78
79 lsdb.installAdjLsa(thisRouterAdjLsa);
80
81 // BUPT Adjacency LSA
82 AdjacencyList buptAdjacencies;
83 buptAdjacencies.insert(thisRouter);
84 AdjLsa buptAdjLsa(buptRouterName,
85 AdjLsa::TYPE_STRING,
86 1,
87 ndn::time::system_clock::now() + ndn::time::seconds(5),
88 0 , buptAdjacencies);
89
90 lsdb.installAdjLsa(buptAdjLsa);
91
92 // BUPT Name LSA
93 ndn::Name buptAdvertisedName("/ndn/cn/edu/bupt");
94
95 NamePrefixList buptNames;
96 buptNames.insert(buptAdvertisedName);
97
98 NameLsa buptNameLsa(buptRouterName,
99 NameLsa::TYPE_STRING,
100 1,
101 ndn::time::system_clock::now(),
102 buptNames);
103
104 lsdb.installNameLsa(buptNameLsa);
105
106 // Advance clocks to expire LSAs
107 this->advanceClocks(ndn::time::seconds(15));
108
109 // LSA expirations should cause NPT entries to be completely removed
110 NamePrefixTable::const_iterator it = npt.begin();
111 BOOST_REQUIRE(it == npt.end());
112
113 // Install new name LSA
114 NameLsa buptNewNameLsa(buptRouterName, NameLsa::TYPE_STRING,
115 12,
116 ndn::time::system_clock::now() + ndn::time::seconds(3600),
117 buptNames);
118
119 lsdb.installNameLsa(buptNewNameLsa);
120
121 this->advanceClocks(ndn::time::seconds(1));
122
123 // Install new adjacency LSA
124 AdjLsa buptNewAdjLsa(buptRouterName, AdjLsa::TYPE_STRING,
125 12,
126 ndn::time::system_clock::now() + ndn::time::seconds(3600),
127 0, buptAdjacencies);
128 lsdb.installAdjLsa(buptNewAdjLsa);
129
130 this->advanceClocks(ndn::time::seconds(1));
131
132 // Each NPT entry should have a destination router
133 it = npt.begin();
134 BOOST_REQUIRE_EQUAL(it->getNamePrefix(), buptRouterName);
135 BOOST_REQUIRE_EQUAL(it->getRteList().size(), 1);
136 BOOST_CHECK_EQUAL(it->getRteList().begin()->getDestination(), buptRouterName);
137
138 ++it;
139 BOOST_REQUIRE_EQUAL(it->getNamePrefix(), buptAdvertisedName);
140 BOOST_REQUIRE_EQUAL(it->getRteList().size(), 1);
141 BOOST_CHECK_EQUAL(it->getRteList().begin()->getDestination(), buptRouterName);
142}
143
144BOOST_AUTO_TEST_SUITE_END()
145
146} // namespace test
147} // namespace nlsr