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 | { |
| 60 | Adjacent adj1("adjacent"); |
| 61 | Adjacent adj2("adjacent2"); |
| 62 | |
| 63 | AdjacencyList adjList; |
| 64 | adjList.insert(adj1); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 65 | ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 66 | //For AdjLsa, lsType is 2. |
| 67 | //1 is the number of adjacent in adjacent list. |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 68 | AdjLsa alsa1("router1", AdjLsa::TYPE_STRING, 12, testTimePoint, 1, adjList); |
| 69 | AdjLsa alsa2("router1", AdjLsa::TYPE_STRING, 12, testTimePoint, 1, adjList); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 70 | |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 71 | BOOST_CHECK_EQUAL(alsa1.getLsType(), AdjLsa::TYPE_STRING); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 72 | BOOST_CHECK_EQUAL(alsa1.getLsSeqNo(), (uint32_t)12); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 73 | BOOST_CHECK_EQUAL(alsa1.getExpirationTimePoint(), testTimePoint); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 74 | BOOST_CHECK_EQUAL(alsa1.getNoLink(), (uint32_t)1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 75 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 76 | BOOST_CHECK(alsa1.isEqualContent(alsa2)); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 77 | |
| 78 | alsa1.addAdjacent(adj2); |
| 79 | |
| 80 | const std::string ADJACENT_1 = "adjacent2"; |
| 81 | BOOST_CHECK(alsa1.getAdl().isNeighbor(ADJACENT_1)); |
| 82 | } |
| 83 | |
| 84 | BOOST_AUTO_TEST_CASE(CoordinateLsaConstructorAndGetters) |
| 85 | { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 86 | ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 87 | //For CoordinateLsa, lsType is 3. |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 88 | CoordinateLsa clsa1("router1", CoordinateLsa::TYPE_STRING, 12, testTimePoint, 2.5, 30.0); |
| 89 | CoordinateLsa clsa2("router1", CoordinateLsa::TYPE_STRING, 12, testTimePoint, 2.5, 30.0); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 90 | |
| 91 | BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001); |
| 92 | BOOST_CHECK_CLOSE(clsa1.getCorTheta(), 30.0, 0.0001); |
| 93 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 94 | BOOST_CHECK(clsa1.isEqualContent(clsa2)); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 95 | |
| 96 | BOOST_CHECK_EQUAL(clsa1.getData(), clsa2.getData()); |
| 97 | } |
| 98 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 99 | BOOST_AUTO_TEST_CASE(IncrementAdjacentNumber) |
| 100 | { |
| 101 | Adjacent adj1("adjacent1"); |
| 102 | Adjacent adj2("adjacent2"); |
| 103 | |
| 104 | adj1.setStatus(Adjacent::STATUS_ACTIVE); |
| 105 | adj2.setStatus(Adjacent::STATUS_ACTIVE); |
| 106 | |
| 107 | AdjacencyList adjList; |
| 108 | adjList.insert(adj1); |
| 109 | adjList.insert(adj2); |
| 110 | |
| 111 | ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now(); |
| 112 | |
| 113 | std::ostringstream ss; |
| 114 | ss << testTimePoint; |
| 115 | |
| 116 | const std::string TEST_TIME_POINT_STRING = ss.str(); |
| 117 | |
| 118 | AdjLsa lsa("router1", AdjLsa::TYPE_STRING, 12, testTimePoint, 1, adjList); |
| 119 | |
| 120 | std::string EXPECTED_OUTPUT = |
| 121 | "Adj Lsa:\n" |
| 122 | " Origination Router: /router1\n" |
| 123 | " Ls Type: adjacency\n" |
| 124 | " Ls Seq No: 12\n" |
| 125 | " Ls Lifetime: " + TEST_TIME_POINT_STRING + "\n" |
| 126 | " Adjacents: \n" |
| 127 | " Adjacent 1:\n" |
| 128 | " Adjacent Name: /adjacent1\n" |
| 129 | " Connecting FaceUri: \n" |
| 130 | " Link Cost: 10\n" |
| 131 | " Adjacent 2:\n" |
| 132 | " Adjacent Name: /adjacent2\n" |
| 133 | " Connecting FaceUri: \n" |
| 134 | " Link Cost: 10\n" |
| 135 | "adj_lsa_end"; |
| 136 | |
| 137 | std::ostringstream os; |
| 138 | os << lsa; |
| 139 | |
| 140 | BOOST_CHECK_EQUAL(os.str(), EXPECTED_OUTPUT); |
| 141 | } |
| 142 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 143 | BOOST_AUTO_TEST_SUITE_END() |
| 144 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 145 | } // namespace test |
| 146 | } // namespace nlsr |