blob: d89fef67b30edad8a11cd555ba4c02088459493d [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 "test-common.hpp"
26#include "adjacent.hpp"
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050027#include "name-prefix-list.hpp"
alvydce3f182015-04-09 11:23:30 -050028
akmhoquec7a79b22014-05-26 08:06:19 -050029#include <ndn-cxx/util/time.hpp>
alvydce3f182015-04-09 11:23:30 -050030
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050031namespace nlsr {
32namespace test {
alvydce3f182015-04-09 11:23:30 -050033
Davide Pesaventoe28d8752022-03-19 03:55:25 -040034/*
35static void
36printBytes(ndn::span<const uint8_t> buf)
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080037{
Davide Pesaventoe28d8752022-03-19 03:55:25 -040038 std::string hex = ndn::toHex(buf);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080039
40 for (size_t i = 0; i < hex.size(); i++) {
41 if (i > 0 && i % 30 == 0)
42 std::cout << "\n ";
43
44 std::cout << "0x" << hex[i];
45 std::cout << hex[++i];
46
47 if ((i + 1) != hex.size())
48 std::cout << ", ";
49 }
50 std::cout << "\n" << "};" << std::endl;
51}
52
Davide Pesaventoe28d8752022-03-19 03:55:25 -040053printBytes(block);
54*/
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080055
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050056BOOST_AUTO_TEST_SUITE(TestLsa)
57
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080058const uint8_t NAME_LSA1[] = {
59 0x89, 0x37, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31,
60 0x82, 0x01, 0x0C, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36,
61 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61,
62 0x6D, 0x65, 0x31, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32
63};
64
65const uint8_t NAME_LSA_EXTRA_NAME[] = {
66 0x89, 0x40, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31,
67 0x82, 0x01, 0x0C, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36,
68 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61,
69 0x6D, 0x65, 0x31, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32, 0x07, 0x07, 0x08,
70 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x33
71};
72
73const uint8_t NAME_LSA_DIFF_SEQ[] = {
74 0x89, 0x40, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31,
75 0x82, 0x01, 0x0E, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36,
76 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61,
77 0x6D, 0x65, 0x31, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32, 0x07, 0x07, 0x08,
78 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x33
79};
80
81const uint8_t NAME_LSA_DIFF_TS[] = {
82 0x89, 0x40, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31,
83 0x82, 0x01, 0x0E, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36,
84 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x34, 0x34, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61,
85 0x6D, 0x65, 0x31, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32, 0x07, 0x07, 0x08,
86 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x33
87};
88
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050089BOOST_AUTO_TEST_CASE(NameLsaBasic)
90{
Nick Gordon96861ca2017-10-17 18:25:21 -050091 ndn::Name s1{"name1"};
92 ndn::Name s2{"name2"};
93 NamePrefixList npl1{s1, s2};
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050094
Davide Pesaventoe28d8752022-03-19 03:55:25 -040095 auto testTimePoint = ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196014943));
Ashlesh Gawanded02c3882015-12-29 16:02:51 -060096
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080097 // 3rd argument is seqNo
Ashlesh Gawanded02c3882015-12-29 16:02:51 -060098 NameLsa nlsa1("router1", 12, testTimePoint, npl1);
99 NameLsa nlsa2("router2", 12, testTimePoint, npl1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500100
Nick Gordon727d4832017-10-13 18:04:25 -0500101 BOOST_CHECK_EQUAL(nlsa1.getType(), Lsa::Type::NAME);
akmhoquec7a79b22014-05-26 08:06:19 -0500102 BOOST_CHECK(nlsa1.getExpirationTimePoint() == nlsa2.getExpirationTimePoint());
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800103
104 auto wire = nlsa1.wireEncode();
105 BOOST_CHECK_EQUAL_COLLECTIONS(NAME_LSA1, NAME_LSA1 + sizeof(NAME_LSA1),
106 wire.begin(), wire.end());
107
108 nlsa1.addName("name3");
109 wire = nlsa1.wireEncode();
110 BOOST_CHECK_EQUAL_COLLECTIONS(NAME_LSA_EXTRA_NAME,
111 NAME_LSA_EXTRA_NAME + sizeof(NAME_LSA_EXTRA_NAME),
112 wire.begin(), wire.end());
113
114 nlsa1.setSeqNo(14);
115 wire = nlsa1.wireEncode();
116 BOOST_CHECK_EQUAL_COLLECTIONS(NAME_LSA_DIFF_SEQ, NAME_LSA_DIFF_SEQ + sizeof(NAME_LSA_DIFF_SEQ),
117 wire.begin(), wire.end());
118
119 testTimePoint =
120 ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196024993));
121 nlsa1.setExpirationTimePoint(testTimePoint);
122 wire = nlsa1.wireEncode();
123 BOOST_CHECK_EQUAL_COLLECTIONS(NAME_LSA_DIFF_TS, NAME_LSA_DIFF_TS + sizeof(NAME_LSA_DIFF_TS),
124 wire.begin(), wire.end());
125 // Not testing router name as not sure if that will ever change once set
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500126}
127
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800128const uint8_t ADJ_LSA1[] = {
129 0x83, 0x58, 0x80, 0x2D, 0x07, 0x13, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x04, 0x73, 0x69,
130 0x74, 0x65, 0x08, 0x06, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x82, 0x01, 0x0C, 0x8B, 0x13,
131 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, 0x20, 0x30, 0x34, 0x3A, 0x31,
132 0x33, 0x3A, 0x33, 0x34, 0x84, 0x27, 0x07, 0x16, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x04,
133 0x73, 0x69, 0x74, 0x65, 0x08, 0x09, 0x61, 0x64, 0x6A, 0x61, 0x63, 0x65, 0x6E, 0x63, 0x79,
134 0x8D, 0x03, 0x3A, 0x2F, 0x2F, 0x8C, 0x08, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
135};
136
137const uint8_t ADJ_LSA_EXTRA_NEIGHBOR[] = {
138 0x83, 0x80, 0x80, 0x2D, 0x07, 0x13, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x04, 0x73, 0x69,
139 0x74, 0x65, 0x08, 0x06, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x82, 0x01, 0x0C, 0x8B, 0x13,
140 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, 0x20, 0x30, 0x34, 0x3A, 0x31,
141 0x33, 0x3A, 0x33, 0x34, 0x84, 0x27, 0x07, 0x16, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x04,
142 0x73, 0x69, 0x74, 0x65, 0x08, 0x09, 0x61, 0x64, 0x6A, 0x61, 0x63, 0x65, 0x6E, 0x63, 0x79,
143 0x8D, 0x03, 0x3A, 0x2F, 0x2F, 0x8C, 0x08, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
144 0x84, 0x26, 0x07, 0x15, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x03, 0x65, 0x64, 0x75, 0x08,
145 0x09, 0x61, 0x64, 0x6A, 0x61, 0x63, 0x65, 0x6E, 0x63, 0x79, 0x8D, 0x03, 0x3A, 0x2F, 0x2F,
146 0x8C, 0x08, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
147};
148
149const uint8_t ADJ_LSA_DIFF_SEQ[] = {
150 0x83, 0x80, 0x80, 0x2D, 0x07, 0x13, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x04, 0x73, 0x69,
151 0x74, 0x65, 0x08, 0x06, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x82, 0x01, 0x0E, 0x8B, 0x13,
152 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, 0x20, 0x30, 0x34, 0x3A, 0x31,
153 0x33, 0x3A, 0x33, 0x34, 0x84, 0x27, 0x07, 0x16, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x04,
154 0x73, 0x69, 0x74, 0x65, 0x08, 0x09, 0x61, 0x64, 0x6A, 0x61, 0x63, 0x65, 0x6E, 0x63, 0x79,
155 0x8D, 0x03, 0x3A, 0x2F, 0x2F, 0x8C, 0x08, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
156 0x84, 0x26, 0x07, 0x15, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x03, 0x65, 0x64, 0x75, 0x08,
157 0x09, 0x61, 0x64, 0x6A, 0x61, 0x63, 0x65, 0x6E, 0x63, 0x79, 0x8D, 0x03, 0x3A, 0x2F, 0x2F,
158 0x8C, 0x08, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
159
160const uint8_t ADJ_LSA_DIFF_TS[] = {
161 0x83, 0x80, 0x80, 0x2D, 0x07, 0x13, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x04, 0x73, 0x69,
162 0x74, 0x65, 0x08, 0x06, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x82, 0x01, 0x0E, 0x8B, 0x13,
163 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, 0x20, 0x30, 0x34, 0x3A, 0x31,
164 0x33, 0x3A, 0x34, 0x34, 0x84, 0x27, 0x07, 0x16, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x04,
165 0x73, 0x69, 0x74, 0x65, 0x08, 0x09, 0x61, 0x64, 0x6A, 0x61, 0x63, 0x65, 0x6E, 0x63, 0x79,
166 0x8D, 0x03, 0x3A, 0x2F, 0x2F, 0x8C, 0x08, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
167 0x84, 0x26, 0x07, 0x15, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x03, 0x65, 0x64, 0x75, 0x08,
168 0x09, 0x61, 0x64, 0x6A, 0x61, 0x63, 0x65, 0x6E, 0x63, 0x79, 0x8D, 0x03, 0x3A, 0x2F, 0x2F,
169 0x8C, 0x08, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
170};
171
172BOOST_AUTO_TEST_CASE(AdjLsaBasic)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500173{
alvyc69c9af2015-04-09 12:38:54 -0500174 ndn::Name routerName("/ndn/site/router");
175 ndn::Name adjacencyName("/ndn/site/adjacency");
Davide Pesaventoe28d8752022-03-19 03:55:25 -0400176 auto testTimePoint = ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196014943));
alvyc69c9af2015-04-09 12:38:54 -0500177 uint32_t seqNo = 12;
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500178
alvyc69c9af2015-04-09 12:38:54 -0500179 // 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 Gawanded02c3882015-12-29 16:02:51 -0600185 AdjLsa alsa1(routerName, seqNo, testTimePoint,
Nick Gordonff9a6272017-10-12 13:38:29 -0500186 activeAdjacencies.size(), activeAdjacencies);
187 BOOST_CHECK_EQUAL(alsa1.getAdl().size(), 1);
Nick Gordon727d4832017-10-13 18:04:25 -0500188 BOOST_CHECK_EQUAL(alsa1.getType(), Lsa::Type::ADJACENCY);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800189 BOOST_CHECK_EQUAL(alsa1.getSeqNo(), seqNo);
akmhoquec7a79b22014-05-26 08:06:19 -0500190 BOOST_CHECK_EQUAL(alsa1.getExpirationTimePoint(), testTimePoint);
alvyc69c9af2015-04-09 12:38:54 -0500191 BOOST_CHECK_EQUAL(alsa1.getNoLink(), 1);
192 BOOST_CHECK(alsa1.getAdl().isNeighbor(activeAdjacency.getName()));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500193
alvyc69c9af2015-04-09 12:38:54 -0500194 // 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 Gawandeeb582eb2014-05-01 14:25:20 -0500199
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600200 AdjLsa alsa2(routerName, seqNo, testTimePoint,
Nick Gordonff9a6272017-10-12 13:38:29 -0500201 inactiveAdjacencies.size(), inactiveAdjacencies);
202 BOOST_CHECK_EQUAL(alsa2.getAdl().size(), 0);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500203
alvyc69c9af2015-04-09 12:38:54 -0500204 // 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 Gawanded02c3882015-12-29 16:02:51 -0600208 AdjLsa alsa3(routerName, seqNo, testTimePoint,
Nick Gordonff9a6272017-10-12 13:38:29 -0500209 activeAdjacencies.size(), activeAdjacencies);
alvyc69c9af2015-04-09 12:38:54 -0500210 BOOST_CHECK(alsa1.isEqualContent(alsa3));
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800211
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 Gawandeeb582eb2014-05-01 14:25:20 -0500235}
236
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800237const 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
245const 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
252const 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
259const 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
266const 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
273BOOST_AUTO_TEST_CASE(CoordinateLsaBasic)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500274{
Davide Pesaventoe28d8752022-03-19 03:55:25 -0400275 auto testTimePoint = ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196014943));
276 std::vector<double> angles1{30.0}, angles2{30.0};
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600277 angles1.push_back(30.0);
278 angles2.push_back(30.0);
279 CoordinateLsa clsa1("router1", 12, testTimePoint, 2.5, angles1);
280 CoordinateLsa clsa2("router1", 12, testTimePoint, 2.5, angles2);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500281
282 BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001);
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600283 BOOST_CHECK(clsa1.getCorTheta() == angles1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500284
akmhoquefdbddb12014-05-02 18:35:19 -0500285 BOOST_CHECK(clsa1.isEqualContent(clsa2));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500286
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800287 BOOST_CHECK_EQUAL(clsa1.wireEncode(), clsa2.wireEncode());
288
289 auto wire = clsa1.wireEncode();
290 BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA1, COORDINATE_LSA1 + sizeof(COORDINATE_LSA1),
291 wire.begin(), wire.end());
292
293 std::vector<double> angles3{40.0};
294 clsa1.setCorTheta(angles3);
295 wire = clsa1.wireEncode();
296 BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA_DIFF_ANGLE,
297 COORDINATE_LSA_DIFF_ANGLE + sizeof(COORDINATE_LSA_DIFF_ANGLE),
298 wire.begin(), wire.end());
299
300 clsa1.setCorRadius(2.3);
301 wire = clsa1.wireEncode();
302 BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA_DIFF_RADIUS,
303 COORDINATE_LSA_DIFF_RADIUS + sizeof(COORDINATE_LSA_DIFF_RADIUS),
304 wire.begin(), wire.end());
305
306 clsa1.setSeqNo(14);
307 wire = clsa1.wireEncode();
308 BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA_DIFF_SEQ,
309 COORDINATE_LSA_DIFF_SEQ + sizeof(COORDINATE_LSA_DIFF_SEQ),
310 wire.begin(), wire.end());
311
312 testTimePoint =
313 ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196024993));
314 clsa1.setExpirationTimePoint(testTimePoint);
315 wire = clsa1.wireEncode();
316 BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA_DIFF_TS,
317 COORDINATE_LSA_DIFF_TS + sizeof(COORDINATE_LSA_DIFF_TS),
318 wire.begin(), wire.end());
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500319}
320
alvydce3f182015-04-09 11:23:30 -0500321BOOST_AUTO_TEST_CASE(IncrementAdjacentNumber)
322{
323 Adjacent adj1("adjacent1");
324 Adjacent adj2("adjacent2");
325
326 adj1.setStatus(Adjacent::STATUS_ACTIVE);
327 adj2.setStatus(Adjacent::STATUS_ACTIVE);
328
329 AdjacencyList adjList;
330 adjList.insert(adj1);
331 adjList.insert(adj2);
332
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700333 auto testTimePoint = ndn::time::system_clock::now() + ndn::time::seconds(3600);
alvydce3f182015-04-09 11:23:30 -0500334
Nick Gordonff9a6272017-10-12 13:38:29 -0500335 AdjLsa lsa("router1", 12, testTimePoint, adjList.size(), adjList);
alvydce3f182015-04-09 11:23:30 -0500336
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700337 std::ostringstream os;
338 os << lsa;
339
alvydce3f182015-04-09 11:23:30 -0500340 std::string EXPECTED_OUTPUT =
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800341 " ADJACENCY LSA:\n"
342 " Origin Router : /router1\n"
343 " Sequence Number : 12\n"
344 " Expires in : 3599999 milliseconds\n"
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700345 " Adjacent(s):\n"
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800346 " Adjacent 0: (name=/adjacent1, uri=://, cost=10)\n"
347 " Adjacent 1: (name=/adjacent2, uri=://, cost=10)\n";
alvydce3f182015-04-09 11:23:30 -0500348
alvydce3f182015-04-09 11:23:30 -0500349 BOOST_CHECK_EQUAL(os.str(), EXPECTED_OUTPUT);
350}
351
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600352BOOST_AUTO_TEST_CASE(TestInitializeFromContent)
353{
354 //Adj LSA
355 Adjacent adj1("adjacent1");
356 Adjacent adj2("adjacent2");
357
358 adj1.setStatus(Adjacent::STATUS_ACTIVE);
359 adj2.setStatus(Adjacent::STATUS_ACTIVE);
360
361 //If we don't do this the test will fail
362 //Adjacent has default cost of 10 but no default
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500363 //connecting face URI, so initializeFromContent fails
364 adj1.setFaceUri(ndn::FaceUri("udp://10.0.0.1"));
365 adj2.setFaceUri(ndn::FaceUri("udp://10.0.0.2"));
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600366
367 AdjacencyList adjList;
368 adjList.insert(adj1);
369 adjList.insert(adj2);
370
Davide Pesaventoe28d8752022-03-19 03:55:25 -0400371 auto testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600372
Nick Gordonff9a6272017-10-12 13:38:29 -0500373 AdjLsa adjlsa1("router1", 1, testTimePoint, adjList.size(), adjList);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800374 AdjLsa adjlsa2(adjlsa1.wireEncode());
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600375 BOOST_CHECK(adjlsa1.isEqualContent(adjlsa2));
376
377 //Name LSA
Ashlesh Gawande3781c7e2021-05-22 22:36:26 -0700378 ndn::Name s1{"name1"};
Nick Gordon96861ca2017-10-17 18:25:21 -0500379 ndn::Name s2{"name2"};
380 NamePrefixList npl1{s1, s2};
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600381
382 NameLsa nlsa1("router1", 1, testTimePoint, npl1);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800383 NameLsa nlsa2(nlsa1.wireEncode());
384 BOOST_CHECK_EQUAL(nlsa1.wireEncode(), nlsa2.wireEncode());
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600385
386 //Coordinate LSA
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600387 std::vector<double> angles = {30, 40.0};
388 CoordinateLsa clsa1("router1", 12, testTimePoint, 2.5, angles);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800389 CoordinateLsa clsa2(clsa1.wireEncode());
Ashlesh Gawande3781c7e2021-05-22 22:36:26 -0700390 BOOST_CHECK_EQUAL(clsa1.wireEncode(), clsa2.wireEncode());
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600391}
392
Nick Gordon56d1fae2017-05-26 16:39:25 -0500393BOOST_AUTO_TEST_CASE(OperatorEquals)
394{
395 NameLsa lsa1;
396 NameLsa lsa2;
397 ndn::Name name1("/ndn/test/name1");
398 ndn::Name name2("/ndn/test/name2");
399 ndn::Name name3("/ndn/some/other/name1");
400
401 lsa1.addName(name1);
402 lsa1.addName(name2);
403 lsa1.addName(name3);
404
405 lsa2.addName(name1);
406 lsa2.addName(name2);
407 lsa2.addName(name3);
408
409 BOOST_CHECK(lsa1.isEqualContent(lsa2));
410}
411
Ashlesh Gawande3781c7e2021-05-22 22:36:26 -0700412BOOST_AUTO_TEST_CASE(NameLsaUpdate)
413{
414 NameLsa knownNameLsa;
415 knownNameLsa.m_originRouter = ndn::Name("/yoursunny/_/%C1.Router/dal");
416 knownNameLsa.m_seqNo = 2683;
417 knownNameLsa.setExpirationTimePoint(ndn::time::system_clock::now() + 3561_ms);
418 knownNameLsa.addName("/yoursunny/_/dal");
419 knownNameLsa.addName("/ndn");
420
421 std::shared_ptr<Lsa> rcvdLsa = std::make_shared<NameLsa>();
422
423 rcvdLsa->m_originRouter = ndn::Name("/yoursunny/_/%C1.Router/dal");
424 rcvdLsa->m_seqNo = 2684;
425 rcvdLsa->setExpirationTimePoint(ndn::time::system_clock::now() + 3600_ms);
426 auto nlsa = std::static_pointer_cast<NameLsa>(rcvdLsa);
427 nlsa->addName("/ndn");
428 nlsa->addName("/yoursunny/_/dal");
429 ndn::Name addedName1("/yoursunny/video/ndn-dpdk_acmicn20_20200917");
430 ndn::Name addedName2("/yoursunny/pushups");
431 nlsa->addName(addedName1);
432 nlsa->addName(addedName2);
433
434 bool updated;
435 std::list<ndn::Name> namesToAdd, namesToRemove;
436 std::tie(updated, namesToAdd, namesToRemove) = knownNameLsa.update(rcvdLsa);
437
438 BOOST_CHECK_EQUAL(namesToRemove.size(), 0);
439 BOOST_CHECK_EQUAL(namesToAdd.size(), 2);
440 auto it = std::find(namesToAdd.begin(), namesToAdd.end(), addedName1);
441 BOOST_CHECK(it != namesToAdd.end());
442 it = std::find(namesToAdd.begin(), namesToAdd.end(), addedName2);
443 BOOST_CHECK(it != namesToAdd.end());
444}
445
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500446BOOST_AUTO_TEST_SUITE_END()
447
alvydce3f182015-04-09 11:23:30 -0500448} // namespace test
449} // namespace nlsr