blob: fb08473abb094348f0f796c9821e18e9e314cab1 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -05002/**
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/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
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 Gawandeeb582eb2014-05-01 14:25:20 -0500102 BOOST_CHECK(nlsa1.getKey() != nlsa2.getKey());
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");
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800176 ndn::time::system_clock::TimePoint testTimePoint =
177 ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196014943));
alvyc69c9af2015-04-09 12:38:54 -0500178 uint32_t seqNo = 12;
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500179
alvyc69c9af2015-04-09 12:38:54 -0500180 // An AdjLsa initialized with ACTIVE adjacencies should copy the adjacencies
181 AdjacencyList activeAdjacencies;
182 Adjacent activeAdjacency(adjacencyName);
183 activeAdjacency.setStatus(Adjacent::STATUS_ACTIVE);
184 activeAdjacencies.insert(activeAdjacency);
185
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600186 AdjLsa alsa1(routerName, seqNo, testTimePoint,
Nick Gordonff9a6272017-10-12 13:38:29 -0500187 activeAdjacencies.size(), activeAdjacencies);
188 BOOST_CHECK_EQUAL(alsa1.getAdl().size(), 1);
Nick Gordon727d4832017-10-13 18:04:25 -0500189 BOOST_CHECK_EQUAL(alsa1.getType(), Lsa::Type::ADJACENCY);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800190 BOOST_CHECK_EQUAL(alsa1.getSeqNo(), seqNo);
akmhoquec7a79b22014-05-26 08:06:19 -0500191 BOOST_CHECK_EQUAL(alsa1.getExpirationTimePoint(), testTimePoint);
alvyc69c9af2015-04-09 12:38:54 -0500192 BOOST_CHECK_EQUAL(alsa1.getNoLink(), 1);
193 BOOST_CHECK(alsa1.getAdl().isNeighbor(activeAdjacency.getName()));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500194
alvyc69c9af2015-04-09 12:38:54 -0500195 // An AdjLsa initialized with INACTIVE adjacencies should not copy the adjacencies
196 AdjacencyList inactiveAdjacencies;
197 Adjacent inactiveAdjacency(adjacencyName);
198 inactiveAdjacency.setStatus(Adjacent::STATUS_INACTIVE);
199 inactiveAdjacencies.insert(inactiveAdjacency);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500200
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600201 AdjLsa alsa2(routerName, seqNo, testTimePoint,
Nick Gordonff9a6272017-10-12 13:38:29 -0500202 inactiveAdjacencies.size(), inactiveAdjacencies);
203 BOOST_CHECK_EQUAL(alsa2.getAdl().size(), 0);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500204
alvyc69c9af2015-04-09 12:38:54 -0500205 // Thus, the two LSAs should not have equal content
206 BOOST_CHECK_EQUAL(alsa1.isEqualContent(alsa2), false);
207
208 // Create a duplicate of alsa1 which should have equal content
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600209 AdjLsa alsa3(routerName, seqNo, testTimePoint,
Nick Gordonff9a6272017-10-12 13:38:29 -0500210 activeAdjacencies.size(), activeAdjacencies);
alvyc69c9af2015-04-09 12:38:54 -0500211 BOOST_CHECK(alsa1.isEqualContent(alsa3));
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800212
213 auto wire = alsa1.wireEncode();
214 BOOST_CHECK_EQUAL_COLLECTIONS(ADJ_LSA1, ADJ_LSA1 + sizeof(ADJ_LSA1),
215 wire.begin(), wire.end());
216
217 Adjacent activeAdjacency2("/ndn/edu/adjacency");
218 activeAdjacency2.setStatus(Adjacent::STATUS_ACTIVE);
219 alsa1.addAdjacent(activeAdjacency2);
220 wire = alsa1.wireEncode();
221 BOOST_CHECK_EQUAL_COLLECTIONS(ADJ_LSA_EXTRA_NEIGHBOR,
222 ADJ_LSA_EXTRA_NEIGHBOR + sizeof(ADJ_LSA_EXTRA_NEIGHBOR),
223 wire.begin(), wire.end());
224
225 alsa1.setSeqNo(14);
226 wire = alsa1.wireEncode();
227 BOOST_CHECK_EQUAL_COLLECTIONS(ADJ_LSA_DIFF_SEQ, ADJ_LSA_DIFF_SEQ + sizeof(ADJ_LSA_DIFF_SEQ),
228 wire.begin(), wire.end());
229
230 testTimePoint =
231 ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196024993));
232 alsa1.setExpirationTimePoint(testTimePoint);
233 wire = alsa1.wireEncode();
234 BOOST_CHECK_EQUAL_COLLECTIONS(ADJ_LSA_DIFF_TS, ADJ_LSA_DIFF_TS + sizeof(ADJ_LSA_DIFF_TS),
235 wire.begin(), wire.end());
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500236}
237
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800238const uint8_t COORDINATE_LSA1[] = {
239 0x85, 0x43, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31,
240 0x82, 0x01, 0x0C, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36,
241 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x87, 0x08, 0x40, 0x04, 0x00, 0x00,
242 0x00, 0x00, 0x00, 0x00, 0x88, 0x08, 0x40, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88,
243 0x08, 0x40, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
244};
245
246const uint8_t COORDINATE_LSA_DIFF_ANGLE[] = {
247 0x85, 0x39, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31,
248 0x82, 0x01, 0x0C, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36,
249 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x87, 0x08, 0x40, 0x04, 0x00, 0x00,
250 0x00, 0x00, 0x00, 0x00, 0x88, 0x08, 0x40, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
251};
252
253const uint8_t COORDINATE_LSA_DIFF_RADIUS[] = {
254 0x85, 0x39, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31,
255 0x82, 0x01, 0x0C, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36,
256 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x87, 0x08, 0x40, 0x02, 0x66, 0x66,
257 0x66, 0x66, 0x66, 0x66, 0x88, 0x08, 0x40, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
258};
259
260const uint8_t COORDINATE_LSA_DIFF_SEQ[] = {
261 0x85, 0x39, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31,
262 0x82, 0x01, 0x0E, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36,
263 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x87, 0x08, 0x40, 0x02, 0x66, 0x66,
264 0x66, 0x66, 0x66, 0x66, 0x88, 0x08, 0x40, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
265};
266
267const uint8_t COORDINATE_LSA_DIFF_TS[] = {
268 0x85, 0x39, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31,
269 0x82, 0x01, 0x0E, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36,
270 0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x34, 0x34, 0x87, 0x08, 0x40, 0x02, 0x66, 0x66,
271 0x66, 0x66, 0x66, 0x66, 0x88, 0x08, 0x40, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
272};
273
274BOOST_AUTO_TEST_CASE(CoordinateLsaBasic)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500275{
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800276 ndn::time::system_clock::TimePoint testTimePoint =
277 ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196014943));
278 std::vector<double> angles1 {30.0}, angles2 {30.0};
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600279 angles1.push_back(30.0);
280 angles2.push_back(30.0);
281 CoordinateLsa clsa1("router1", 12, testTimePoint, 2.5, angles1);
282 CoordinateLsa clsa2("router1", 12, testTimePoint, 2.5, angles2);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500283
284 BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001);
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600285 BOOST_CHECK(clsa1.getCorTheta() == angles1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500286
akmhoquefdbddb12014-05-02 18:35:19 -0500287 BOOST_CHECK(clsa1.isEqualContent(clsa2));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500288
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800289 BOOST_CHECK_EQUAL(clsa1.wireEncode(), clsa2.wireEncode());
290
291 auto wire = clsa1.wireEncode();
292 BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA1, COORDINATE_LSA1 + sizeof(COORDINATE_LSA1),
293 wire.begin(), wire.end());
294
295 std::vector<double> angles3{40.0};
296 clsa1.setCorTheta(angles3);
297 wire = clsa1.wireEncode();
298 BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA_DIFF_ANGLE,
299 COORDINATE_LSA_DIFF_ANGLE + sizeof(COORDINATE_LSA_DIFF_ANGLE),
300 wire.begin(), wire.end());
301
302 clsa1.setCorRadius(2.3);
303 wire = clsa1.wireEncode();
304 BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA_DIFF_RADIUS,
305 COORDINATE_LSA_DIFF_RADIUS + sizeof(COORDINATE_LSA_DIFF_RADIUS),
306 wire.begin(), wire.end());
307
308 clsa1.setSeqNo(14);
309 wire = clsa1.wireEncode();
310 BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA_DIFF_SEQ,
311 COORDINATE_LSA_DIFF_SEQ + sizeof(COORDINATE_LSA_DIFF_SEQ),
312 wire.begin(), wire.end());
313
314 testTimePoint =
315 ndn::time::fromUnixTimestamp(ndn::time::milliseconds(1585196024993));
316 clsa1.setExpirationTimePoint(testTimePoint);
317 wire = clsa1.wireEncode();
318 BOOST_CHECK_EQUAL_COLLECTIONS(COORDINATE_LSA_DIFF_TS,
319 COORDINATE_LSA_DIFF_TS + sizeof(COORDINATE_LSA_DIFF_TS),
320 wire.begin(), wire.end());
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500321}
322
alvydce3f182015-04-09 11:23:30 -0500323BOOST_AUTO_TEST_CASE(IncrementAdjacentNumber)
324{
325 Adjacent adj1("adjacent1");
326 Adjacent adj2("adjacent2");
327
328 adj1.setStatus(Adjacent::STATUS_ACTIVE);
329 adj2.setStatus(Adjacent::STATUS_ACTIVE);
330
331 AdjacencyList adjList;
332 adjList.insert(adj1);
333 adjList.insert(adj2);
334
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800335 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now() + ndn::time::seconds(3600);
alvydce3f182015-04-09 11:23:30 -0500336 std::ostringstream ss;
337 ss << testTimePoint;
338
339 const std::string TEST_TIME_POINT_STRING = ss.str();
340
Nick Gordonff9a6272017-10-12 13:38:29 -0500341 AdjLsa lsa("router1", 12, testTimePoint, adjList.size(), adjList);
alvydce3f182015-04-09 11:23:30 -0500342
343 std::string EXPECTED_OUTPUT =
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800344 " ADJACENCY LSA:\n"
345 " Origin Router : /router1\n"
346 " Sequence Number : 12\n"
347 " Expires in : 3599999 milliseconds\n"
348 " Adjacents:\n"
349 " Adjacent 0: (name=/adjacent1, uri=://, cost=10)\n"
350 " Adjacent 1: (name=/adjacent2, uri=://, cost=10)\n";
alvydce3f182015-04-09 11:23:30 -0500351
352 std::ostringstream os;
353 os << lsa;
354
355 BOOST_CHECK_EQUAL(os.str(), EXPECTED_OUTPUT);
356}
357
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600358BOOST_AUTO_TEST_CASE(TestInitializeFromContent)
359{
360 //Adj LSA
361 Adjacent adj1("adjacent1");
362 Adjacent adj2("adjacent2");
363
364 adj1.setStatus(Adjacent::STATUS_ACTIVE);
365 adj2.setStatus(Adjacent::STATUS_ACTIVE);
366
367 //If we don't do this the test will fail
368 //Adjacent has default cost of 10 but no default
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500369 //connecting face URI, so initializeFromContent fails
370 adj1.setFaceUri(ndn::FaceUri("udp://10.0.0.1"));
371 adj2.setFaceUri(ndn::FaceUri("udp://10.0.0.2"));
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600372
373 AdjacencyList adjList;
374 adjList.insert(adj1);
375 adjList.insert(adj2);
376
377 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
378
Nick Gordonff9a6272017-10-12 13:38:29 -0500379 AdjLsa adjlsa1("router1", 1, testTimePoint, adjList.size(), adjList);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800380 AdjLsa adjlsa2(adjlsa1.wireEncode());
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600381 BOOST_CHECK(adjlsa1.isEqualContent(adjlsa2));
382
383 //Name LSA
Nick Gordon96861ca2017-10-17 18:25:21 -0500384 ndn::Name s1{"name1"};
385 ndn::Name s2{"name2"};
386 NamePrefixList npl1{s1, s2};
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600387
388 NameLsa nlsa1("router1", 1, testTimePoint, npl1);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800389 NameLsa nlsa2(nlsa1.wireEncode());
390 BOOST_CHECK_EQUAL(nlsa1.wireEncode(), nlsa2.wireEncode());
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600391
392 //Coordinate LSA
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600393 std::vector<double> angles = {30, 40.0};
394 CoordinateLsa clsa1("router1", 12, testTimePoint, 2.5, angles);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800395 CoordinateLsa clsa2(clsa1.wireEncode());
396 BOOST_CHECK_EQUAL(clsa1.wireEncode(), clsa2.wireEncode());
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600397}
398
Nick Gordon56d1fae2017-05-26 16:39:25 -0500399BOOST_AUTO_TEST_CASE(OperatorEquals)
400{
401 NameLsa lsa1;
402 NameLsa lsa2;
403 ndn::Name name1("/ndn/test/name1");
404 ndn::Name name2("/ndn/test/name2");
405 ndn::Name name3("/ndn/some/other/name1");
406
407 lsa1.addName(name1);
408 lsa1.addName(name2);
409 lsa1.addName(name3);
410
411 lsa2.addName(name1);
412 lsa2.addName(name2);
413 lsa2.addName(name3);
414
415 BOOST_CHECK(lsa1.isEqualContent(lsa2));
416}
417
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500418BOOST_AUTO_TEST_SUITE_END()
419
alvydce3f182015-04-09 11:23:30 -0500420} // namespace test
421} // namespace nlsr