Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 1 | /* -*- 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 "nlsr.hpp" |
| 27 | |
| 28 | namespace nlsr { |
| 29 | namespace test { |
| 30 | |
| 31 | using ndn::DummyFace; |
| 32 | using ndn::shared_ptr; |
| 33 | |
| 34 | BOOST_FIXTURE_TEST_SUITE(TestNlsr, BaseFixture) |
| 35 | |
| 36 | BOOST_AUTO_TEST_CASE(HyperbolicOn_ZeroCostNeighbors) |
| 37 | { |
| 38 | shared_ptr<DummyFace> face = ndn::makeDummyFace(); |
| 39 | Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face)); |
| 40 | |
| 41 | // Simulate loading configuration file |
| 42 | AdjacencyList& neighbors = nlsr.getAdjacencyList(); |
| 43 | |
| 44 | Adjacent neighborA("/ndn/neighborA", "uri://faceA", 25, Adjacent::STATUS_INACTIVE, 0, 0); |
| 45 | neighbors.insert(neighborA); |
| 46 | |
| 47 | Adjacent neighborB("/ndn/neighborB", "uri://faceB", 10, Adjacent::STATUS_INACTIVE, 0, 0); |
| 48 | neighbors.insert(neighborB); |
| 49 | |
| 50 | Adjacent neighborC("/ndn/neighborC", "uri://faceC", 17, Adjacent::STATUS_INACTIVE, 0, 0); |
| 51 | neighbors.insert(neighborC); |
| 52 | |
| 53 | nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON); |
| 54 | |
| 55 | nlsr.initialize(); |
| 56 | |
| 57 | std::list<Adjacent> neighborList = neighbors.getAdjList(); |
| 58 | for (std::list<Adjacent>::iterator it = neighborList.begin(); it != neighborList.end(); ++it) { |
| 59 | BOOST_CHECK_EQUAL(it->getLinkCost(), 0); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | BOOST_AUTO_TEST_CASE(HyperbolicOff_LinkStateCost) |
| 64 | { |
| 65 | shared_ptr<DummyFace> face = ndn::makeDummyFace(); |
| 66 | Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face)); |
| 67 | |
| 68 | // Simulate loading configuration file |
| 69 | AdjacencyList& neighbors = nlsr.getAdjacencyList(); |
| 70 | |
| 71 | Adjacent neighborA("/ndn/neighborA", "uri://faceA", 25, Adjacent::STATUS_INACTIVE, 0, 0); |
| 72 | neighbors.insert(neighborA); |
| 73 | |
| 74 | Adjacent neighborB("/ndn/neighborB", "uri://faceB", 10, Adjacent::STATUS_INACTIVE, 0, 0); |
| 75 | neighbors.insert(neighborB); |
| 76 | |
| 77 | Adjacent neighborC("/ndn/neighborC", "uri://faceC", 17, Adjacent::STATUS_INACTIVE, 0, 0); |
| 78 | neighbors.insert(neighborC); |
| 79 | |
| 80 | nlsr.initialize(); |
| 81 | |
| 82 | std::list<Adjacent> neighborList = neighbors.getAdjList(); |
| 83 | for (std::list<Adjacent>::iterator it = neighborList.begin(); it != neighborList.end(); ++it) { |
| 84 | BOOST_CHECK(it->getLinkCost() != 0); |
| 85 | } |
| 86 | } |
| 87 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame^] | 88 | BOOST_AUTO_TEST_CASE(SetEventIntervals) |
| 89 | { |
| 90 | shared_ptr<DummyFace> face = ndn::makeDummyFace(); |
| 91 | Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face)); |
| 92 | |
| 93 | // Simulate loading configuration file |
| 94 | ConfParameter& conf = nlsr.getConfParameter(); |
| 95 | conf.setAdjLsaBuildInterval(3); |
| 96 | conf.setFirstHelloInterval(6); |
| 97 | conf.setRoutingCalcInterval(9); |
| 98 | |
| 99 | nlsr.initialize(); |
| 100 | |
| 101 | const HelloProtocol& hello = nlsr.m_helloProtocol; |
| 102 | const RoutingTable& rt = nlsr.getRoutingTable(); |
| 103 | |
| 104 | BOOST_CHECK_EQUAL(hello.getAdjLsaBuildInterval(), ndn::time::seconds(3)); |
| 105 | BOOST_CHECK_EQUAL(nlsr.getFirstHelloInterval(), 6); |
| 106 | BOOST_CHECK_EQUAL(rt.getRoutingCalcInterval(), ndn::time::seconds(9)); |
| 107 | } |
| 108 | |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 109 | BOOST_AUTO_TEST_SUITE_END() |
| 110 | |
| 111 | } //namespace test |
| 112 | } //namespace nlsr |