blob: f30e17ea0b9f4e131406d835384366b6622a2f22 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande0421bc62020-05-08 20:42:19 -07002/*
Davide Pesaventoe28d8752022-03-19 03:55:25 -04003 * Copyright (c) 2014-2022, The University of Memphis,
Nick Gordonf8b5bcd2016-08-11 15:06:50 -05004 * Regents of the University of California
akmhoque3d06e792014-05-27 16:23:20 -05005 *
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/>.
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070019 */
Davide Pesaventocb065f12019-12-27 01:03:34 -050020
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050021#include "route/routing-table-entry.hpp"
Davide Pesaventocb065f12019-12-27 01:03:34 -050022#include "tests/boost-test.hpp"
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050023
24namespace nlsr {
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050025namespace test {
26
27BOOST_AUTO_TEST_SUITE(TestRoutingTableEntry)
28
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040029BOOST_AUTO_TEST_CASE(Destination)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050030{
31 RoutingTableEntry rte1("router1");
32
33 BOOST_CHECK_EQUAL(rte1.getDestination(), "router1");
34}
35
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040036const uint8_t RoutingTableEntryWithNexthopsData[] = {
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070037 // Header
38 0x91, 0x35,
39 // Destination Name
40 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31, 0x8f, 0x14,
41 // Nexthop
42 0x8d, 0x08, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x31, 0x86, 0x08, 0x3f, 0xfa,
43 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x8f, 0x14, 0x8d, 0x08,
44 // Nexthop
45 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x32, 0x86, 0x08, 0x3f, 0xfa, 0x66, 0x66,
46 0x66, 0x66, 0x66, 0x66
47};
48
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040049const uint8_t RoutingTableEntryWithoutNexthopsData[] = {
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070050 // Header
51 0x91, 0x09,
52 // Destination Name
53 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31
54};
55
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040056BOOST_AUTO_TEST_CASE(EncodeWithNexthops)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070057{
58 RoutingTableEntry rte(ndn::Name("dest1"));
59
60 NextHop nexthops1;
61 nexthops1.setConnectingFaceUri("nexthop1");
62 nexthops1.setRouteCost(1.65);
63 rte.getNexthopList().addNextHop(nexthops1);
64
65 NextHop nexthops2;
66 nexthops2.setConnectingFaceUri("nexthop2");
67 nexthops2.setRouteCost(1.65);
68 rte.getNexthopList().addNextHop(nexthops2);
69
Davide Pesaventoe28d8752022-03-19 03:55:25 -040070 BOOST_TEST(rte.wireEncode() == RoutingTableEntryWithNexthopsData,
71 boost::test_tools::per_element());
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070072}
73
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040074BOOST_AUTO_TEST_CASE(DecodeWithNexthops)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070075{
Davide Pesaventoe28d8752022-03-19 03:55:25 -040076 RoutingTableEntry rte(ndn::Block{RoutingTableEntryWithNexthopsData});
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070077 BOOST_CHECK_EQUAL(rte.getDestination(), "dest1");
78
79 BOOST_CHECK(rte.getNexthopList().size() != 0);
80 auto it = rte.getNexthopList().begin();
81 BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop1");
82 BOOST_CHECK_EQUAL(it->getRouteCost(), 1.65);
83
84 it++;
85 BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop2");
86 BOOST_CHECK_EQUAL(it->getRouteCost(), 1.65);
87}
88
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040089BOOST_AUTO_TEST_CASE(EncodeWithoutNexthops)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070090{
91 RoutingTableEntry rte(ndn::Name("dest1"));
Davide Pesaventoe28d8752022-03-19 03:55:25 -040092 BOOST_TEST(rte.wireEncode() == RoutingTableEntryWithoutNexthopsData,
93 boost::test_tools::per_element());
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070094}
95
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040096BOOST_AUTO_TEST_CASE(DecodeWithoutNexthops)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070097{
Davide Pesaventoe28d8752022-03-19 03:55:25 -040098 RoutingTableEntry rte(ndn::Block{RoutingTableEntryWithoutNexthopsData});
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070099 BOOST_CHECK_EQUAL(rte.getDestination(), "dest1");
Davide Pesaventoe28d8752022-03-19 03:55:25 -0400100 BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 0);
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700101}
102
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400103BOOST_AUTO_TEST_CASE(Clear)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700104{
105 RoutingTableEntry rte(ndn::Name("dest1"));
106
107 NextHop nexthops1;
108 nexthops1.setConnectingFaceUri("nexthop1");
109 nexthops1.setRouteCost(99);
110 rte.getNexthopList().addNextHop(nexthops1);
111
112 BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 1);
113
114 auto it = rte.getNexthopList().begin();
115 BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop1");
116 BOOST_CHECK_EQUAL(it->getRouteCost(), 99);
117
118 rte.getNexthopList().clear();
119 BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 0);
120
121 NextHop nexthops2;
122 nexthops2.setConnectingFaceUri("nexthop2");
123 nexthops2.setRouteCost(99);
124 rte.getNexthopList().addNextHop(nexthops2);
125
126 BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 1);
127 it = rte.getNexthopList().begin();
128 BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop2");
129 BOOST_CHECK_EQUAL(it->getRouteCost(), 99);
130}
131
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400132BOOST_AUTO_TEST_CASE(OutputStream)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700133{
134 RoutingTableEntry rte(ndn::Name("dest1"));
135
136 NextHop nexthops1;
137 nexthops1.setConnectingFaceUri("nexthop1");
138 nexthops1.setRouteCost(99);
139 rte.getNexthopList().addNextHop(nexthops1);
140
141 std::ostringstream os;
142 os << rte;
143
144 BOOST_CHECK_EQUAL(os.str(),
145 " Destination: /dest1\n"
146 " NextHop(Uri: nexthop1, Cost: 99)\n");
147}
148
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500149BOOST_AUTO_TEST_SUITE_END()
150
Nick Gordonfad8e252016-08-11 14:21:38 -0500151} // namespace test
152} // namespace nlsr