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