blob: e409c51c9941ec33e0e56ff0291a7131466f2e45 [file] [log] [blame]
Vince Lehman4387e782014-06-19 16:57:45 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, 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
10 *
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
35BOOST_FIXTURE_TEST_SUITE(FibUpdates, FibUpdatesFixture)
36
37BOOST_AUTO_TEST_SUITE(NewNamespace)
38
39BOOST_AUTO_TEST_CASE(NoFlags)
40{
41 // No flags, empty RIB, should generate 1 update for the inserted face
42 insertFaceEntry("/a/b", 1, 0, 10, 0);
43
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
54 eraseFaceEntry("/a/b", 1, 0);
55 rib.clearFibUpdates();
56
57 // Parent with child inherit flag
58 insertFaceEntry("/a", 2, 0, 70, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
59 insertFaceEntry("/a", 3, 0, 30, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
60
61 // Clear updates generated from previous insertions
62 rib.clearFibUpdates();
63
64 // Should generate 3 updates, 1 for the inserted face and 2 from inheritance
65 insertFaceEntry("/a/b", 1, 0, 10, 0);
66
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{
91 // Empty RIB, should generate 1 update for the inserted face
92 insertFaceEntry("/a", 1, 0, 10, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT |
93 ndn::nfd::ROUTE_FLAG_CAPTURE));
94
95 Rib::FibUpdateList updates = getSortedFibUpdates();
96 BOOST_REQUIRE_EQUAL(updates.size(), 1);
97
98 Rib::FibUpdateList::const_iterator update = updates.begin();
99 BOOST_CHECK_EQUAL((*update)->name, "/a");
100 BOOST_CHECK_EQUAL((*update)->faceId, 1);
101 BOOST_CHECK_EQUAL((*update)->cost, 10);
102 BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
103
104 // Reset RIB
105 eraseFaceEntry("/a", 1, 0);
106 rib.clearFibUpdates();
107
108 insertFaceEntry("/", 2, 0, 70, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
109 insertFaceEntry("/a/b", 3, 0, 30, 0);
110
111 // Clear updates generated from previous insertions
112 rib.clearFibUpdates();
113
114 // Should generate 3 updates, 1 for the inserted face, 1 to add the face to the child,
115 // and 1 to remove the previously inherited entry
116 insertFaceEntry("/a", 1, 0, 10, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT |
117 ndn::nfd::ROUTE_FLAG_CAPTURE));
118
119 updates = getSortedFibUpdates();
120 BOOST_REQUIRE_EQUAL(updates.size(), 3);
121
122 update = updates.begin();
123 BOOST_CHECK_EQUAL((*update)->name, "/a");
124 BOOST_CHECK_EQUAL((*update)->faceId, 1);
125 BOOST_CHECK_EQUAL((*update)->cost, 10);
126 BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
127
128 ++update;
129 BOOST_CHECK_EQUAL((*update)->name, "/a/b");
130 BOOST_CHECK_EQUAL((*update)->faceId, 1);
131 BOOST_CHECK_EQUAL((*update)->cost, 10);
132 BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
133
134 ++update;
135 BOOST_CHECK_EQUAL((*update)->name, "/a/b");
136 BOOST_CHECK_EQUAL((*update)->faceId, 2);
137 BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
138}
139
140BOOST_AUTO_TEST_CASE(ChildInherit)
141{
142 insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
143 insertFaceEntry("/a/b", 2, 0, 10, 0);
144 insertFaceEntry("/a/c", 3, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
145
146 // Clear updates generated from previous insertions
147 rib.clearFibUpdates();
148
149 // Should generate 2 updates: 1 for the inserted face and 1 to add the face to "/a/b"
150 insertFaceEntry("/a", 1, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
151
152 Rib::FibUpdateList updates = getSortedFibUpdates();
153 BOOST_REQUIRE_EQUAL(updates.size(), 2);
154
155 Rib::FibUpdateList::const_iterator update = updates.begin();
156 BOOST_CHECK_EQUAL((*update)->name, "/a");
157 BOOST_CHECK_EQUAL((*update)->faceId, 1);
158 BOOST_CHECK_EQUAL((*update)->cost, 10);
159 BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
160
161 ++update;
162 BOOST_CHECK_EQUAL((*update)->name, "/a/b");
163 BOOST_CHECK_EQUAL((*update)->faceId, 1);
164 BOOST_CHECK_EQUAL((*update)->cost, 10);
165 BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
166}
167
168BOOST_AUTO_TEST_CASE(Capture)
169{
170 insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
171 insertFaceEntry("/a/b", 2, 0, 10, 0);
172 insertFaceEntry("/a/c", 3, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
173
174 // Clear updates generated from previous insertions
175 rib.clearFibUpdates();
176
177 // Should generate 2 updates: 1 for the inserted face and
178 // 1 to remove inherited face from "/a/b"
179 insertFaceEntry("/a", 1, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
180
181 Rib::FibUpdateList updates = getSortedFibUpdates();
182 BOOST_REQUIRE_EQUAL(updates.size(), 2);
183
184 Rib::FibUpdateList::const_iterator update = updates.begin();
185 BOOST_CHECK_EQUAL((*update)->name, "/a");
186 BOOST_CHECK_EQUAL((*update)->faceId, 1);
187 BOOST_CHECK_EQUAL((*update)->cost, 10);
188 BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP);
189
190 ++update;
191 BOOST_CHECK_EQUAL((*update)->name, "/a/b");
192 BOOST_CHECK_EQUAL((*update)->faceId, 1);
193 BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
194}
195
196BOOST_AUTO_TEST_SUITE_END() // NewNamespace
197
198BOOST_AUTO_TEST_SUITE_END() // FibUpdates
199
200} // namespace tests
201} // namespace rib
202} // namespace nfd