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