blob: 50975fa6b017f54735d9a411022d989b0aa90373 [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/**
akmhoque3d06e792014-05-27 16:23:20 -05003 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * \author Ashlesh Gawande <agawande@memphis.edu>
21 *
22 **/
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050023#include "lsa.hpp"
24#include "name-prefix-list.hpp"
25#include "adjacent.hpp"
26#include <boost/test/unit_test.hpp>
akmhoquec7a79b22014-05-26 08:06:19 -050027#include <ndn-cxx/util/time.hpp>
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050028
29namespace nlsr {
30namespace test {
31BOOST_AUTO_TEST_SUITE(TestLsa)
32
33BOOST_AUTO_TEST_CASE(NameLsaBasic)
34{
35 NamePrefixList npl1;
36
37 std::string s1 = "name1";
38 std::string s2 = "name2";
39
40 npl1.insert(s1);
41 npl1.insert(s2);
akmhoquec7a79b22014-05-26 08:06:19 -050042 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050043//lsType is 1 for NameLsa, 3rd arg is seqNo. which will be a random number I just put in 12.
akmhoquec7a79b22014-05-26 08:06:19 -050044 NameLsa nlsa1("router1", std::string("name"), 12, testTimePoint, npl1);
45 NameLsa nlsa2("router2", std::string("name"), 12, testTimePoint, npl1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050046
akmhoque31d1d4b2014-05-05 22:08:14 -050047 BOOST_CHECK_EQUAL(nlsa1.getLsType(), "name");
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050048
akmhoquec7a79b22014-05-26 08:06:19 -050049 BOOST_CHECK(nlsa1.getExpirationTimePoint() == nlsa2.getExpirationTimePoint());
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050050
51 BOOST_CHECK(nlsa1.getKey() != nlsa2.getKey());
52}
53
54BOOST_AUTO_TEST_CASE(AdjacentLsaConstructorAndGetters)
55{
56 Adjacent adj1("adjacent");
57 Adjacent adj2("adjacent2");
58
59 AdjacencyList adjList;
60 adjList.insert(adj1);
akmhoquec7a79b22014-05-26 08:06:19 -050061 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050062//For AdjLsa, lsType is 2.
63//1 is the number of adjacent in adjacent list.
akmhoquec7a79b22014-05-26 08:06:19 -050064 AdjLsa alsa1("router1", std::string("adjacency"), 12, testTimePoint, 1, adjList);
65 AdjLsa alsa2("router1", std::string("adjacency"), 12, testTimePoint, 1, adjList);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050066
akmhoque31d1d4b2014-05-05 22:08:14 -050067 BOOST_CHECK_EQUAL(alsa1.getLsType(), "adjacency");
akmhoquefdbddb12014-05-02 18:35:19 -050068 BOOST_CHECK_EQUAL(alsa1.getLsSeqNo(), (uint32_t)12);
akmhoquec7a79b22014-05-26 08:06:19 -050069 BOOST_CHECK_EQUAL(alsa1.getExpirationTimePoint(), testTimePoint);
akmhoquefdbddb12014-05-02 18:35:19 -050070 BOOST_CHECK_EQUAL(alsa1.getNoLink(), (uint32_t)1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050071
akmhoquefdbddb12014-05-02 18:35:19 -050072 BOOST_CHECK(alsa1.isEqualContent(alsa2));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050073
74 alsa1.addAdjacent(adj2);
75
76 const std::string ADJACENT_1 = "adjacent2";
77 BOOST_CHECK(alsa1.getAdl().isNeighbor(ADJACENT_1));
78}
79
80BOOST_AUTO_TEST_CASE(CoordinateLsaConstructorAndGetters)
81{
akmhoquec7a79b22014-05-26 08:06:19 -050082 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050083//For CoordinateLsa, lsType is 3.
akmhoquec7a79b22014-05-26 08:06:19 -050084 CoordinateLsa clsa1("router1", std::string("coordinate"), 12, testTimePoint, 2.5, 30.0);
85 CoordinateLsa clsa2("router1", std::string("coordinate"), 12, testTimePoint, 2.5, 30.0);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050086
87 BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001);
88 BOOST_CHECK_CLOSE(clsa1.getCorTheta(), 30.0, 0.0001);
89
akmhoquefdbddb12014-05-02 18:35:19 -050090 BOOST_CHECK(clsa1.isEqualContent(clsa2));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050091
92 BOOST_CHECK_EQUAL(clsa1.getData(), clsa2.getData());
93}
94
95BOOST_AUTO_TEST_SUITE_END()
96
97} //namespace test
98} //namespace nlsr