Nick Gordon | 89c4cca | 2016-11-02 15:42:32 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 2 | /** |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, 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. |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [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/>. |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 24 | */ |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 25 | |
| 26 | #include "rib/rib.hpp" |
| 27 | |
| 28 | #include "tests/test-common.hpp" |
| 29 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 30 | #include <ndn-cxx/encoding/tlv-nfd.hpp> |
| 31 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 32 | namespace nfd { |
| 33 | namespace rib { |
| 34 | namespace tests { |
| 35 | |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 36 | BOOST_FIXTURE_TEST_SUITE(TestRib, nfd::tests::BaseFixture) |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 37 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 38 | BOOST_AUTO_TEST_CASE(Parent) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 39 | { |
| 40 | rib::Rib rib; |
| 41 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 42 | Route root; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 43 | Name name1("/"); |
| 44 | root.faceId = 1; |
| 45 | root.origin = 20; |
| 46 | rib.insert(name1, root); |
| 47 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 48 | Route route1; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 49 | Name name2("/hello"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 50 | route1.faceId = 2; |
| 51 | route1.origin = 20; |
| 52 | rib.insert(name2, route1); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 53 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 54 | Route route2; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 55 | Name name3("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 56 | route2.faceId = 3; |
| 57 | route2.origin = 20; |
| 58 | rib.insert(name3, route2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 59 | |
| 60 | shared_ptr<rib::RibEntry> ribEntry = rib.findParent(name3); |
| 61 | BOOST_REQUIRE(static_cast<bool>(ribEntry)); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 62 | BOOST_CHECK_EQUAL(ribEntry->getRoutes().front().faceId, 2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 63 | |
| 64 | ribEntry = rib.findParent(name2); |
| 65 | BOOST_REQUIRE(static_cast<bool>(ribEntry)); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 66 | BOOST_CHECK_EQUAL(ribEntry->getRoutes().front().faceId, 1); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 67 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 68 | Route route3; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 69 | Name name4("/hello/test/foo/bar"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 70 | route2.faceId = 3; |
| 71 | route2.origin = 20; |
| 72 | rib.insert(name4, route3); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 73 | |
| 74 | ribEntry = rib.findParent(name4); |
| 75 | BOOST_CHECK(ribEntry != shared_ptr<rib::RibEntry>()); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 76 | BOOST_CHECK(ribEntry->getRoutes().front().faceId == 2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 77 | } |
| 78 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 79 | BOOST_AUTO_TEST_CASE(Children) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 80 | { |
| 81 | rib::Rib rib; |
| 82 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 83 | Route route1; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 84 | Name name1("/"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 85 | route1.faceId = 1; |
| 86 | route1.origin = 20; |
| 87 | rib.insert(name1, route1); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 88 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 89 | Route route2; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 90 | Name name2("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 91 | route2.faceId = 2; |
| 92 | route2.origin = 20; |
| 93 | rib.insert(name2, route2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 94 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 95 | Route route3; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 96 | Name name3("/hello/test/foo/bar"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 97 | route3.faceId = 3; |
| 98 | route3.origin = 20; |
| 99 | rib.insert(name3, route3); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 100 | |
| 101 | BOOST_CHECK_EQUAL((rib.find(name1)->second)->getChildren().size(), 2); |
| 102 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getChildren().size(), 0); |
| 103 | BOOST_CHECK_EQUAL((rib.find(name3)->second)->getChildren().size(), 0); |
| 104 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 105 | Route entry4; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 106 | Name name4("/hello"); |
| 107 | entry4.faceId = 4; |
| 108 | entry4.origin = 20; |
| 109 | rib.insert(name4, entry4); |
| 110 | |
| 111 | BOOST_CHECK_EQUAL((rib.find(name1)->second)->getChildren().size(), 1); |
| 112 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getChildren().size(), 0); |
| 113 | BOOST_CHECK_EQUAL((rib.find(name3)->second)->getChildren().size(), 0); |
| 114 | BOOST_CHECK_EQUAL((rib.find(name4)->second)->getChildren().size(), 2); |
| 115 | |
| 116 | BOOST_CHECK_EQUAL((rib.find(name1)->second)->getChildren().front()->getName(), "/hello"); |
| 117 | BOOST_CHECK_EQUAL((rib.find(name4)->second)->getParent()->getName(), "/"); |
| 118 | |
| 119 | BOOST_REQUIRE(static_cast<bool>((rib.find(name2)->second)->getParent())); |
| 120 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getParent()->getName(), name4); |
| 121 | BOOST_REQUIRE(static_cast<bool>((rib.find(name3)->second)->getParent())); |
| 122 | BOOST_CHECK_EQUAL((rib.find(name3)->second)->getParent()->getName(), name4); |
| 123 | } |
| 124 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 125 | BOOST_AUTO_TEST_CASE(EraseFace) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 126 | { |
| 127 | rib::Rib rib; |
| 128 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 129 | Route route1; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 130 | Name name1("/"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 131 | route1.faceId = 1; |
| 132 | route1.origin = 20; |
| 133 | rib.insert(name1, route1); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 134 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 135 | Route route2; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 136 | Name name2("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 137 | route2.faceId = 2; |
| 138 | route2.origin = 20; |
| 139 | rib.insert(name2, route2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 140 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 141 | Route route3; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 142 | Name name3("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 143 | route3.faceId = 1; |
| 144 | route3.origin = 20; |
| 145 | rib.insert(name3, route3); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 146 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 147 | Route entry4; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 148 | Name name4("/not/inserted"); |
| 149 | entry4.faceId = 1; |
| 150 | entry4.origin = 20; |
| 151 | |
| 152 | rib.erase(name4, entry4); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 153 | rib.erase(name1, route1); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 154 | |
| 155 | BOOST_CHECK(rib.find(name1) == rib.end()); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 156 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getRoutes().size(), 2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 157 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 158 | rib.erase(name2, route2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 159 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 160 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getRoutes().size(), 1); |
| 161 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getRoutes().front().faceId, 1); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 162 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 163 | rib.erase(name3, route3); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 164 | |
| 165 | BOOST_CHECK(rib.find(name2) == rib.end()); |
| 166 | |
| 167 | rib.erase(name4, entry4); |
| 168 | } |
| 169 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 170 | BOOST_AUTO_TEST_CASE(EraseRibEntry) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 171 | { |
| 172 | rib::Rib rib; |
| 173 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 174 | Route route1; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 175 | Name name1("/"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 176 | route1.faceId = 1; |
| 177 | route1.origin = 20; |
| 178 | rib.insert(name1, route1); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 179 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 180 | Route route2; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 181 | Name name2("/hello"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 182 | route2.faceId = 2; |
| 183 | route2.origin = 20; |
| 184 | rib.insert(name2, route2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 185 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 186 | Route route3; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 187 | Name name3("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 188 | route3.faceId = 1; |
| 189 | route3.origin = 20; |
| 190 | rib.insert(name3, route3); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 191 | |
| 192 | shared_ptr<rib::RibEntry> ribEntry1 = rib.find(name1)->second; |
| 193 | shared_ptr<rib::RibEntry> ribEntry2 = rib.find(name2)->second; |
| 194 | shared_ptr<rib::RibEntry> ribEntry3 = rib.find(name3)->second; |
| 195 | |
| 196 | BOOST_CHECK(ribEntry1->getChildren().front() == ribEntry2); |
| 197 | BOOST_CHECK(ribEntry3->getParent() == ribEntry2); |
| 198 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 199 | rib.erase(name2, route2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 200 | BOOST_CHECK(ribEntry1->getChildren().front() == ribEntry3); |
| 201 | BOOST_CHECK(ribEntry3->getParent() == ribEntry1); |
| 202 | } |
| 203 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 204 | BOOST_AUTO_TEST_CASE(Basic) |
| 205 | { |
| 206 | rib::Rib rib; |
| 207 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 208 | Route route1; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 209 | Name name1("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 210 | route1.faceId = 1; |
| 211 | route1.origin = 20; |
| 212 | route1.cost = 10; |
| 213 | route1.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE; |
| 214 | route1.expires = time::steady_clock::now() + time::milliseconds(1500); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 215 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 216 | rib.insert(name1, route1); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 217 | BOOST_CHECK_EQUAL(rib.size(), 1); |
| 218 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 219 | rib.insert(name1, route1); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 220 | BOOST_CHECK_EQUAL(rib.size(), 1); |
| 221 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 222 | Route route2; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 223 | Name name2("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 224 | route2.faceId = 1; |
| 225 | route2.origin = 20; |
| 226 | route2.cost = 100; |
| 227 | route2.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT; |
| 228 | route2.expires = time::steady_clock::now() + time::seconds(0); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 229 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 230 | rib.insert(name2, route2); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 231 | BOOST_CHECK_EQUAL(rib.size(), 1); |
| 232 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 233 | route2.faceId = 2; |
| 234 | rib.insert(name2, route2); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 235 | BOOST_CHECK_EQUAL(rib.size(), 2); |
| 236 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 237 | BOOST_CHECK(rib.find(name1)->second->hasFaceId(route1.faceId)); |
| 238 | BOOST_CHECK(rib.find(name1)->second->hasFaceId(route2.faceId)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 239 | |
| 240 | Name name3("/foo/bar"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 241 | rib.insert(name3, route2); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 242 | BOOST_CHECK_EQUAL(rib.size(), 3); |
| 243 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 244 | route2.origin = 1; |
| 245 | rib.insert(name3, route2); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 246 | BOOST_CHECK_EQUAL(rib.size(), 4); |
| 247 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 248 | rib.erase(name3, route2); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 249 | BOOST_CHECK_EQUAL(rib.size(), 3); |
| 250 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 251 | Name name4("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 252 | rib.erase(name4, route2); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 253 | BOOST_CHECK_EQUAL(rib.size(), 3); |
| 254 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 255 | route2.origin = 20; |
| 256 | rib.erase(name4, route2); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 257 | BOOST_CHECK_EQUAL(rib.size(), 2); |
| 258 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 259 | BOOST_CHECK_EQUAL(rib.find(name2, route2), static_cast<Route*>(0)); |
| 260 | BOOST_CHECK_NE(rib.find(name1, route1), static_cast<Route*>(0)); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 261 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 262 | rib.erase(name1, route1); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 263 | BOOST_CHECK_EQUAL(rib.size(), 1); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Nick Gordon | 89c4cca | 2016-11-02 15:42:32 +0000 | [diff] [blame] | 266 | BOOST_AUTO_TEST_CASE(RibSignals) |
| 267 | { |
| 268 | rib::Rib rib; |
| 269 | |
| 270 | Route route; |
| 271 | Name name("/hello/world"); |
| 272 | |
| 273 | Route route1; |
| 274 | route1.faceId = 1; |
| 275 | route1.origin = 20; |
| 276 | route1.cost = 10; |
| 277 | |
| 278 | Route route2; |
| 279 | route2.faceId = 2; |
| 280 | route2.origin = 30; |
| 281 | route2.cost = 20; |
| 282 | |
| 283 | RibRouteRef routeInfo; |
| 284 | |
| 285 | int nAfterInsertEntryInvocations = 0; |
| 286 | int nAfterAddRouteInvocations = 0; |
| 287 | int nBeforeRemoveRouteInvocations = 0; |
| 288 | int nAfterEraseEntryInvocations = 0; |
| 289 | rib.afterInsertEntry.connect([&] (const Name& inName) { |
| 290 | BOOST_CHECK_EQUAL(nAfterInsertEntryInvocations, 0); |
| 291 | BOOST_CHECK_EQUAL(nAfterAddRouteInvocations, 0); |
| 292 | BOOST_CHECK(rib.find(name) != rib.end()); |
| 293 | nAfterInsertEntryInvocations++; |
| 294 | }); |
| 295 | |
| 296 | rib.afterAddRoute.connect([&] (const RibRouteRef& rrr) { |
| 297 | BOOST_CHECK_EQUAL(nAfterInsertEntryInvocations, 1); |
| 298 | BOOST_CHECK(rib.find(name) != rib.end()); |
| 299 | BOOST_CHECK(rib.find(name, route) != nullptr); |
| 300 | nAfterAddRouteInvocations++; |
| 301 | }); |
| 302 | |
| 303 | rib.beforeRemoveRoute.connect([&] (const RibRouteRef& rrr) { |
| 304 | BOOST_CHECK_EQUAL(nAfterEraseEntryInvocations, 0); |
| 305 | BOOST_CHECK(rib.find(name) != rib.end()); |
| 306 | BOOST_CHECK(rib.find(name, route) != nullptr); |
| 307 | nBeforeRemoveRouteInvocations++; |
| 308 | }); |
| 309 | |
| 310 | rib.afterEraseEntry.connect([&] (const Name& inName) { |
| 311 | BOOST_CHECK_EQUAL(nBeforeRemoveRouteInvocations, 2); |
| 312 | BOOST_CHECK_EQUAL(nAfterEraseEntryInvocations, 0); |
| 313 | BOOST_CHECK(rib.find(name) == rib.end()); |
| 314 | nAfterEraseEntryInvocations++; |
| 315 | }); |
| 316 | |
| 317 | route = route1; |
| 318 | rib.insert(name, route); |
| 319 | BOOST_CHECK_EQUAL(nAfterInsertEntryInvocations, 1); |
| 320 | BOOST_CHECK_EQUAL(nAfterAddRouteInvocations, 1); |
| 321 | |
| 322 | route = route2; |
| 323 | rib.insert(name, route); |
| 324 | BOOST_CHECK_EQUAL(nAfterInsertEntryInvocations, 1); |
| 325 | BOOST_CHECK_EQUAL(nAfterAddRouteInvocations, 2); |
| 326 | |
| 327 | route = route1; |
| 328 | rib.erase(name, route); |
| 329 | BOOST_CHECK_EQUAL(nBeforeRemoveRouteInvocations, 1); |
| 330 | BOOST_CHECK_EQUAL(nAfterEraseEntryInvocations, 0); |
| 331 | |
| 332 | route = route2; |
| 333 | rib.erase(name, route); |
| 334 | BOOST_CHECK_EQUAL(nBeforeRemoveRouteInvocations, 2); |
| 335 | BOOST_CHECK_EQUAL(nAfterEraseEntryInvocations, 1); |
| 336 | |
| 337 | } |
| 338 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 339 | BOOST_AUTO_TEST_SUITE_END() // TestRib |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 340 | |
| 341 | } // namespace tests |
| 342 | } // namespace rib |
| 343 | } // namespace nfd |