blob: ca6d05b403775d1d516c81760a304fe44f93545d [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
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050022#include "lsa.hpp"
23#include "name-prefix-list.hpp"
24#include "adjacent.hpp"
25#include <boost/test/unit_test.hpp>
akmhoquec7a79b22014-05-26 08:06:19 -050026#include <ndn-cxx/util/time.hpp>
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050027
28namespace nlsr {
29namespace test {
30BOOST_AUTO_TEST_SUITE(TestLsa)
31
32BOOST_AUTO_TEST_CASE(NameLsaBasic)
33{
34 NamePrefixList npl1;
35
36 std::string s1 = "name1";
37 std::string s2 = "name2";
38
39 npl1.insert(s1);
40 npl1.insert(s2);
akmhoquec7a79b22014-05-26 08:06:19 -050041 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050042//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 -060043 NameLsa nlsa1("router1", NameLsa::TYPE_STRING, 12, testTimePoint, npl1);
44 NameLsa nlsa2("router2", NameLsa::TYPE_STRING, 12, testTimePoint, npl1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050045
alvy49b1c0c2014-12-19 13:57:46 -060046 BOOST_CHECK_EQUAL(nlsa1.getLsType(), NameLsa::TYPE_STRING);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050047
akmhoquec7a79b22014-05-26 08:06:19 -050048 BOOST_CHECK(nlsa1.getExpirationTimePoint() == nlsa2.getExpirationTimePoint());
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050049
50 BOOST_CHECK(nlsa1.getKey() != nlsa2.getKey());
51}
52
53BOOST_AUTO_TEST_CASE(AdjacentLsaConstructorAndGetters)
54{
55 Adjacent adj1("adjacent");
56 Adjacent adj2("adjacent2");
57
58 AdjacencyList adjList;
59 adjList.insert(adj1);
akmhoquec7a79b22014-05-26 08:06:19 -050060 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050061//For AdjLsa, lsType is 2.
62//1 is the number of adjacent in adjacent list.
alvy49b1c0c2014-12-19 13:57:46 -060063 AdjLsa alsa1("router1", AdjLsa::TYPE_STRING, 12, testTimePoint, 1, adjList);
64 AdjLsa alsa2("router1", AdjLsa::TYPE_STRING, 12, testTimePoint, 1, adjList);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050065
alvy49b1c0c2014-12-19 13:57:46 -060066 BOOST_CHECK_EQUAL(alsa1.getLsType(), AdjLsa::TYPE_STRING);
akmhoquefdbddb12014-05-02 18:35:19 -050067 BOOST_CHECK_EQUAL(alsa1.getLsSeqNo(), (uint32_t)12);
akmhoquec7a79b22014-05-26 08:06:19 -050068 BOOST_CHECK_EQUAL(alsa1.getExpirationTimePoint(), testTimePoint);
akmhoquefdbddb12014-05-02 18:35:19 -050069 BOOST_CHECK_EQUAL(alsa1.getNoLink(), (uint32_t)1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050070
akmhoquefdbddb12014-05-02 18:35:19 -050071 BOOST_CHECK(alsa1.isEqualContent(alsa2));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050072
73 alsa1.addAdjacent(adj2);
74
75 const std::string ADJACENT_1 = "adjacent2";
76 BOOST_CHECK(alsa1.getAdl().isNeighbor(ADJACENT_1));
77}
78
79BOOST_AUTO_TEST_CASE(CoordinateLsaConstructorAndGetters)
80{
akmhoquec7a79b22014-05-26 08:06:19 -050081 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050082//For CoordinateLsa, lsType is 3.
alvy49b1c0c2014-12-19 13:57:46 -060083 CoordinateLsa clsa1("router1", CoordinateLsa::TYPE_STRING, 12, testTimePoint, 2.5, 30.0);
84 CoordinateLsa clsa2("router1", CoordinateLsa::TYPE_STRING, 12, testTimePoint, 2.5, 30.0);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050085
86 BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001);
87 BOOST_CHECK_CLOSE(clsa1.getCorTheta(), 30.0, 0.0001);
88
akmhoquefdbddb12014-05-02 18:35:19 -050089 BOOST_CHECK(clsa1.isEqualContent(clsa2));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050090
91 BOOST_CHECK_EQUAL(clsa1.getData(), clsa2.getData());
92}
93
94BOOST_AUTO_TEST_SUITE_END()
95
96} //namespace test
97} //namespace nlsr