blob: f063f5d4363e90258fe056d3e08e613f9e608e92 [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/*
3 * Copyright (c) 2014-2018, 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 Pesavento22db5392017-04-14 00:56:43 -040026#ifndef NFD_TESTS_RIB_FIB_UPDATES_COMMON_HPP
27#define NFD_TESTS_RIB_FIB_UPDATES_COMMON_HPP
28
Vince Lehman76c751c2014-11-18 17:36:38 -060029#include "rib/fib-updater.hpp"
Junxiao Shi221b6fe2016-07-14 18:21:56 +000030#include "rib-test-common.hpp"
31#include "tests/identity-management-fixture.hpp"
Vince Lehman76c751c2014-11-18 17:36:38 -060032
33#include <ndn-cxx/util/dummy-client-face.hpp>
34
Vince Lehman4387e782014-06-19 16:57:45 -050035namespace nfd {
36namespace rib {
37namespace tests {
38
Vince Lehman4387e782014-06-19 16:57:45 -050039inline bool
Vince Lehman76c751c2014-11-18 17:36:38 -060040compareNameFaceIdCostAction(const FibUpdate& lhs, const FibUpdate& rhs)
Vince Lehman4387e782014-06-19 16:57:45 -050041{
Vince Lehman76c751c2014-11-18 17:36:38 -060042 if (lhs.name < rhs.name) {
43 return true;
44 }
45 else if (lhs.name == rhs.name) {
46 if (lhs.faceId < rhs.faceId) {
Vince Lehman4387e782014-06-19 16:57:45 -050047 return true;
48 }
Vince Lehman76c751c2014-11-18 17:36:38 -060049 else if (lhs.faceId == rhs.faceId) {
50 if (lhs.cost < rhs.cost) {
51 return true;
52 }
53 else if (lhs.cost == rhs.cost) {
54 return lhs.action < rhs.action;
55 }
Vince Lehman4387e782014-06-19 16:57:45 -050056 }
Vince Lehman76c751c2014-11-18 17:36:38 -060057 }
Vince Lehman4387e782014-06-19 16:57:45 -050058
59 return false;
60}
61
Davide Pesavento97210d52016-10-14 15:45:48 +020062class FibUpdatesFixture : public nfd::tests::IdentityManagementFixture
Vince Lehman4387e782014-06-19 16:57:45 -050063{
64public:
Vince Lehman76c751c2014-11-18 17:36:38 -060065 FibUpdatesFixture()
Junxiao Shi221b6fe2016-07-14 18:21:56 +000066 : face(getGlobalIoService(), m_keyChain)
67 , controller(face, m_keyChain)
Vince Lehman76c751c2014-11-18 17:36:38 -060068 , fibUpdater(rib, controller)
69 {
70 }
71
Vince Lehman4387e782014-06-19 16:57:45 -050072 void
Davide Pesavento22db5392017-04-14 00:56:43 -040073 insertRoute(const Name& name, uint64_t faceId,
74 std::underlying_type<ndn::nfd::RouteOrigin>::type origin,
Junxiao Shi3f21e582017-05-29 15:26:32 +000075 uint64_t cost, std::underlying_type<ndn::nfd::RouteFlags>::type flags)
Vince Lehman4387e782014-06-19 16:57:45 -050076 {
Vince Lehman76c751c2014-11-18 17:36:38 -060077 Route route = createRoute(faceId, origin, cost, flags);
Vince Lehman4387e782014-06-19 16:57:45 -050078
Vince Lehman76c751c2014-11-18 17:36:38 -060079 RibUpdate update;
80 update.setAction(RibUpdate::REGISTER)
81 .setName(name)
82 .setRoute(route);
83
Junxiao Shi52009042018-09-10 12:33:56 +000084 simulateSuccessfulResponse();
85 rib.beginApplyUpdate(update, nullptr, nullptr);
Vince Lehman4387e782014-06-19 16:57:45 -050086 }
87
88 void
Davide Pesavento22db5392017-04-14 00:56:43 -040089 eraseRoute(const Name& name, uint64_t faceId,
90 std::underlying_type<ndn::nfd::RouteOrigin>::type origin)
Vince Lehman4387e782014-06-19 16:57:45 -050091 {
Vince Lehman76c751c2014-11-18 17:36:38 -060092 Route route = createRoute(faceId, origin, 0, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050093
Vince Lehman76c751c2014-11-18 17:36:38 -060094 RibUpdate update;
95 update.setAction(RibUpdate::UNREGISTER)
96 .setName(name)
97 .setRoute(route);
98
Junxiao Shi52009042018-09-10 12:33:56 +000099 simulateSuccessfulResponse();
100 rib.beginApplyUpdate(update, nullptr, nullptr);
Vince Lehman76c751c2014-11-18 17:36:38 -0600101 }
102
103 void
104 destroyFace(uint64_t faceId)
105 {
Junxiao Shi52009042018-09-10 12:33:56 +0000106 simulateSuccessfulResponse();
Vince Lehman76c751c2014-11-18 17:36:38 -0600107 rib.beginRemoveFace(faceId);
108 }
109
Vince Lehman76c751c2014-11-18 17:36:38 -0600110 const FibUpdater::FibUpdateList&
111 getFibUpdates()
112 {
113 fibUpdates.clear();
114 fibUpdates = fibUpdater.m_updatesForBatchFaceId;
115 fibUpdates.insert(fibUpdates.end(), fibUpdater.m_updatesForNonBatchFaceId.begin(),
116 fibUpdater.m_updatesForNonBatchFaceId.end());
117
118 return fibUpdates;
Vince Lehman4387e782014-06-19 16:57:45 -0500119 }
120
Vince Lehman76c751c2014-11-18 17:36:38 -0600121 FibUpdater::FibUpdateList
Vince Lehman4387e782014-06-19 16:57:45 -0500122 getSortedFibUpdates()
123 {
Vince Lehman76c751c2014-11-18 17:36:38 -0600124 FibUpdater::FibUpdateList updates = getFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500125 updates.sort(&compareNameFaceIdCostAction);
126 return updates;
127 }
128
Vince Lehman76c751c2014-11-18 17:36:38 -0600129 void
130 clearFibUpdates()
131 {
132 fibUpdater.m_updatesForBatchFaceId.clear();
133 fibUpdater.m_updatesForNonBatchFaceId.clear();
134 }
135
Junxiao Shi52009042018-09-10 12:33:56 +0000136private:
137 void
138 simulateSuccessfulResponse()
139 {
140 rib.mockFibResponse = [] (const RibUpdateBatch&) { return true; };
141 rib.wantMockFibResponseOnce = true;
142 }
143
Vince Lehman4387e782014-06-19 16:57:45 -0500144public:
Junxiao Shi221b6fe2016-07-14 18:21:56 +0000145 ndn::util::DummyClientFace face;
Vince Lehman76c751c2014-11-18 17:36:38 -0600146 ndn::nfd::Controller controller;
Vince Lehman76c751c2014-11-18 17:36:38 -0600147
Davide Pesavento97210d52016-10-14 15:45:48 +0200148 Rib rib;
149 FibUpdater fibUpdater;
Vince Lehman76c751c2014-11-18 17:36:38 -0600150 FibUpdater::FibUpdateList fibUpdates;
Vince Lehman4387e782014-06-19 16:57:45 -0500151};
152
153} // namespace tests
154} // namespace rib
155} // namespace nfd
Davide Pesavento22db5392017-04-14 00:56:43 -0400156
157#endif // NFD_TESTS_RIB_FIB_UPDATES_COMMON_HPP