Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 1 | /* -*- 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 | |
| 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 |
| 42 | insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 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 |
| 58 | insertFaceEntry("/a", 2, 0, 50, 0); |
| 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 |
| 79 | insertFaceEntry("/a/b", 3, 0, 10, 0); |
| 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 | { |
| 99 | insertFaceEntry("/", 1, 0, 50, 0); |
| 100 | |
| 101 | // Clear any updates generated from previous insertions |
| 102 | rib.clearFibUpdates(); |
| 103 | |
| 104 | // Should generate 0 updates |
| 105 | insertFaceEntry("/", 1, 128, 75, 0); |
| 106 | |
| 107 | BOOST_CHECK_EQUAL(rib.getFibUpdates().size(), 0); |
| 108 | } |
| 109 | |
| 110 | BOOST_AUTO_TEST_CASE(UpdateOnLowerCostOnly) |
| 111 | { |
| 112 | insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 113 | insertFaceEntry("/a", 2, 0, 10, 0); |
| 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 |
| 119 | insertFaceEntry("/", 1, 0, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 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 |
| 140 | insertFaceEntry("/", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 141 | |
| 142 | BOOST_CHECK_EQUAL(rib.getFibUpdates().size(), 0); |
| 143 | } |
| 144 | |
| 145 | BOOST_AUTO_TEST_CASE(NoCaptureChangeWithoutChildInherit) |
| 146 | { |
| 147 | insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 148 | insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 149 | insertFaceEntry("/a/b", 3, 0, 10, 0); |
| 150 | insertFaceEntry("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE); |
| 151 | |
| 152 | // Clear updates generated from previous insertions |
| 153 | rib.clearFibUpdates(); |
| 154 | |
| 155 | // Should generate 1 update: 1 to add face 5 to /a |
| 156 | insertFaceEntry("/a", 5, 128, 50, 0); |
| 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 | { |
| 171 | insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 172 | insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 173 | insertFaceEntry("/a/b", 3, 0, 10, 0); |
| 174 | insertFaceEntry("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE); |
| 175 | |
| 176 | // Clear updates generated from previous insertions |
| 177 | rib.clearFibUpdates(); |
| 178 | |
| 179 | // Should generate 2 updates: one for the inserted face and |
| 180 | // one to add face to /a/b |
| 181 | insertFaceEntry("/a", 4, 128, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 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 | { |
| 201 | insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 202 | insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 203 | insertFaceEntry("/a/b", 3, 0, 10, 0); |
| 204 | insertFaceEntry("/a/c", 4, 0, 10, 0); |
| 205 | |
| 206 | // Clear updates generated from previous insertions |
| 207 | rib.clearFibUpdates(); |
| 208 | |
| 209 | // Should generate 3 updates: |
| 210 | // - one for the inserted face for /a and |
| 211 | // - two to remove face1 from /a/b and /a/c |
| 212 | insertFaceEntry("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CAPTURE); |
| 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 | { |
| 236 | insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 237 | insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 238 | insertFaceEntry("/a/b", 3, 0, 10, 0); |
| 239 | insertFaceEntry("/a/c", 4, 0, 10, 0); |
| 240 | |
| 241 | // Clear updates generated from previous insertions |
| 242 | rib.clearFibUpdates(); |
| 243 | |
| 244 | // Should generate 2 updates: |
| 245 | // - one for the inserted face for /a and |
| 246 | // - one to update /a/b with the new cost |
| 247 | insertFaceEntry("/a", 1, 128, 50, (ndn::nfd::ROUTE_FLAG_CAPTURE | |
| 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 |