SocketSink.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_SocketSink_
18 #define HH_SENF_PPI_SocketSink_ 1
19 
20 // Custom includes
21 #include <senf/Packets/Packets.hh>
31 #include "Module.hh"
32 #include "Connectors.hh"
33 #include "IOEvent.hh"
34 
35 //#include "SocketSink.mpp"
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
37 
38 namespace senf {
39 namespace ppi {
40 
46  {
47  public:
53  typedef Packet PacketType;
54 
55  bool operator()(Handle & handle, Packet const & packet);
57 
61  };
62 
70  template <class HandleType>
72  {
73  public:
74  typedef HandleType Handle;
75  typedef Packet PacketType;
76 
78  TargetDgramWriter(typename Handle::Address const & target);
80 
81  typename Handle::Address target() const;
82  void target(typename Handle::Address const & target);
83 
84  bool operator()(Handle & handle, Packet const & packet);
85 
90  private:
91  typename Handle::Address target_;
92  };
93 
95  {
96  public:
104 
105  void source(senf::INet4Address & source);
106  senf::INet4Address source();
107  void destination(senf::INet4SocketAddress & dest);
108  senf::INet4SocketAddress destination();
109 
110  bool operator()(Handle & handle, Packet const & packet);
112 
116  private:
117  int sendtoandfrom(int sock, const void *data, size_t dataLen, const in_addr *dst, int port, const in_addr *src);
118  senf::INet4Address source_;
119  senf::INet4Address destination_;
120  unsigned int protocolId_;
121  };
122 
124  {
125  public:
128  typedef senf::ClientSocketHandle<
133 
134  void source(senf::INet6Address & source);
135  senf::INet6Address source();
136  void destination(senf::INet6SocketAddress & dest);
137  senf::INet6SocketAddress destination();
138 
139  bool operator()(Handle & handle, Packet const & packet);
141 
145  private:
146  int sendtoandfrom(int sock, const void *data, size_t dataLen, const in6_addr *dst, int port, const in6_addr *src);
147  senf::INet6Address source_;
148  senf::INet6Address destination_;
149  unsigned int protocolId_;
150  };
151 
152 
154  {
155  public:
158 
159  void source(Handle &, LLSocketAddress source);
160 
161  bool operator()(Handle & handle, Packet const & packet);
163 
167  };
168 
169 
171  {
172  public:
175 
177 
178  void target(LLSocketAddress const & target);
179 
180  bool operator()(Handle & handle, EthernetPacket const & packet);
181 
182  private:
183  LLSocketAddress target_;
184  };
185 
186 }}
187 
188 namespace senf {
189 namespace ppi {
190 namespace module {
191 
221  template <class Writer=ConnectedDgramWriter>
222  class ActiveSocketSink : public Module
223  {
225 
226  public:
227  typedef typename Writer::Handle Handle;
228 
230 
231  ActiveSocketSink();
232 
234  explicit ActiveSocketSink(Writer const & writer);
236 
240  explicit ActiveSocketSink(Handle const & handle);
242 
245  ActiveSocketSink(Handle const & handle, Writer const & writer);
247 
253  Writer & writer();
254  Handle handle();
255  void handle(Handle const & handle);
257 
260  private:
261  void write();
262 
263  Handle handle_;
264  IOEvent event_;
265  Writer writer_;
266  };
267 
299  template <class Writer=ConnectedDgramWriter>
300  class PassiveSocketSink : public Module
301  {
303 
304  public:
305  typedef typename Writer::Handle Handle;
306 
308 
310 
312  explicit PassiveSocketSink(Writer const & writer);
314 
318  explicit PassiveSocketSink(Handle const & handle);
320 
323  PassiveSocketSink(Handle const & handle, Writer const & writer);
325 
331  Writer & writer();
332  Handle & handle();
333  void handle(Handle const & handle);
335 
338  struct TxStats {
339  TxStats () {
340  clear();
341  }
342  void clear() {
343  memset(this, 0, sizeof(*this));
344  }
345  void dump(std::ostream & os) const {
346  os << "sent " << sent << ", "
347  << "error " << error << ".";
348  }
349 
350  unsigned sent;
351  unsigned error;
352  };
353 
355  return txStats_;
356  }
357 
358  private:
359  void write();
360  void checkThrottle();
361 
362  Handle handle_;
363  Writer writer_;
364  TxStats txStats_;
365  };
366 
367 }}}
368 
369 
370 //-/////////////////////////////////////////////////////////////////////////////////////////////////
371 #include "SocketSink.cci"
372 #include "SocketSink.ct"
373 #include "SocketSink.cti"
374 #endif
375 
376 
377 // Local Variables:
378 // mode: c++
379 // fill-column: 100
380 // c-file-style: "senf"
381 // indent-tabs-mode: nil
382 // ispell-local-dictionary: "american"
383 // compile-command: "scons -u test"
384 // comment-column: 40
385 // End:
senf::PacketSocketHandle Handle
Definition: SocketSink.hh:156
IOEvent public header.
Module base-class.
Definition: Module.hh:169
Connectors public header.
Module public header.
senf::ClientSocketHandle< senf::MakeSocketPolicy< senf::WriteablePolicy, senf::DatagramFramingPolicy, senf::ConnectedCommunicationPolicy >::policy > Handle
Handle type supported by this writer.
Definition: SocketSink.hh:51
bool operator()(Handle &handle, Packet const &packet)
Write packet to handle.
Writer::Handle Handle
Handle type requested by writer.
Definition: SocketSink.hh:224
senf::ClientSocketHandle< senf::MakeSocketPolicy< senf::WriteablePolicy, senf::DatagramFramingPolicy >::policy > Handle
Handle type supported by this writer.
Definition: SocketSink.hh:101
Writer::Handle Handle
Handle type requested by writer.
Definition: SocketSink.hh:302
Output module writing data to a FileHandle using the provided Writer. If using the default ConnectedD...
Definition: SocketSink.hh:222
connector::ActiveInput< typename Writer::PacketType > input
Input connector from which data is received.
Definition: SocketSink.hh:229
#define SENF_PPI_MODULE(name)
Define PPI Module.
Definition: Module.hh:346
FileHandle based I/O read/write event.
Definition: IOEvent.hh:61
ProtocolClientSocketHandle< PacketSocketProtocol > PacketSocketHandle
connector::PassiveInput< typename Writer::PacketType > input
Input connector from which data is received.
Definition: SocketSink.hh:307
Writer sending data with ClientSocketHandle::writeto()
Definition: SocketSink.hh:71
Writer for module::ActiveSocketSink / module::PassiveSocketSink.
Definition: SocketSink.hh:45
senf::ClientSocketHandle< senf::MakeSocketPolicy< senf::WriteablePolicy, senf::DatagramFramingPolicy >::policy > Handle
Handle type supported by this writer.
Definition: SocketSink.hh:130
SPolicy::AddressingPolicy::Address Address
ConcretePacket< EthernetPacketType > EthernetPacket
::phoenix::function< detail::clear > const clear
Output module writing data to a FileHandle using the provided Writer. If using the default ConnectedD...
Definition: SocketSink.hh:300