DABC (Data Acquisition Backbone Core)  2.9.9
UdpTransport.h
Go to the documentation of this file.
1 // $Id: UdpTransport.h 4543 2020-06-10 07:21:48Z linev $
2 
3 /********************************************************************
4  * The Data Acquisition Backbone Core (DABC)
5  ********************************************************************
6  * Copyright (C) 2009-
7  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
8  * Planckstr. 1
9  * 64291 Darmstadt
10  * Germany
11  * Contact: http://dabc.gsi.de
12  ********************************************************************
13  * This software can be used under the GPL license agreements as stated
14  * in LICENSE.txt file which is part of the distribution.
15  ********************************************************************/
16 
17 #ifndef HADAQ_UDPTRANSPORT_H
18 #define HADAQ_UDPTRANSPORT_H
19 
20 #ifndef DABC_SocketThread
21 #include "dabc/SocketThread.h"
22 #endif
23 
24  #ifndef DABC_Pointer
25 #include "dabc/Pointer.h"
26 #endif
27 
28 #ifndef DABC_DataTransport
29 #include "dabc/DataTransport.h"
30 #endif
31 
32 #ifndef HADAQ_HadaqTypeDefs
33 #include "hadaq/HadaqTypeDefs.h"
34 #endif
35 
36 namespace hadaq {
37 
38  class DataTransport;
39  class NewTransport;
40  class TerminalModule;
41 
42  struct TransportInfo {
43  int fNPort;
44 
45  uint64_t fTotalRecvPacket;
50  uint64_t fTotalRecvBytes;
53 
55  {
56  fTotalRecvPacket = 0;
61  fTotalRecvBytes = 0;
64  }
65 
66  TransportInfo(int port) : fNPort(port) { ClearCounters(); }
67 
68  std::string GetDiscardString()
69  {
70  std::string res = dabc::number_to_str(fTotalDiscardPacket);
71 
72  if (fTotalArtificialLosts > 0)
73  res = std::string("*") + dabc::number_to_str(fTotalArtificialLosts);
74 
75  return res;
76  }
77 
78  std::string GetDiscard32String()
79  {
80 
81  std::string res = dabc::number_to_str(fTotalDiscard32Packet);
82 
83  if (fTotalArtificialSkip > 0)
84  res = std::string("#") + dabc::number_to_str(fTotalArtificialSkip);
85 
86  return res;
87  }
88 
89  };
90 
91  // ==================================================================================
92 
93  class NewAddon : public dabc::SocketAddon,
94  public TransportInfo {
95  protected:
96 
97  friend class TerminalModule; // use only to access statistic, nothing else
98  friend class NewTransport;
99 
101  unsigned fMTU;
102  void* fMtuBuffer;
103  int fSkipCnt;
104  int fSendCnt;
106  double fReduce;
107  double fLostRate;
108  int fLostCnt;
109  bool fDebug;
110  bool fRunning;
112  double fMaxProcDist;
113 
114  virtual void ProcessEvent(const dabc::EventId&);
115 
117  virtual long Notify(const std::string&, int);
118 
119  /* Use codes which are valid for Read_Start */
120  bool ReadUdp();
121 
122  bool CloseBuffer();
123 
124  public:
125  NewAddon(int fd, int nport, int mtu, bool debug, int maxloop, double reduce, double lost);
126  virtual ~NewAddon();
127 
128  bool HasBuffer() const { return !fTgtPtr.null(); }
129 
130  static int OpenUdp(const std::string &host, int nport, int rcvbuflen);
131  };
132 
133  // ==================================================================================
134 
135  class NewTransport : public dabc::Transport {
136 
137  protected:
138 
139  int fIdNumber;
140  unsigned fNumReadyBufs;
144 
145  virtual void ProcessTimerEvent(unsigned timer);
146 
147  virtual int ExecuteCommand(dabc::Command cmd);
148 
149  public:
150  NewTransport(dabc::Command, const dabc::PortRef& inpport, NewAddon* addon, double flush = 1, double heartbeat = -1);
151  virtual ~NewTransport();
152 
154  virtual bool StartTransport();
155  virtual bool StopTransport();
156 
157  virtual bool ProcessSend(unsigned port);
158  virtual bool ProcessBuffer(unsigned pool);
159 
160  bool AssignNewBuffer(unsigned pool, NewAddon* addon = nullptr);
161  void BufferReady();
162  void FlushBuffer(bool onclose = false);
163 
164  };
165 
166 }
167 
168 #endif
Represents command with its arguments.
Definition: Command.h:99
Manipulator with dabc::Buffer class.
Definition: Pointer.h:34
bool null() const
Definition: Pointer.h:147
Reference on the dabc::Port class
Definition: Port.h:195
Special addon class for handling of socket and socket events.
Definition: SocketThread.h:52
Base class for transport implementations.
Definition: Transport.h:37
dabc::TimeStamp fLastProcTm
last time when udp reading was performed
Definition: UdpTransport.h:111
virtual ~NewAddon()
int fSendCnt
counter of send buffers since last timeout active
Definition: UdpTransport.h:104
int fSkipCnt
counter used to control buffers skipping
Definition: UdpTransport.h:103
int fLostCnt
counter used to drop buffers
Definition: UdpTransport.h:108
double fMaxProcDist
maximal time between calls to BuildEvent method
Definition: UdpTransport.h:112
NewAddon(int fd, int nport, int mtu, bool debug, int maxloop, double reduce, double lost)
unsigned fMTU
maximal size of packet expected from TRB
Definition: UdpTransport.h:101
virtual long Notify(const std::string &, int)
Light-weight command interface.
void * fMtuBuffer
buffer used to skip packets when no normal buffer is available
Definition: UdpTransport.h:102
int fMaxLoopCnt
maximal number of UDP packets, read at once
Definition: UdpTransport.h:105
double fReduce
reduce filled buffer size to let reformat data later
Definition: UdpTransport.h:106
bool fDebug
when true, produce more debug output
Definition: UdpTransport.h:109
static int OpenUdp(const std::string &host, int nport, int rcvbuflen)
virtual void ProcessEvent(const dabc::EventId &)
bool HasBuffer() const
Definition: UdpTransport.h:128
double fLostRate
artificial lost of received UDP packets
Definition: UdpTransport.h:107
dabc::Pointer fTgtPtr
pointer used to read data
Definition: UdpTransport.h:100
bool fRunning
is transport running
Definition: UdpTransport.h:110
int fLastSendCnt
used for flushing
Definition: UdpTransport.h:142
bool fBufAssigned
if next buffer assigned
Definition: UdpTransport.h:141
bool AssignNewBuffer(unsigned pool, NewAddon *addon=nullptr)
virtual bool ProcessBuffer(unsigned pool)
Method called by framework when at least one buffer available in pool handle.
void FlushBuffer(bool onclose=false)
virtual bool StartTransport()
Methods activated by Port, when transport starts/stops.
dabc::TimeStamp fLastDebugTm
timer used to generate rare debugs output
Definition: UdpTransport.h:143
virtual bool ProcessSend(unsigned port)
Method called by framework when at least one buffer can be send to output port.
virtual void ProcessTimerEvent(unsigned timer)
Method called by framework when timer event is produced.
virtual int ExecuteCommand(dabc::Command cmd)
Main method where commands are executed.
unsigned fNumReadyBufs
number of filled buffers which could be posted
Definition: UdpTransport.h:140
NewTransport(dabc::Command, const dabc::PortRef &inpport, NewAddon *addon, double flush=1, double heartbeat=-1)
int fIdNumber
input port item id
Definition: UdpTransport.h:139
virtual bool StopTransport()
Terminal for HADAQ event builder.
std::string number_to_str(unsigned long num, int prec=1, int select=0)
Convert number to string of form like 4.2G or 3.7M.
Definition: string.cxx:107
Support for HADAQ - HADES DAQ
Definition: api.h:27
Event structure, exchanged between DABC threads.
Definition: Thread.h:70
Class for acquiring and holding timestamps.
Definition: timing.h:40
int fNPort
upd port number
Definition: UdpTransport.h:43
uint64_t fTotalDiscardPacket
Definition: UdpTransport.h:46
uint64_t fTotalRecvPacket
Definition: UdpTransport.h:45
uint64_t fTotalArtificialSkip
Definition: UdpTransport.h:49
uint64_t fTotalProducedBuffers
Definition: UdpTransport.h:52
uint64_t fTotalDiscard32Packet
Definition: UdpTransport.h:47
std::string GetDiscard32String()
Definition: UdpTransport.h:78
uint64_t fTotalRecvBytes
Definition: UdpTransport.h:50
uint64_t fTotalArtificialLosts
Definition: UdpTransport.h:48
std::string GetDiscardString()
Definition: UdpTransport.h:68
uint64_t fTotalDiscardBytes
Definition: UdpTransport.h:51
TransportInfo(int port)
Definition: UdpTransport.h:66