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