blob: 66b1c8ebf0c875436bfa2c39f7c6e6a487c21b86 [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"
Davide Pesaventoe1bdc082018-10-11 21:20:23 -040030
Junxiao Shi221b6fe2016-07-14 18:21:56 +000031#include "rib-test-common.hpp"
32#include "tests/identity-management-fixture.hpp"
Vince Lehman76c751c2014-11-18 17:36:38 -060033
34#include <ndn-cxx/util/dummy-client-face.hpp>
35
Vince Lehman4387e782014-06-19 16:57:45 -050036namespace nfd {
37namespace rib {
38namespace tests {
39
Vince Lehman4387e782014-06-19 16:57:45 -050040inline bool
Vince Lehman76c751c2014-11-18 17:36:38 -060041compareNameFaceIdCostAction(const FibUpdate& lhs, const FibUpdate& rhs)
Vince Lehman4387e782014-06-19 16:57:45 -050042{
Vince Lehman76c751c2014-11-18 17:36:38 -060043 if (lhs.name < rhs.name) {
44 return true;
45 }
46 else if (lhs.name == rhs.name) {
47 if (lhs.faceId < rhs.faceId) {
Vince Lehman4387e782014-06-19 16:57:45 -050048 return true;
49 }
Vince Lehman76c751c2014-11-18 17:36:38 -060050 else if (lhs.faceId == rhs.faceId) {
51 if (lhs.cost < rhs.cost) {
52 return true;
53 }
54 else if (lhs.cost == rhs.cost) {
55 return lhs.action < rhs.action;
56 }
Vince Lehman4387e782014-06-19 16:57:45 -050057 }
Vince Lehman76c751c2014-11-18 17:36:38 -060058 }
Vince Lehman4387e782014-06-19 16:57:45 -050059
60 return false;
61}
62
Davide Pesavento97210d52016-10-14 15:45:48 +020063class FibUpdatesFixture : public nfd::tests::IdentityManagementFixture
Vince Lehman4387e782014-06-19 16:57:45 -050064{
65public:
Vince Lehman76c751c2014-11-18 17:36:38 -060066 FibUpdatesFixture()
Davide Pesaventoe1bdc082018-10-11 21:20:23 -040067 : face(g_io, m_keyChain)
Junxiao Shi221b6fe2016-07-14 18:21:56 +000068 , controller(face, m_keyChain)
Vince Lehman76c751c2014-11-18 17:36:38 -060069 , fibUpdater(rib, controller)
70 {
71 }
72
Vince Lehman4387e782014-06-19 16:57:45 -050073 void
Davide Pesavento22db5392017-04-14 00:56:43 -040074 insertRoute(const Name& name, uint64_t faceId,
75 std::underlying_type<ndn::nfd::RouteOrigin>::type origin,
Junxiao Shi3f21e582017-05-29 15:26:32 +000076 uint64_t cost, std::underlying_type<ndn::nfd::RouteFlags>::type flags)
Vince Lehman4387e782014-06-19 16:57:45 -050077 {
Vince Lehman76c751c2014-11-18 17:36:38 -060078 Route route = createRoute(faceId, origin, cost, flags);
Vince Lehman4387e782014-06-19 16:57:45 -050079
Vince Lehman76c751c2014-11-18 17:36:38 -060080 RibUpdate update;
81 update.setAction(RibUpdate::REGISTER)
82 .setName(name)
83 .setRoute(route);
84
Junxiao Shi52009042018-09-10 12:33:56 +000085 simulateSuccessfulResponse();
86 rib.beginApplyUpdate(update, nullptr, nullptr);
Vince Lehman4387e782014-06-19 16:57:45 -050087 }
88
89 void
Davide Pesavento22db5392017-04-14 00:56:43 -040090 eraseRoute(const Name& name, uint64_t faceId,
91 std::underlying_type<ndn::nfd::RouteOrigin>::type origin)
Vince Lehman4387e782014-06-19 16:57:45 -050092 {
Vince Lehman76c751c2014-11-18 17:36:38 -060093 Route route = createRoute(faceId, origin, 0, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050094
Vince Lehman76c751c2014-11-18 17:36:38 -060095 RibUpdate update;
96 update.setAction(RibUpdate::UNREGISTER)
97 .setName(name)
98 .setRoute(route);
99
Junxiao Shi52009042018-09-10 12:33:56 +0000100 simulateSuccessfulResponse();
101 rib.beginApplyUpdate(update, nullptr, nullptr);
Vince Lehman76c751c2014-11-18 17:36:38 -0600102 }
103
104 void
105 destroyFace(uint64_t faceId)
106 {
Junxiao Shi52009042018-09-10 12:33:56 +0000107 simulateSuccessfulResponse();
Vince Lehman76c751c2014-11-18 17:36:38 -0600108 rib.beginRemoveFace(faceId);
109 }
110
Vince Lehman76c751c2014-11-18 17:36:38 -0600111 const FibUpdater::FibUpdateList&
112 getFibUpdates()
113 {
114 fibUpdates.clear();
115 fibUpdates = fibUpdater.m_updatesForBatchFaceId;
116 fibUpdates.insert(fibUpdates.end(), fibUpdater.m_updatesForNonBatchFaceId.begin(),
117 fibUpdater.m_updatesForNonBatchFaceId.end());
118
119 return fibUpdates;
Vince Lehman4387e782014-06-19 16:57:45 -0500120 }
121
Vince Lehman76c751c2014-11-18 17:36:38 -0600122 FibUpdater::FibUpdateList
Vince Lehman4387e782014-06-19 16:57:45 -0500123 getSortedFibUpdates()
124 {
Vince Lehman76c751c2014-11-18 17:36:38 -0600125 FibUpdater::FibUpdateList updates = getFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500126 updates.sort(&compareNameFaceIdCostAction);
127 return updates;
128 }
129
Vince Lehman76c751c2014-11-18 17:36:38 -0600130 void
131 clearFibUpdates()
132 {
133 fibUpdater.m_updatesForBatchFaceId.clear();
134 fibUpdater.m_updatesForNonBatchFaceId.clear();
135 }
136
Junxiao Shi52009042018-09-10 12:33:56 +0000137private:
138 void
139 simulateSuccessfulResponse()
140 {
141 rib.mockFibResponse = [] (const RibUpdateBatch&) { return true; };
142 rib.wantMockFibResponseOnce = true;
143 }
144
Vince Lehman4387e782014-06-19 16:57:45 -0500145public:
Junxiao Shi221b6fe2016-07-14 18:21:56 +0000146 ndn::util::DummyClientFace face;
Vince Lehman76c751c2014-11-18 17:36:38 -0600147 ndn::nfd::Controller controller;
Vince Lehman76c751c2014-11-18 17:36:38 -0600148
Davide Pesavento97210d52016-10-14 15:45:48 +0200149 Rib rib;
150 FibUpdater fibUpdater;
Vince Lehman76c751c2014-11-18 17:36:38 -0600151 FibUpdater::FibUpdateList fibUpdates;
Vince Lehman4387e782014-06-19 16:57:45 -0500152};
153
154} // namespace tests
155} // namespace rib
156} // namespace nfd
Davide Pesavento22db5392017-04-14 00:56:43 -0400157
158#endif // NFD_TESTS_RIB_FIB_UPDATES_COMMON_HPP