QueueReadWritePolicy.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_Socket_QueueReadWritePolicy_
18 #define HH_SENF_Socket_QueueReadWritePolicy_ 1
19 
20 // Custom includes
21 #include <linux/if_packet.h>
22 #include <boost/optional.hpp>
24 #include "SocketPolicy.hh"
25 #include "FileHandle.hh"
26 
27 //#include "QueueReadWritePolicy.mpp"
28 #include "QueueReadWritePolicy.ih"
29 //-/////////////////////////////////////////////////////////////////////////////////////////////////
30 
31 namespace senf {
32 
33  struct QueueReadPolicy;
34  struct QueueWritePolicy;
35 
50  {
51  public:
52  typedef unsigned char * iterator;
53  typedef unsigned char const * const_iterator;
54  typedef std::size_t size_type;
55 
57 
58  iterator begin();
59  iterator end();
60  const_iterator begin() const;
61  const_iterator end() const;
62  size_type size() const;
63  bool empty() const;
64 
65  iterator frameBegin();
66  iterator frameEnd();
67  const_iterator frameBegin() const;
68  const_iterator frameEnd() const;
69  size_type frameSize() const;
70 
71  unsigned dataOffset() const;
72 
75  std::uint32_t const * timestampPtr() const;
79  boost::optional<unsigned> vlan() const;
81  unsigned tpid() const;
83 
84  void resize(size_type sz
85 #ifdef SENF_ENABLE_TPACKET_OFFSET
86  , int offset=-1
87 #endif
88  );
89 
90  private:
91  SocketQueueBuffer(unsigned char * b, unsigned char * e, unsigned hdrlen);
92 
93  struct ::tpacket2_hdr & hdr();
94  struct ::tpacket2_hdr const & hdr() const;
95 
96  unsigned char * b_;
97  unsigned char * e_;
98  unsigned hdrlen_;
99 
100  friend struct QueueReadPolicy;
101  friend struct QueueWritePolicy;
102  };
103 
105  //\{
106 
112  : public ReadPolicyBase,
113  private detail::QueuePolicyBase
114  {
117 
118  static boost::optional<Buffer> dequeue(FileHandle & handle);
119  static void release(FileHandle & handle);
120 
121  // classic read API
122  static unsigned read(FileHandle & handle, char * buffer, unsigned size);
123  };
124 
130  : public WritePolicyBase,
131  private detail::QueuePolicyBase
132  {
135 
136  static boost::optional<Buffer> enqueue(FileHandle & handle);
137  static bool send(FileHandle & handle);
138  static void flush(FileHandle & handle);
139 
140  // classic write API
141  static unsigned write(FileHandle & handle, char const * buffer, unsigned size);
142  };
143 
144  //\}
145 }
146 
147 //-/////////////////////////////////////////////////////////////////////////////////////////////////
148 #include "QueueReadWritePolicy.cci"
149 //#include "QueueReadWritePolicy.ct"
150 //#include "QueueReadWritePolicy.cti"
151 #endif
152 
153 
154 // Local Variables:
155 // mode: c++
156 // fill-column: 100
157 // comment-column: 40
158 // c-file-style: "senf"
159 // indent-tabs-mode: nil
160 // ispell-local-dictionary: "american"
161 // compile-command: "scons -u test"
162 // End:
config::time_type clock_type
unsigned tpid() const
return the preprocessed VLAN TPID
unsigned char const * const_iterator
Policy Framework public header.
WritePolicy for sockets writeable via packet queue API.
void resize(size_type sz)
resize active packet data to given size
ReadPolicy for sockets readable via packet queue API.
Basic file handle wrapper.
Definition: FileHandle.hh:102
size_type size() const
Link local address.
Definition: LLAddressing.hh:46
LLSocketAddress and LLAddressingPolicy public header.
SocketQueueBuffer::size_type size_type
SocketQueueBuffer::size_type size_type
Policy defining the readability.
size_type frameSize() const
senf::ClockService::clock_type timestamp() const
return packet receive timestamp
senf::LLSocketAddress address() const
return incoming interface address
boost::optional< unsigned > vlan() const
return the preprocessed VLAN TCI if any
FileHandle public header.
unsigned dataOffset() const
std::uint32_t const * timestampPtr() const
return a pointer to the tp_hdr sec/nsec fieldes
Buffer used by QueueReadPolicy / QueueWritePolicy.
Policy defining the writability.