blob: 53e0138b205537511214c6583df33aa0856214b4 [file] [log] [blame]
Junxiao Shi4b469982015-12-03 18:20:19 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2015 Regents of the University of California.
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
22#include "tags.hpp"
23#include "../encoding/nfd-constants.hpp"
24
25namespace ndn {
26namespace lp {
27
28#ifdef NDN_LP_KEEP_LOCAL_CONTROL_HEADER
29
30using ndn::nfd::INVALID_FACE_ID;
31
32LocalControlHeaderFacade::LocalControlHeaderFacade(TagHost& pkt)
33 : m_pkt(pkt)
34{
35}
36
37bool
38LocalControlHeaderFacade::hasIncomingFaceId() const
39{
40 return m_pkt.getTag<IncomingFaceIdTag>() != nullptr;
41}
42
43uint64_t
44LocalControlHeaderFacade::getIncomingFaceId() const
45{
46 shared_ptr<IncomingFaceIdTag> tag = m_pkt.getTag<IncomingFaceIdTag>();
47 if (tag == nullptr) {
48 return INVALID_FACE_ID;
49 }
50 return *tag;
51}
52
53void
54LocalControlHeaderFacade::setIncomingFaceId(uint64_t incomingFaceId)
55{
56 if (incomingFaceId == INVALID_FACE_ID) {
57 m_pkt.removeTag<IncomingFaceIdTag>();
58 return;
59 }
60
61 auto tag = make_shared<IncomingFaceIdTag>(incomingFaceId);
62 m_pkt.setTag(tag);
63}
64
65bool
66LocalControlHeaderFacade::hasNextHopFaceId() const
67{
68 return m_pkt.getTag<NextHopFaceIdTag>() != nullptr;
69}
70
71uint64_t
72LocalControlHeaderFacade::getNextHopFaceId() const
73{
74 shared_ptr<NextHopFaceIdTag> tag = m_pkt.getTag<NextHopFaceIdTag>();
75 if (tag == nullptr) {
76 return INVALID_FACE_ID;
77 }
78 return *tag;
79}
80
81void
82LocalControlHeaderFacade::setNextHopFaceId(uint64_t nextHopFaceId)
83{
84 if (nextHopFaceId == INVALID_FACE_ID) {
85 m_pkt.removeTag<NextHopFaceIdTag>();
86 return;
87 }
88
89 auto tag = make_shared<NextHopFaceIdTag>(nextHopFaceId);
90 m_pkt.setTag(tag);
91}
92
93bool
94LocalControlHeaderFacade::hasCachingPolicy() const
95{
96 return m_pkt.getTag<CachePolicyTag>() != nullptr;
97}
98
99LocalControlHeaderFacade::CachingPolicy
100LocalControlHeaderFacade::getCachingPolicy() const
101{
102 shared_ptr<CachePolicyTag> tag = m_pkt.getTag<CachePolicyTag>();
103 if (tag == nullptr) {
104 return INVALID_POLICY;
105 }
106 switch (tag->get().getPolicy()) {
107 case CachePolicyType::NO_CACHE:
108 return NO_CACHE;
109 default:
110 return INVALID_POLICY;
111 }
112}
113
114void
115LocalControlHeaderFacade::setCachingPolicy(CachingPolicy cachingPolicy)
116{
117 switch (cachingPolicy) {
118 case NO_CACHE: {
119 m_pkt.setTag(make_shared<CachePolicyTag>(CachePolicy().setPolicy(CachePolicyType::NO_CACHE)));
120 break;
121 }
122 default:
123 m_pkt.removeTag<CachePolicyTag>();
124 break;
125 }
126}
127
128#endif // NDN_LP_KEEP_LOCAL_CONTROL_HEADER
129
130} // namespace lp
131} // namespace ndn