blob: 533439a36feef4d0f6e51da4f8ccb2573b147dda [file] [log] [blame]
Vince Lehman76c751c2014-11-18 17:36:38 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento1b077f62019-02-19 19:19:44 -05002/*
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Vince Lehman76c751c2014-11-18 17:36:38 -06004 * 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.
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
Vince Lehman76c751c2014-11-18 17:36:38 -060026#include "rib/rib-update.hpp"
27#include "rib/rib-update-batch.hpp"
28
Davide Pesavento97210d52016-10-14 15:45:48 +020029#include "tests/test-common.hpp"
Davide Pesavento1b077f62019-02-19 19:19:44 -050030#include "tests/daemon/rib/create-route.hpp"
Davide Pesavento97210d52016-10-14 15:45:48 +020031
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040032namespace nfd::tests {
33
34using namespace nfd::rib;
Vince Lehman76c751c2014-11-18 17:36:38 -060035
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040036BOOST_AUTO_TEST_SUITE(TestRibUpdate)
Vince Lehman76c751c2014-11-18 17:36:38 -060037
38BOOST_AUTO_TEST_CASE(BatchBasic)
39{
40 const uint64_t faceId = 1;
Vince Lehman76c751c2014-11-18 17:36:38 -060041 RibUpdateBatch batch(faceId);
42
43 Route routeRegister = createRoute(faceId, 128, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman76c751c2014-11-18 17:36:38 -060044 RibUpdate registerUpdate;
45 registerUpdate.setAction(RibUpdate::REGISTER)
46 .setName("/a")
47 .setRoute(routeRegister);
48
49 batch.add(registerUpdate);
50
51 BOOST_CHECK_EQUAL(batch.getFaceId(), faceId);
52
53 Route routeUnregister = createRoute(faceId, 0, 0, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman76c751c2014-11-18 17:36:38 -060054 RibUpdate unregisterUpdate;
55 unregisterUpdate.setAction(RibUpdate::UNREGISTER)
56 .setName("/a/b")
57 .setRoute(routeUnregister);
58
59 batch.add(unregisterUpdate);
60
61 BOOST_REQUIRE_EQUAL(batch.size(), 2);
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040062 auto it = batch.begin();
Vince Lehman76c751c2014-11-18 17:36:38 -060063
64 BOOST_CHECK_EQUAL(it->getAction(), RibUpdate::REGISTER);
65 BOOST_CHECK_EQUAL(it->getName(), "/a");
66 BOOST_CHECK_EQUAL(it->getRoute(), routeRegister);
67
68 ++it;
69 BOOST_CHECK_EQUAL(it->getAction(), RibUpdate::UNREGISTER);
70 BOOST_CHECK_EQUAL(it->getName(), "/a/b");
71 BOOST_CHECK_EQUAL(it->getRoute(), routeUnregister);
72
73 ++it;
74 BOOST_CHECK(it == batch.end());
75}
76
Davide Pesavento97210d52016-10-14 15:45:48 +020077BOOST_AUTO_TEST_SUITE_END() // TestRibUpdate
Vince Lehman76c751c2014-11-18 17:36:38 -060078
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040079} // namespace nfd::tests