blob: 9afd4a5c67f5251b8459a769e41775a116e22c8b [file] [log] [blame]
Vince Lehman4387e782014-06-19 16:57:45 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi52009042018-09-10 12:33:56 +00002/*
Davide Pesavento1b077f62019-02-19 19:19:44 -05003 * Copyright (c) 2014-2019, Regents of the University of California,
Alexander Afanasyev7c10b3b2015-01-20 12:24:27 -08004 * 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 Lehman4387e782014-06-19 16:57:45 -050010 *
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
Davide Pesavento1b077f62019-02-19 19:19:44 -050026#ifndef NFD_TESTS_DAEMON_RIB_FIB_UPDATES_COMMON_HPP
27#define NFD_TESTS_DAEMON_RIB_FIB_UPDATES_COMMON_HPP
Davide Pesavento22db5392017-04-14 00:56:43 -040028
Vince Lehman76c751c2014-11-18 17:36:38 -060029#include "rib/fib-updater.hpp"
Davide Pesaventoe1bdc082018-10-11 21:20:23 -040030
Davide Pesavento1d12d2f2019-03-22 12:44:14 -040031#include "tests/key-chain-fixture.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040032#include "tests/daemon/global-io-fixture.hpp"
Davide Pesavento1b077f62019-02-19 19:19:44 -050033#include "tests/daemon/rib/create-route.hpp"
Vince Lehman76c751c2014-11-18 17:36:38 -060034
35#include <ndn-cxx/util/dummy-client-face.hpp>
36
Vince Lehman4387e782014-06-19 16:57:45 -050037namespace nfd {
38namespace rib {
39namespace tests {
40
Davide Pesavento14e71f02019-03-28 17:35:25 -040041using namespace nfd::tests;
Vince Lehman4387e782014-06-19 16:57:45 -050042
Davide Pesavento14e71f02019-03-28 17:35:25 -040043class FibUpdatesFixture : public GlobalIoFixture, public KeyChainFixture
Vince Lehman4387e782014-06-19 16:57:45 -050044{
45public:
Vince Lehman76c751c2014-11-18 17:36:38 -060046 FibUpdatesFixture()
Davide Pesaventoe1bdc082018-10-11 21:20:23 -040047 : face(g_io, m_keyChain)
Junxiao Shi221b6fe2016-07-14 18:21:56 +000048 , controller(face, m_keyChain)
Vince Lehman76c751c2014-11-18 17:36:38 -060049 , fibUpdater(rib, controller)
50 {
51 }
52
Vince Lehman4387e782014-06-19 16:57:45 -050053 void
Davide Pesavento22db5392017-04-14 00:56:43 -040054 insertRoute(const Name& name, uint64_t faceId,
Davide Pesavento1b077f62019-02-19 19:19:44 -050055 std::underlying_type_t<ndn::nfd::RouteOrigin> origin,
56 uint64_t cost,
57 std::underlying_type_t<ndn::nfd::RouteFlags> flags)
Vince Lehman4387e782014-06-19 16:57:45 -050058 {
Vince Lehman76c751c2014-11-18 17:36:38 -060059 Route route = createRoute(faceId, origin, cost, flags);
Vince Lehman4387e782014-06-19 16:57:45 -050060
Vince Lehman76c751c2014-11-18 17:36:38 -060061 RibUpdate update;
62 update.setAction(RibUpdate::REGISTER)
63 .setName(name)
64 .setRoute(route);
65
Junxiao Shi52009042018-09-10 12:33:56 +000066 simulateSuccessfulResponse();
67 rib.beginApplyUpdate(update, nullptr, nullptr);
Vince Lehman4387e782014-06-19 16:57:45 -050068 }
69
70 void
Davide Pesavento22db5392017-04-14 00:56:43 -040071 eraseRoute(const Name& name, uint64_t faceId,
Davide Pesavento1b077f62019-02-19 19:19:44 -050072 std::underlying_type_t<ndn::nfd::RouteOrigin> origin)
Vince Lehman4387e782014-06-19 16:57:45 -050073 {
Vince Lehman76c751c2014-11-18 17:36:38 -060074 Route route = createRoute(faceId, origin, 0, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050075
Vince Lehman76c751c2014-11-18 17:36:38 -060076 RibUpdate update;
77 update.setAction(RibUpdate::UNREGISTER)
78 .setName(name)
79 .setRoute(route);
80
Junxiao Shi52009042018-09-10 12:33:56 +000081 simulateSuccessfulResponse();
82 rib.beginApplyUpdate(update, nullptr, nullptr);
Vince Lehman76c751c2014-11-18 17:36:38 -060083 }
84
85 void
86 destroyFace(uint64_t faceId)
87 {
Junxiao Shi52009042018-09-10 12:33:56 +000088 simulateSuccessfulResponse();
Vince Lehman76c751c2014-11-18 17:36:38 -060089 rib.beginRemoveFace(faceId);
90 }
91
Vince Lehman76c751c2014-11-18 17:36:38 -060092 const FibUpdater::FibUpdateList&
93 getFibUpdates()
94 {
95 fibUpdates.clear();
96 fibUpdates = fibUpdater.m_updatesForBatchFaceId;
97 fibUpdates.insert(fibUpdates.end(), fibUpdater.m_updatesForNonBatchFaceId.begin(),
98 fibUpdater.m_updatesForNonBatchFaceId.end());
99
100 return fibUpdates;
Vince Lehman4387e782014-06-19 16:57:45 -0500101 }
102
Vince Lehman76c751c2014-11-18 17:36:38 -0600103 FibUpdater::FibUpdateList
Vince Lehman4387e782014-06-19 16:57:45 -0500104 getSortedFibUpdates()
105 {
Vince Lehman76c751c2014-11-18 17:36:38 -0600106 FibUpdater::FibUpdateList updates = getFibUpdates();
Davide Pesavento14e71f02019-03-28 17:35:25 -0400107 updates.sort([] (const auto& lhs, const auto& rhs) {
108 return std::tie(lhs.name, lhs.faceId, lhs.cost, lhs.action) <
109 std::tie(rhs.name, rhs.faceId, rhs.cost, rhs.action);
110 });
Vince Lehman4387e782014-06-19 16:57:45 -0500111 return updates;
112 }
113
Vince Lehman76c751c2014-11-18 17:36:38 -0600114 void
115 clearFibUpdates()
116 {
117 fibUpdater.m_updatesForBatchFaceId.clear();
118 fibUpdater.m_updatesForNonBatchFaceId.clear();
119 }
120
Junxiao Shi52009042018-09-10 12:33:56 +0000121private:
122 void
123 simulateSuccessfulResponse()
124 {
125 rib.mockFibResponse = [] (const RibUpdateBatch&) { return true; };
126 rib.wantMockFibResponseOnce = true;
127 }
128
Vince Lehman4387e782014-06-19 16:57:45 -0500129public:
Junxiao Shi221b6fe2016-07-14 18:21:56 +0000130 ndn::util::DummyClientFace face;
Vince Lehman76c751c2014-11-18 17:36:38 -0600131 ndn::nfd::Controller controller;
Vince Lehman76c751c2014-11-18 17:36:38 -0600132
Davide Pesavento97210d52016-10-14 15:45:48 +0200133 Rib rib;
134 FibUpdater fibUpdater;
Vince Lehman76c751c2014-11-18 17:36:38 -0600135 FibUpdater::FibUpdateList fibUpdates;
Vince Lehman4387e782014-06-19 16:57:45 -0500136};
137
138} // namespace tests
139} // namespace rib
140} // namespace nfd
Davide Pesavento22db5392017-04-14 00:56:43 -0400141
Davide Pesavento1b077f62019-02-19 19:19:44 -0500142#endif // NFD_TESTS_DAEMON_RIB_FIB_UPDATES_COMMON_HPP