blob: 57fa403674a0d9f253422f2cd9cdf5d1dd61620d [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{
60 Adjacent adj1("adjacent");
61 Adjacent adj2("adjacent2");
62
63 AdjacencyList adjList;
64 adjList.insert(adj1);
akmhoquec7a79b22014-05-26 08:06:19 -050065 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050066//For AdjLsa, lsType is 2.
67//1 is the number of adjacent in adjacent list.
alvy49b1c0c2014-12-19 13:57:46 -060068 AdjLsa alsa1("router1", AdjLsa::TYPE_STRING, 12, testTimePoint, 1, adjList);
69 AdjLsa alsa2("router1", AdjLsa::TYPE_STRING, 12, testTimePoint, 1, adjList);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050070
alvy49b1c0c2014-12-19 13:57:46 -060071 BOOST_CHECK_EQUAL(alsa1.getLsType(), AdjLsa::TYPE_STRING);
akmhoquefdbddb12014-05-02 18:35:19 -050072 BOOST_CHECK_EQUAL(alsa1.getLsSeqNo(), (uint32_t)12);
akmhoquec7a79b22014-05-26 08:06:19 -050073 BOOST_CHECK_EQUAL(alsa1.getExpirationTimePoint(), testTimePoint);
akmhoquefdbddb12014-05-02 18:35:19 -050074 BOOST_CHECK_EQUAL(alsa1.getNoLink(), (uint32_t)1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050075
akmhoquefdbddb12014-05-02 18:35:19 -050076 BOOST_CHECK(alsa1.isEqualContent(alsa2));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050077
78 alsa1.addAdjacent(adj2);
79
80 const std::string ADJACENT_1 = "adjacent2";
81 BOOST_CHECK(alsa1.getAdl().isNeighbor(ADJACENT_1));
82}
83
84BOOST_AUTO_TEST_CASE(CoordinateLsaConstructorAndGetters)
85{
akmhoquec7a79b22014-05-26 08:06:19 -050086 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050087//For CoordinateLsa, lsType is 3.
alvy49b1c0c2014-12-19 13:57:46 -060088 CoordinateLsa clsa1("router1", CoordinateLsa::TYPE_STRING, 12, testTimePoint, 2.5, 30.0);
89 CoordinateLsa clsa2("router1", CoordinateLsa::TYPE_STRING, 12, testTimePoint, 2.5, 30.0);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050090
91 BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001);
92 BOOST_CHECK_CLOSE(clsa1.getCorTheta(), 30.0, 0.0001);
93
akmhoquefdbddb12014-05-02 18:35:19 -050094 BOOST_CHECK(clsa1.isEqualContent(clsa2));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050095
96 BOOST_CHECK_EQUAL(clsa1.getData(), clsa2.getData());
97}
98
alvydce3f182015-04-09 11:23:30 -050099BOOST_AUTO_TEST_CASE(IncrementAdjacentNumber)
100{
101 Adjacent adj1("adjacent1");
102 Adjacent adj2("adjacent2");
103
104 adj1.setStatus(Adjacent::STATUS_ACTIVE);
105 adj2.setStatus(Adjacent::STATUS_ACTIVE);
106
107 AdjacencyList adjList;
108 adjList.insert(adj1);
109 adjList.insert(adj2);
110
111 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
112
113 std::ostringstream ss;
114 ss << testTimePoint;
115
116 const std::string TEST_TIME_POINT_STRING = ss.str();
117
118 AdjLsa lsa("router1", AdjLsa::TYPE_STRING, 12, testTimePoint, 1, adjList);
119
120 std::string EXPECTED_OUTPUT =
121 "Adj Lsa:\n"
122 " Origination Router: /router1\n"
123 " Ls Type: adjacency\n"
124 " Ls Seq No: 12\n"
125 " Ls Lifetime: " + TEST_TIME_POINT_STRING + "\n"
126 " Adjacents: \n"
127 " Adjacent 1:\n"
128 " Adjacent Name: /adjacent1\n"
129 " Connecting FaceUri: \n"
130 " Link Cost: 10\n"
131 " Adjacent 2:\n"
132 " Adjacent Name: /adjacent2\n"
133 " Connecting FaceUri: \n"
134 " Link Cost: 10\n"
135 "adj_lsa_end";
136
137 std::ostringstream os;
138 os << lsa;
139
140 BOOST_CHECK_EQUAL(os.str(), EXPECTED_OUTPUT);
141}
142
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500143BOOST_AUTO_TEST_SUITE_END()
144
alvydce3f182015-04-09 11:23:30 -0500145} // namespace test
146} // namespace nlsr