akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 2 | /** |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, The University of Memphis, |
| 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 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/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 20 | **/ |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 21 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 22 | #include "test-common.hpp" |
| 23 | |
| 24 | #include "adjacent.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 25 | #include "lsa.hpp" |
| 26 | #include "name-prefix-list.hpp" |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 27 | |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 28 | #include <ndn-cxx/util/time.hpp> |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 29 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 30 | #include <sstream> |
| 31 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 32 | namespace nlsr { |
| 33 | namespace test { |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 34 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 35 | BOOST_AUTO_TEST_SUITE(TestLsa) |
| 36 | |
| 37 | BOOST_AUTO_TEST_CASE(NameLsaBasic) |
| 38 | { |
| 39 | NamePrefixList npl1; |
| 40 | |
| 41 | std::string s1 = "name1"; |
| 42 | std::string s2 = "name2"; |
| 43 | |
| 44 | npl1.insert(s1); |
| 45 | npl1.insert(s2); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 46 | ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 47 | //lsType is 1 for NameLsa, 3rd arg is seqNo. which will be a random number I just put in 12. |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 48 | NameLsa nlsa1("router1", NameLsa::TYPE_STRING, 12, testTimePoint, npl1); |
| 49 | NameLsa nlsa2("router2", NameLsa::TYPE_STRING, 12, testTimePoint, npl1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 50 | |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 51 | BOOST_CHECK_EQUAL(nlsa1.getLsType(), NameLsa::TYPE_STRING); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 52 | |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 53 | BOOST_CHECK(nlsa1.getExpirationTimePoint() == nlsa2.getExpirationTimePoint()); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 54 | |
| 55 | BOOST_CHECK(nlsa1.getKey() != nlsa2.getKey()); |
| 56 | } |
| 57 | |
| 58 | BOOST_AUTO_TEST_CASE(AdjacentLsaConstructorAndGetters) |
| 59 | { |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame^] | 60 | ndn::Name routerName("/ndn/site/router"); |
| 61 | ndn::Name adjacencyName("/ndn/site/adjacency"); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 62 | ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now(); |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame^] | 63 | uint32_t seqNo = 12; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 64 | |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame^] | 65 | // An AdjLsa initialized with ACTIVE adjacencies should copy the adjacencies |
| 66 | AdjacencyList activeAdjacencies; |
| 67 | Adjacent activeAdjacency(adjacencyName); |
| 68 | activeAdjacency.setStatus(Adjacent::STATUS_ACTIVE); |
| 69 | activeAdjacencies.insert(activeAdjacency); |
| 70 | |
| 71 | AdjLsa alsa1(routerName, AdjLsa::TYPE_STRING, seqNo, testTimePoint, |
| 72 | activeAdjacencies.getSize(), activeAdjacencies); |
| 73 | BOOST_CHECK_EQUAL(alsa1.getAdl().getSize(), 1); |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 74 | BOOST_CHECK_EQUAL(alsa1.getLsType(), AdjLsa::TYPE_STRING); |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame^] | 75 | BOOST_CHECK_EQUAL(alsa1.getLsSeqNo(), seqNo); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 76 | BOOST_CHECK_EQUAL(alsa1.getExpirationTimePoint(), testTimePoint); |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame^] | 77 | BOOST_CHECK_EQUAL(alsa1.getNoLink(), 1); |
| 78 | BOOST_CHECK(alsa1.getAdl().isNeighbor(activeAdjacency.getName())); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 79 | |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame^] | 80 | // An AdjLsa initialized with INACTIVE adjacencies should not copy the adjacencies |
| 81 | AdjacencyList inactiveAdjacencies; |
| 82 | Adjacent inactiveAdjacency(adjacencyName); |
| 83 | inactiveAdjacency.setStatus(Adjacent::STATUS_INACTIVE); |
| 84 | inactiveAdjacencies.insert(inactiveAdjacency); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 85 | |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame^] | 86 | AdjLsa alsa2(routerName, AdjLsa::TYPE_STRING, seqNo, testTimePoint, |
| 87 | inactiveAdjacencies.getSize(), inactiveAdjacencies); |
| 88 | BOOST_CHECK_EQUAL(alsa2.getAdl().getSize(), 0); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 89 | |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame^] | 90 | // Thus, the two LSAs should not have equal content |
| 91 | BOOST_CHECK_EQUAL(alsa1.isEqualContent(alsa2), false); |
| 92 | |
| 93 | // Create a duplicate of alsa1 which should have equal content |
| 94 | AdjLsa alsa3(routerName, AdjLsa::TYPE_STRING, seqNo, testTimePoint, |
| 95 | activeAdjacencies.getSize(), activeAdjacencies); |
| 96 | BOOST_CHECK(alsa1.isEqualContent(alsa3)); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | BOOST_AUTO_TEST_CASE(CoordinateLsaConstructorAndGetters) |
| 100 | { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 101 | ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 102 | //For CoordinateLsa, lsType is 3. |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 103 | CoordinateLsa clsa1("router1", CoordinateLsa::TYPE_STRING, 12, testTimePoint, 2.5, 30.0); |
| 104 | CoordinateLsa clsa2("router1", CoordinateLsa::TYPE_STRING, 12, testTimePoint, 2.5, 30.0); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 105 | |
| 106 | BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001); |
| 107 | BOOST_CHECK_CLOSE(clsa1.getCorTheta(), 30.0, 0.0001); |
| 108 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 109 | BOOST_CHECK(clsa1.isEqualContent(clsa2)); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 110 | |
| 111 | BOOST_CHECK_EQUAL(clsa1.getData(), clsa2.getData()); |
| 112 | } |
| 113 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 114 | BOOST_AUTO_TEST_CASE(IncrementAdjacentNumber) |
| 115 | { |
| 116 | Adjacent adj1("adjacent1"); |
| 117 | Adjacent adj2("adjacent2"); |
| 118 | |
| 119 | adj1.setStatus(Adjacent::STATUS_ACTIVE); |
| 120 | adj2.setStatus(Adjacent::STATUS_ACTIVE); |
| 121 | |
| 122 | AdjacencyList adjList; |
| 123 | adjList.insert(adj1); |
| 124 | adjList.insert(adj2); |
| 125 | |
| 126 | ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now(); |
| 127 | |
| 128 | std::ostringstream ss; |
| 129 | ss << testTimePoint; |
| 130 | |
| 131 | const std::string TEST_TIME_POINT_STRING = ss.str(); |
| 132 | |
| 133 | AdjLsa lsa("router1", AdjLsa::TYPE_STRING, 12, testTimePoint, 1, adjList); |
| 134 | |
| 135 | std::string EXPECTED_OUTPUT = |
| 136 | "Adj Lsa:\n" |
| 137 | " Origination Router: /router1\n" |
| 138 | " Ls Type: adjacency\n" |
| 139 | " Ls Seq No: 12\n" |
| 140 | " Ls Lifetime: " + TEST_TIME_POINT_STRING + "\n" |
| 141 | " Adjacents: \n" |
| 142 | " Adjacent 1:\n" |
| 143 | " Adjacent Name: /adjacent1\n" |
| 144 | " Connecting FaceUri: \n" |
| 145 | " Link Cost: 10\n" |
| 146 | " Adjacent 2:\n" |
| 147 | " Adjacent Name: /adjacent2\n" |
| 148 | " Connecting FaceUri: \n" |
| 149 | " Link Cost: 10\n" |
| 150 | "adj_lsa_end"; |
| 151 | |
| 152 | std::ostringstream os; |
| 153 | os << lsa; |
| 154 | |
| 155 | BOOST_CHECK_EQUAL(os.str(), EXPECTED_OUTPUT); |
| 156 | } |
| 157 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 158 | BOOST_AUTO_TEST_SUITE_END() |
| 159 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 160 | } // namespace test |
| 161 | } // namespace nlsr |