blob: e4b8c1461f1f35ed19e9f1e7c68df9864f018d3a [file] [log] [blame]
Eric Newberry38982622015-08-06 21:39:55 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento88a0d812017-08-19 21:31:42 -04002/*
3 * Copyright (c) 2013-2017 Regents of the University of California.
Eric Newberry38982622015-08-06 21:39:55 -07004 *
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
33namespace ndn {
34namespace lp {
35
36/**
37 * \brief indicates the reason type of a network NACK
38 */
39enum class NackReason {
40 NONE = 0,
41 CONGESTION = 50,
42 DUPLICATE = 100,
43 NO_ROUTE = 150
44};
45
46std::ostream&
47operator<<(std::ostream& os, NackReason reason);
48
Junxiao Shi79a7a162017-09-09 08:33:57 +000049/** \brief compare NackReason for severity
50 *
51 * lp::NackReason::NONE is treated as most severe
52 */
53bool
54isLessSevere(lp::NackReason x, lp::NackReason y);
55
Eric Newberry38982622015-08-06 21:39:55 -070056/**
57 * \brief represents a Network NACK header
58 */
59class NackHeader
60{
61public:
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
77public: // 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
92private:
93 NackReason m_reason;
94 mutable Block m_wire;
95};
96
Davide Pesavento88a0d812017-08-19 21:31:42 -040097NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(NackHeader);
98
Eric Newberry38982622015-08-06 21:39:55 -070099} // namespace lp
100} // namespace ndn
101
Davide Pesavento88a0d812017-08-19 21:31:42 -0400102#endif // NDN_CXX_LP_NACK_HEADER_HPP