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