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