blob: 34a89762eac161e0d2ce67f9737c71c0c426d73b [file] [log] [blame]
Yanbiao Lid7c96362015-01-30 23:58:24 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoa3148082018-04-12 18:21:54 -04002/*
3 * Copyright (c) 2014-2018, Regents of the University of California,
Yanbiao Lid7c96362015-01-30 23:58:24 -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.
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
Yanbiao Lid7c96362015-01-30 23:58:24 -080026#include "propagated-entry.hpp"
27
28namespace nfd {
29namespace rib {
30
31void
32operator<<(std::ostream& out, PropagationStatus status)
33{
34 switch (status) {
35 case PropagationStatus::NEW:
36 out << "NEW";
37 break;
38 case PropagationStatus::PROPAGATING:
39 out << "PROPAGATING";
40 break;
41 case PropagationStatus::PROPAGATED:
42 out << "PROPAGATED";
43 break;
44 case PropagationStatus::PROPAGATE_FAIL:
45 out << "PROPAGATE_FAIL";
46 break;
47 default:
48 out << "undefined status";
49 break;
50 }
51}
52
Yanbiao Lid7c96362015-01-30 23:58:24 -080053PropagatedEntry::PropagatedEntry(const PropagatedEntry& other)
54 : m_signingIdentity(other.m_signingIdentity)
55 , m_propagationStatus(other.m_propagationStatus)
56{
57 BOOST_ASSERT(!other.isPropagated() && !other.isPropagateFail());
58}
59
60PropagatedEntry&
61PropagatedEntry::setSigningIdentity(const Name& identity)
62{
63 m_signingIdentity = identity;
64 return *this;
65}
66
67const Name&
68PropagatedEntry::getSigningIdentity() const
69{
70 return m_signingIdentity;
71}
72
73void
74PropagatedEntry::startPropagation()
75{
76 m_propagationStatus = PropagationStatus::PROPAGATING;
77}
78
79void
Davide Pesaventoe1bdc082018-10-11 21:20:23 -040080PropagatedEntry::succeed(ndn::util::Scheduler& scheduler, const ndn::util::scheduler::EventId& event)
Yanbiao Lid7c96362015-01-30 23:58:24 -080081{
82 m_propagationStatus = PropagationStatus::PROPAGATED;
Davide Pesaventoe1bdc082018-10-11 21:20:23 -040083 m_rePropagateEvent = ndn::util::scheduler::ScopedEventId(scheduler);
84 *m_rePropagateEvent = event;
Yanbiao Lid7c96362015-01-30 23:58:24 -080085}
86
87void
Davide Pesaventoe1bdc082018-10-11 21:20:23 -040088PropagatedEntry::fail(ndn::util::Scheduler& scheduler, const ndn::util::scheduler::EventId& event)
Yanbiao Lid7c96362015-01-30 23:58:24 -080089{
90 m_propagationStatus = PropagationStatus::PROPAGATE_FAIL;
Davide Pesaventoe1bdc082018-10-11 21:20:23 -040091 m_rePropagateEvent = ndn::util::scheduler::ScopedEventId(scheduler);
92 *m_rePropagateEvent = event;
Yanbiao Lid7c96362015-01-30 23:58:24 -080093}
94
95void
96PropagatedEntry::initialize()
97{
98 m_propagationStatus = PropagationStatus::NEW;
Davide Pesaventoe1bdc082018-10-11 21:20:23 -040099 if (m_rePropagateEvent)
100 m_rePropagateEvent->cancel();
Yanbiao Lid7c96362015-01-30 23:58:24 -0800101}
102
103bool
104PropagatedEntry::isNew() const
105{
106 return PropagationStatus::NEW == m_propagationStatus;
107}
108
109bool
110PropagatedEntry::isPropagating() const
111{
112 return PropagationStatus::PROPAGATING == m_propagationStatus;
113}
114
115bool
116PropagatedEntry::isPropagated() const
117{
118 return PropagationStatus::PROPAGATED == m_propagationStatus;
119}
120
121bool
122PropagatedEntry::isPropagateFail() const
123{
124 return PropagationStatus::PROPAGATE_FAIL == m_propagationStatus;
125}
126
127} // namespace rib
128} // namespace nfd