Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 1 | /* -*- 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 | |
| 27 | namespace nlsr { |
| 28 | namespace test { |
| 29 | |
| 30 | class NamePrefixTableFixture : public UnitTestTimeFixture |
| 31 | { |
| 32 | public: |
| 33 | NamePrefixTableFixture() |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 34 | : face(make_shared<ndn::util::DummyClientFace>(g_ioService)) |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 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 | |
| 42 | public: |
| 43 | shared_ptr<ndn::util::DummyClientFace> face; |
| 44 | Nlsr nlsr; |
| 45 | |
| 46 | Lsdb& lsdb; |
| 47 | NamePrefixTable& npt; |
| 48 | }; |
| 49 | |
| 50 | BOOST_AUTO_TEST_SUITE(TestNamePrefixTable) |
| 51 | |
| 52 | BOOST_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); |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 72 | AdjLsa thisRouterAdjLsa(thisRouter.getName(), 1, |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 73 | ndn::time::system_clock::now() + ndn::time::seconds::max(), |
| 74 | 2, |
| 75 | nlsr.getAdjacencyList()); |
| 76 | |
| 77 | lsdb.installAdjLsa(thisRouterAdjLsa); |
| 78 | |
| 79 | // BUPT Adjacency LSA |
| 80 | AdjacencyList buptAdjacencies; |
| 81 | buptAdjacencies.insert(thisRouter); |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 82 | AdjLsa buptAdjLsa(buptRouterName, 1, |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 83 | ndn::time::system_clock::now() + ndn::time::seconds(5), |
| 84 | 0 , buptAdjacencies); |
| 85 | |
| 86 | lsdb.installAdjLsa(buptAdjLsa); |
| 87 | |
| 88 | // BUPT Name LSA |
| 89 | ndn::Name buptAdvertisedName("/ndn/cn/edu/bupt"); |
| 90 | |
| 91 | NamePrefixList buptNames; |
| 92 | buptNames.insert(buptAdvertisedName); |
| 93 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 94 | NameLsa buptNameLsa(buptRouterName, 1, ndn::time::system_clock::now(), |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 95 | buptNames); |
| 96 | |
| 97 | lsdb.installNameLsa(buptNameLsa); |
| 98 | |
| 99 | // Advance clocks to expire LSAs |
| 100 | this->advanceClocks(ndn::time::seconds(15)); |
| 101 | |
| 102 | // LSA expirations should cause NPT entries to be completely removed |
| 103 | NamePrefixTable::const_iterator it = npt.begin(); |
| 104 | BOOST_REQUIRE(it == npt.end()); |
| 105 | |
| 106 | // Install new name LSA |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 107 | NameLsa buptNewNameLsa(buptRouterName, 12, |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 108 | ndn::time::system_clock::now() + ndn::time::seconds(3600), |
| 109 | buptNames); |
| 110 | |
| 111 | lsdb.installNameLsa(buptNewNameLsa); |
| 112 | |
| 113 | this->advanceClocks(ndn::time::seconds(1)); |
| 114 | |
| 115 | // Install new adjacency LSA |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 116 | AdjLsa buptNewAdjLsa(buptRouterName, 12, |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 117 | ndn::time::system_clock::now() + ndn::time::seconds(3600), |
| 118 | 0, buptAdjacencies); |
| 119 | lsdb.installAdjLsa(buptNewAdjLsa); |
| 120 | |
| 121 | this->advanceClocks(ndn::time::seconds(1)); |
| 122 | |
| 123 | // Each NPT entry should have a destination router |
| 124 | it = npt.begin(); |
| 125 | BOOST_REQUIRE_EQUAL(it->getNamePrefix(), buptRouterName); |
| 126 | BOOST_REQUIRE_EQUAL(it->getRteList().size(), 1); |
| 127 | BOOST_CHECK_EQUAL(it->getRteList().begin()->getDestination(), buptRouterName); |
| 128 | |
| 129 | ++it; |
| 130 | BOOST_REQUIRE_EQUAL(it->getNamePrefix(), buptAdvertisedName); |
| 131 | BOOST_REQUIRE_EQUAL(it->getRteList().size(), 1); |
| 132 | BOOST_CHECK_EQUAL(it->getRteList().begin()->getDestination(), buptRouterName); |
| 133 | } |
| 134 | |
| 135 | BOOST_AUTO_TEST_SUITE_END() |
| 136 | |
| 137 | } // namespace test |
| 138 | } // namespace nlsr |