blob: 0d8c942ac78900c2df939266797093e5cca7a884 [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/**
Vince Lehmanc2e51f62015-01-20 15:03:11 -06003 * Copyright (c) 2014-2015, The University of Memphis,
4 * 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
alvydce3f182015-04-09 11:23:30 -050022#include "test-common.hpp"
23
24#include "adjacent.hpp"
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050025#include "lsa.hpp"
26#include "name-prefix-list.hpp"
alvydce3f182015-04-09 11:23:30 -050027
akmhoquec7a79b22014-05-26 08:06:19 -050028#include <ndn-cxx/util/time.hpp>
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050029
alvydce3f182015-04-09 11:23:30 -050030#include <sstream>
31
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050032namespace nlsr {
33namespace test {
alvydce3f182015-04-09 11:23:30 -050034
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050035BOOST_AUTO_TEST_SUITE(TestLsa)
36
37BOOST_AUTO_TEST_CASE(NameLsaBasic)
38{
39 NamePrefixList npl1;
40
41 std::string s1 = "name1";
42 std::string s2 = "name2";
43
44 npl1.insert(s1);
45 npl1.insert(s2);
akmhoquec7a79b22014-05-26 08:06:19 -050046 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050047//lsType is 1 for NameLsa, 3rd arg is seqNo. which will be a random number I just put in 12.
alvy49b1c0c2014-12-19 13:57:46 -060048 NameLsa nlsa1("router1", NameLsa::TYPE_STRING, 12, testTimePoint, npl1);
49 NameLsa nlsa2("router2", NameLsa::TYPE_STRING, 12, testTimePoint, npl1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050050
alvy49b1c0c2014-12-19 13:57:46 -060051 BOOST_CHECK_EQUAL(nlsa1.getLsType(), NameLsa::TYPE_STRING);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050052
akmhoquec7a79b22014-05-26 08:06:19 -050053 BOOST_CHECK(nlsa1.getExpirationTimePoint() == nlsa2.getExpirationTimePoint());
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050054
55 BOOST_CHECK(nlsa1.getKey() != nlsa2.getKey());
56}
57
58BOOST_AUTO_TEST_CASE(AdjacentLsaConstructorAndGetters)
59{
alvyc69c9af2015-04-09 12:38:54 -050060 ndn::Name routerName("/ndn/site/router");
61 ndn::Name adjacencyName("/ndn/site/adjacency");
akmhoquec7a79b22014-05-26 08:06:19 -050062 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
alvyc69c9af2015-04-09 12:38:54 -050063 uint32_t seqNo = 12;
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050064
alvyc69c9af2015-04-09 12:38:54 -050065 // An AdjLsa initialized with ACTIVE adjacencies should copy the adjacencies
66 AdjacencyList activeAdjacencies;
67 Adjacent activeAdjacency(adjacencyName);
68 activeAdjacency.setStatus(Adjacent::STATUS_ACTIVE);
69 activeAdjacencies.insert(activeAdjacency);
70
71 AdjLsa alsa1(routerName, AdjLsa::TYPE_STRING, seqNo, testTimePoint,
72 activeAdjacencies.getSize(), activeAdjacencies);
73 BOOST_CHECK_EQUAL(alsa1.getAdl().getSize(), 1);
alvy49b1c0c2014-12-19 13:57:46 -060074 BOOST_CHECK_EQUAL(alsa1.getLsType(), AdjLsa::TYPE_STRING);
alvyc69c9af2015-04-09 12:38:54 -050075 BOOST_CHECK_EQUAL(alsa1.getLsSeqNo(), seqNo);
akmhoquec7a79b22014-05-26 08:06:19 -050076 BOOST_CHECK_EQUAL(alsa1.getExpirationTimePoint(), testTimePoint);
alvyc69c9af2015-04-09 12:38:54 -050077 BOOST_CHECK_EQUAL(alsa1.getNoLink(), 1);
78 BOOST_CHECK(alsa1.getAdl().isNeighbor(activeAdjacency.getName()));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050079
alvyc69c9af2015-04-09 12:38:54 -050080 // An AdjLsa initialized with INACTIVE adjacencies should not copy the adjacencies
81 AdjacencyList inactiveAdjacencies;
82 Adjacent inactiveAdjacency(adjacencyName);
83 inactiveAdjacency.setStatus(Adjacent::STATUS_INACTIVE);
84 inactiveAdjacencies.insert(inactiveAdjacency);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050085
alvyc69c9af2015-04-09 12:38:54 -050086 AdjLsa alsa2(routerName, AdjLsa::TYPE_STRING, seqNo, testTimePoint,
87 inactiveAdjacencies.getSize(), inactiveAdjacencies);
88 BOOST_CHECK_EQUAL(alsa2.getAdl().getSize(), 0);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050089
alvyc69c9af2015-04-09 12:38:54 -050090 // Thus, the two LSAs should not have equal content
91 BOOST_CHECK_EQUAL(alsa1.isEqualContent(alsa2), false);
92
93 // Create a duplicate of alsa1 which should have equal content
94 AdjLsa alsa3(routerName, AdjLsa::TYPE_STRING, seqNo, testTimePoint,
95 activeAdjacencies.getSize(), activeAdjacencies);
96 BOOST_CHECK(alsa1.isEqualContent(alsa3));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050097}
98
99BOOST_AUTO_TEST_CASE(CoordinateLsaConstructorAndGetters)
100{
akmhoquec7a79b22014-05-26 08:06:19 -0500101 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500102//For CoordinateLsa, lsType is 3.
alvy49b1c0c2014-12-19 13:57:46 -0600103 CoordinateLsa clsa1("router1", CoordinateLsa::TYPE_STRING, 12, testTimePoint, 2.5, 30.0);
104 CoordinateLsa clsa2("router1", CoordinateLsa::TYPE_STRING, 12, testTimePoint, 2.5, 30.0);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500105
106 BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001);
107 BOOST_CHECK_CLOSE(clsa1.getCorTheta(), 30.0, 0.0001);
108
akmhoquefdbddb12014-05-02 18:35:19 -0500109 BOOST_CHECK(clsa1.isEqualContent(clsa2));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500110
111 BOOST_CHECK_EQUAL(clsa1.getData(), clsa2.getData());
112}
113
alvydce3f182015-04-09 11:23:30 -0500114BOOST_AUTO_TEST_CASE(IncrementAdjacentNumber)
115{
116 Adjacent adj1("adjacent1");
117 Adjacent adj2("adjacent2");
118
119 adj1.setStatus(Adjacent::STATUS_ACTIVE);
120 adj2.setStatus(Adjacent::STATUS_ACTIVE);
121
122 AdjacencyList adjList;
123 adjList.insert(adj1);
124 adjList.insert(adj2);
125
126 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
127
128 std::ostringstream ss;
129 ss << testTimePoint;
130
131 const std::string TEST_TIME_POINT_STRING = ss.str();
132
133 AdjLsa lsa("router1", AdjLsa::TYPE_STRING, 12, testTimePoint, 1, adjList);
134
135 std::string EXPECTED_OUTPUT =
136 "Adj Lsa:\n"
137 " Origination Router: /router1\n"
138 " Ls Type: adjacency\n"
139 " Ls Seq No: 12\n"
140 " Ls Lifetime: " + TEST_TIME_POINT_STRING + "\n"
141 " Adjacents: \n"
142 " Adjacent 1:\n"
143 " Adjacent Name: /adjacent1\n"
144 " Connecting FaceUri: \n"
145 " Link Cost: 10\n"
146 " Adjacent 2:\n"
147 " Adjacent Name: /adjacent2\n"
148 " Connecting FaceUri: \n"
149 " Link Cost: 10\n"
150 "adj_lsa_end";
151
152 std::ostringstream os;
153 os << lsa;
154
155 BOOST_CHECK_EQUAL(os.str(), EXPECTED_OUTPUT);
156}
157
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500158BOOST_AUTO_TEST_SUITE_END()
159
alvydce3f182015-04-09 11:23:30 -0500160} // namespace test
161} // namespace nlsr