blob: c4b06019ed35ef9f577ad67a0ffdd8637eb259b8 [file] [log] [blame]
Yanbiao Lid7c96362015-01-30 23:58:24 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoe1bdc082018-10-11 21:20:23 -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
26#ifndef NFD_RIB_PROPAGATED_ENTRY_HPP
27#define NFD_RIB_PROPAGATED_ENTRY_HPP
28
Davide Pesaventoe1bdc082018-10-11 21:20:23 -040029#include "core/common.hpp"
30
31#include <ndn-cxx/util/scheduler-scoped-event-id.hpp>
Yanbiao Lid7c96362015-01-30 23:58:24 -080032
33namespace nfd {
34namespace rib {
35
36enum class PropagationStatus {
37 /// initial status
38 NEW,
39 /// is being propagated
40 PROPAGATING,
41 /// has been propagated successfully
42 PROPAGATED,
43 /// has failed in propagation
44 PROPAGATE_FAIL
45};
46
47void
48operator<<(std::ostream& out, PropagationStatus status);
49
50/**
51 * @brief represents an entry for prefix propagation.
Yanbiao Lid7c96362015-01-30 23:58:24 -080052 *
53 * it consists of a PropagationStatus indicates current state of the state machine, as
54 * well as an event scheduled for refresh or retry (i.e., the RefreshTimer and the RetryTimer of
55 * the state machine respectively). Besides, it stores a copy of signing identity for this entry.
56 */
57class PropagatedEntry
58{
59public:
Davide Pesaventoe1bdc082018-10-11 21:20:23 -040060 PropagatedEntry() = default;
Yanbiao Lid7c96362015-01-30 23:58:24 -080061
62 /**
63 * @pre other is not in PROPAGATED or PROPAGATE_FAIL state
64 */
65 PropagatedEntry(const PropagatedEntry& other);
66
67 PropagatedEntry&
68 operator=(const PropagatedEntry& other) = delete;
69
70 /**
71 * @brief set the signing identity
72 */
73 PropagatedEntry&
74 setSigningIdentity(const Name& identity);
75
76 /**
77 * @brief get the signing identity
78 *
79 * @return the signing identity
80 */
81 const Name&
82 getSigningIdentity() const;
83
84 /**
85 * @brief switch the propagation status to PROPAGATING.
86 *
87 * this is called before start the propagation process of this entry.
88 */
89 void
90 startPropagation();
91
92 /**
93 * @brief switch the propagation status to PROPAGATED, and set the
94 * rePropagateEvent to @p event for refresh.
95 *
96 * this is called just after this entry is successfully propagated.
97 */
98 void
Davide Pesaventoe1bdc082018-10-11 21:20:23 -040099 succeed(ndn::util::Scheduler& scheduler, const ndn::util::scheduler::EventId& event);
Yanbiao Lid7c96362015-01-30 23:58:24 -0800100
101 /**
102 * @brief switch the propagation status to PROPAGATE_FAIL, and then set the
103 * rePropagateEvent to @p event for retry.
104 *
105 * this is called just after propagation for this entry fails.
106 */
107 void
Davide Pesaventoe1bdc082018-10-11 21:20:23 -0400108 fail(ndn::util::Scheduler& scheduler, const ndn::util::scheduler::EventId& event);
Yanbiao Lid7c96362015-01-30 23:58:24 -0800109
110 /**
111 * @brief cancel the events of re-sending propagation commands.
112 *
113 * switch the propagation status to NEW.
114 */
115 void
116 initialize();
117
118 /**
119 * @brief check whether this entry is a new entry.
120 *
121 * @return true if current status is NEW.
122 */
123 bool
124 isNew() const;
125
126 /**
127 * @brief check whether this entry is being propagated.
128 *
129 * @return true if current status is PROPAGATING.
130 */
131 bool
132 isPropagating() const;
133
134 /**
135 * @brief check whether this entry has been successfully propagated.
136 *
137 * @return true if current status is PROPAGATED.
138 */
139 bool
140 isPropagated() const;
141
142 /**
143 * @brief check whether this entry has failed in propagating.
144 *
145 * @return true if current status is PROPAGATE_FAIL.
146 */
147 bool
148 isPropagateFail() const;
149
150PUBLIC_WITH_TESTS_ELSE_PRIVATE:
151 Name m_signingIdentity;
Davide Pesaventoe1bdc082018-10-11 21:20:23 -0400152 optional<ndn::util::scheduler::ScopedEventId> m_rePropagateEvent;
153 PropagationStatus m_propagationStatus = PropagationStatus::NEW;
Yanbiao Lid7c96362015-01-30 23:58:24 -0800154};
155
156} // namespace rib
157} // namespace nfd
158
159#endif // NFD_RIB_PROPAGATED_ENTRY_HPP