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 | /** |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, The University of Memphis, |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 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 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 22 | #include "lsa/name-lsa.hpp" |
| 23 | #include "lsa/adj-lsa.hpp" |
| 24 | #include "lsa/coordinate-lsa.hpp" |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 25 | #include "test-common.hpp" |
| 26 | #include "adjacent.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 27 | #include "name-prefix-list.hpp" |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 28 | |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 29 | #include <ndn-cxx/util/time.hpp> |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 30 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 31 | namespace nlsr { |
| 32 | namespace test { |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 33 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 34 | /*static void |
| 35 | printBytes(const uint8_t* buf, size_t size) |
| 36 | { |
| 37 | std::string hex = ndn::toHex(buf, size); |
| 38 | |
| 39 | for (size_t i = 0; i < hex.size(); i++) { |
| 40 | if (i > 0 && i % 30 == 0) |
| 41 | std::cout << "\n "; |
| 42 | |
| 43 | std::cout << "0x" << hex[i]; |
| 44 | std::cout << hex[++i]; |
| 45 | |
| 46 | if ((i + 1) != hex.size()) |
| 47 | std::cout << ", "; |
| 48 | } |
| 49 | std::cout << "\n" << "};" << std::endl; |
| 50 | } |
| 51 | |
| 52 | printBytes(wire.wire(), wire.size());*/ |
| 53 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 54 | BOOST_AUTO_TEST_SUITE(TestLsa) |
| 55 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 56 | const uint8_t NAME_LSA1[] = { |
| 57 | 0x89, 0x37, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, |
| 58 | 0x82, 0x01, 0x0C, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, |
| 59 | 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, |
| 60 | 0x6D, 0x65, 0x31, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32 |
| 61 | }; |
| 62 | |
| 63 | const uint8_t NAME_LSA_EXTRA_NAME[] = { |
| 64 | 0x89, 0x40, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, |
| 65 | 0x82, 0x01, 0x0C, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, |
| 66 | 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, |
| 67 | 0x6D, 0x65, 0x31, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32, 0x07, 0x07, 0x08, |
| 68 | 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x33 |
| 69 | }; |
| 70 | |
| 71 | const uint8_t NAME_LSA_DIFF_SEQ[] = { |
| 72 | 0x89, 0x40, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, |
| 73 | 0x82, 0x01, 0x0E, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, |
| 74 | 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, |
| 75 | 0x6D, 0x65, 0x31, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32, 0x07, 0x07, 0x08, |
| 76 | 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x33 |
| 77 | }; |
| 78 | |
| 79 | const uint8_t NAME_LSA_DIFF_TS[] = { |
| 80 | 0x89, 0x40, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, |
| 81 | 0x82, 0x01, 0x0E, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, |
| 82 | 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x34, 0x34, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, |
| 83 | 0x6D, 0x65, 0x31, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32, 0x07, 0x07, 0x08, |
| 84 | 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x33 |
| 85 | }; |
| 86 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 87 | BOOST_AUTO_TEST_CASE(NameLsaBasic) |
| 88 | { |
Nick Gordon | 96861ca | 2017-10-17 18:25:21 -0500 | [diff] [blame] | 89 | ndn::Name s1{"name1"}; |
| 90 | ndn::Name s2{"name2"}; |
| 91 | NamePrefixList npl1{s1, s2}; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 92 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 93 | ndn::time::system_clock::TimePoint testTimePoint = |
| 94 | ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196014943)); |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 95 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 96 | // 3rd argument is seqNo |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 97 | NameLsa nlsa1("router1", 12, testTimePoint, npl1); |
| 98 | NameLsa nlsa2("router2", 12, testTimePoint, npl1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 99 | |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 100 | BOOST_CHECK_EQUAL(nlsa1.getType(), Lsa::Type::NAME); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 101 | BOOST_CHECK(nlsa1.getExpirationTimePoint() == nlsa2.getExpirationTimePoint()); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 102 | BOOST_CHECK(nlsa1.getKey() != nlsa2.getKey()); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 103 | |
| 104 | auto wire = nlsa1.wireEncode(); |
| 105 | BOOST_CHECK_EQUAL_COLLECTIONS(NAME_LSA1, NAME_LSA1 + sizeof(NAME_LSA1), |
| 106 | wire.begin(), wire.end()); |
| 107 | |
| 108 | nlsa1.addName("name3"); |
| 109 | wire = nlsa1.wireEncode(); |
| 110 | BOOST_CHECK_EQUAL_COLLECTIONS(NAME_LSA_EXTRA_NAME, |
| 111 | NAME_LSA_EXTRA_NAME + sizeof(NAME_LSA_EXTRA_NAME), |
| 112 | wire.begin(), wire.end()); |
| 113 | |
| 114 | nlsa1.setSeqNo(14); |
| 115 | wire = nlsa1.wireEncode(); |
| 116 | BOOST_CHECK_EQUAL_COLLECTIONS(NAME_LSA_DIFF_SEQ, NAME_LSA_DIFF_SEQ + sizeof(NAME_LSA_DIFF_SEQ), |
| 117 | wire.begin(), wire.end()); |
| 118 | |
| 119 | testTimePoint = |
| 120 | ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196024993)); |
| 121 | nlsa1.setExpirationTimePoint(testTimePoint); |
| 122 | wire = nlsa1.wireEncode(); |
| 123 | BOOST_CHECK_EQUAL_COLLECTIONS(NAME_LSA_DIFF_TS, NAME_LSA_DIFF_TS + sizeof(NAME_LSA_DIFF_TS), |
| 124 | wire.begin(), wire.end()); |
| 125 | // Not testing router name as not sure if that will ever change once set |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 126 | } |
| 127 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 128 | const uint8_t ADJ_LSA1[] = { |
| 129 | 0x83, 0x58, 0x80, 0x2D, 0x07, 0x13, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x04, 0x73, 0x69, |
| 130 | 0x74, 0x65, 0x08, 0x06, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x82, 0x01, 0x0C, 0x8B, 0x13, |
| 131 | 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, 0x20, 0x30, 0x34, 0x3A, 0x31, |
| 132 | 0x33, 0x3A, 0x33, 0x34, 0x84, 0x27, 0x07, 0x16, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x04, |
| 133 | 0x73, 0x69, 0x74, 0x65, 0x08, 0x09, 0x61, 0x64, 0x6A, 0x61, 0x63, 0x65, 0x6E, 0x63, 0x79, |
| 134 | 0x8D, 0x03, 0x3A, 0x2F, 0x2F, 0x8C, 0x08, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 135 | }; |
| 136 | |
| 137 | const uint8_t ADJ_LSA_EXTRA_NEIGHBOR[] = { |
| 138 | 0x83, 0x80, 0x80, 0x2D, 0x07, 0x13, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x04, 0x73, 0x69, |
| 139 | 0x74, 0x65, 0x08, 0x06, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x82, 0x01, 0x0C, 0x8B, 0x13, |
| 140 | 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, 0x20, 0x30, 0x34, 0x3A, 0x31, |
| 141 | 0x33, 0x3A, 0x33, 0x34, 0x84, 0x27, 0x07, 0x16, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x04, |
| 142 | 0x73, 0x69, 0x74, 0x65, 0x08, 0x09, 0x61, 0x64, 0x6A, 0x61, 0x63, 0x65, 0x6E, 0x63, 0x79, |
| 143 | 0x8D, 0x03, 0x3A, 0x2F, 0x2F, 0x8C, 0x08, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 144 | 0x84, 0x26, 0x07, 0x15, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x03, 0x65, 0x64, 0x75, 0x08, |
| 145 | 0x09, 0x61, 0x64, 0x6A, 0x61, 0x63, 0x65, 0x6E, 0x63, 0x79, 0x8D, 0x03, 0x3A, 0x2F, 0x2F, |
| 146 | 0x8C, 0x08, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 147 | }; |
| 148 | |
| 149 | const uint8_t ADJ_LSA_DIFF_SEQ[] = { |
| 150 | 0x83, 0x80, 0x80, 0x2D, 0x07, 0x13, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x04, 0x73, 0x69, |
| 151 | 0x74, 0x65, 0x08, 0x06, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x82, 0x01, 0x0E, 0x8B, 0x13, |
| 152 | 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, 0x20, 0x30, 0x34, 0x3A, 0x31, |
| 153 | 0x33, 0x3A, 0x33, 0x34, 0x84, 0x27, 0x07, 0x16, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x04, |
| 154 | 0x73, 0x69, 0x74, 0x65, 0x08, 0x09, 0x61, 0x64, 0x6A, 0x61, 0x63, 0x65, 0x6E, 0x63, 0x79, |
| 155 | 0x8D, 0x03, 0x3A, 0x2F, 0x2F, 0x8C, 0x08, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 156 | 0x84, 0x26, 0x07, 0x15, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x03, 0x65, 0x64, 0x75, 0x08, |
| 157 | 0x09, 0x61, 0x64, 0x6A, 0x61, 0x63, 0x65, 0x6E, 0x63, 0x79, 0x8D, 0x03, 0x3A, 0x2F, 0x2F, |
| 158 | 0x8C, 0x08, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 159 | |
| 160 | const uint8_t ADJ_LSA_DIFF_TS[] = { |
| 161 | 0x83, 0x80, 0x80, 0x2D, 0x07, 0x13, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x04, 0x73, 0x69, |
| 162 | 0x74, 0x65, 0x08, 0x06, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x82, 0x01, 0x0E, 0x8B, 0x13, |
| 163 | 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, 0x20, 0x30, 0x34, 0x3A, 0x31, |
| 164 | 0x33, 0x3A, 0x34, 0x34, 0x84, 0x27, 0x07, 0x16, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x04, |
| 165 | 0x73, 0x69, 0x74, 0x65, 0x08, 0x09, 0x61, 0x64, 0x6A, 0x61, 0x63, 0x65, 0x6E, 0x63, 0x79, |
| 166 | 0x8D, 0x03, 0x3A, 0x2F, 0x2F, 0x8C, 0x08, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 167 | 0x84, 0x26, 0x07, 0x15, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x03, 0x65, 0x64, 0x75, 0x08, |
| 168 | 0x09, 0x61, 0x64, 0x6A, 0x61, 0x63, 0x65, 0x6E, 0x63, 0x79, 0x8D, 0x03, 0x3A, 0x2F, 0x2F, |
| 169 | 0x8C, 0x08, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 170 | }; |
| 171 | |
| 172 | BOOST_AUTO_TEST_CASE(AdjLsaBasic) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 173 | { |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame] | 174 | ndn::Name routerName("/ndn/site/router"); |
| 175 | ndn::Name adjacencyName("/ndn/site/adjacency"); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 176 | ndn::time::system_clock::TimePoint testTimePoint = |
| 177 | ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196014943)); |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame] | 178 | uint32_t seqNo = 12; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 179 | |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame] | 180 | // An AdjLsa initialized with ACTIVE adjacencies should copy the adjacencies |
| 181 | AdjacencyList activeAdjacencies; |
| 182 | Adjacent activeAdjacency(adjacencyName); |
| 183 | activeAdjacency.setStatus(Adjacent::STATUS_ACTIVE); |
| 184 | activeAdjacencies.insert(activeAdjacency); |
| 185 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 186 | AdjLsa alsa1(routerName, seqNo, testTimePoint, |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 187 | activeAdjacencies.size(), activeAdjacencies); |
| 188 | BOOST_CHECK_EQUAL(alsa1.getAdl().size(), 1); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 189 | BOOST_CHECK_EQUAL(alsa1.getType(), Lsa::Type::ADJACENCY); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 190 | BOOST_CHECK_EQUAL(alsa1.getSeqNo(), seqNo); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 191 | BOOST_CHECK_EQUAL(alsa1.getExpirationTimePoint(), testTimePoint); |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame] | 192 | BOOST_CHECK_EQUAL(alsa1.getNoLink(), 1); |
| 193 | BOOST_CHECK(alsa1.getAdl().isNeighbor(activeAdjacency.getName())); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 194 | |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame] | 195 | // An AdjLsa initialized with INACTIVE adjacencies should not copy the adjacencies |
| 196 | AdjacencyList inactiveAdjacencies; |
| 197 | Adjacent inactiveAdjacency(adjacencyName); |
| 198 | inactiveAdjacency.setStatus(Adjacent::STATUS_INACTIVE); |
| 199 | inactiveAdjacencies.insert(inactiveAdjacency); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 200 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 201 | AdjLsa alsa2(routerName, seqNo, testTimePoint, |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 202 | inactiveAdjacencies.size(), inactiveAdjacencies); |
| 203 | BOOST_CHECK_EQUAL(alsa2.getAdl().size(), 0); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 204 | |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame] | 205 | // Thus, the two LSAs should not have equal content |
| 206 | BOOST_CHECK_EQUAL(alsa1.isEqualContent(alsa2), false); |
| 207 | |
| 208 | // Create a duplicate of alsa1 which should have equal content |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 209 | AdjLsa alsa3(routerName, seqNo, testTimePoint, |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 210 | activeAdjacencies.size(), activeAdjacencies); |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame] | 211 | BOOST_CHECK(alsa1.isEqualContent(alsa3)); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 212 | |
| 213 | auto wire = alsa1.wireEncode(); |
| 214 | BOOST_CHECK_EQUAL_COLLECTIONS(ADJ_LSA1, ADJ_LSA1 + sizeof(ADJ_LSA1), |
| 215 | wire.begin(), wire.end()); |
| 216 | |
| 217 | Adjacent activeAdjacency2("/ndn/edu/adjacency"); |
| 218 | activeAdjacency2.setStatus(Adjacent::STATUS_ACTIVE); |
| 219 | alsa1.addAdjacent(activeAdjacency2); |
| 220 | wire = alsa1.wireEncode(); |
| 221 | BOOST_CHECK_EQUAL_COLLECTIONS(ADJ_LSA_EXTRA_NEIGHBOR, |
| 222 | ADJ_LSA_EXTRA_NEIGHBOR + sizeof(ADJ_LSA_EXTRA_NEIGHBOR), |
| 223 | wire.begin(), wire.end()); |
| 224 | |
| 225 | alsa1.setSeqNo(14); |
| 226 | wire = alsa1.wireEncode(); |
| 227 | BOOST_CHECK_EQUAL_COLLECTIONS(ADJ_LSA_DIFF_SEQ, ADJ_LSA_DIFF_SEQ + sizeof(ADJ_LSA_DIFF_SEQ), |
| 228 | wire.begin(), wire.end()); |
| 229 | |
| 230 | testTimePoint = |
| 231 | ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196024993)); |
| 232 | alsa1.setExpirationTimePoint(testTimePoint); |
| 233 | wire = alsa1.wireEncode(); |
| 234 | BOOST_CHECK_EQUAL_COLLECTIONS(ADJ_LSA_DIFF_TS, ADJ_LSA_DIFF_TS + sizeof(ADJ_LSA_DIFF_TS), |
| 235 | wire.begin(), wire.end()); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 236 | } |
| 237 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 238 | const uint8_t COORDINATE_LSA1[] = { |
| 239 | 0x85, 0x43, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, |
| 240 | 0x82, 0x01, 0x0C, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, |
| 241 | 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x87, 0x08, 0x40, 0x04, 0x00, 0x00, |
| 242 | 0x00, 0x00, 0x00, 0x00, 0x88, 0x08, 0x40, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, |
| 243 | 0x08, 0x40, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 244 | }; |
| 245 | |
| 246 | const uint8_t COORDINATE_LSA_DIFF_ANGLE[] = { |
| 247 | 0x85, 0x39, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, |
| 248 | 0x82, 0x01, 0x0C, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, |
| 249 | 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x87, 0x08, 0x40, 0x04, 0x00, 0x00, |
| 250 | 0x00, 0x00, 0x00, 0x00, 0x88, 0x08, 0x40, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 251 | }; |
| 252 | |
| 253 | const uint8_t COORDINATE_LSA_DIFF_RADIUS[] = { |
| 254 | 0x85, 0x39, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, |
| 255 | 0x82, 0x01, 0x0C, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, |
| 256 | 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x87, 0x08, 0x40, 0x02, 0x66, 0x66, |
| 257 | 0x66, 0x66, 0x66, 0x66, 0x88, 0x08, 0x40, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 258 | }; |
| 259 | |
| 260 | const uint8_t COORDINATE_LSA_DIFF_SEQ[] = { |
| 261 | 0x85, 0x39, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, |
| 262 | 0x82, 0x01, 0x0E, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, |
| 263 | 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x87, 0x08, 0x40, 0x02, 0x66, 0x66, |
| 264 | 0x66, 0x66, 0x66, 0x66, 0x88, 0x08, 0x40, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 265 | }; |
| 266 | |
| 267 | const uint8_t COORDINATE_LSA_DIFF_TS[] = { |
| 268 | 0x85, 0x39, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, |
| 269 | 0x82, 0x01, 0x0E, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, |
| 270 | 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x34, 0x34, 0x87, 0x08, 0x40, 0x02, 0x66, 0x66, |
| 271 | 0x66, 0x66, 0x66, 0x66, 0x88, 0x08, 0x40, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 272 | }; |
| 273 | |
| 274 | BOOST_AUTO_TEST_CASE(CoordinateLsaBasic) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 275 | { |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 276 | ndn::time::system_clock::TimePoint testTimePoint = |
| 277 | ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196014943)); |
| 278 | std::vector<double> angles1 {30.0}, angles2 {30.0}; |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 279 | angles1.push_back(30.0); |
| 280 | angles2.push_back(30.0); |
| 281 | CoordinateLsa clsa1("router1", 12, testTimePoint, 2.5, angles1); |
| 282 | CoordinateLsa clsa2("router1", 12, testTimePoint, 2.5, angles2); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 283 | |
| 284 | BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001); |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 285 | BOOST_CHECK(clsa1.getCorTheta() == angles1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 286 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 287 | BOOST_CHECK(clsa1.isEqualContent(clsa2)); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 288 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 289 | BOOST_CHECK_EQUAL(clsa1.wireEncode(), clsa2.wireEncode()); |
| 290 | |
| 291 | auto wire = clsa1.wireEncode(); |
| 292 | BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA1, COORDINATE_LSA1 + sizeof(COORDINATE_LSA1), |
| 293 | wire.begin(), wire.end()); |
| 294 | |
| 295 | std::vector<double> angles3{40.0}; |
| 296 | clsa1.setCorTheta(angles3); |
| 297 | wire = clsa1.wireEncode(); |
| 298 | BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA_DIFF_ANGLE, |
| 299 | COORDINATE_LSA_DIFF_ANGLE + sizeof(COORDINATE_LSA_DIFF_ANGLE), |
| 300 | wire.begin(), wire.end()); |
| 301 | |
| 302 | clsa1.setCorRadius(2.3); |
| 303 | wire = clsa1.wireEncode(); |
| 304 | BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA_DIFF_RADIUS, |
| 305 | COORDINATE_LSA_DIFF_RADIUS + sizeof(COORDINATE_LSA_DIFF_RADIUS), |
| 306 | wire.begin(), wire.end()); |
| 307 | |
| 308 | clsa1.setSeqNo(14); |
| 309 | wire = clsa1.wireEncode(); |
| 310 | BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA_DIFF_SEQ, |
| 311 | COORDINATE_LSA_DIFF_SEQ + sizeof(COORDINATE_LSA_DIFF_SEQ), |
| 312 | wire.begin(), wire.end()); |
| 313 | |
| 314 | testTimePoint = |
| 315 | ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196024993)); |
| 316 | clsa1.setExpirationTimePoint(testTimePoint); |
| 317 | wire = clsa1.wireEncode(); |
| 318 | BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA_DIFF_TS, |
| 319 | COORDINATE_LSA_DIFF_TS + sizeof(COORDINATE_LSA_DIFF_TS), |
| 320 | wire.begin(), wire.end()); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 321 | } |
| 322 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 323 | BOOST_AUTO_TEST_CASE(IncrementAdjacentNumber) |
| 324 | { |
| 325 | Adjacent adj1("adjacent1"); |
| 326 | Adjacent adj2("adjacent2"); |
| 327 | |
| 328 | adj1.setStatus(Adjacent::STATUS_ACTIVE); |
| 329 | adj2.setStatus(Adjacent::STATUS_ACTIVE); |
| 330 | |
| 331 | AdjacencyList adjList; |
| 332 | adjList.insert(adj1); |
| 333 | adjList.insert(adj2); |
| 334 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 335 | ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now() + ndn::time::seconds(3600); |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 336 | std::ostringstream ss; |
| 337 | ss << testTimePoint; |
| 338 | |
| 339 | const std::string TEST_TIME_POINT_STRING = ss.str(); |
| 340 | |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 341 | AdjLsa lsa("router1", 12, testTimePoint, adjList.size(), adjList); |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 342 | |
| 343 | std::string EXPECTED_OUTPUT = |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 344 | " ADJACENCY LSA:\n" |
| 345 | " Origin Router : /router1\n" |
| 346 | " Sequence Number : 12\n" |
| 347 | " Expires in : 3599999 milliseconds\n" |
| 348 | " Adjacents:\n" |
| 349 | " Adjacent 0: (name=/adjacent1, uri=://, cost=10)\n" |
| 350 | " Adjacent 1: (name=/adjacent2, uri=://, cost=10)\n"; |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 351 | |
| 352 | std::ostringstream os; |
| 353 | os << lsa; |
| 354 | |
| 355 | BOOST_CHECK_EQUAL(os.str(), EXPECTED_OUTPUT); |
| 356 | } |
| 357 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 358 | BOOST_AUTO_TEST_CASE(TestInitializeFromContent) |
| 359 | { |
| 360 | //Adj LSA |
| 361 | Adjacent adj1("adjacent1"); |
| 362 | Adjacent adj2("adjacent2"); |
| 363 | |
| 364 | adj1.setStatus(Adjacent::STATUS_ACTIVE); |
| 365 | adj2.setStatus(Adjacent::STATUS_ACTIVE); |
| 366 | |
| 367 | //If we don't do this the test will fail |
| 368 | //Adjacent has default cost of 10 but no default |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 369 | //connecting face URI, so initializeFromContent fails |
| 370 | adj1.setFaceUri(ndn::FaceUri("udp://10.0.0.1")); |
| 371 | adj2.setFaceUri(ndn::FaceUri("udp://10.0.0.2")); |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 372 | |
| 373 | AdjacencyList adjList; |
| 374 | adjList.insert(adj1); |
| 375 | adjList.insert(adj2); |
| 376 | |
| 377 | ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now(); |
| 378 | |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 379 | AdjLsa adjlsa1("router1", 1, testTimePoint, adjList.size(), adjList); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 380 | AdjLsa adjlsa2(adjlsa1.wireEncode()); |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 381 | BOOST_CHECK(adjlsa1.isEqualContent(adjlsa2)); |
| 382 | |
| 383 | //Name LSA |
Nick Gordon | 96861ca | 2017-10-17 18:25:21 -0500 | [diff] [blame] | 384 | ndn::Name s1{"name1"}; |
| 385 | ndn::Name s2{"name2"}; |
| 386 | NamePrefixList npl1{s1, s2}; |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 387 | |
| 388 | NameLsa nlsa1("router1", 1, testTimePoint, npl1); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 389 | NameLsa nlsa2(nlsa1.wireEncode()); |
| 390 | BOOST_CHECK_EQUAL(nlsa1.wireEncode(), nlsa2.wireEncode()); |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 391 | |
| 392 | //Coordinate LSA |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 393 | std::vector<double> angles = {30, 40.0}; |
| 394 | CoordinateLsa clsa1("router1", 12, testTimePoint, 2.5, angles); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 395 | CoordinateLsa clsa2(clsa1.wireEncode()); |
| 396 | BOOST_CHECK_EQUAL(clsa1.wireEncode(), clsa2.wireEncode()); |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 397 | } |
| 398 | |
Nick Gordon | 56d1fae | 2017-05-26 16:39:25 -0500 | [diff] [blame] | 399 | BOOST_AUTO_TEST_CASE(OperatorEquals) |
| 400 | { |
| 401 | NameLsa lsa1; |
| 402 | NameLsa lsa2; |
| 403 | ndn::Name name1("/ndn/test/name1"); |
| 404 | ndn::Name name2("/ndn/test/name2"); |
| 405 | ndn::Name name3("/ndn/some/other/name1"); |
| 406 | |
| 407 | lsa1.addName(name1); |
| 408 | lsa1.addName(name2); |
| 409 | lsa1.addName(name3); |
| 410 | |
| 411 | lsa2.addName(name1); |
| 412 | lsa2.addName(name2); |
| 413 | lsa2.addName(name3); |
| 414 | |
| 415 | BOOST_CHECK(lsa1.isEqualContent(lsa2)); |
| 416 | } |
| 417 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 418 | BOOST_AUTO_TEST_SUITE_END() |
| 419 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 420 | } // namespace test |
| 421 | } // namespace nlsr |