NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
tags.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "tags.hpp"
23 #include "../encoding/nfd-constants.hpp"
24 
25 namespace ndn {
26 namespace lp {
27 
28 #ifdef NDN_LP_KEEP_LOCAL_CONTROL_HEADER
29 
31 
32 LocalControlHeaderFacade::LocalControlHeaderFacade(TagHost& pkt)
33  : m_pkt(pkt)
34 {
35 }
36 
37 bool
39 {
40  return m_pkt.getTag<IncomingFaceIdTag>() != nullptr;
41 }
42 
43 uint64_t
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 
53 void
55 {
56  if (incomingFaceId == INVALID_FACE_ID) {
58  return;
59  }
60 
61  auto tag = make_shared<IncomingFaceIdTag>(incomingFaceId);
62  m_pkt.setTag(tag);
63 }
64 
65 bool
67 {
68  return m_pkt.getTag<NextHopFaceIdTag>() != nullptr;
69 }
70 
71 uint64_t
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 
81 void
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 
93 bool
95 {
96  return m_pkt.getTag<CachePolicyTag>() != nullptr;
97 }
98 
101 {
102  shared_ptr<CachePolicyTag> tag = m_pkt.getTag<CachePolicyTag>();
103  if (tag == nullptr) {
104  return INVALID_POLICY;
105  }
106  switch (tag->get().getPolicy()) {
108  return NO_CACHE;
109  default:
110  return INVALID_POLICY;
111  }
112 }
113 
114 void
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
void setTag(shared_ptr< T > tag) const
set a tag item
Definition: tag-host.hpp:80
Copyright (c) 2011-2015 Regents of the University of California.
shared_ptr< T > getTag() const
get a tag item
Definition: tag-host.hpp:67
void removeTag() const
remove tag item
Definition: tag-host.hpp:94
bool hasIncomingFaceId() const
Definition: tags.cpp:38
uint64_t getIncomingFaceId() const
Definition: tags.cpp:44
void setCachingPolicy(CachingPolicy cachingPolicy)
Definition: tags.cpp:115
provides a tag type for simple types
Definition: tag.hpp:58
uint64_t getNextHopFaceId() const
Definition: tags.cpp:72
CachingPolicy getCachingPolicy() const
Definition: tags.cpp:100
void setIncomingFaceId(uint64_t incomingFaceId)
Definition: tags.cpp:54
void setNextHopFaceId(uint64_t nextHopFaceId)
Definition: tags.cpp:82
static const uint64_t INVALID_FACE_ID