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(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 | |
| 44 | Rib::FibUpdateList updates = getSortedFibUpdates(); |
| 45 | BOOST_REQUIRE_EQUAL(updates.size(), 1); |
| 46 | |
| 47 | Rib::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); |
| 52 | |
| 53 | // Reset RIB |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 54 | eraseRoute("/a/b", 1, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 55 | rib.clearFibUpdates(); |
| 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 |
| 62 | rib.clearFibUpdates(); |
| 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(); |
| 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); |
| 75 | |
| 76 | ++update; |
| 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); |
| 81 | |
| 82 | ++update; |
| 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); |
| 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 | |
| 94 | Rib::FibUpdateList updates = getSortedFibUpdates(); |
| 95 | BOOST_REQUIRE_EQUAL(updates.size(), 1); |
| 96 | |
| 97 | Rib::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); |
| 102 | |
| 103 | // Reset RIB |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 104 | eraseRoute("/a", 1, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 105 | rib.clearFibUpdates(); |
| 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 |
| 111 | rib.clearFibUpdates(); |
| 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(); |
| 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); |
| 125 | |
| 126 | ++update; |
| 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); |
| 131 | |
| 132 | ++update; |
| 133 | BOOST_CHECK_EQUAL((*update)->name, "/a/b"); |
| 134 | BOOST_CHECK_EQUAL((*update)->faceId, 2); |
| 135 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP); |
| 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 |
| 145 | rib.clearFibUpdates(); |
| 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 | |
| 150 | Rib::FibUpdateList updates = getSortedFibUpdates(); |
| 151 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 152 | |
| 153 | Rib::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); |
| 158 | |
| 159 | ++update; |
| 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); |
| 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 |
| 173 | rib.clearFibUpdates(); |
| 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 | |
| 179 | Rib::FibUpdateList updates = getSortedFibUpdates(); |
| 180 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 181 | |
| 182 | Rib::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); |
| 187 | |
| 188 | ++update; |
| 189 | BOOST_CHECK_EQUAL((*update)->name, "/a/b"); |
| 190 | BOOST_CHECK_EQUAL((*update)->faceId, 1); |
| 191 | BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP); |
| 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 |