blob: 0bce1534de372294d17fe7a2ac7729c1d8dd8798 [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/*
Saurab Dulal427e0122019-11-28 11:58:02 -06003 * 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 */
Vince Lehman7c603292014-09-11 17:48:16 -050020
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050021#include "route/routing-table.hpp"
Ashlesh Gawande85998a12017-12-07 22:22:13 -060022#include "nlsr.hpp"
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050023#include "route/routing-table-entry.hpp"
24#include "route/nexthop.hpp"
Davide Pesaventocb065f12019-12-27 01:03:34 -050025
26#include "tests/test-common.hpp"
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050027
28namespace nlsr {
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050029namespace test {
30
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070031class RoutingTableFixture
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050032{
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070033public:
34 RoutingTableFixture()
35 : conf(face, keyChain)
36 , nlsr(face, keyChain, conf)
37 , rt(nlsr.m_routingTable)
38 {
39 }
40
41public:
Ashlesh Gawande85998a12017-12-07 22:22:13 -060042 ndn::util::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -060043 ndn::KeyChain keyChain;
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070044 ConfParameter conf;
45 Nlsr nlsr;
Ashlesh Gawande85998a12017-12-07 22:22:13 -060046
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070047 RoutingTable& rt;
48};
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050049
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070050BOOST_AUTO_TEST_SUITE(TestRoutingTable)
51
52BOOST_FIXTURE_TEST_CASE(RoutingTableAddNextHop, RoutingTableFixture)
53{
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050054 NextHop nh1;
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050055 const std::string DEST_ROUTER = "destRouter";
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070056 rt.addNextHop(DEST_ROUTER, nh1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050057
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070058 BOOST_CHECK_EQUAL(rt.findRoutingTableEntry(DEST_ROUTER)->getDestination(), DEST_ROUTER);
59}
60
61const uint8_t RoutingTableData1[] =
62{
63 // Header
64 0x90, 0x20,
65 // Routing table entry
66 0x91, 0x1e,
67 // Destination
68 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31, 0x8f, 0x13,
69 // Nexthop
70 0x8d, 0x07, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x86, 0x08, 0x3f, 0xfa, 0x66,
71 0x66, 0x66, 0x66, 0x66, 0x66
72};
73
74const uint8_t RoutingTableData2[] =
75{
76 // Header
77 0x90, 0x00
78};
79
80BOOST_FIXTURE_TEST_CASE(RoutingTableEncode1, RoutingTableFixture)
81{
82 NextHop nexthops;
83 nexthops.setConnectingFaceUri("nexthop");
84 nexthops.setRouteCost(1.65);
85 rt.addNextHop("dest1", nexthops);
86
87 auto wire = rt.wireEncode();
88 BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableData1,
89 RoutingTableData1 + sizeof(RoutingTableData1),
90 wire.begin(), wire.end());
91}
92
93BOOST_FIXTURE_TEST_CASE(RoutingTableEncode2, RoutingTableFixture)
94{
95 auto wire = rt.wireEncode();
96 BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableData2,
97 RoutingTableData2 + sizeof(RoutingTableData2),
98 wire.begin(), wire.end());
99}
100
101BOOST_FIXTURE_TEST_CASE(RoutingTableDecode1, RoutingTableFixture)
102{
103 RoutingTableStatus rtStatus(ndn::Block(RoutingTableData1, sizeof(RoutingTableData1)));
104
105 auto it1 = rtStatus.m_rTable.begin();
106
107 ndn::Name des1 = it1->getDestination();
108 BOOST_CHECK_EQUAL(des1, "dest1");
109
110 auto it2 = it1->getNexthopList().begin();
111 BOOST_CHECK_EQUAL(it2->getConnectingFaceUri(), "nexthop");
112 BOOST_CHECK_EQUAL(it2->getRouteCost(), 1.65);
113
114 BOOST_CHECK_EQUAL(rtStatus.m_rTable.size(), 1);
115}
116
117BOOST_FIXTURE_TEST_CASE(RoutingTableOutputStream, RoutingTableFixture)
118{
119 NextHop nexthops;
120 nexthops.setConnectingFaceUri("nexthop");
121 nexthops.setRouteCost(99);
122 rt.addNextHop("dest1", nexthops);
123
124 std::ostringstream os;
125 os << rt;
126
127 BOOST_CHECK_EQUAL(os.str(),
128 "Routing Table:\n"
129 " Destination: /dest1\n"
130 " NextHop(Uri: nexthop, Cost: 99)\n");
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500131}
132
133BOOST_AUTO_TEST_SUITE_END()
134
Nick Gordonfad8e252016-08-11 14:21:38 -0500135} // namespace test
136} // namespace nlsr