blob: 9b2be00ffa1a98a4188fe559651a0c7d6245ddd4 [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/*
3 * Copyright (c) 2014-2023, 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>
Nick Gordonb50e51b2016-07-22 16:05:57 -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
29namespace nlsr {
Nick Gordonb50e51b2016-07-22 16:05:57 -050030namespace test {
31
32BOOST_AUTO_TEST_SUITE(TestRoutingTablePoolEntry)
33
34BOOST_AUTO_TEST_CASE(EqualsOperator)
35{
36 NextHop hop1;
37 hop1.setRouteCost(25);
Junxiao Shi6593a432023-08-21 10:50:28 +000038 hop1.setConnectingFaceUri(ndn::FaceUri("udp4://192.168.3.1:6363"));
Nick Gordonb50e51b2016-07-22 16:05:57 -050039
40 NextHop hop2;
41 hop2.setRouteCost(10);
Junxiao Shi6593a432023-08-21 10:50:28 +000042 hop2.setConnectingFaceUri(ndn::FaceUri("udp4://192.168.3.2:6363"));
Nick Gordonb50e51b2016-07-22 16:05:57 -050043
44 NexthopList nhl1;
45 NexthopList nhl2;
46
47 nhl1.addNextHop(hop1);
48 nhl1.addNextHop(hop2);
49
50 RoutingTablePoolEntry rtpe1("/memphis/ndn/rtr1", 0);
51 RoutingTablePoolEntry rtpe2("/memphis/ndn/rtr1", 0);
52
53 rtpe1.setNexthopList(nhl1);
54 rtpe2.setNexthopList(nhl1);
55
56 BOOST_CHECK_EQUAL(rtpe1, rtpe2);
57}
58
59BOOST_AUTO_TEST_CASE(IncrementEntryUseCount)
60{
61 RoutingTablePoolEntry rtpe1("router1");
62
63 rtpe1.incrementUseCount();
64
65 BOOST_CHECK_EQUAL(rtpe1.getUseCount(), 2);
66}
67
68BOOST_AUTO_TEST_CASE(DecrementEntryUseCountNotZero)
69{
70 RoutingTablePoolEntry rtpe1("router1");
71
72 rtpe1.decrementUseCount();
73
74 BOOST_CHECK_EQUAL(rtpe1.getUseCount(), 0);
75}
76
77BOOST_AUTO_TEST_CASE(DecrementEntryUseCountAtZero)
78{
79 RoutingTablePoolEntry rtpe1("router1");
80
81 rtpe1.decrementUseCount();
82 rtpe1.decrementUseCount();
83
84 BOOST_CHECK_EQUAL(rtpe1.getUseCount(), 0);
85}
86
87BOOST_AUTO_TEST_CASE(UpdateNextHopList)
88{
89 RoutingTablePoolEntry rtpe1("router1");
90 NextHop nh1;
91 NexthopList nhl1;
92
93 nhl1.addNextHop(nh1);
94
95 rtpe1.setNexthopList(nhl1);
96
97 BOOST_CHECK_EQUAL(rtpe1.getNexthopList(), nhl1);
98}
99
100BOOST_AUTO_TEST_SUITE_END()
101
102} // namespace test
103} // namespace nlsr