Yanbiao Li | d7c9636 | 2015-01-30 23:58:24 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame^] | 2 | /* |
| 3 | * Copyright (c) 2014-2018, Regents of the University of California, |
Yanbiao Li | d7c9636 | 2015-01-30 23:58:24 -0800 | [diff] [blame] | 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 | |
| 26 | #ifndef NFD_RIB_PROPAGATED_ENTRY_HPP |
| 27 | #define NFD_RIB_PROPAGATED_ENTRY_HPP |
| 28 | |
Davide Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame^] | 29 | #include "core/common.hpp" |
| 30 | |
| 31 | #include <ndn-cxx/util/scheduler-scoped-event-id.hpp> |
Yanbiao Li | d7c9636 | 2015-01-30 23:58:24 -0800 | [diff] [blame] | 32 | |
| 33 | namespace nfd { |
| 34 | namespace rib { |
| 35 | |
| 36 | enum 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 | |
| 47 | void |
| 48 | operator<<(std::ostream& out, PropagationStatus status); |
| 49 | |
| 50 | /** |
| 51 | * @brief represents an entry for prefix propagation. |
Yanbiao Li | d7c9636 | 2015-01-30 23:58:24 -0800 | [diff] [blame] | 52 | * |
| 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 | */ |
| 57 | class PropagatedEntry |
| 58 | { |
| 59 | public: |
Davide Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame^] | 60 | PropagatedEntry() = default; |
Yanbiao Li | d7c9636 | 2015-01-30 23:58:24 -0800 | [diff] [blame] | 61 | |
| 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 Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame^] | 99 | succeed(ndn::util::Scheduler& scheduler, const ndn::util::scheduler::EventId& event); |
Yanbiao Li | d7c9636 | 2015-01-30 23:58:24 -0800 | [diff] [blame] | 100 | |
| 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 Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame^] | 108 | fail(ndn::util::Scheduler& scheduler, const ndn::util::scheduler::EventId& event); |
Yanbiao Li | d7c9636 | 2015-01-30 23:58:24 -0800 | [diff] [blame] | 109 | |
| 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 | |
| 150 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 151 | Name m_signingIdentity; |
Davide Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame^] | 152 | optional<ndn::util::scheduler::ScopedEventId> m_rePropagateEvent; |
| 153 | PropagationStatus m_propagationStatus = PropagationStatus::NEW; |
Yanbiao Li | d7c9636 | 2015-01-30 23:58:24 -0800 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | } // namespace rib |
| 157 | } // namespace nfd |
| 158 | |
| 159 | #endif // NFD_RIB_PROPAGATED_ENTRY_HPP |