blob: 9fb68637f461427c5d960f40afe61663d67efbc0 [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();
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 Gawandeeb582eb2014-05-01 14:25:20 -0500125}
126
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800127const 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
136const 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
148const 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
159const 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
171BOOST_AUTO_TEST_CASE(AdjLsaBasic)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500172{
alvyc69c9af2015-04-09 12:38:54 -0500173 ndn::Name routerName("/ndn/site/router");
174 ndn::Name adjacencyName("/ndn/site/adjacency");
Davide Pesaventoe28d8752022-03-19 03:55:25 -0400175 auto testTimePoint = ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196014943));
alvyc69c9af2015-04-09 12:38:54 -0500176 uint32_t seqNo = 12;
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500177
alvyc69c9af2015-04-09 12:38:54 -0500178 // 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 Gawanded02c3882015-12-29 16:02:51 -0600184 AdjLsa alsa1(routerName, seqNo, testTimePoint,
Nick Gordonff9a6272017-10-12 13:38:29 -0500185 activeAdjacencies.size(), activeAdjacencies);
186 BOOST_CHECK_EQUAL(alsa1.getAdl().size(), 1);
Nick Gordon727d4832017-10-13 18:04:25 -0500187 BOOST_CHECK_EQUAL(alsa1.getType(), Lsa::Type::ADJACENCY);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800188 BOOST_CHECK_EQUAL(alsa1.getSeqNo(), seqNo);
akmhoquec7a79b22014-05-26 08:06:19 -0500189 BOOST_CHECK_EQUAL(alsa1.getExpirationTimePoint(), testTimePoint);
alvyc69c9af2015-04-09 12:38:54 -0500190 BOOST_CHECK_EQUAL(alsa1.getNoLink(), 1);
191 BOOST_CHECK(alsa1.getAdl().isNeighbor(activeAdjacency.getName()));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500192
alvyc69c9af2015-04-09 12:38:54 -0500193 // 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 Gawandeeb582eb2014-05-01 14:25:20 -0500198
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600199 AdjLsa alsa2(routerName, seqNo, testTimePoint,
Nick Gordonff9a6272017-10-12 13:38:29 -0500200 inactiveAdjacencies.size(), inactiveAdjacencies);
201 BOOST_CHECK_EQUAL(alsa2.getAdl().size(), 0);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500202
alvyc69c9af2015-04-09 12:38:54 -0500203 // 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 Gawanded02c3882015-12-29 16:02:51 -0600207 AdjLsa alsa3(routerName, seqNo, testTimePoint,
Nick Gordonff9a6272017-10-12 13:38:29 -0500208 activeAdjacencies.size(), activeAdjacencies);
alvyc69c9af2015-04-09 12:38:54 -0500209 BOOST_CHECK(alsa1.isEqualContent(alsa3));
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800210
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 Gawandeeb582eb2014-05-01 14:25:20 -0500234}
235
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800236const 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
244const 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
251const 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
258const 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
265const 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
272BOOST_AUTO_TEST_CASE(CoordinateLsaBasic)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500273{
Davide Pesaventoe28d8752022-03-19 03:55:25 -0400274 auto testTimePoint = ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196014943));
275 std::vector<double> angles1{30.0}, angles2{30.0};
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600276 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 Gawandeeb582eb2014-05-01 14:25:20 -0500280
281 BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001);
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600282 BOOST_CHECK(clsa1.getCorTheta() == angles1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500283
akmhoquefdbddb12014-05-02 18:35:19 -0500284 BOOST_CHECK(clsa1.isEqualContent(clsa2));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500285
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800286 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 Gawandeeb582eb2014-05-01 14:25:20 -0500318}
319
alvydce3f182015-04-09 11:23:30 -0500320BOOST_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 Gawande57a87172020-05-09 19:47:06 -0700332 auto testTimePoint = ndn::time::system_clock::now() + ndn::time::seconds(3600);
alvydce3f182015-04-09 11:23:30 -0500333
Nick Gordonff9a6272017-10-12 13:38:29 -0500334 AdjLsa lsa("router1", 12, testTimePoint, adjList.size(), adjList);
alvydce3f182015-04-09 11:23:30 -0500335
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700336 std::ostringstream os;
337 os << lsa;
338
alvydce3f182015-04-09 11:23:30 -0500339 std::string EXPECTED_OUTPUT =
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800340 " ADJACENCY LSA:\n"
341 " Origin Router : /router1\n"
342 " Sequence Number : 12\n"
343 " Expires in : 3599999 milliseconds\n"
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700344 " Adjacent(s):\n"
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800345 " Adjacent 0: (name=/adjacent1, uri=://, cost=10)\n"
346 " Adjacent 1: (name=/adjacent2, uri=://, cost=10)\n";
alvydce3f182015-04-09 11:23:30 -0500347
alvydce3f182015-04-09 11:23:30 -0500348 BOOST_CHECK_EQUAL(os.str(), EXPECTED_OUTPUT);
349}
350
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600351BOOST_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 Chowdhuryf04f9892017-08-20 20:42:56 -0500362 //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 Gawanded02c3882015-12-29 16:02:51 -0600365
366 AdjacencyList adjList;
367 adjList.insert(adj1);
368 adjList.insert(adj2);
369
Davide Pesaventoe28d8752022-03-19 03:55:25 -0400370 auto testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600371
Nick Gordonff9a6272017-10-12 13:38:29 -0500372 AdjLsa adjlsa1("router1", 1, testTimePoint, adjList.size(), adjList);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800373 AdjLsa adjlsa2(adjlsa1.wireEncode());
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600374 BOOST_CHECK(adjlsa1.isEqualContent(adjlsa2));
375
376 //Name LSA
Ashlesh Gawande3781c7e2021-05-22 22:36:26 -0700377 ndn::Name s1{"name1"};
Nick Gordon96861ca2017-10-17 18:25:21 -0500378 ndn::Name s2{"name2"};
379 NamePrefixList npl1{s1, s2};
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600380
381 NameLsa nlsa1("router1", 1, testTimePoint, npl1);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800382 NameLsa nlsa2(nlsa1.wireEncode());
383 BOOST_CHECK_EQUAL(nlsa1.wireEncode(), nlsa2.wireEncode());
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600384
385 //Coordinate LSA
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600386 std::vector<double> angles = {30, 40.0};
387 CoordinateLsa clsa1("router1", 12, testTimePoint, 2.5, angles);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800388 CoordinateLsa clsa2(clsa1.wireEncode());
Ashlesh Gawande3781c7e2021-05-22 22:36:26 -0700389 BOOST_CHECK_EQUAL(clsa1.wireEncode(), clsa2.wireEncode());
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600390}
391
Nick Gordon56d1fae2017-05-26 16:39:25 -0500392BOOST_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 Gawande3781c7e2021-05-22 22:36:26 -0700411BOOST_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 Gawandeeb582eb2014-05-01 14:25:20 -0500445BOOST_AUTO_TEST_SUITE_END()
446
alvydce3f182015-04-09 11:23:30 -0500447} // namespace test
448} // namespace nlsr