blob: 5c46855b071fdf0e4c97260773755ae4c9a0e03e [file] [log] [blame]
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -05001/**
2 * Copyright (C) 2014 Regents of the University of Memphis.
3 * See COPYING for copyright and distribution information.
4 */
5
6#include "lsa.hpp"
7#include "name-prefix-list.hpp"
8#include "adjacent.hpp"
9#include <boost/test/unit_test.hpp>
akmhoquec7a79b22014-05-26 08:06:19 -050010#include <ndn-cxx/util/time.hpp>
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050011
12namespace nlsr {
13namespace test {
14BOOST_AUTO_TEST_SUITE(TestLsa)
15
16BOOST_AUTO_TEST_CASE(NameLsaBasic)
17{
18 NamePrefixList npl1;
19
20 std::string s1 = "name1";
21 std::string s2 = "name2";
22
23 npl1.insert(s1);
24 npl1.insert(s2);
akmhoquec7a79b22014-05-26 08:06:19 -050025 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050026//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 -050027 NameLsa nlsa1("router1", std::string("name"), 12, testTimePoint, npl1);
28 NameLsa nlsa2("router2", std::string("name"), 12, testTimePoint, npl1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050029
akmhoque31d1d4b2014-05-05 22:08:14 -050030 BOOST_CHECK_EQUAL(nlsa1.getLsType(), "name");
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050031
akmhoquec7a79b22014-05-26 08:06:19 -050032 BOOST_CHECK(nlsa1.getExpirationTimePoint() == nlsa2.getExpirationTimePoint());
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050033
34 BOOST_CHECK(nlsa1.getKey() != nlsa2.getKey());
35}
36
37BOOST_AUTO_TEST_CASE(AdjacentLsaConstructorAndGetters)
38{
39 Adjacent adj1("adjacent");
40 Adjacent adj2("adjacent2");
41
42 AdjacencyList adjList;
43 adjList.insert(adj1);
akmhoquec7a79b22014-05-26 08:06:19 -050044 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050045//For AdjLsa, lsType is 2.
46//1 is the number of adjacent in adjacent list.
akmhoquec7a79b22014-05-26 08:06:19 -050047 AdjLsa alsa1("router1", std::string("adjacency"), 12, testTimePoint, 1, adjList);
48 AdjLsa alsa2("router1", std::string("adjacency"), 12, testTimePoint, 1, adjList);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050049
akmhoque31d1d4b2014-05-05 22:08:14 -050050 BOOST_CHECK_EQUAL(alsa1.getLsType(), "adjacency");
akmhoquefdbddb12014-05-02 18:35:19 -050051 BOOST_CHECK_EQUAL(alsa1.getLsSeqNo(), (uint32_t)12);
akmhoquec7a79b22014-05-26 08:06:19 -050052 BOOST_CHECK_EQUAL(alsa1.getExpirationTimePoint(), testTimePoint);
akmhoquefdbddb12014-05-02 18:35:19 -050053 BOOST_CHECK_EQUAL(alsa1.getNoLink(), (uint32_t)1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050054
akmhoquefdbddb12014-05-02 18:35:19 -050055 BOOST_CHECK(alsa1.isEqualContent(alsa2));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050056
57 alsa1.addAdjacent(adj2);
58
59 const std::string ADJACENT_1 = "adjacent2";
60 BOOST_CHECK(alsa1.getAdl().isNeighbor(ADJACENT_1));
61}
62
63BOOST_AUTO_TEST_CASE(CoordinateLsaConstructorAndGetters)
64{
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 CoordinateLsa, lsType is 3.
akmhoquec7a79b22014-05-26 08:06:19 -050067 CoordinateLsa clsa1("router1", std::string("coordinate"), 12, testTimePoint, 2.5, 30.0);
68 CoordinateLsa clsa2("router1", std::string("coordinate"), 12, testTimePoint, 2.5, 30.0);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050069
70 BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001);
71 BOOST_CHECK_CLOSE(clsa1.getCorTheta(), 30.0, 0.0001);
72
akmhoquefdbddb12014-05-02 18:35:19 -050073 BOOST_CHECK(clsa1.isEqualContent(clsa2));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050074
75 BOOST_CHECK_EQUAL(clsa1.getData(), clsa2.getData());
76}
77
78BOOST_AUTO_TEST_SUITE_END()
79
80} //namespace test
81} //namespace nlsr