blob: c8c0af4f9eeff00a3a0d94f53f4db029e0abd35c [file] [log] [blame]
Vince Lehman4387e782014-06-19 16:57:45 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, 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
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
26namespace nfd {
27namespace rib {
28namespace tests {
29
30inline FaceEntry
31createFaceEntry(uint64_t faceId, uint64_t origin, uint64_t cost, uint64_t flags)
32{
33 FaceEntry temp;
34 temp.faceId = faceId;
35 temp.origin = origin;
36 temp.cost = cost;
37 temp.flags = flags;
38
39 return temp;
40}
41
42inline bool
43compareNameFaceIdCostAction(const shared_ptr<const FibUpdate>& lhs,
44 const shared_ptr<const FibUpdate>& rhs)
45{
46 if (lhs->name < rhs->name)
47 {
48 return true;
49 }
50 else if (lhs->name == rhs->name)
51 {
52 if (lhs->faceId < rhs->faceId)
53 {
54 return true;
55 }
56 else if (lhs->faceId == rhs->faceId)
57 {
58 if (lhs->cost < rhs->cost)
59 {
60 return true;
61 }
62 else if (lhs->cost == rhs->cost)
63 {
64 return lhs->action < rhs->action;
65 }
66 }
67 }
68
69 return false;
70}
71
72class FibUpdatesFixture : public nfd::tests::BaseFixture
73{
74public:
75 void
76 insertFaceEntry(const Name& name, uint64_t faceId, uint64_t origin, uint64_t cost, uint64_t flags)
77 {
78 rib::FaceEntry faceEntry;
79 faceEntry.faceId = faceId;
80 faceEntry.origin = origin;
81 faceEntry.cost = cost;
82 faceEntry.flags = flags;
83
84 rib.insert(name, faceEntry);
85 }
86
87 void
88 eraseFaceEntry(const Name& name, uint64_t faceId, uint64_t origin)
89 {
90 rib::FaceEntry faceEntry;
91 faceEntry.faceId = faceId;
92 faceEntry.origin = origin;
93
94 rib.erase(name, faceEntry);
95 }
96
97
98 Rib::FibUpdateList
99 getSortedFibUpdates()
100 {
101 Rib::FibUpdateList updates = rib.getFibUpdates();
102 updates.sort(&compareNameFaceIdCostAction);
103 return updates;
104 }
105
106public:
107 rib::Rib rib;
108};
109
110} // namespace tests
111} // namespace rib
112} // namespace nfd