blob: 16af2155c89953e3881992f2a08e340ab5b71def [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/*
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -08003 * Copyright (c) 2014-2020, 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
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080034/*static void
35printBytes(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
52printBytes(wire.wire(), wire.size());*/
53
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050054BOOST_AUTO_TEST_SUITE(TestLsa)
55
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080056const 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
63const 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
71const 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
79const 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 Gawandeeb582eb2014-05-01 14:25:20 -050087BOOST_AUTO_TEST_CASE(NameLsaBasic)
88{
Nick Gordon96861ca2017-10-17 18:25:21 -050089 ndn::Name s1{"name1"};
90 ndn::Name s2{"name2"};
91 NamePrefixList npl1{s1, s2};
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050092
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080093 ndn::time::system_clock::TimePoint testTimePoint =
94 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");
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800175 ndn::time::system_clock::TimePoint testTimePoint =
176 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{
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800275 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 Chowdhuryb00dc2a2016-11-05 10:48:58 -0600278 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 Gawandeeb582eb2014-05-01 14:25:20 -0500282
283 BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001);
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600284 BOOST_CHECK(clsa1.getCorTheta() == angles1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500285
akmhoquefdbddb12014-05-02 18:35:19 -0500286 BOOST_CHECK(clsa1.isEqualContent(clsa2));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500287
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800288 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 Gawandeeb582eb2014-05-01 14:25:20 -0500320}
321
alvydce3f182015-04-09 11:23:30 -0500322BOOST_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 Gawande57a87172020-05-09 19:47:06 -0700334 auto testTimePoint = ndn::time::system_clock::now() + ndn::time::seconds(3600);
alvydce3f182015-04-09 11:23:30 -0500335
Nick Gordonff9a6272017-10-12 13:38:29 -0500336 AdjLsa lsa("router1", 12, testTimePoint, adjList.size(), adjList);
alvydce3f182015-04-09 11:23:30 -0500337
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700338 std::ostringstream os;
339 os << lsa;
340
alvydce3f182015-04-09 11:23:30 -0500341 std::string EXPECTED_OUTPUT =
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800342 " ADJACENCY LSA:\n"
343 " Origin Router : /router1\n"
344 " Sequence Number : 12\n"
345 " Expires in : 3599999 milliseconds\n"
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700346 " Adjacent(s):\n"
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800347 " Adjacent 0: (name=/adjacent1, uri=://, cost=10)\n"
348 " Adjacent 1: (name=/adjacent2, uri=://, cost=10)\n";
alvydce3f182015-04-09 11:23:30 -0500349
alvydce3f182015-04-09 11:23:30 -0500350 BOOST_CHECK_EQUAL(os.str(), EXPECTED_OUTPUT);
351}
352
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600353BOOST_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 Chowdhuryf04f9892017-08-20 20:42:56 -0500364 //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 Gawanded02c3882015-12-29 16:02:51 -0600367
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 Gordonff9a6272017-10-12 13:38:29 -0500374 AdjLsa adjlsa1("router1", 1, testTimePoint, adjList.size(), adjList);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800375 AdjLsa adjlsa2(adjlsa1.wireEncode());
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600376 BOOST_CHECK(adjlsa1.isEqualContent(adjlsa2));
377
378 //Name LSA
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700379 /*ndn::Name s1{"name1"};
Nick Gordon96861ca2017-10-17 18:25:21 -0500380 ndn::Name s2{"name2"};
381 NamePrefixList npl1{s1, s2};
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600382
383 NameLsa nlsa1("router1", 1, testTimePoint, npl1);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800384 NameLsa nlsa2(nlsa1.wireEncode());
385 BOOST_CHECK_EQUAL(nlsa1.wireEncode(), nlsa2.wireEncode());
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600386
387 //Coordinate LSA
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600388 std::vector<double> angles = {30, 40.0};
389 CoordinateLsa clsa1("router1", 12, testTimePoint, 2.5, angles);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800390 CoordinateLsa clsa2(clsa1.wireEncode());
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700391 BOOST_CHECK_EQUAL(clsa1.wireEncode(), clsa2.wireEncode());*/
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600392}
393
Nick Gordon56d1fae2017-05-26 16:39:25 -0500394BOOST_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 Gawandeeb582eb2014-05-01 14:25:20 -0500413BOOST_AUTO_TEST_SUITE_END()
414
alvydce3f182015-04-09 11:23:30 -0500415} // namespace test
416} // namespace nlsr