blob: e42271f0372c4372f04b2547d93bdca56d49471c [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
44 Rib::FibUpdateList updates = getSortedFibUpdates();
45 BOOST_REQUIRE_EQUAL(updates.size(), 1);
46
47 Rib::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);
52
53 // Reset RIB
Vince Lehman218be0a2015-01-15 17:25:20 -060054 eraseRoute("/a/b", 1, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050055 rib.clearFibUpdates();
56
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
62 rib.clearFibUpdates();
63
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();
71 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);
75
76 ++update;
77 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);
81
82 ++update;
83 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);
87}
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
94 Rib::FibUpdateList updates = getSortedFibUpdates();
95 BOOST_REQUIRE_EQUAL(updates.size(), 1);
96
97 Rib::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);
102
103 // Reset RIB
Vince Lehman218be0a2015-01-15 17:25:20 -0600104 eraseRoute("/a", 1, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500105 rib.clearFibUpdates();
106
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
111 rib.clearFibUpdates();
112
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();
121 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);
125
126 ++update;
127 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);
131
132 ++update;
133 BOOST_CHECK_EQUAL((*update)->name, "/a/b");
134 BOOST_CHECK_EQUAL((*update)->faceId, 2);
135 BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
136}
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
145 rib.clearFibUpdates();
146
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
150 Rib::FibUpdateList updates = getSortedFibUpdates();
151 BOOST_REQUIRE_EQUAL(updates.size(), 2);
152
153 Rib::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);
158
159 ++update;
160 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);
164}
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
173 rib.clearFibUpdates();
174
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
179 Rib::FibUpdateList updates = getSortedFibUpdates();
180 BOOST_REQUIRE_EQUAL(updates.size(), 2);
181
182 Rib::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);
187
188 ++update;
189 BOOST_CHECK_EQUAL((*update)->name, "/a/b");
190 BOOST_CHECK_EQUAL((*update)->faceId, 1);
191 BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
192}
193
194BOOST_AUTO_TEST_SUITE_END() // NewNamespace
195
196BOOST_AUTO_TEST_SUITE_END() // FibUpdates
197
198} // namespace tests
199} // namespace rib
200} // namespace nfd