blob: 9d685ae6fe4a5a961ecab2f3b078a2373520d2cd [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/*
Junxiao Shi6593a432023-08-21 10:50:28 +00003 * Copyright (c) 2014-2023, 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
Junxiao Shi6593a432023-08-21 10:50:28 +000036static const ndn::FaceUri NEXTHOP1("udp4://192.168.3.1:6363");
37static const ndn::FaceUri NEXTHOP2("udp4://192.168.3.2:6363");
38
39static const uint8_t RoutingTableEntryWithNexthopsData[] = {
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070040 // Header
Junxiao Shi6593a432023-08-21 10:50:28 +000041 0x91, 0x53,
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070042 // Destination Name
Junxiao Shi6593a432023-08-21 10:50:28 +000043 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31,
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070044 // Nexthop
Junxiao Shi6593a432023-08-21 10:50:28 +000045 0x8f, 0x23,
46 // Nexthop.Uri
47 0x8d, 0x17, 0x75, 0x64, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x31, 0x36, 0x38,
48 0x2e, 0x33, 0x2e, 0x31, 0x3a, 0x36, 0x33, 0x36, 0x33,
49 // Nexthop.CostDouble
50 0x86, 0x08, 0x3f, 0xfa, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070051 // Nexthop
Junxiao Shi6593a432023-08-21 10:50:28 +000052 0x8f, 0x23,
53 // Nexthop.Uri
54 0x8d, 0x17, 0x75, 0x64, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x31, 0x36, 0x38,
55 0x2e, 0x33, 0x2e, 0x32, 0x3a, 0x36, 0x33, 0x36, 0x33,
56 // Nexthop.CostDouble
57 0x86, 0x08, 0x3f, 0xfa, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070058};
59
Junxiao Shi6593a432023-08-21 10:50:28 +000060static const uint8_t RoutingTableEntryWithoutNexthopsData[] = {
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070061 // Header
62 0x91, 0x09,
63 // Destination Name
64 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31
65};
66
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040067BOOST_AUTO_TEST_CASE(EncodeWithNexthops)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070068{
69 RoutingTableEntry rte(ndn::Name("dest1"));
70
71 NextHop nexthops1;
Junxiao Shi6593a432023-08-21 10:50:28 +000072 nexthops1.setConnectingFaceUri(NEXTHOP1);
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070073 nexthops1.setRouteCost(1.65);
74 rte.getNexthopList().addNextHop(nexthops1);
75
76 NextHop nexthops2;
Junxiao Shi6593a432023-08-21 10:50:28 +000077 nexthops2.setConnectingFaceUri(NEXTHOP2);
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070078 nexthops2.setRouteCost(1.65);
79 rte.getNexthopList().addNextHop(nexthops2);
80
Davide Pesaventoe28d8752022-03-19 03:55:25 -040081 BOOST_TEST(rte.wireEncode() == RoutingTableEntryWithNexthopsData,
82 boost::test_tools::per_element());
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070083}
84
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040085BOOST_AUTO_TEST_CASE(DecodeWithNexthops)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070086{
Davide Pesaventoe28d8752022-03-19 03:55:25 -040087 RoutingTableEntry rte(ndn::Block{RoutingTableEntryWithNexthopsData});
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070088 BOOST_CHECK_EQUAL(rte.getDestination(), "dest1");
89
90 BOOST_CHECK(rte.getNexthopList().size() != 0);
91 auto it = rte.getNexthopList().begin();
Junxiao Shi6593a432023-08-21 10:50:28 +000092 BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), NEXTHOP1);
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070093 BOOST_CHECK_EQUAL(it->getRouteCost(), 1.65);
94
95 it++;
Junxiao Shi6593a432023-08-21 10:50:28 +000096 BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), NEXTHOP2);
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070097 BOOST_CHECK_EQUAL(it->getRouteCost(), 1.65);
98}
99
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400100BOOST_AUTO_TEST_CASE(EncodeWithoutNexthops)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700101{
102 RoutingTableEntry rte(ndn::Name("dest1"));
Davide Pesaventoe28d8752022-03-19 03:55:25 -0400103 BOOST_TEST(rte.wireEncode() == RoutingTableEntryWithoutNexthopsData,
104 boost::test_tools::per_element());
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700105}
106
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400107BOOST_AUTO_TEST_CASE(DecodeWithoutNexthops)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700108{
Davide Pesaventoe28d8752022-03-19 03:55:25 -0400109 RoutingTableEntry rte(ndn::Block{RoutingTableEntryWithoutNexthopsData});
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700110 BOOST_CHECK_EQUAL(rte.getDestination(), "dest1");
Davide Pesaventoe28d8752022-03-19 03:55:25 -0400111 BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 0);
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700112}
113
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400114BOOST_AUTO_TEST_CASE(Clear)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700115{
116 RoutingTableEntry rte(ndn::Name("dest1"));
117
118 NextHop nexthops1;
Junxiao Shi6593a432023-08-21 10:50:28 +0000119 nexthops1.setConnectingFaceUri(NEXTHOP1);
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700120 nexthops1.setRouteCost(99);
121 rte.getNexthopList().addNextHop(nexthops1);
122
123 BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 1);
124
125 auto it = rte.getNexthopList().begin();
Junxiao Shi6593a432023-08-21 10:50:28 +0000126 BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), NEXTHOP1);
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700127 BOOST_CHECK_EQUAL(it->getRouteCost(), 99);
128
129 rte.getNexthopList().clear();
130 BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 0);
131
132 NextHop nexthops2;
Junxiao Shi6593a432023-08-21 10:50:28 +0000133 nexthops2.setConnectingFaceUri(NEXTHOP2);
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700134 nexthops2.setRouteCost(99);
135 rte.getNexthopList().addNextHop(nexthops2);
136
137 BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 1);
138 it = rte.getNexthopList().begin();
Junxiao Shi6593a432023-08-21 10:50:28 +0000139 BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), NEXTHOP2);
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700140 BOOST_CHECK_EQUAL(it->getRouteCost(), 99);
141}
142
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400143BOOST_AUTO_TEST_CASE(OutputStream)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700144{
145 RoutingTableEntry rte(ndn::Name("dest1"));
Junxiao Shi6593a432023-08-21 10:50:28 +0000146 rte.getNexthopList().addNextHop({NEXTHOP1, 99});
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700147
148 std::ostringstream os;
149 os << rte;
150
151 BOOST_CHECK_EQUAL(os.str(),
152 " Destination: /dest1\n"
Junxiao Shi6593a432023-08-21 10:50:28 +0000153 " NextHop(Uri: udp4://192.168.3.1:6363, Cost: 99)\n");
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700154}
155
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500156BOOST_AUTO_TEST_SUITE_END()
157
Nick Gordonfad8e252016-08-11 14:21:38 -0500158} // namespace test
159} // namespace nlsr