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 | /* |
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/>. |
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 "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 | 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"); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 175 | ndn::time::system_clock::TimePoint testTimePoint = |
| 176 | ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196014943)); |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame] | 177 | uint32_t seqNo = 12; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 178 | |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame] | 179 | // An AdjLsa initialized with ACTIVE adjacencies should copy the adjacencies |
| 180 | AdjacencyList activeAdjacencies; |
| 181 | Adjacent activeAdjacency(adjacencyName); |
| 182 | activeAdjacency.setStatus(Adjacent::STATUS_ACTIVE); |
| 183 | activeAdjacencies.insert(activeAdjacency); |
| 184 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 185 | AdjLsa alsa1(routerName, seqNo, testTimePoint, |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 186 | activeAdjacencies.size(), activeAdjacencies); |
| 187 | BOOST_CHECK_EQUAL(alsa1.getAdl().size(), 1); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 188 | BOOST_CHECK_EQUAL(alsa1.getType(), Lsa::Type::ADJACENCY); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 189 | BOOST_CHECK_EQUAL(alsa1.getSeqNo(), seqNo); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 190 | BOOST_CHECK_EQUAL(alsa1.getExpirationTimePoint(), testTimePoint); |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame] | 191 | BOOST_CHECK_EQUAL(alsa1.getNoLink(), 1); |
| 192 | BOOST_CHECK(alsa1.getAdl().isNeighbor(activeAdjacency.getName())); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 193 | |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame] | 194 | // An AdjLsa initialized with INACTIVE adjacencies should not copy the adjacencies |
| 195 | AdjacencyList inactiveAdjacencies; |
| 196 | Adjacent inactiveAdjacency(adjacencyName); |
| 197 | inactiveAdjacency.setStatus(Adjacent::STATUS_INACTIVE); |
| 198 | inactiveAdjacencies.insert(inactiveAdjacency); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 199 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 200 | AdjLsa alsa2(routerName, seqNo, testTimePoint, |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 201 | inactiveAdjacencies.size(), inactiveAdjacencies); |
| 202 | BOOST_CHECK_EQUAL(alsa2.getAdl().size(), 0); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 203 | |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame] | 204 | // Thus, the two LSAs should not have equal content |
| 205 | BOOST_CHECK_EQUAL(alsa1.isEqualContent(alsa2), false); |
| 206 | |
| 207 | // Create a duplicate of alsa1 which should have equal content |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 208 | AdjLsa alsa3(routerName, seqNo, testTimePoint, |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 209 | activeAdjacencies.size(), activeAdjacencies); |
alvy | c69c9af | 2015-04-09 12:38:54 -0500 | [diff] [blame] | 210 | BOOST_CHECK(alsa1.isEqualContent(alsa3)); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 211 | |
| 212 | auto wire = alsa1.wireEncode(); |
| 213 | BOOST_CHECK_EQUAL_COLLECTIONS(ADJ_LSA1, ADJ_LSA1 + sizeof(ADJ_LSA1), |
| 214 | wire.begin(), wire.end()); |
| 215 | |
| 216 | Adjacent activeAdjacency2("/ndn/edu/adjacency"); |
| 217 | activeAdjacency2.setStatus(Adjacent::STATUS_ACTIVE); |
| 218 | alsa1.addAdjacent(activeAdjacency2); |
| 219 | wire = alsa1.wireEncode(); |
| 220 | BOOST_CHECK_EQUAL_COLLECTIONS(ADJ_LSA_EXTRA_NEIGHBOR, |
| 221 | ADJ_LSA_EXTRA_NEIGHBOR + sizeof(ADJ_LSA_EXTRA_NEIGHBOR), |
| 222 | wire.begin(), wire.end()); |
| 223 | |
| 224 | alsa1.setSeqNo(14); |
| 225 | wire = alsa1.wireEncode(); |
| 226 | BOOST_CHECK_EQUAL_COLLECTIONS(ADJ_LSA_DIFF_SEQ, ADJ_LSA_DIFF_SEQ + sizeof(ADJ_LSA_DIFF_SEQ), |
| 227 | wire.begin(), wire.end()); |
| 228 | |
| 229 | testTimePoint = |
| 230 | ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196024993)); |
| 231 | alsa1.setExpirationTimePoint(testTimePoint); |
| 232 | wire = alsa1.wireEncode(); |
| 233 | BOOST_CHECK_EQUAL_COLLECTIONS(ADJ_LSA_DIFF_TS, ADJ_LSA_DIFF_TS + sizeof(ADJ_LSA_DIFF_TS), |
| 234 | wire.begin(), wire.end()); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 235 | } |
| 236 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 237 | const uint8_t COORDINATE_LSA1[] = { |
| 238 | 0x85, 0x43, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, |
| 239 | 0x82, 0x01, 0x0C, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, |
| 240 | 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x87, 0x08, 0x40, 0x04, 0x00, 0x00, |
| 241 | 0x00, 0x00, 0x00, 0x00, 0x88, 0x08, 0x40, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, |
| 242 | 0x08, 0x40, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 243 | }; |
| 244 | |
| 245 | const uint8_t COORDINATE_LSA_DIFF_ANGLE[] = { |
| 246 | 0x85, 0x39, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, |
| 247 | 0x82, 0x01, 0x0C, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, |
| 248 | 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x87, 0x08, 0x40, 0x04, 0x00, 0x00, |
| 249 | 0x00, 0x00, 0x00, 0x00, 0x88, 0x08, 0x40, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 250 | }; |
| 251 | |
| 252 | const uint8_t COORDINATE_LSA_DIFF_RADIUS[] = { |
| 253 | 0x85, 0x39, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, |
| 254 | 0x82, 0x01, 0x0C, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, |
| 255 | 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x87, 0x08, 0x40, 0x02, 0x66, 0x66, |
| 256 | 0x66, 0x66, 0x66, 0x66, 0x88, 0x08, 0x40, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 257 | }; |
| 258 | |
| 259 | const uint8_t COORDINATE_LSA_DIFF_SEQ[] = { |
| 260 | 0x85, 0x39, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, |
| 261 | 0x82, 0x01, 0x0E, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, |
| 262 | 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x87, 0x08, 0x40, 0x02, 0x66, 0x66, |
| 263 | 0x66, 0x66, 0x66, 0x66, 0x88, 0x08, 0x40, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 264 | }; |
| 265 | |
| 266 | const uint8_t COORDINATE_LSA_DIFF_TS[] = { |
| 267 | 0x85, 0x39, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, |
| 268 | 0x82, 0x01, 0x0E, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, |
| 269 | 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x34, 0x34, 0x87, 0x08, 0x40, 0x02, 0x66, 0x66, |
| 270 | 0x66, 0x66, 0x66, 0x66, 0x88, 0x08, 0x40, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 271 | }; |
| 272 | |
| 273 | BOOST_AUTO_TEST_CASE(CoordinateLsaBasic) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 274 | { |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 275 | ndn::time::system_clock::TimePoint testTimePoint = |
| 276 | ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196014943)); |
| 277 | std::vector<double> angles1 {30.0}, angles2 {30.0}; |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 278 | angles1.push_back(30.0); |
| 279 | angles2.push_back(30.0); |
| 280 | CoordinateLsa clsa1("router1", 12, testTimePoint, 2.5, angles1); |
| 281 | CoordinateLsa clsa2("router1", 12, testTimePoint, 2.5, angles2); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 282 | |
| 283 | BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001); |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 284 | BOOST_CHECK(clsa1.getCorTheta() == angles1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 285 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 286 | BOOST_CHECK(clsa1.isEqualContent(clsa2)); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 287 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 288 | BOOST_CHECK_EQUAL(clsa1.wireEncode(), clsa2.wireEncode()); |
| 289 | |
| 290 | auto wire = clsa1.wireEncode(); |
| 291 | BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA1, COORDINATE_LSA1 + sizeof(COORDINATE_LSA1), |
| 292 | wire.begin(), wire.end()); |
| 293 | |
| 294 | std::vector<double> angles3{40.0}; |
| 295 | clsa1.setCorTheta(angles3); |
| 296 | wire = clsa1.wireEncode(); |
| 297 | BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA_DIFF_ANGLE, |
| 298 | COORDINATE_LSA_DIFF_ANGLE + sizeof(COORDINATE_LSA_DIFF_ANGLE), |
| 299 | wire.begin(), wire.end()); |
| 300 | |
| 301 | clsa1.setCorRadius(2.3); |
| 302 | wire = clsa1.wireEncode(); |
| 303 | BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA_DIFF_RADIUS, |
| 304 | COORDINATE_LSA_DIFF_RADIUS + sizeof(COORDINATE_LSA_DIFF_RADIUS), |
| 305 | wire.begin(), wire.end()); |
| 306 | |
| 307 | clsa1.setSeqNo(14); |
| 308 | wire = clsa1.wireEncode(); |
| 309 | BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA_DIFF_SEQ, |
| 310 | COORDINATE_LSA_DIFF_SEQ + sizeof(COORDINATE_LSA_DIFF_SEQ), |
| 311 | wire.begin(), wire.end()); |
| 312 | |
| 313 | testTimePoint = |
| 314 | ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196024993)); |
| 315 | clsa1.setExpirationTimePoint(testTimePoint); |
| 316 | wire = clsa1.wireEncode(); |
| 317 | BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA_DIFF_TS, |
| 318 | COORDINATE_LSA_DIFF_TS + sizeof(COORDINATE_LSA_DIFF_TS), |
| 319 | wire.begin(), wire.end()); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 320 | } |
| 321 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 322 | BOOST_AUTO_TEST_CASE(IncrementAdjacentNumber) |
| 323 | { |
| 324 | Adjacent adj1("adjacent1"); |
| 325 | Adjacent adj2("adjacent2"); |
| 326 | |
| 327 | adj1.setStatus(Adjacent::STATUS_ACTIVE); |
| 328 | adj2.setStatus(Adjacent::STATUS_ACTIVE); |
| 329 | |
| 330 | AdjacencyList adjList; |
| 331 | adjList.insert(adj1); |
| 332 | adjList.insert(adj2); |
| 333 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame^] | 334 | auto testTimePoint = ndn::time::system_clock::now() + ndn::time::seconds(3600); |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 335 | |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 336 | AdjLsa lsa("router1", 12, testTimePoint, adjList.size(), adjList); |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 337 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame^] | 338 | std::ostringstream os; |
| 339 | os << lsa; |
| 340 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 341 | std::string EXPECTED_OUTPUT = |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 342 | " ADJACENCY LSA:\n" |
| 343 | " Origin Router : /router1\n" |
| 344 | " Sequence Number : 12\n" |
| 345 | " Expires in : 3599999 milliseconds\n" |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame^] | 346 | " Adjacent(s):\n" |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 347 | " Adjacent 0: (name=/adjacent1, uri=://, cost=10)\n" |
| 348 | " Adjacent 1: (name=/adjacent2, uri=://, cost=10)\n"; |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 349 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 350 | BOOST_CHECK_EQUAL(os.str(), EXPECTED_OUTPUT); |
| 351 | } |
| 352 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 353 | BOOST_AUTO_TEST_CASE(TestInitializeFromContent) |
| 354 | { |
| 355 | //Adj LSA |
| 356 | Adjacent adj1("adjacent1"); |
| 357 | Adjacent adj2("adjacent2"); |
| 358 | |
| 359 | adj1.setStatus(Adjacent::STATUS_ACTIVE); |
| 360 | adj2.setStatus(Adjacent::STATUS_ACTIVE); |
| 361 | |
| 362 | //If we don't do this the test will fail |
| 363 | //Adjacent has default cost of 10 but no default |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 364 | //connecting face URI, so initializeFromContent fails |
| 365 | adj1.setFaceUri(ndn::FaceUri("udp://10.0.0.1")); |
| 366 | adj2.setFaceUri(ndn::FaceUri("udp://10.0.0.2")); |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 367 | |
| 368 | AdjacencyList adjList; |
| 369 | adjList.insert(adj1); |
| 370 | adjList.insert(adj2); |
| 371 | |
| 372 | ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now(); |
| 373 | |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 374 | AdjLsa adjlsa1("router1", 1, testTimePoint, adjList.size(), adjList); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 375 | AdjLsa adjlsa2(adjlsa1.wireEncode()); |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 376 | BOOST_CHECK(adjlsa1.isEqualContent(adjlsa2)); |
| 377 | |
| 378 | //Name LSA |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame^] | 379 | /*ndn::Name s1{"name1"}; |
Nick Gordon | 96861ca | 2017-10-17 18:25:21 -0500 | [diff] [blame] | 380 | ndn::Name s2{"name2"}; |
| 381 | NamePrefixList npl1{s1, s2}; |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 382 | |
| 383 | NameLsa nlsa1("router1", 1, testTimePoint, npl1); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 384 | NameLsa nlsa2(nlsa1.wireEncode()); |
| 385 | BOOST_CHECK_EQUAL(nlsa1.wireEncode(), nlsa2.wireEncode()); |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 386 | |
| 387 | //Coordinate LSA |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 388 | std::vector<double> angles = {30, 40.0}; |
| 389 | CoordinateLsa clsa1("router1", 12, testTimePoint, 2.5, angles); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 390 | CoordinateLsa clsa2(clsa1.wireEncode()); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame^] | 391 | BOOST_CHECK_EQUAL(clsa1.wireEncode(), clsa2.wireEncode());*/ |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 392 | } |
| 393 | |
Nick Gordon | 56d1fae | 2017-05-26 16:39:25 -0500 | [diff] [blame] | 394 | BOOST_AUTO_TEST_CASE(OperatorEquals) |
| 395 | { |
| 396 | NameLsa lsa1; |
| 397 | NameLsa lsa2; |
| 398 | ndn::Name name1("/ndn/test/name1"); |
| 399 | ndn::Name name2("/ndn/test/name2"); |
| 400 | ndn::Name name3("/ndn/some/other/name1"); |
| 401 | |
| 402 | lsa1.addName(name1); |
| 403 | lsa1.addName(name2); |
| 404 | lsa1.addName(name3); |
| 405 | |
| 406 | lsa2.addName(name1); |
| 407 | lsa2.addName(name2); |
| 408 | lsa2.addName(name3); |
| 409 | |
| 410 | BOOST_CHECK(lsa1.isEqualContent(lsa2)); |
| 411 | } |
| 412 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 413 | BOOST_AUTO_TEST_SUITE_END() |
| 414 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 415 | } // namespace test |
| 416 | } // namespace nlsr |