blob: 90abd31c6ea2c1f65b31982e3bc7c9239598450b [file] [log] [blame]
Vince Lehman4387e782014-06-19 16:57:45 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev7c10b3b2015-01-20 12:24:27 -08003 * Copyright (c) 2014-2015, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
Vince Lehman4387e782014-06-19 16:57:45 -050010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "rib/rib.hpp"
27
28#include "tests/test-common.hpp"
29#include "fib-updates-common.hpp"
30
31namespace nfd {
32namespace rib {
33namespace tests {
34
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080035BOOST_FIXTURE_TEST_SUITE(TestFibUpdates, FibUpdatesFixture)
Vince Lehman4387e782014-06-19 16:57:45 -050036
37BOOST_AUTO_TEST_SUITE(NewNamespace)
38
39BOOST_AUTO_TEST_CASE(NoFlags)
40{
Vince Lehman218be0a2015-01-15 17:25:20 -060041 // No flags, empty RIB, should generate 1 update for the inserted route
42 insertRoute("/a/b", 1, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050043
Vince Lehman76c751c2014-11-18 17:36:38 -060044 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050045 BOOST_REQUIRE_EQUAL(updates.size(), 1);
46
Vince Lehman76c751c2014-11-18 17:36:38 -060047 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
48 BOOST_CHECK_EQUAL(update->name, "/a/b");
49 BOOST_CHECK_EQUAL(update->faceId, 1);
50 BOOST_CHECK_EQUAL(update->cost, 10);
51 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050052
53 // Reset RIB
Vince Lehman218be0a2015-01-15 17:25:20 -060054 eraseRoute("/a/b", 1, 0);
Vince Lehman76c751c2014-11-18 17:36:38 -060055 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050056
57 // Parent with child inherit flag
Vince Lehman218be0a2015-01-15 17:25:20 -060058 insertRoute("/a", 2, 0, 70, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
59 insertRoute("/a", 3, 0, 30, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -050060
61 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -060062 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050063
Vince Lehman218be0a2015-01-15 17:25:20 -060064 // Should generate 3 updates, 1 for the inserted route and 2 from inheritance
65 insertRoute("/a/b", 1, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050066
67 updates = getSortedFibUpdates();
68 BOOST_REQUIRE_EQUAL(updates.size(), 3);
69
70 update = updates.begin();
Vince Lehman76c751c2014-11-18 17:36:38 -060071 BOOST_CHECK_EQUAL(update->name, "/a/b");
72 BOOST_CHECK_EQUAL(update->faceId, 1);
73 BOOST_CHECK_EQUAL(update->cost, 10);
74 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050075
76 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -060077 BOOST_CHECK_EQUAL(update->name, "/a/b");
78 BOOST_CHECK_EQUAL(update->faceId, 2);
79 BOOST_CHECK_EQUAL(update->cost, 70);
80 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050081
82 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -060083 BOOST_CHECK_EQUAL(update->name, "/a/b");
84 BOOST_CHECK_EQUAL(update->faceId, 3);
85 BOOST_CHECK_EQUAL(update->cost, 30);
86 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050087}
88
89BOOST_AUTO_TEST_CASE(BothFlags)
90{
Vince Lehman218be0a2015-01-15 17:25:20 -060091 // Empty RIB, should generate 1 update for the inserted route
92 insertRoute("/a", 1, 0, 10, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE));
Vince Lehman4387e782014-06-19 16:57:45 -050093
Vince Lehman76c751c2014-11-18 17:36:38 -060094 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050095 BOOST_REQUIRE_EQUAL(updates.size(), 1);
96
Vince Lehman76c751c2014-11-18 17:36:38 -060097 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
98 BOOST_CHECK_EQUAL(update->name, "/a");
99 BOOST_CHECK_EQUAL(update->faceId, 1);
100 BOOST_CHECK_EQUAL(update->cost, 10);
101 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500102
103 // Reset RIB
Vince Lehman218be0a2015-01-15 17:25:20 -0600104 eraseRoute("/a", 1, 0);
Vince Lehman76c751c2014-11-18 17:36:38 -0600105 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500106
Vince Lehman218be0a2015-01-15 17:25:20 -0600107 insertRoute("/", 2, 0, 70, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
108 insertRoute("/a/b", 3, 0, 30, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500109
110 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600111 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500112
Vince Lehman218be0a2015-01-15 17:25:20 -0600113 // Should generate 3 updates, 1 for the inserted route, 1 to add the route to the child,
114 // and 1 to remove the previously inherited route
115 insertRoute("/a", 1, 0, 10, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE));
Vince Lehman4387e782014-06-19 16:57:45 -0500116
117 updates = getSortedFibUpdates();
118 BOOST_REQUIRE_EQUAL(updates.size(), 3);
119
120 update = updates.begin();
Vince Lehman76c751c2014-11-18 17:36:38 -0600121 BOOST_CHECK_EQUAL(update->name, "/a");
122 BOOST_CHECK_EQUAL(update->faceId, 1);
123 BOOST_CHECK_EQUAL(update->cost, 10);
124 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500125
126 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600127 BOOST_CHECK_EQUAL(update->name, "/a/b");
128 BOOST_CHECK_EQUAL(update->faceId, 1);
129 BOOST_CHECK_EQUAL(update->cost, 10);
130 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500131
132 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600133 BOOST_CHECK_EQUAL(update->name, "/a/b");
134 BOOST_CHECK_EQUAL(update->faceId, 2);
135 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500136}
137
138BOOST_AUTO_TEST_CASE(ChildInherit)
139{
Vince Lehman218be0a2015-01-15 17:25:20 -0600140 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
141 insertRoute("/a/b", 2, 0, 10, 0);
142 insertRoute("/a/c", 3, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500143
144 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600145 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500146
Vince Lehman218be0a2015-01-15 17:25:20 -0600147 // Should generate 2 updates: 1 for the inserted route and 1 to add the route to "/a/b"
148 insertRoute("/a", 1, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500149
Vince Lehman76c751c2014-11-18 17:36:38 -0600150 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500151 BOOST_REQUIRE_EQUAL(updates.size(), 2);
152
Vince Lehman76c751c2014-11-18 17:36:38 -0600153 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
154 BOOST_CHECK_EQUAL(update->name, "/a");
155 BOOST_CHECK_EQUAL(update->faceId, 1);
156 BOOST_CHECK_EQUAL(update->cost, 10);
157 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500158
159 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600160 BOOST_CHECK_EQUAL(update->name, "/a/b");
161 BOOST_CHECK_EQUAL(update->faceId, 1);
162 BOOST_CHECK_EQUAL(update->cost, 10);
163 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500164}
165
166BOOST_AUTO_TEST_CASE(Capture)
167{
Vince Lehman218be0a2015-01-15 17:25:20 -0600168 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
169 insertRoute("/a/b", 2, 0, 10, 0);
170 insertRoute("/a/c", 3, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500171
172 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600173 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500174
Vince Lehman218be0a2015-01-15 17:25:20 -0600175 // Should generate 2 updates: 1 for the inserted route and
176 // 1 to remove the inherited route from "/a/b"
177 insertRoute("/a", 1, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500178
Vince Lehman76c751c2014-11-18 17:36:38 -0600179 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500180 BOOST_REQUIRE_EQUAL(updates.size(), 2);
181
Vince Lehman76c751c2014-11-18 17:36:38 -0600182 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
183 BOOST_CHECK_EQUAL(update->name, "/a");
184 BOOST_CHECK_EQUAL(update->faceId, 1);
185 BOOST_CHECK_EQUAL(update->cost, 10);
186 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500187
188 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600189 BOOST_CHECK_EQUAL(update->name, "/a/b");
190 BOOST_CHECK_EQUAL(update->faceId, 1);
191 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500192}
193
194BOOST_AUTO_TEST_SUITE_END() // NewNamespace
195
196BOOST_AUTO_TEST_SUITE_END() // FibUpdates
197
198} // namespace tests
199} // namespace rib
200} // namespace nfd