blob: c17b9813c3e0a4854ddecf1ee015c6a027ef367b [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/*
3 * Copyright (c) 2014-2020, 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
72 const ndn::Block& wire = rte.wireEncode();
73
74 BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableEntryWithNexthopsData,
75 RoutingTableEntryWithNexthopsData +
76 sizeof(RoutingTableEntryWithNexthopsData),
77 wire.begin(), wire.end());
78}
79
80BOOST_AUTO_TEST_CASE(RoutingTableEntryDecodeWithNexthops)
81{
82 RoutingTableEntry rte(ndn::Block(RoutingTableEntryWithNexthopsData,
83 sizeof(RoutingTableEntryWithNexthopsData)));
84 BOOST_CHECK_EQUAL(rte.getDestination(), "dest1");
85
86 BOOST_CHECK(rte.getNexthopList().size() != 0);
87 auto it = rte.getNexthopList().begin();
88 BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop1");
89 BOOST_CHECK_EQUAL(it->getRouteCost(), 1.65);
90
91 it++;
92 BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop2");
93 BOOST_CHECK_EQUAL(it->getRouteCost(), 1.65);
94}
95
96BOOST_AUTO_TEST_CASE(RoutingTableEntryEncodeWithoutNexthops)
97{
98 RoutingTableEntry rte(ndn::Name("dest1"));
99
100 auto wire = rte.wireEncode();
101
102 BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableEntryWithoutNexthopsData,
103 RoutingTableEntryWithoutNexthopsData +
104 sizeof(RoutingTableEntryWithoutNexthopsData),
105 wire.begin(), wire.end());
106}
107
108BOOST_AUTO_TEST_CASE(RoutingTableEntryDecodeWithoutNexthops)
109{
110 RoutingTableEntry rte(ndn::Block(RoutingTableEntryWithoutNexthopsData,
111 sizeof(RoutingTableEntryWithoutNexthopsData)));
112
113 BOOST_CHECK_EQUAL(rte.getDestination(), "dest1");
114 BOOST_CHECK(rte.getNexthopList().size() == 0);
115}
116
117
118BOOST_AUTO_TEST_CASE(RoutingTableEntryClear)
119{
120 RoutingTableEntry rte(ndn::Name("dest1"));
121
122 NextHop nexthops1;
123 nexthops1.setConnectingFaceUri("nexthop1");
124 nexthops1.setRouteCost(99);
125 rte.getNexthopList().addNextHop(nexthops1);
126
127 BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 1);
128
129 auto it = rte.getNexthopList().begin();
130 BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop1");
131 BOOST_CHECK_EQUAL(it->getRouteCost(), 99);
132
133 rte.getNexthopList().clear();
134 BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 0);
135
136 NextHop nexthops2;
137 nexthops2.setConnectingFaceUri("nexthop2");
138 nexthops2.setRouteCost(99);
139 rte.getNexthopList().addNextHop(nexthops2);
140
141 BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 1);
142 it = rte.getNexthopList().begin();
143 BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop2");
144 BOOST_CHECK_EQUAL(it->getRouteCost(), 99);
145}
146
147BOOST_AUTO_TEST_CASE(RoutingTableEntryOutputStream)
148{
149 RoutingTableEntry rte(ndn::Name("dest1"));
150
151 NextHop nexthops1;
152 nexthops1.setConnectingFaceUri("nexthop1");
153 nexthops1.setRouteCost(99);
154 rte.getNexthopList().addNextHop(nexthops1);
155
156 std::ostringstream os;
157 os << rte;
158
159 BOOST_CHECK_EQUAL(os.str(),
160 " Destination: /dest1\n"
161 " NextHop(Uri: nexthop1, Cost: 99)\n");
162}
163
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500164BOOST_AUTO_TEST_SUITE_END()
165
Nick Gordonfad8e252016-08-11 14:21:38 -0500166} // namespace test
167} // namespace nlsr