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 | |
| 49 | /** |
| 50 | * \brief represents a Network NACK header |
| 51 | */ |
| 52 | class NackHeader |
| 53 | { |
| 54 | public: |
| 55 | NackHeader(); |
| 56 | |
| 57 | explicit |
| 58 | NackHeader(const Block& block); |
| 59 | |
| 60 | template<encoding::Tag TAG> |
| 61 | size_t |
| 62 | wireEncode(EncodingImpl<TAG>& encoder) const; |
| 63 | |
| 64 | const Block& |
| 65 | wireEncode() const; |
| 66 | |
| 67 | void |
| 68 | wireDecode(const Block& wire); |
| 69 | |
| 70 | public: // reason |
| 71 | /** |
| 72 | * \return reason code |
| 73 | * \retval NackReason::NONE if NackReason element does not exist or has an unknown code |
| 74 | */ |
| 75 | NackReason |
| 76 | getReason() const; |
| 77 | |
| 78 | /** |
| 79 | * \brief set reason code |
| 80 | * \param reason a reason code; NackReason::NONE clears the reason |
| 81 | */ |
| 82 | NackHeader& |
| 83 | setReason(NackReason reason); |
| 84 | |
| 85 | private: |
| 86 | NackReason m_reason; |
| 87 | mutable Block m_wire; |
| 88 | }; |
| 89 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 90 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(NackHeader); |
| 91 | |
Eric Newberry | 3898262 | 2015-08-06 21:39:55 -0700 | [diff] [blame] | 92 | } // namespace lp |
| 93 | } // namespace ndn |
| 94 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 95 | #endif // NDN_CXX_LP_NACK_HEADER_HPP |