blob: f3edd8f72624ff37bd09d88616d429bb6ac58d48 [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
Vince Lehman218be0a2015-01-15 17:25:20 -060030inline Route
31createRoute(uint64_t faceId, uint64_t origin, uint64_t cost, uint64_t flags)
Vince Lehman4387e782014-06-19 16:57:45 -050032{
Vince Lehman218be0a2015-01-15 17:25:20 -060033 Route temp;
Vince Lehman4387e782014-06-19 16:57:45 -050034 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
Vince Lehman218be0a2015-01-15 17:25:20 -060076 insertRoute(const Name& name, uint64_t faceId, uint64_t origin, uint64_t cost, uint64_t flags)
Vince Lehman4387e782014-06-19 16:57:45 -050077 {
Vince Lehman218be0a2015-01-15 17:25:20 -060078 rib::Route route;
79 route.faceId = faceId;
80 route.origin = origin;
81 route.cost = cost;
82 route.flags = flags;
Vince Lehman4387e782014-06-19 16:57:45 -050083
Vince Lehman218be0a2015-01-15 17:25:20 -060084 rib.insert(name, route);
Vince Lehman4387e782014-06-19 16:57:45 -050085 }
86
87 void
Vince Lehman218be0a2015-01-15 17:25:20 -060088 eraseRoute(const Name& name, uint64_t faceId, uint64_t origin)
Vince Lehman4387e782014-06-19 16:57:45 -050089 {
Vince Lehman218be0a2015-01-15 17:25:20 -060090 rib::Route route;
91 route.faceId = faceId;
92 route.origin = origin;
Vince Lehman4387e782014-06-19 16:57:45 -050093
Vince Lehman218be0a2015-01-15 17:25:20 -060094 rib.erase(name, route);
Vince Lehman4387e782014-06-19 16:57:45 -050095 }
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