Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | caa60cc | 2024-02-18 18:18:37 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, Regents of the University of California, |
Alexander Afanasyev | 7c10b3b | 2015-01-20 12:24:27 -0800 | [diff] [blame] | 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 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 31 | namespace nfd::tests { |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 32 | |
Davide Pesavento | caa60cc | 2024-02-18 18:18:37 -0500 | [diff] [blame] | 33 | BOOST_AUTO_TEST_SUITE(Rib) |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 34 | BOOST_FIXTURE_TEST_SUITE(TestFibUpdates, FibUpdatesFixture) |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 35 | BOOST_AUTO_TEST_SUITE(NewNamespace) |
| 36 | |
| 37 | BOOST_AUTO_TEST_CASE(NoFlags) |
| 38 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 39 | // No flags, empty RIB, should generate 1 update for the inserted route |
| 40 | insertRoute("/a/b", 1, 0, 10, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 41 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 42 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 43 | BOOST_REQUIRE_EQUAL(updates.size(), 1); |
| 44 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 45 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 46 | BOOST_CHECK_EQUAL(update->name, "/a/b"); |
| 47 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 48 | BOOST_CHECK_EQUAL(update->cost, 10); |
| 49 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 50 | |
| 51 | // Reset RIB |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 52 | eraseRoute("/a/b", 1, 0); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 53 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 54 | |
| 55 | // Parent with child inherit flag |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 56 | insertRoute("/a", 2, 0, 70, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 57 | insertRoute("/a", 3, 0, 30, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 58 | |
| 59 | // Clear updates generated from previous insertions |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 60 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 61 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 62 | // Should generate 3 updates, 1 for the inserted route and 2 from inheritance |
| 63 | insertRoute("/a/b", 1, 0, 10, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 64 | |
| 65 | updates = getSortedFibUpdates(); |
| 66 | BOOST_REQUIRE_EQUAL(updates.size(), 3); |
| 67 | |
| 68 | update = updates.begin(); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 69 | BOOST_CHECK_EQUAL(update->name, "/a/b"); |
| 70 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 71 | BOOST_CHECK_EQUAL(update->cost, 10); |
| 72 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 73 | |
| 74 | ++update; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 75 | BOOST_CHECK_EQUAL(update->name, "/a/b"); |
| 76 | BOOST_CHECK_EQUAL(update->faceId, 2); |
| 77 | BOOST_CHECK_EQUAL(update->cost, 70); |
| 78 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 79 | |
| 80 | ++update; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 81 | BOOST_CHECK_EQUAL(update->name, "/a/b"); |
| 82 | BOOST_CHECK_EQUAL(update->faceId, 3); |
| 83 | BOOST_CHECK_EQUAL(update->cost, 30); |
| 84 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | BOOST_AUTO_TEST_CASE(BothFlags) |
| 88 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 89 | // Empty RIB, should generate 1 update for the inserted route |
| 90 | insertRoute("/a", 1, 0, 10, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE)); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 91 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 92 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 93 | BOOST_REQUIRE_EQUAL(updates.size(), 1); |
| 94 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 95 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 96 | BOOST_CHECK_EQUAL(update->name, "/a"); |
| 97 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 98 | BOOST_CHECK_EQUAL(update->cost, 10); |
| 99 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 100 | |
| 101 | // Reset RIB |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 102 | eraseRoute("/a", 1, 0); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 103 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 104 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 105 | insertRoute("/", 2, 0, 70, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 106 | insertRoute("/a/b", 3, 0, 30, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 107 | |
| 108 | // Clear updates generated from previous insertions |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 109 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 110 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 111 | // Should generate 3 updates, 1 for the inserted route, 1 to add the route to the child, |
| 112 | // and 1 to remove the previously inherited route |
| 113 | insertRoute("/a", 1, 0, 10, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE)); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 114 | |
| 115 | updates = getSortedFibUpdates(); |
| 116 | BOOST_REQUIRE_EQUAL(updates.size(), 3); |
| 117 | |
| 118 | update = updates.begin(); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 119 | BOOST_CHECK_EQUAL(update->name, "/a"); |
| 120 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 121 | BOOST_CHECK_EQUAL(update->cost, 10); |
| 122 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 123 | |
| 124 | ++update; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 125 | BOOST_CHECK_EQUAL(update->name, "/a/b"); |
| 126 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 127 | BOOST_CHECK_EQUAL(update->cost, 10); |
| 128 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 129 | |
| 130 | ++update; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 131 | BOOST_CHECK_EQUAL(update->name, "/a/b"); |
| 132 | BOOST_CHECK_EQUAL(update->faceId, 2); |
| 133 | BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | BOOST_AUTO_TEST_CASE(ChildInherit) |
| 137 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 138 | insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 139 | insertRoute("/a/b", 2, 0, 10, 0); |
| 140 | insertRoute("/a/c", 3, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 141 | |
| 142 | // Clear updates generated from previous insertions |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 143 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 144 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 145 | // Should generate 2 updates: 1 for the inserted route and 1 to add the route to "/a/b" |
| 146 | insertRoute("/a", 1, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 147 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 148 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 149 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 150 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 151 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 152 | BOOST_CHECK_EQUAL(update->name, "/a"); |
| 153 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 154 | BOOST_CHECK_EQUAL(update->cost, 10); |
| 155 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 156 | |
| 157 | ++update; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 158 | BOOST_CHECK_EQUAL(update->name, "/a/b"); |
| 159 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 160 | BOOST_CHECK_EQUAL(update->cost, 10); |
| 161 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | BOOST_AUTO_TEST_CASE(Capture) |
| 165 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 166 | insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 167 | insertRoute("/a/b", 2, 0, 10, 0); |
| 168 | insertRoute("/a/c", 3, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 169 | |
| 170 | // Clear updates generated from previous insertions |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 171 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 172 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 173 | // Should generate 2 updates: 1 for the inserted route and |
| 174 | // 1 to remove the inherited route from "/a/b" |
| 175 | insertRoute("/a", 1, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 176 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 177 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 178 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 179 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 180 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 181 | BOOST_CHECK_EQUAL(update->name, "/a"); |
| 182 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 183 | BOOST_CHECK_EQUAL(update->cost, 10); |
| 184 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 185 | |
| 186 | ++update; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 187 | BOOST_CHECK_EQUAL(update->name, "/a/b"); |
| 188 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 189 | BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | BOOST_AUTO_TEST_SUITE_END() // NewNamespace |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 193 | BOOST_AUTO_TEST_SUITE_END() // FibUpdates |
Davide Pesavento | caa60cc | 2024-02-18 18:18:37 -0500 | [diff] [blame] | 194 | BOOST_AUTO_TEST_SUITE_END() // Rib |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 195 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 196 | } // namespace nfd::tests |