blob: ef470e1b355b37162bd248d19259350d59366fa0 [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
29BOOST_AUTO_TEST_CASE(RoutingTableEntryDestination)
30{
31 RoutingTableEntry rte1("router1");
32
33 BOOST_CHECK_EQUAL(rte1.getDestination(), "router1");
34}
35
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070036const uint8_t RoutingTableEntryWithNexthopsData[] =
37{
38 // Header
39 0x91, 0x35,
40 // Destination Name
41 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31, 0x8f, 0x14,
42 // Nexthop
43 0x8d, 0x08, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x31, 0x86, 0x08, 0x3f, 0xfa,
44 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x8f, 0x14, 0x8d, 0x08,
45 // Nexthop
46 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x32, 0x86, 0x08, 0x3f, 0xfa, 0x66, 0x66,
47 0x66, 0x66, 0x66, 0x66
48};
49
50const uint8_t RoutingTableEntryWithoutNexthopsData[] =
51{
52 // Header
53 0x91, 0x09,
54 // Destination Name
55 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31
56};
57
58BOOST_AUTO_TEST_CASE(RoutingTableEntryEncodeWithNexthops)
59{
60 RoutingTableEntry rte(ndn::Name("dest1"));
61
62 NextHop nexthops1;
63 nexthops1.setConnectingFaceUri("nexthop1");
64 nexthops1.setRouteCost(1.65);
65 rte.getNexthopList().addNextHop(nexthops1);
66
67 NextHop nexthops2;
68 nexthops2.setConnectingFaceUri("nexthop2");
69 nexthops2.setRouteCost(1.65);
70 rte.getNexthopList().addNextHop(nexthops2);
71
Davide Pesaventoe28d8752022-03-19 03:55:25 -040072 BOOST_TEST(rte.wireEncode() == RoutingTableEntryWithNexthopsData,
73 boost::test_tools::per_element());
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070074}
75
76BOOST_AUTO_TEST_CASE(RoutingTableEntryDecodeWithNexthops)
77{
Davide Pesaventoe28d8752022-03-19 03:55:25 -040078 RoutingTableEntry rte(ndn::Block{RoutingTableEntryWithNexthopsData});
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070079 BOOST_CHECK_EQUAL(rte.getDestination(), "dest1");
80
81 BOOST_CHECK(rte.getNexthopList().size() != 0);
82 auto it = rte.getNexthopList().begin();
83 BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop1");
84 BOOST_CHECK_EQUAL(it->getRouteCost(), 1.65);
85
86 it++;
87 BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop2");
88 BOOST_CHECK_EQUAL(it->getRouteCost(), 1.65);
89}
90
91BOOST_AUTO_TEST_CASE(RoutingTableEntryEncodeWithoutNexthops)
92{
93 RoutingTableEntry rte(ndn::Name("dest1"));
Davide Pesaventoe28d8752022-03-19 03:55:25 -040094 BOOST_TEST(rte.wireEncode() == RoutingTableEntryWithoutNexthopsData,
95 boost::test_tools::per_element());
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070096}
97
98BOOST_AUTO_TEST_CASE(RoutingTableEntryDecodeWithoutNexthops)
99{
Davide Pesaventoe28d8752022-03-19 03:55:25 -0400100 RoutingTableEntry rte(ndn::Block{RoutingTableEntryWithoutNexthopsData});
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700101 BOOST_CHECK_EQUAL(rte.getDestination(), "dest1");
Davide Pesaventoe28d8752022-03-19 03:55:25 -0400102 BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 0);
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700103}
104
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700105BOOST_AUTO_TEST_CASE(RoutingTableEntryClear)
106{
107 RoutingTableEntry rte(ndn::Name("dest1"));
108
109 NextHop nexthops1;
110 nexthops1.setConnectingFaceUri("nexthop1");
111 nexthops1.setRouteCost(99);
112 rte.getNexthopList().addNextHop(nexthops1);
113
114 BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 1);
115
116 auto it = rte.getNexthopList().begin();
117 BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop1");
118 BOOST_CHECK_EQUAL(it->getRouteCost(), 99);
119
120 rte.getNexthopList().clear();
121 BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 0);
122
123 NextHop nexthops2;
124 nexthops2.setConnectingFaceUri("nexthop2");
125 nexthops2.setRouteCost(99);
126 rte.getNexthopList().addNextHop(nexthops2);
127
128 BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 1);
129 it = rte.getNexthopList().begin();
130 BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop2");
131 BOOST_CHECK_EQUAL(it->getRouteCost(), 99);
132}
133
134BOOST_AUTO_TEST_CASE(RoutingTableEntryOutputStream)
135{
136 RoutingTableEntry rte(ndn::Name("dest1"));
137
138 NextHop nexthops1;
139 nexthops1.setConnectingFaceUri("nexthop1");
140 nexthops1.setRouteCost(99);
141 rte.getNexthopList().addNextHop(nexthops1);
142
143 std::ostringstream os;
144 os << rte;
145
146 BOOST_CHECK_EQUAL(os.str(),
147 " Destination: /dest1\n"
148 " NextHop(Uri: nexthop1, Cost: 99)\n");
149}
150
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500151BOOST_AUTO_TEST_SUITE_END()
152
Nick Gordonfad8e252016-08-11 14:21:38 -0500153} // namespace test
154} // namespace nlsr