NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
lp-reassembler.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_FACE_LP_REASSEMBLER_HPP
27 #define NFD_DAEMON_FACE_LP_REASSEMBLER_HPP
28 
29 #include "core/scheduler.hpp"
30 #include "face-log.hpp"
31 #include "transport.hpp"
32 
33 #include <ndn-cxx/lp/packet.hpp>
34 
35 namespace nfd {
36 namespace face {
37 
38 class LinkService;
39 
43 class LpReassembler : noncopyable
44 {
45 public:
48  class Options
49  {
50  public:
51  Options();
52 
53  public:
58  size_t nMaxFragments;
59 
62  time::nanoseconds reassemblyTimeout;
63  };
64 
65  explicit
66  LpReassembler(const Options& options = Options(), const LinkService* linkService = nullptr);
67 
70  void
71  setOptions(const Options& options);
72 
77  const LinkService*
78  getLinkService() const;
79 
89  std::tuple<bool, Block, lp::Packet>
90  receiveFragment(Transport::EndpointId remoteEndpoint, const lp::Packet& packet);
91 
94  size_t
95  size() const;
96 
105 
106 private:
109  struct PartialPacket
110  {
111  std::vector<lp::Packet> fragments;
112  size_t fragCount;
113  size_t nReceivedFragments;
114  scheduler::ScopedEventId dropTimer;
115  };
116 
119  typedef std::tuple<
120  Transport::EndpointId, // remoteEndpoint
121  lp::Sequence // message identifier (sequence of the first fragment)
122  > Key;
123 
124  Block
125  doReassembly(const Key& key);
126 
127  void
128  timeoutPartialPacket(const Key& key);
129 
130 private:
131  Options m_options;
132  std::map<Key, PartialPacket> m_partialPackets;
133  const LinkService* m_linkService;
134 };
135 
136 std::ostream&
137 operator<<(std::ostream& os, const FaceLogHelper<LpReassembler>& flh);
138 
139 inline void
141 {
142  m_options = options;
143 }
144 
145 inline const LinkService*
147 {
148  return m_linkService;
149 }
150 
151 inline size_t
153 {
154  return m_partialPackets.size();
155 }
156 
157 } // namespace face
158 } // namespace nfd
159 
160 #endif // NFD_DAEMON_FACE_LP_REASSEMBLER_HPP
signal::Signal< LpReassembler, Transport::EndpointId, size_t > beforeTimeout
signals before a partial packet is dropped due to timeout
the upper part of a Face
size_t nMaxFragments
maximum number of fragments in a packet
LpReassembler(const Options &options=Options(), const LinkService *linkService=nullptr)
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
provides a lightweight signal / event system
Definition: signal.hpp:50
uint64_t Sequence
represents a sequence number
Definition: sequence.hpp:35
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
cancels an event automatically upon destruction
Definition: scheduler.hpp:59
reassembles fragmented network-layer packets
void setOptions(const Options &options)
set options for reassembler
Options that control the behavior of LpReassembler.
time::nanoseconds reassemblyTimeout
timeout before a partially reassembled packet is dropped
std::tuple< bool, Block, lp::Packet > receiveFragment(Transport::EndpointId remoteEndpoint, const lp::Packet &packet)
adds received fragment to buffer
const LinkService * getLinkService() const
uint64_t EndpointId
identifies an endpoint on the link
Definition: transport.hpp:118
size_t size() const
count of partial packets