Eric Newberry | 3898262 | 2015-08-06 21:39:55 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Eric Newberry | 3898262 | 2015-08-06 21:39:55 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | * |
| 21 | * @author Eric Newberry <enewberry@email.arizona.edu> |
| 22 | */ |
| 23 | |
| 24 | #ifndef NDN_CXX_LP_NACK_HEADER_HPP |
| 25 | #define NDN_CXX_LP_NACK_HEADER_HPP |
| 26 | |
| 27 | #include "../common.hpp" |
| 28 | #include "../encoding/encoding-buffer.hpp" |
| 29 | #include "../encoding/block-helpers.hpp" |
| 30 | |
| 31 | #include "tlv.hpp" |
| 32 | |
| 33 | namespace ndn { |
| 34 | namespace lp { |
| 35 | |
| 36 | /** |
| 37 | * \brief indicates the reason type of a network NACK |
| 38 | */ |
| 39 | enum class NackReason { |
| 40 | NONE = 0, |
| 41 | CONGESTION = 50, |
| 42 | DUPLICATE = 100, |
| 43 | NO_ROUTE = 150 |
| 44 | }; |
| 45 | |
| 46 | std::ostream& |
| 47 | operator<<(std::ostream& os, NackReason reason); |
| 48 | |
Junxiao Shi | 79a7a16 | 2017-09-09 08:33:57 +0000 | [diff] [blame^] | 49 | /** \brief compare NackReason for severity |
| 50 | * |
| 51 | * lp::NackReason::NONE is treated as most severe |
| 52 | */ |
| 53 | bool |
| 54 | isLessSevere(lp::NackReason x, lp::NackReason y); |
| 55 | |
Eric Newberry | 3898262 | 2015-08-06 21:39:55 -0700 | [diff] [blame] | 56 | /** |
| 57 | * \brief represents a Network NACK header |
| 58 | */ |
| 59 | class NackHeader |
| 60 | { |
| 61 | public: |
| 62 | NackHeader(); |
| 63 | |
| 64 | explicit |
| 65 | NackHeader(const Block& block); |
| 66 | |
| 67 | template<encoding::Tag TAG> |
| 68 | size_t |
| 69 | wireEncode(EncodingImpl<TAG>& encoder) const; |
| 70 | |
| 71 | const Block& |
| 72 | wireEncode() const; |
| 73 | |
| 74 | void |
| 75 | wireDecode(const Block& wire); |
| 76 | |
| 77 | public: // reason |
| 78 | /** |
| 79 | * \return reason code |
| 80 | * \retval NackReason::NONE if NackReason element does not exist or has an unknown code |
| 81 | */ |
| 82 | NackReason |
| 83 | getReason() const; |
| 84 | |
| 85 | /** |
| 86 | * \brief set reason code |
| 87 | * \param reason a reason code; NackReason::NONE clears the reason |
| 88 | */ |
| 89 | NackHeader& |
| 90 | setReason(NackReason reason); |
| 91 | |
| 92 | private: |
| 93 | NackReason m_reason; |
| 94 | mutable Block m_wire; |
| 95 | }; |
| 96 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 97 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(NackHeader); |
| 98 | |
Eric Newberry | 3898262 | 2015-08-06 21:39:55 -0700 | [diff] [blame] | 99 | } // namespace lp |
| 100 | } // namespace ndn |
| 101 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 102 | #endif // NDN_CXX_LP_NACK_HEADER_HPP |