Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 7c10b3b | 2015-01-20 12:24:27 -0800 | [diff] [blame^] | 3 | * 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 Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 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 | |
| 31 | namespace nfd { |
| 32 | namespace rib { |
| 33 | namespace tests { |
| 34 | |
| 35 | BOOST_FIXTURE_TEST_SUITE(FibUpdates, FibUpdatesFixture) |
| 36 | |
| 37 | BOOST_AUTO_TEST_SUITE(NewFace) |
| 38 | |
| 39 | BOOST_AUTO_TEST_CASE(Basic) |
| 40 | { |
| 41 | // should generate 1 update |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 42 | insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 43 | |
| 44 | Rib::FibUpdateList updates = rib.getFibUpdates(); |
| 45 | BOOST_REQUIRE_EQUAL(updates.size(), 1); |
| 46 | |
| 47 | Rib::FibUpdateList::const_iterator update = updates.begin(); |
| 48 | |
| 49 | BOOST_CHECK_EQUAL((*update)->name, "/"); |
| 50 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 51 | BOOST_CHECK_EQUAL((*update)->cost, 50); |
| 52 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 53 | |
| 54 | // Clear any updates generated from previous insertions |
| 55 | rib.clearFibUpdates(); |
| 56 | |
| 57 | // should generate 2 updates |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 58 | insertRoute("/a", 2, 0, 50, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 59 | |
| 60 | updates = getSortedFibUpdates(); |
| 61 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 62 | |
| 63 | update = updates.begin(); |
| 64 | BOOST_CHECK_EQUAL((*update)->name, "/a"); |
| 65 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 66 | BOOST_CHECK_EQUAL((*update)->cost, 50); |
| 67 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 68 | |
| 69 | ++update; |
| 70 | BOOST_CHECK_EQUAL((*update)->name, "/a"); |
| 71 | BOOST_CHECK_EQUAL((*update)->faceId, 2); |
| 72 | BOOST_CHECK_EQUAL((*update)->cost, 50); |
| 73 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 74 | |
| 75 | // Clear updates generated from previous insertions |
| 76 | rib.clearFibUpdates(); |
| 77 | |
| 78 | // should generate 2 updates |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 79 | insertRoute("/a/b", 3, 0, 10, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 80 | |
| 81 | updates = getSortedFibUpdates(); |
| 82 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 83 | |
| 84 | update = updates.begin(); |
| 85 | BOOST_CHECK_EQUAL((*update)->name, "/a/b"); |
| 86 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 87 | BOOST_CHECK_EQUAL((*update)->cost, 50); |
| 88 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 89 | |
| 90 | ++update; |
| 91 | BOOST_CHECK_EQUAL((*update)->name, "/a/b"); |
| 92 | BOOST_CHECK_EQUAL((*update)->faceId, 3); |
| 93 | BOOST_CHECK_EQUAL((*update)->cost, 10); |
| 94 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 95 | } |
| 96 | |
| 97 | BOOST_AUTO_TEST_CASE(UpdateOnLowerCostNoChildInherit) |
| 98 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 99 | insertRoute("/", 1, 0, 50, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 100 | |
| 101 | // Clear any updates generated from previous insertions |
| 102 | rib.clearFibUpdates(); |
| 103 | |
| 104 | // Should generate 0 updates |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 105 | insertRoute("/", 1, 128, 75, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 106 | |
| 107 | BOOST_CHECK_EQUAL(rib.getFibUpdates().size(), 0); |
| 108 | } |
| 109 | |
| 110 | BOOST_AUTO_TEST_CASE(UpdateOnLowerCostOnly) |
| 111 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 112 | insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 113 | insertRoute("/a", 2, 0, 10, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 114 | |
| 115 | // Clear updates generated from previous insertions |
| 116 | rib.clearFibUpdates(); |
| 117 | |
| 118 | // Should generate 2 updates: to update cost for face 1 on / and /a |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 119 | insertRoute("/", 1, 0, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 120 | |
| 121 | Rib::FibUpdateList updates = getSortedFibUpdates(); |
| 122 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 123 | |
| 124 | Rib::FibUpdateList::const_iterator update = updates.begin(); |
| 125 | BOOST_CHECK_EQUAL((*update)->name, "/"); |
| 126 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 127 | BOOST_CHECK_EQUAL((*update)->cost, 25); |
| 128 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 129 | |
| 130 | ++update; |
| 131 | BOOST_CHECK_EQUAL((*update)->name, "/a"); |
| 132 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 133 | BOOST_CHECK_EQUAL((*update)->cost, 25); |
| 134 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 135 | |
| 136 | // Clear updates generated from previous insertions |
| 137 | rib.clearFibUpdates(); |
| 138 | |
| 139 | // Should generate 0 updates |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 140 | insertRoute("/", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 141 | |
| 142 | BOOST_CHECK_EQUAL(rib.getFibUpdates().size(), 0); |
| 143 | } |
| 144 | |
| 145 | BOOST_AUTO_TEST_CASE(NoCaptureChangeWithoutChildInherit) |
| 146 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 147 | insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 148 | insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 149 | insertRoute("/a/b", 3, 0, 10, 0); |
| 150 | insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 151 | |
| 152 | // Clear updates generated from previous insertions |
| 153 | rib.clearFibUpdates(); |
| 154 | |
| 155 | // Should generate 1 update: 1 to add face 5 to /a |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 156 | insertRoute("/a", 5, 128, 50, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 157 | |
| 158 | const Rib::FibUpdateList& updates = rib.getFibUpdates(); |
| 159 | BOOST_REQUIRE_EQUAL(updates.size(), 1); |
| 160 | |
| 161 | Rib::FibUpdateList::const_iterator update = updates.begin(); |
| 162 | |
| 163 | BOOST_CHECK_EQUAL((*update)->name, "/a"); |
| 164 | BOOST_CHECK_EQUAL((*update)->faceId, 5); |
| 165 | BOOST_CHECK_EQUAL((*update)->cost, 50); |
| 166 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 167 | } |
| 168 | |
| 169 | BOOST_AUTO_TEST_CASE(NoCaptureChangeWithChildInherit) |
| 170 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 171 | insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 172 | insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 173 | insertRoute("/a/b", 3, 0, 10, 0); |
| 174 | insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 175 | |
| 176 | // Clear updates generated from previous insertions |
| 177 | rib.clearFibUpdates(); |
| 178 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 179 | // Should generate 2 updates: one for the inserted route and |
| 180 | // one to add route to /a/b |
| 181 | insertRoute("/a", 4, 128, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 182 | |
| 183 | Rib::FibUpdateList updates = getSortedFibUpdates(); |
| 184 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 185 | |
| 186 | Rib::FibUpdateList::const_iterator update = updates.begin(); |
| 187 | BOOST_CHECK_EQUAL((*update)->name, "/a"); |
| 188 | BOOST_CHECK_EQUAL((*update)->faceId, 4); |
| 189 | BOOST_CHECK_EQUAL((*update)->cost, 5); |
| 190 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 191 | |
| 192 | ++update; |
| 193 | BOOST_CHECK_EQUAL((*update)->name, "/a/b"); |
| 194 | BOOST_CHECK_EQUAL((*update)->faceId, 4); |
| 195 | BOOST_CHECK_EQUAL((*update)->cost, 5); |
| 196 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 197 | } |
| 198 | |
| 199 | BOOST_AUTO_TEST_CASE(CaptureTurnedOnWithoutChildInherit) |
| 200 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 201 | insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 202 | insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 203 | insertRoute("/a/b", 3, 0, 10, 0); |
| 204 | insertRoute("/a/c", 4, 0, 10, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 205 | |
| 206 | // Clear updates generated from previous insertions |
| 207 | rib.clearFibUpdates(); |
| 208 | |
| 209 | // Should generate 3 updates: |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 210 | // - one for the inserted route for /a and |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 211 | // - two to remove face1 from /a/b and /a/c |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 212 | insertRoute("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 213 | |
| 214 | Rib::FibUpdateList updates = getSortedFibUpdates(); |
| 215 | BOOST_REQUIRE_EQUAL(updates.size(), 3); |
| 216 | |
| 217 | Rib::FibUpdateList::const_iterator update = updates.begin(); |
| 218 | BOOST_CHECK_EQUAL((*update)->name, "/a"); |
| 219 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 220 | BOOST_CHECK_EQUAL((*update)->cost, 50); |
| 221 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 222 | |
| 223 | ++update; |
| 224 | BOOST_CHECK_EQUAL((*update)->name, "/a/b"); |
| 225 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 226 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP); |
| 227 | |
| 228 | ++update; |
| 229 | BOOST_CHECK_EQUAL((*update)->name, "/a/c"); |
| 230 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 231 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP); |
| 232 | } |
| 233 | |
| 234 | BOOST_AUTO_TEST_CASE(CaptureTurnedOnWithChildInherit) |
| 235 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 236 | insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 237 | insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 238 | insertRoute("/a/b", 3, 0, 10, 0); |
| 239 | insertRoute("/a/c", 4, 0, 10, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 240 | |
| 241 | // Clear updates generated from previous insertions |
| 242 | rib.clearFibUpdates(); |
| 243 | |
| 244 | // Should generate 2 updates: |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 245 | // - one for the inserted route for /a and |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 246 | // - one to update /a/b with the new cost |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 247 | insertRoute("/a", 1, 128, 50, (ndn::nfd::ROUTE_FLAG_CAPTURE | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 248 | ndn::nfd::ROUTE_FLAG_CHILD_INHERIT)); |
| 249 | |
| 250 | Rib::FibUpdateList updates = getSortedFibUpdates(); |
| 251 | BOOST_REQUIRE_EQUAL(updates.size(), 3); |
| 252 | |
| 253 | Rib::FibUpdateList::const_iterator update = updates.begin(); |
| 254 | BOOST_CHECK_EQUAL((*update)->name, "/a"); |
| 255 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 256 | BOOST_CHECK_EQUAL((*update)->cost, 50); |
| 257 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 258 | |
| 259 | ++update; |
| 260 | BOOST_CHECK_EQUAL((*update)->name, "/a/b"); |
| 261 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 262 | BOOST_CHECK_EQUAL((*update)->cost, 50); |
| 263 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 264 | } |
| 265 | |
| 266 | BOOST_AUTO_TEST_SUITE_END() // NewFace |
| 267 | |
| 268 | BOOST_AUTO_TEST_SUITE_END() // FibUpdates |
| 269 | |
| 270 | } // namespace tests |
| 271 | } // namespace rib |
| 272 | } // namespace nfd |