QueueSocketSourceSink.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_PPI_QueueSocketSourceSink_
18 #define HH_SENF_PPI_QueueSocketSourceSink_ 1
19 
20 // Custom includes
28 #include "QueueingSocketSink.hh"
29 #include "Module.hh"
30 #include "Connectors.hh"
31 #include "IOEvent.hh"
32 
33 #include "QueueSocketSourceSink.ih"
34 //#include "QueueSocketSourceSink.mpp"
35 //-/////////////////////////////////////////////////////////////////////////////////////////////////
36 
37 namespace senf {
38 namespace ppi {
39 
41  {
42  mutable QueueReadPolicy::Buffer const * value;
43  QueueReadPolicy::Buffer const * operator->() const;
44  };
45 
46  std::ostream & operator<<(std::ostream & os, QueueBufferAnnotation const & annotation);
47 
48  typedef std::function<bool (senf::Packet const & pkt, std::uint32_t usage)> REDFilterCallback;
49 
50 namespace module {
51 
60  template <class Packet=DataPacket,
61  class Connector=connector::ActiveOutput<Packet> >
63  : public Module
64  {
66  public:
67  typedef Packet PacketType;
71 
72  Connector output;
73 
74  explicit ActiveQueueSocketSource(unsigned burst=1);
75  explicit ActiveQueueSocketSource(Handle const & handle, unsigned burst=1);
76 
77  Handle handle() const;
78  void handle(Handle const & handle);
79 
80  unsigned maxBurst() const;
81  void maxBurst(unsigned burst);
82 
83  void flush();
84 
85 #ifdef SENF_DEBUG
86  unsigned burstMax();
87 #endif
88 
89  void setREDFilterCallback(REDFilterCallback const & cb);
90 
91  std::pair<unsigned,unsigned> dropped();
92 
93  private:
94  Handle handle_;
95  IOEvent event_;
96  REDFilterCallback redFilterCallback_;
97  unsigned maxBurst_;
98  unsigned burst_;
99  bool flushPending_;
100  unsigned red_;
101 
102 #ifdef SENF_DEBUG
103  unsigned burstMax_;
104 #endif
105 
106  void read();
107  };
108 
109  template <class Connector=connector::PassiveInput<> >
111  : public Module
112  {
114  public:
115  typedef Packet PacketType;
116  typedef senf::ClientSocketHandle<
120 
121  Connector input;
122 
124  explicit PassiveQueueSocketSink(Handle const & handle);
125 
126  Handle handle() const;
127  void handle(Handle const & handle);
128 
129  std::tuple<unsigned,unsigned,unsigned> dropped();
130 
131  void send();
132  void flush();
133 
134 #ifdef SENF_DEBUG
135  unsigned burstMax();
136 #endif
137 
138  void setREDFilterCallback(REDFilterCallback const & cb);
139 
140  private:
141  void write();
142  void writable();
143  void writePacket(senf::Packet const & packet, QueueReadPolicy::Buffer & buf);
144 
145  Handle handle_;
146  scheduler::EventHook eventHook_;
147  IOEvent writeEvent_;
148  REDFilterCallback redFilterCallback_;
149  unsigned red_;
150  unsigned dropped_;
151 
152 #ifdef SENF_DEBUG
153  unsigned burst_;
154  unsigned burstMax_;
155 #endif
156  };
157 
159  : public Module
160  {
162  public:
165 
167 
168  private:
169  void request();
170  };
171 }}}
172 
173 //-/////////////////////////////////////////////////////////////////////////////////////////////////
174 #include "QueueSocketSourceSink.cci"
175 #include "QueueSocketSourceSink.ct"
176 #include "QueueSocketSourceSink.cti"
177 #endif
178 
179 
180 // Local Variables:
181 // mode: c++
182 // fill-column: 100
183 // comment-column: 40
184 // c-file-style: "senf"
185 // indent-tabs-mode: nil
186 // ispell-local-dictionary: "american"
187 // compile-command: "scons -u test"
188 // End:
Reader for module::ActiveSocketSource (read from socket packet queue)
IOEvent public header.
Module base-class.
Definition: Module.hh:169
Connectors public header.
Module public header.
QueueingSocketSink public header.
QueueReadPolicy::Buffer const * value
connector::PassiveInput< EthernetPacket > input
connector::ActiveOutput< EthernetPacket > output
std::ostream & operator<<(std::ostream &os, QueueBufferAnnotation const &annotation)
senf::ClientSocketHandle< senf::MakeSocketPolicy< senf::QueueReadPolicy, senf::DatagramFramingPolicy >::policy > Handle
#define SENF_PPI_MODULE(name)
Define PPI Module.
Definition: Module.hh:346
FileHandle based I/O read/write event.
Definition: IOEvent.hh:61
std::function< bool(senf::Packet const &pkt, std::uint32_t usage)> REDFilterCallback
QueueReadPolicy::Buffer const * operator->() const
senf::ClientSocketHandle< senf::MakeSocketPolicy< senf::QueueWritePolicy, senf::DatagramFramingPolicy, senf::ConnectedCommunicationPolicy >::policy > Handle
ConcretePacket< DataPacketType > DataPacket