NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
status-dataset-context.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
27 
28 namespace ndn {
29 namespace mgmt {
30 
31 const time::milliseconds DEFAULT_STATUS_DATASET_FRESHNESS_PERIOD = time::milliseconds(1000);
32 
33 const Name&
35 {
36  return m_prefix;
37 }
38 
41 {
42  if (!m_interest.getName().isPrefixOf(prefix)) {
43  BOOST_THROW_EXCEPTION(std::invalid_argument("prefix does not start with Interest Name"));
44  }
45 
46  if (m_state != State::INITIAL) {
47  BOOST_THROW_EXCEPTION(std::domain_error("state is not in INITIAL"));
48  }
49 
50  m_prefix = prefix;
51 
52  if (!m_prefix[-1].isVersion()) {
53  m_prefix.appendVersion();
54  }
55 
56  return *this;
57 }
58 
59 const time::milliseconds&
61 {
62  return m_expiry;
63 }
64 
66 StatusDatasetContext::setExpiry(const time::milliseconds& expiry)
67 {
68  m_expiry = expiry;
69  return *this;
70 }
71 
72 void
74 {
75  if (m_state == State::FINALIZED) {
76  BOOST_THROW_EXCEPTION(std::domain_error("state is in FINALIZED"));
77  }
78 
79  m_state = State::RESPONDED;
80 
81  size_t nBytesLeft = block.size();
82 
83  while (nBytesLeft > 0) {
84  size_t nBytesAppend = std::min(nBytesLeft,
85  (ndn::MAX_NDN_PACKET_SIZE >> 1) - m_buffer->size());
86  m_buffer->appendByteArray(block.wire() + (block.size() - nBytesLeft), nBytesAppend);
87  nBytesLeft -= nBytesAppend;
88 
89  if (nBytesLeft > 0) {
90  const Block& content = makeBinaryBlock(tlv::Content, m_buffer->buf(), m_buffer->size());
91  m_dataSender(Name(m_prefix).appendSegment(m_segmentNo++), content,
92  MetaInfo().setFreshnessPeriod(m_expiry));
93 
94  m_buffer = std::make_shared<EncodingBuffer>();
95  }
96  }
97 }
98 
99 void
101 {
102  if (m_state == State::FINALIZED) {
103  BOOST_THROW_EXCEPTION(std::domain_error("state is in FINALIZED"));
104  }
105 
106  m_state = State::FINALIZED;
107 
108  auto dataName = Name(m_prefix).appendSegment(m_segmentNo++);
109  m_dataSender(dataName, makeBinaryBlock(tlv::Content, m_buffer->buf(), m_buffer->size()),
110  MetaInfo().setFreshnessPeriod(m_expiry).setFinalBlockId(dataName[-1]));
111 }
112 
113 void
114 StatusDatasetContext::reject(const ControlResponse& resp /*= a ControlResponse with 400*/)
115 {
116  if (m_state != State::INITIAL) {
117  BOOST_THROW_EXCEPTION(std::domain_error("state is in REPONSED or FINALIZED"));
118  }
119 
120  m_state = State::FINALIZED;
121 
122  m_dataSender(m_interest.getName(), resp.wireEncode(),
123  MetaInfo().setType(tlv::ContentType_Nack));
124 }
125 
127  const DataSender& dataSender)
128  : m_interest(interest)
129  , m_dataSender(dataSender)
130  , m_expiry(DEFAULT_STATUS_DATASET_FRESHNESS_PERIOD)
131  , m_buffer(make_shared<EncodingBuffer>())
132  , m_segmentNo(0)
133  , m_state(State::INITIAL)
134 {
135  setPrefix(interest.getName());
136 }
137 
138 } // namespace mgmt
139 } // namespace ndn
StatusDatasetContext(const Interest &interest, const DataSender &dataSender)
void reject(const ControlResponse &resp=ControlResponse().setCode(400))
declare the non-existence of a response
const Name & getName() const
Definition: interest.hpp:216
Copyright (c) 2011-2015 Regents of the University of California.
StatusDatasetContext & setExpiry(const time::milliseconds &expiry)
set expiration duration
indicates a producer generated NACK
Definition: tlv.hpp:135
const time::milliseconds DEFAULT_STATUS_DATASET_FRESHNESS_PERIOD
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
represents an Interest packet
Definition: interest.hpp:45
const Block & wireEncode() const
size_t size() const
Definition: block.cpp:504
EncodingImpl< EncoderTag > EncodingBuffer
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE const Block const MetaInfo &metaInfo DataSender
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE const Block & content
Block makeBinaryBlock(uint32_t type, const uint8_t *value, size_t length)
Create a TLV block type type with value from a buffer value of size length.
void end()
end the response successfully after appending zero or more blocks
Name abstraction to represent an absolute name.
Definition: name.hpp:46
const uint8_t * wire() const
Definition: block.cpp:495
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
Definition: name.cpp:320
StatusDatasetContext & setPrefix(const Name &prefix)
change prefix of Data packets
void append(const Block &block)
append a Block to the response
ControlCommand response.
const time::milliseconds & getExpiry() const
Name & appendVersion(uint64_t version)
Append version using NDN naming conventions.
Definition: name.cpp:218
const size_t MAX_NDN_PACKET_SIZE
practical limit of network layer packet size
Definition: tlv.hpp:39