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(UpdateFace) |
| 38 | |
| 39 | BOOST_AUTO_TEST_CASE(TurnOffChildInheritLowerCost) |
| 40 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 41 | insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 42 | insertRoute("/a", 2, 0, 10, 0); |
| 43 | insertRoute("/", 1, 128, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 44 | |
| 45 | // Clear updates generated from previous insertions |
| 46 | rib.clearFibUpdates(); |
| 47 | |
| 48 | // Should generate 2 updates: 1 to update the cost of / face 1 to 50 and |
| 49 | // 1 to update the cost of /a face 1 to 50 |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 50 | insertRoute("/", 1, 128, 75, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 51 | |
| 52 | Rib::FibUpdateList updates = getSortedFibUpdates(); |
| 53 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 54 | |
| 55 | Rib::FibUpdateList::const_iterator update = updates.begin(); |
| 56 | BOOST_CHECK_EQUAL((*update)->name, "/"); |
| 57 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 58 | BOOST_CHECK_EQUAL((*update)->cost, 50); |
| 59 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 60 | |
| 61 | ++update; |
| 62 | BOOST_CHECK_EQUAL((*update)->name, "/a"); |
| 63 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 64 | BOOST_CHECK_EQUAL((*update)->cost, 50); |
| 65 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 66 | } |
| 67 | |
| 68 | BOOST_AUTO_TEST_CASE(UpdateOnLowerCostOnly) |
| 69 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 70 | insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 71 | insertRoute("/a", 2, 0, 10, 0); |
| 72 | insertRoute("/", 1, 128, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 73 | |
| 74 | // Clear updates generated from previous insertions |
| 75 | rib.clearFibUpdates(); |
| 76 | |
| 77 | // Should generate 0 updates |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 78 | insertRoute("/", 1, 128, 75, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 79 | |
| 80 | Rib::FibUpdateList updates = getSortedFibUpdates(); |
| 81 | BOOST_REQUIRE_EQUAL(updates.size(), 0); |
| 82 | |
| 83 | // Clear updates generated from previous insertions |
| 84 | rib.clearFibUpdates(); |
| 85 | |
| 86 | // Should generate 2 updates |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 87 | insertRoute("/", 1, 128, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 88 | |
| 89 | updates = getSortedFibUpdates(); |
| 90 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 91 | |
| 92 | Rib::FibUpdateList::const_iterator update = updates.begin(); |
| 93 | BOOST_CHECK_EQUAL((*update)->name, "/"); |
| 94 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 95 | BOOST_CHECK_EQUAL((*update)->cost, 25); |
| 96 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 97 | |
| 98 | ++update; |
| 99 | BOOST_CHECK_EQUAL((*update)->name, "/a"); |
| 100 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 101 | BOOST_CHECK_EQUAL((*update)->cost, 25); |
| 102 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 103 | } |
| 104 | |
| 105 | BOOST_AUTO_TEST_CASE(NoChangeInCost) |
| 106 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 107 | insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 108 | insertRoute("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 109 | insertRoute("/a/b", 3, 0, 10, 0); |
| 110 | insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 111 | |
| 112 | // Clear updates generated from previous insertions |
| 113 | rib.clearFibUpdates(); |
| 114 | |
| 115 | // Should generate 0 updates |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 116 | insertRoute("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 117 | |
| 118 | Rib::FibUpdateList updates = getSortedFibUpdates(); |
| 119 | BOOST_REQUIRE_EQUAL(updates.size(), 0); |
| 120 | } |
| 121 | |
| 122 | BOOST_AUTO_TEST_CASE(ChangeCost) |
| 123 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 124 | insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 125 | insertRoute("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 126 | insertRoute("/a/b", 3, 0, 10, 0); |
| 127 | insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 128 | |
| 129 | // Clear updates generated from previous insertions |
| 130 | rib.clearFibUpdates(); |
| 131 | |
| 132 | // Should generate 2 updates: 1 to add face2 with new cost to /a and |
| 133 | // 1 to add face2 with new cost to /a/b |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 134 | insertRoute("/a", 2, 0, 300, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 135 | |
| 136 | Rib::FibUpdateList updates = getSortedFibUpdates(); |
| 137 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 138 | |
| 139 | Rib::FibUpdateList::const_iterator update = updates.begin(); |
| 140 | BOOST_CHECK_EQUAL((*update)->name, "/a"); |
| 141 | BOOST_CHECK_EQUAL((*update)->faceId, 2); |
| 142 | BOOST_CHECK_EQUAL((*update)->cost, 300); |
| 143 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 144 | |
| 145 | ++update; |
| 146 | BOOST_CHECK_EQUAL((*update)->name, "/a/b"); |
| 147 | BOOST_CHECK_EQUAL((*update)->faceId, 2); |
| 148 | BOOST_CHECK_EQUAL((*update)->cost, 300); |
| 149 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 150 | } |
| 151 | |
| 152 | BOOST_AUTO_TEST_CASE(TurnOnChildInherit) |
| 153 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 154 | insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 155 | insertRoute("/a", 2, 0, 10, 0); |
| 156 | insertRoute("/a/b", 3, 0, 10, 0); |
| 157 | insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 158 | |
| 159 | // Clear updates generated from previous insertions |
| 160 | rib.clearFibUpdates(); |
| 161 | |
| 162 | // Turn on child inherit flag for the entry in /a |
| 163 | // Should generate 1 updates: 1 to add face to /a/b |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 164 | insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 165 | |
| 166 | Rib::FibUpdateList updates = getSortedFibUpdates(); |
| 167 | BOOST_REQUIRE_EQUAL(updates.size(), 1); |
| 168 | |
| 169 | Rib::FibUpdateList::const_iterator update = updates.begin(); |
| 170 | BOOST_CHECK_EQUAL((*update)->name, "/a/b"); |
| 171 | BOOST_CHECK_EQUAL((*update)->faceId, 2); |
| 172 | BOOST_CHECK_EQUAL((*update)->cost, 10); |
| 173 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 174 | } |
| 175 | |
| 176 | BOOST_AUTO_TEST_CASE(TurnOffChildInherit) |
| 177 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 178 | insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 179 | insertRoute("/a", 1, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 180 | insertRoute("/a/b", 2, 0, 10, 0); |
| 181 | insertRoute("/a/c", 1, 0, 25, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 182 | |
| 183 | // Clear updates generated from previous insertions |
| 184 | rib.clearFibUpdates(); |
| 185 | |
| 186 | // Turn off child inherit flag for the entry in /a |
| 187 | // Should generate 1 update: 1 to add face1 to /a/b |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 188 | insertRoute("/a", 1, 0, 100, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 189 | |
| 190 | Rib::FibUpdateList updates = getSortedFibUpdates(); |
| 191 | BOOST_REQUIRE_EQUAL(updates.size(), 1); |
| 192 | |
| 193 | Rib::FibUpdateList::const_iterator update = updates.begin(); |
| 194 | BOOST_CHECK_EQUAL((*update)->name, "/a/b"); |
| 195 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 196 | BOOST_CHECK_EQUAL((*update)->cost, 50); |
| 197 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 198 | } |
| 199 | |
| 200 | BOOST_AUTO_TEST_CASE(TurnOnCapture) |
| 201 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 202 | insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 203 | insertRoute("/a", 2, 0, 10, 0); |
| 204 | insertRoute("/a/b", 3, 0, 10, 0); |
| 205 | insertRoute("/a/c", 1, 0, 10, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 206 | |
| 207 | // Clear updates generated from previous insertions |
| 208 | rib.clearFibUpdates(); |
| 209 | |
| 210 | // Turn on capture flag for the entry in /a |
| 211 | // Should generate 2 updates: 1 to remove face1 from /a and |
| 212 | // 1 to remove face1 from /a/b |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 213 | insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 214 | |
| 215 | Rib::FibUpdateList updates = getSortedFibUpdates(); |
| 216 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 217 | |
| 218 | Rib::FibUpdateList::const_iterator update = updates.begin(); |
| 219 | BOOST_CHECK_EQUAL((*update)->name, "/a"); |
| 220 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 221 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_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 | |
| 229 | BOOST_AUTO_TEST_CASE(TurnOffCapture) |
| 230 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 231 | insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 232 | insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE); |
| 233 | insertRoute("/a/b", 3, 0, 10, 0); |
| 234 | insertRoute("/a/c", 1, 0, 10, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 235 | |
| 236 | // Clear updates generated from previous insertions |
| 237 | rib.clearFibUpdates(); |
| 238 | |
| 239 | // Turn off capture flag for the entry in /a |
| 240 | // Should generate 2 updates: 1 to add face1 to /a and |
| 241 | // 1 to add face1 to /a/b |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 242 | insertRoute("/a", 2, 0, 10, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 243 | |
| 244 | Rib::FibUpdateList updates = getSortedFibUpdates(); |
| 245 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 246 | |
| 247 | Rib::FibUpdateList::const_iterator update = updates.begin(); |
| 248 | BOOST_CHECK_EQUAL((*update)->name, "/a"); |
| 249 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 250 | BOOST_CHECK_EQUAL((*update)->cost, 50); |
| 251 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::ADD_NEXTHOP); |
| 252 | |
| 253 | ++update; |
| 254 | BOOST_CHECK_EQUAL((*update)->name, "/a/b"); |
| 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 | |
| 260 | BOOST_AUTO_TEST_SUITE_END() // UpdateFace |
| 261 | |
| 262 | BOOST_AUTO_TEST_SUITE_END() // FibUpdates |
| 263 | |
| 264 | } // namespace tests |
| 265 | } // namespace rib |
| 266 | } // namespace nfd |