blob: 08c206284694187be5d3450248018034069a6c08 [file] [log] [blame]
Nick Gordonb50e51b2016-07-22 16:05:57 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi6593a432023-08-21 10:50:28 +00002/*
Davide Pesavento288141a2024-02-13 17:30:35 -05003 * Copyright (c) 2014-2024, The University of Memphis,
Nick Gordonb50e51b2016-07-22 16:05:57 -05004 * 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 Nicholas Gordon <nmgordon@memphis.edu>
Davide Pesavento288141a2024-02-13 17:30:35 -050021 */
Davide Pesaventocb065f12019-12-27 01:03:34 -050022
Nick Gordonb50e51b2016-07-22 16:05:57 -050023#include "route/routing-table-pool-entry.hpp"
24#include "route/nexthop.hpp"
25#include "route/nexthop-list.hpp"
26
Davide Pesaventocb065f12019-12-27 01:03:34 -050027#include "tests/boost-test.hpp"
Nick Gordonb50e51b2016-07-22 16:05:57 -050028
Davide Pesavento288141a2024-02-13 17:30:35 -050029namespace nlsr::tests {
Nick Gordonb50e51b2016-07-22 16:05:57 -050030
31BOOST_AUTO_TEST_SUITE(TestRoutingTablePoolEntry)
32
33BOOST_AUTO_TEST_CASE(EqualsOperator)
34{
35 NextHop hop1;
36 hop1.setRouteCost(25);
Junxiao Shi6593a432023-08-21 10:50:28 +000037 hop1.setConnectingFaceUri(ndn::FaceUri("udp4://192.168.3.1:6363"));
Nick Gordonb50e51b2016-07-22 16:05:57 -050038
39 NextHop hop2;
40 hop2.setRouteCost(10);
Junxiao Shi6593a432023-08-21 10:50:28 +000041 hop2.setConnectingFaceUri(ndn::FaceUri("udp4://192.168.3.2:6363"));
Nick Gordonb50e51b2016-07-22 16:05:57 -050042
43 NexthopList nhl1;
44 NexthopList nhl2;
45
46 nhl1.addNextHop(hop1);
47 nhl1.addNextHop(hop2);
48
49 RoutingTablePoolEntry rtpe1("/memphis/ndn/rtr1", 0);
50 RoutingTablePoolEntry rtpe2("/memphis/ndn/rtr1", 0);
51
52 rtpe1.setNexthopList(nhl1);
53 rtpe2.setNexthopList(nhl1);
54
55 BOOST_CHECK_EQUAL(rtpe1, rtpe2);
56}
57
58BOOST_AUTO_TEST_CASE(IncrementEntryUseCount)
59{
60 RoutingTablePoolEntry rtpe1("router1");
61
62 rtpe1.incrementUseCount();
63
64 BOOST_CHECK_EQUAL(rtpe1.getUseCount(), 2);
65}
66
67BOOST_AUTO_TEST_CASE(DecrementEntryUseCountNotZero)
68{
69 RoutingTablePoolEntry rtpe1("router1");
70
71 rtpe1.decrementUseCount();
72
73 BOOST_CHECK_EQUAL(rtpe1.getUseCount(), 0);
74}
75
76BOOST_AUTO_TEST_CASE(DecrementEntryUseCountAtZero)
77{
78 RoutingTablePoolEntry rtpe1("router1");
79
80 rtpe1.decrementUseCount();
81 rtpe1.decrementUseCount();
82
83 BOOST_CHECK_EQUAL(rtpe1.getUseCount(), 0);
84}
85
86BOOST_AUTO_TEST_CASE(UpdateNextHopList)
87{
88 RoutingTablePoolEntry rtpe1("router1");
89 NextHop nh1;
90 NexthopList nhl1;
91
92 nhl1.addNextHop(nh1);
93
94 rtpe1.setNexthopList(nhl1);
95
96 BOOST_CHECK_EQUAL(rtpe1.getNexthopList(), nhl1);
97}
98
99BOOST_AUTO_TEST_SUITE_END()
100
Davide Pesavento288141a2024-02-13 17:30:35 -0500101} // namespace nlsr::tests