blob: 5d37aff4e34ae19986389f87b49b8396c5c829ed [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/**
Ashlesh Gawande85998a12017-12-07 22:22:13 -06003 * Copyright (c) 2014-2019, The University of Memphis,
Vince Lehmanf7eec4f2015-05-08 19:02:31 -05004 * 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 Lehmanf7eec4f2015-05-08 19:02:31 -050021
Nick Gordone98480b2017-05-24 11:23:03 -050022#include "adjacency-list.hpp"
Nick Gordonff9a6272017-10-12 13:38:29 -050023#include "common.hpp"
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050024#include "adjacent.hpp"
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050025#include "conf-parameter.hpp"
26
Ashlesh Gawande85998a12017-12-07 22:22:13 -060027#include <ndn-cxx/util/dummy-client-face.hpp>
28
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050029#include <boost/test/unit_test.hpp>
30
31namespace nlsr {
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050032namespace test {
33
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050034BOOST_AUTO_TEST_SUITE(TestAdjacencyList)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050035
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050036BOOST_AUTO_TEST_CASE(Basic)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050037{
Nick Gordone9733ed2017-04-26 10:48:39 -050038 const std::string ADJ_NAME_1 = "testname";
39 const std::string ADJ_NAME_2 = "testname2";
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050040
41//adjacent needed to test adjacency list.
42 Adjacent adjacent1(ADJ_NAME_1);
43 Adjacent adjacent2(ADJ_NAME_2);
44
45 adjacent1.setLinkCost(4);
46 adjacent2.setLinkCost(5);
47
48 AdjacencyList adjacentList1;
49 AdjacencyList adjacentList2;
50
51 adjacentList1.insert(adjacent1);
52 adjacentList2.insert(adjacent2);
53
Nick Gordonff9a6272017-10-12 13:38:29 -050054 BOOST_CHECK_EQUAL(adjacentList1.size(), (uint32_t)1);
akmhoquefdbddb12014-05-02 18:35:19 -050055 BOOST_CHECK_EQUAL(adjacentList1 == adjacentList2, false);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050056
57 BOOST_CHECK(adjacentList1.isNeighbor("testname"));
58 BOOST_CHECK_EQUAL(adjacentList1.isNeighbor("adjacent"), false);
59
Nick Gordone9733ed2017-04-26 10:48:39 -050060 std::string n1 = "testname";
Vince Lehmancb76ade2014-08-28 21:24:41 -050061 BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), Adjacent::STATUS_INACTIVE);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050062
Vince Lehmancb76ade2014-08-28 21:24:41 -050063 adjacentList1.setStatusOfNeighbor(n1, Adjacent::STATUS_ACTIVE);
64 BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), Adjacent::STATUS_ACTIVE);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050065}
66
Nick Gordone9733ed2017-04-26 10:48:39 -050067BOOST_AUTO_TEST_CASE(findAdjacentByFaceUri)
68{
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050069 ndn::FaceUri faceUri("udp4://10.0.0.1:6363");
Nick Gordone9733ed2017-04-26 10:48:39 -050070 Adjacent adj1("/ndn/test/1", faceUri, 10, Adjacent::STATUS_INACTIVE, 0, 0);
71 AdjacencyList adjList;
72 adjList.insert(adj1);
73
74 std::list<Adjacent>::iterator adjIter = adjList.findAdjacent(faceUri);
75 BOOST_CHECK(adjIter != adjList.end());
76}
77
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050078BOOST_AUTO_TEST_CASE(AdjLsaIsBuildableWithOneNodeActive)
79{
80 Adjacent adjacencyA("/router/A");
81 Adjacent adjacencyB("/router/B");
82
83 adjacencyA.setStatus(Adjacent::STATUS_ACTIVE);
84 adjacencyB.setStatus(Adjacent::STATUS_INACTIVE);
85
86 AdjacencyList adjacencies;
87 adjacencies.insert(adjacencyA);
88 adjacencies.insert(adjacencyB);
89
Ashlesh Gawande85998a12017-12-07 22:22:13 -060090 ndn::util::DummyClientFace face;
91 ConfParameter conf(face);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050092 BOOST_CHECK(adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber()));
93}
94
95BOOST_AUTO_TEST_CASE(AdjLsaIsBuildableWithAllNodesTimedOut)
96{
97 Adjacent adjacencyA("/router/A");
98 Adjacent adjacencyB("/router/B");
99
100 adjacencyA.setStatus(Adjacent::STATUS_INACTIVE);
101 adjacencyB.setStatus(Adjacent::STATUS_INACTIVE);
102
103 adjacencyA.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT);
104 adjacencyB.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT);
105
106 AdjacencyList adjacencies;
107 adjacencies.insert(adjacencyA);
108 adjacencies.insert(adjacencyB);
109
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600110 ndn::util::DummyClientFace face;
111 ConfParameter conf(face);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500112 conf.setInterestRetryNumber(HELLO_RETRIES_DEFAULT);
113
114 BOOST_CHECK(adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber()));
115}
116
117BOOST_AUTO_TEST_CASE(AdjLsaIsNotBuildable)
118{
119 Adjacent adjacencyA("/router/A");
120 Adjacent adjacencyB("/router/B");
121
122 adjacencyA.setStatus(Adjacent::STATUS_INACTIVE);
123 adjacencyB.setStatus(Adjacent::STATUS_INACTIVE);
124
125 adjacencyA.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT);
126 adjacencyB.setInterestTimedOutNo(0);
127
128 AdjacencyList adjacencies;
129 adjacencies.insert(adjacencyA);
130 adjacencies.insert(adjacencyB);
131
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600132 ndn::util::DummyClientFace face;
133 ConfParameter conf(face);
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500134 conf.setInterestRetryNumber(HELLO_RETRIES_DEFAULT);
135
136 BOOST_CHECK(!adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber()));
137}
138
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500139BOOST_AUTO_TEST_SUITE_END()
140
Nick Gordone9733ed2017-04-26 10:48:39 -0500141} // namespace test
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500142} // namespace nlsr