blob: 1e89d9f0358c59859d43d50465ae43b206086050 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande57a87172020-05-09 19:47:06 -07002/*
Davide Pesaventoe28d8752022-03-19 03:55:25 -04003 * Copyright (c) 2014-2022, The University of Memphis,
Vince Lehmanc2e51f62015-01-20 15:03:11 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
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 Gawande57a87172020-05-09 19:47:06 -070020 */
Vince Lehmanc2e51f62015-01-20 15:03:11 -060021
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080022#include "lsa/name-lsa.hpp"
23#include "lsa/adj-lsa.hpp"
24#include "lsa/coordinate-lsa.hpp"
Nick Gordonff9a6272017-10-12 13:38:29 -050025#include "adjacent.hpp"
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050026#include "name-prefix-list.hpp"
alvydce3f182015-04-09 11:23:30 -050027
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040028#include "tests/boost-test.hpp"
alvydce3f182015-04-09 11:23:30 -050029
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050030namespace nlsr {
31namespace test {
alvydce3f182015-04-09 11:23:30 -050032
Davide Pesaventoe28d8752022-03-19 03:55:25 -040033/*
34static void
35printBytes(ndn::span<const uint8_t> buf)
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080036{
Davide Pesaventoe28d8752022-03-19 03:55:25 -040037 std::string hex = ndn::toHex(buf);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080038
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 Pesaventoe28d8752022-03-19 03:55:25 -040052printBytes(block);
53*/
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080054
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050055BOOST_AUTO_TEST_SUITE(TestLsa)
56
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080057const 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
64const 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
72const 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
80const 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 Gawandeeb582eb2014-05-01 14:25:20 -050088BOOST_AUTO_TEST_CASE(NameLsaBasic)
89{
Nick Gordon96861ca2017-10-17 18:25:21 -050090 ndn::Name s1{"name1"};
91 ndn::Name s2{"name2"};
92 NamePrefixList npl1{s1, s2};
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050093
Davide Pesaventoe28d8752022-03-19 03:55:25 -040094 auto testTimePoint = ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196014943));
Ashlesh Gawanded02c3882015-12-29 16:02:51 -060095
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080096 // 3rd argument is seqNo
Ashlesh Gawanded02c3882015-12-29 16:02:51 -060097 NameLsa nlsa1("router1", 12, testTimePoint, npl1);
98 NameLsa nlsa2("router2", 12, testTimePoint, npl1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050099
Nick Gordon727d4832017-10-13 18:04:25 -0500100 BOOST_CHECK_EQUAL(nlsa1.getType(), Lsa::Type::NAME);
akmhoquec7a79b22014-05-26 08:06:19 -0500101 BOOST_CHECK(nlsa1.getExpirationTimePoint() == nlsa2.getExpirationTimePoint());
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800102
103 auto wire = nlsa1.wireEncode();
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400104 BOOST_TEST(wire == NAME_LSA1, boost::test_tools::per_element());
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800105
106 nlsa1.addName("name3");
107 wire = nlsa1.wireEncode();
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400108 BOOST_TEST(wire == NAME_LSA_EXTRA_NAME, boost::test_tools::per_element());
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800109
110 nlsa1.setSeqNo(14);
111 wire = nlsa1.wireEncode();
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400112 BOOST_TEST(wire == NAME_LSA_DIFF_SEQ, boost::test_tools::per_element());
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800113
114 testTimePoint =
115 ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196024993));
116 nlsa1.setExpirationTimePoint(testTimePoint);
117 wire = nlsa1.wireEncode();
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400118 BOOST_TEST(wire == NAME_LSA_DIFF_TS, boost::test_tools::per_element());
119
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800120 // Not testing router name as not sure if that will ever change once set
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500121}
122
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800123const 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
132const 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
144const 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
155const 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
167BOOST_AUTO_TEST_CASE(AdjLsaBasic)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500168{
alvyc69c9af2015-04-09 12:38:54 -0500169 ndn::Name routerName("/ndn/site/router");
170 ndn::Name adjacencyName("/ndn/site/adjacency");
Davide Pesaventoe28d8752022-03-19 03:55:25 -0400171 auto testTimePoint = ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196014943));
alvyc69c9af2015-04-09 12:38:54 -0500172 uint32_t seqNo = 12;
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500173
alvyc69c9af2015-04-09 12:38:54 -0500174 // 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 Gawanded02c3882015-12-29 16:02:51 -0600180 AdjLsa alsa1(routerName, seqNo, testTimePoint,
Nick Gordonff9a6272017-10-12 13:38:29 -0500181 activeAdjacencies.size(), activeAdjacencies);
182 BOOST_CHECK_EQUAL(alsa1.getAdl().size(), 1);
Nick Gordon727d4832017-10-13 18:04:25 -0500183 BOOST_CHECK_EQUAL(alsa1.getType(), Lsa::Type::ADJACENCY);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800184 BOOST_CHECK_EQUAL(alsa1.getSeqNo(), seqNo);
akmhoquec7a79b22014-05-26 08:06:19 -0500185 BOOST_CHECK_EQUAL(alsa1.getExpirationTimePoint(), testTimePoint);
alvyc69c9af2015-04-09 12:38:54 -0500186 BOOST_CHECK_EQUAL(alsa1.getNoLink(), 1);
187 BOOST_CHECK(alsa1.getAdl().isNeighbor(activeAdjacency.getName()));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500188
alvyc69c9af2015-04-09 12:38:54 -0500189 // 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 Gawandeeb582eb2014-05-01 14:25:20 -0500194
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600195 AdjLsa alsa2(routerName, seqNo, testTimePoint,
Nick Gordonff9a6272017-10-12 13:38:29 -0500196 inactiveAdjacencies.size(), inactiveAdjacencies);
197 BOOST_CHECK_EQUAL(alsa2.getAdl().size(), 0);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500198
alvyc69c9af2015-04-09 12:38:54 -0500199 // 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 Gawanded02c3882015-12-29 16:02:51 -0600203 AdjLsa alsa3(routerName, seqNo, testTimePoint,
Nick Gordonff9a6272017-10-12 13:38:29 -0500204 activeAdjacencies.size(), activeAdjacencies);
alvyc69c9af2015-04-09 12:38:54 -0500205 BOOST_CHECK(alsa1.isEqualContent(alsa3));
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800206
207 auto wire = alsa1.wireEncode();
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400208 BOOST_TEST(wire == ADJ_LSA1, boost::test_tools::per_element());
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800209
210 Adjacent activeAdjacency2("/ndn/edu/adjacency");
211 activeAdjacency2.setStatus(Adjacent::STATUS_ACTIVE);
212 alsa1.addAdjacent(activeAdjacency2);
213 wire = alsa1.wireEncode();
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400214 BOOST_TEST(wire == ADJ_LSA_EXTRA_NEIGHBOR, boost::test_tools::per_element());
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800215
216 alsa1.setSeqNo(14);
217 wire = alsa1.wireEncode();
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400218 BOOST_TEST(wire == ADJ_LSA_DIFF_SEQ, boost::test_tools::per_element());
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800219
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400220 testTimePoint = ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196024993));
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800221 alsa1.setExpirationTimePoint(testTimePoint);
222 wire = alsa1.wireEncode();
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400223 BOOST_TEST(wire == ADJ_LSA_DIFF_TS, boost::test_tools::per_element());
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500224}
225
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800226const 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
234const 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
241const 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
248const 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
255const 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
262BOOST_AUTO_TEST_CASE(CoordinateLsaBasic)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500263{
Davide Pesaventoe28d8752022-03-19 03:55:25 -0400264 auto testTimePoint = ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196014943));
265 std::vector<double> angles1{30.0}, angles2{30.0};
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600266 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 Gawandeeb582eb2014-05-01 14:25:20 -0500270
271 BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001);
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600272 BOOST_CHECK(clsa1.getCorTheta() == angles1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500273
akmhoquefdbddb12014-05-02 18:35:19 -0500274 BOOST_CHECK(clsa1.isEqualContent(clsa2));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500275
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800276 BOOST_CHECK_EQUAL(clsa1.wireEncode(), clsa2.wireEncode());
277
278 auto wire = clsa1.wireEncode();
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400279 BOOST_TEST(wire == COORDINATE_LSA1, boost::test_tools::per_element());
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800280
281 std::vector<double> angles3{40.0};
282 clsa1.setCorTheta(angles3);
283 wire = clsa1.wireEncode();
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400284 BOOST_TEST(wire == COORDINATE_LSA_DIFF_ANGLE, boost::test_tools::per_element());
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800285
286 clsa1.setCorRadius(2.3);
287 wire = clsa1.wireEncode();
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400288 BOOST_TEST(wire == COORDINATE_LSA_DIFF_RADIUS, boost::test_tools::per_element());
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800289
290 clsa1.setSeqNo(14);
291 wire = clsa1.wireEncode();
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400292 BOOST_TEST(wire == COORDINATE_LSA_DIFF_SEQ, boost::test_tools::per_element());
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800293
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400294 testTimePoint = ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196024993));
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800295 clsa1.setExpirationTimePoint(testTimePoint);
296 wire = clsa1.wireEncode();
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400297 BOOST_TEST(wire == COORDINATE_LSA_DIFF_TS, boost::test_tools::per_element());
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500298}
299
alvydce3f182015-04-09 11:23:30 -0500300BOOST_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 Gawande57a87172020-05-09 19:47:06 -0700312 auto testTimePoint = ndn::time::system_clock::now() + ndn::time::seconds(3600);
alvydce3f182015-04-09 11:23:30 -0500313
Nick Gordonff9a6272017-10-12 13:38:29 -0500314 AdjLsa lsa("router1", 12, testTimePoint, adjList.size(), adjList);
alvydce3f182015-04-09 11:23:30 -0500315
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700316 std::ostringstream os;
317 os << lsa;
318
alvydce3f182015-04-09 11:23:30 -0500319 std::string EXPECTED_OUTPUT =
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800320 " ADJACENCY LSA:\n"
321 " Origin Router : /router1\n"
322 " Sequence Number : 12\n"
323 " Expires in : 3599999 milliseconds\n"
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700324 " Adjacent(s):\n"
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800325 " Adjacent 0: (name=/adjacent1, uri=://, cost=10)\n"
326 " Adjacent 1: (name=/adjacent2, uri=://, cost=10)\n";
alvydce3f182015-04-09 11:23:30 -0500327
alvydce3f182015-04-09 11:23:30 -0500328 BOOST_CHECK_EQUAL(os.str(), EXPECTED_OUTPUT);
329}
330
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600331BOOST_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 Chowdhuryf04f9892017-08-20 20:42:56 -0500342 //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 Gawanded02c3882015-12-29 16:02:51 -0600345
346 AdjacencyList adjList;
347 adjList.insert(adj1);
348 adjList.insert(adj2);
349
Davide Pesaventoe28d8752022-03-19 03:55:25 -0400350 auto testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600351
Nick Gordonff9a6272017-10-12 13:38:29 -0500352 AdjLsa adjlsa1("router1", 1, testTimePoint, adjList.size(), adjList);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800353 AdjLsa adjlsa2(adjlsa1.wireEncode());
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600354 BOOST_CHECK(adjlsa1.isEqualContent(adjlsa2));
355
356 //Name LSA
Ashlesh Gawande3781c7e2021-05-22 22:36:26 -0700357 ndn::Name s1{"name1"};
Nick Gordon96861ca2017-10-17 18:25:21 -0500358 ndn::Name s2{"name2"};
359 NamePrefixList npl1{s1, s2};
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600360
361 NameLsa nlsa1("router1", 1, testTimePoint, npl1);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800362 NameLsa nlsa2(nlsa1.wireEncode());
363 BOOST_CHECK_EQUAL(nlsa1.wireEncode(), nlsa2.wireEncode());
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600364
365 //Coordinate LSA
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600366 std::vector<double> angles = {30, 40.0};
367 CoordinateLsa clsa1("router1", 12, testTimePoint, 2.5, angles);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800368 CoordinateLsa clsa2(clsa1.wireEncode());
Ashlesh Gawande3781c7e2021-05-22 22:36:26 -0700369 BOOST_CHECK_EQUAL(clsa1.wireEncode(), clsa2.wireEncode());
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600370}
371
Nick Gordon56d1fae2017-05-26 16:39:25 -0500372BOOST_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 Gawande3781c7e2021-05-22 22:36:26 -0700391BOOST_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 Pesaventoc1d0e8e2022-06-15 14:26:02 -0400400 auto rcvdLsa = std::make_shared<NameLsa>();
Ashlesh Gawande3781c7e2021-05-22 22:36:26 -0700401 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 Pesaventoc1d0e8e2022-06-15 14:26:02 -0400404
Ashlesh Gawande3781c7e2021-05-22 22:36:26 -0700405 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 Pesaventoc1d0e8e2022-06-15 14:26:02 -0400413 auto [updated, namesToAdd, namesToRemove] = knownNameLsa.update(rcvdLsa);
Ashlesh Gawande3781c7e2021-05-22 22:36:26 -0700414
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400415 BOOST_CHECK_EQUAL(updated, true);
Ashlesh Gawande3781c7e2021-05-22 22:36:26 -0700416 BOOST_CHECK_EQUAL(namesToAdd.size(), 2);
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400417 BOOST_CHECK_EQUAL(namesToRemove.size(), 0);
Ashlesh Gawande3781c7e2021-05-22 22:36:26 -0700418 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 Gawandeeb582eb2014-05-01 14:25:20 -0500424BOOST_AUTO_TEST_SUITE_END()
425
alvydce3f182015-04-09 11:23:30 -0500426} // namespace test
427} // namespace nlsr