This is Unofficial EPICS BASE Doxygen Site
bhe Class Reference

#include "bhe.h"

+ Inheritance diagram for bhe:
+ Collaboration diagram for bhe:

Public Member Functions

LIBCA_API bhe (epicsMutex &, const epicsTime &initialTimeStamp, unsigned initialBeaconNumber, const inetAddrID &addr)
 
LIBCA_API ~bhe ()
 
LIBCA_API bool updatePeriod (epicsGuard< epicsMutex > &, const epicsTime &programBeginTime, const epicsTime &currentTime, ca_uint32_t beaconNumber, unsigned protocolRevision)
 
LIBCA_API double period (epicsGuard< epicsMutex > &) const
 
LIBCA_API epicsTime updateTime (epicsGuard< epicsMutex > &) const
 
LIBCA_API void show (unsigned level) const
 
LIBCA_API void show (epicsGuard< epicsMutex > &, unsigned) const
 
LIBCA_API void registerIIU (epicsGuard< epicsMutex > &, tcpiiu &)
 
LIBCA_API void unregisterIIU (epicsGuard< epicsMutex > &, tcpiiu &)
 
LIBCA_API void * operator new (size_t size, bheMemoryManager &)
 
- Public Member Functions inherited from tsSLNode< bhe >
 tsSLNode ()
 
tsSLNode< bhe > & operator= (const tsSLNode< bhe > &)
 
- Public Member Functions inherited from inetAddrID
 inetAddrID (const struct sockaddr_in &addrIn)
 
bool operator== (const inetAddrID &) const
 
resTableIndex hash () const
 
void name (char *pBuf, unsigned bufSize) const
 

Detailed Description

Definition at line 45 of file bhe.h.

Constructor & Destructor Documentation

bhe::bhe ( epicsMutex &  mutexIn,
const epicsTime &  initialTimeStamp,
unsigned  initialBeaconNumber,
const inetAddrID addr 
)

Definition at line 48 of file bhe.cpp.

49  :
50  inetAddrID ( addr ), timeStamp ( initialTimeStamp ), averagePeriod ( - DBL_MAX ),
51  mutex ( mutexIn ), pIIU ( 0 ), lastBeaconNumber ( initialBeaconNumber )
52 {
53 # ifdef DEBUG
54  {
55  char name[64];
56  addr.name ( name, sizeof ( name ) );
57  ::printf ( "created beacon entry for %s\n", name );
58  }
59 # endif
60 }
#define printf
Definition: epicsStdio.h:41
inetAddrID(const struct sockaddr_in &addrIn)
Definition: inetAddrID.h:37
void name(char *pBuf, unsigned bufSize) const
Definition: inetAddrID.h:64
bhe::~bhe ( )

Definition at line 62 of file bhe.cpp.

63 {
64 }

Member Function Documentation

void * bhe::operator new ( size_t  size,
bheMemoryManager mgr 
)
inline

Definition at line 96 of file bhe.h.

98 {
99  return mgr.allocate ( size );
100 }
virtual void * allocate(size_t)=0
double bhe::period ( epicsGuard< epicsMutex > &  guard) const

Definition at line 302 of file bhe.cpp.

303 {
304  guard.assertIdenticalMutex ( this->mutex );
305  return this->averagePeriod;
306 }
void assertIdenticalMutex(const T &) const
Definition: epicsGuard.h:80
void bhe::registerIIU ( epicsGuard< epicsMutex > &  guard,
tcpiiu iiu 
)

Definition at line 314 of file bhe.cpp.

316 {
317  guard.assertIdenticalMutex ( this->mutex );
318  this->pIIU = & iiu;
319 }
void assertIdenticalMutex(const T &) const
Definition: epicsGuard.h:80
void bhe::show ( unsigned  level) const

Definition at line 276 of file bhe.cpp.

277 {
278  epicsGuard < epicsMutex > guard ( this->mutex );
279  this->show ( guard, level );
280 }
LIBCA_API void show(unsigned level) const
Definition: bhe.cpp:276
void bhe::show ( epicsGuard< epicsMutex > &  ,
unsigned  level 
) const

Definition at line 282 of file bhe.cpp.

283 {
284  char host [64];
285  this->name ( host, sizeof ( host ) );
286  if ( this->averagePeriod == -DBL_MAX ) {
287  ::printf ( "CA beacon hash entry for %s <no period estimate>\n",
288  host );
289  }
290  else {
291  ::printf ( "CA beacon hash entry for %s with period estimate %f\n",
292  host, this->averagePeriod );
293  }
294  if ( level > 0u ) {
295  char date[64];
296  this->timeStamp.strftime ( date, sizeof ( date ), "%a %b %d %Y %H:%M:%S");
297  ::printf ( "\tbeacon number %u, on %s\n",
298  this->lastBeaconNumber, date );
299  }
300 }
#define printf
Definition: epicsStdio.h:41
void date(const char *format)
void name(char *pBuf, unsigned bufSize) const
Definition: inetAddrID.h:64
void bhe::unregisterIIU ( epicsGuard< epicsMutex > &  guard,
tcpiiu iiu 
)

Definition at line 321 of file bhe.cpp.

323 {
324  guard.assertIdenticalMutex ( this->mutex );
325  if ( this->pIIU == & iiu ) {
326  this->pIIU = 0;
327  this->timeStamp = epicsTime();
328  this->averagePeriod = - DBL_MAX;
329  logBeacon ( "ui", this->averagePeriod, epicsTime::getCurrent () );
330  }
331 }
void assertIdenticalMutex(const T &) const
Definition: epicsGuard.h:80
bool bhe::updatePeriod ( epicsGuard< epicsMutex > &  guard,
const epicsTime &  programBeginTime,
const epicsTime &  currentTime,
ca_uint32_t  beaconNumber,
unsigned  protocolRevision 
)

Definition at line 124 of file bhe.cpp.

128 {
129  guard.assertIdenticalMutex ( this->mutex );
130 
131  //
132  // this block is enetered if the beacon was created as a side effect of
133  // creating a connection and so we dont yet know the first beacon time
134  // and sequence number
135  //
136  if ( this->timeStamp == epicsTime () ) {
137  if ( CA_V410 ( protocolRevision ) ) {
138  this->lastBeaconNumber = beaconNumber;
139  }
140 
141  this->beaconAnomalyNotify ( guard );
142 
143  /*
144  * this is the 1st beacon seen - the beacon time stamp
145  * was not initialized during BHE create because
146  * a TCP/IP connection created the beacon.
147  * (nothing to do but set the beacon time stamp and return)
148  */
149  this->timeStamp = currentTime;
150 
151  logBeacon ( "fb", - DBL_MAX, currentTime );
152 
153  return false;
154  }
155 
156  // 1) detect beacon duplications due to redundant routes
157  // 2) detect lost beacons due to input queue overrun or damage
158  if ( CA_V410 ( protocolRevision ) ) {
159  unsigned beaconSeqAdvance;
160  if ( beaconNumber >= this->lastBeaconNumber ) {
161  beaconSeqAdvance = beaconNumber - this->lastBeaconNumber;
162  }
163  else {
164  beaconSeqAdvance = ( ca_uint32_max - this->lastBeaconNumber ) + beaconNumber;
165  }
166  this->lastBeaconNumber = beaconNumber;
167 
168  // throw out sequence numbers just prior to, or the same as, the last one received
169  // (this situation is probably caused by a temporary duplicate route )
170  if ( beaconSeqAdvance == 0 || beaconSeqAdvance > ca_uint32_max - 256 ) {
171  logBeaconDiscard ( beaconSeqAdvance, currentTime );
172  return false;
173  }
174 
175  // throw out sequence numbers that jump forward by only a few numbers
176  // (this situation is probably caused by a duplicate route
177  // or a beacon due to input queue overun)
178  if ( beaconSeqAdvance > 1 && beaconSeqAdvance < 4 ) {
179  logBeaconDiscard ( beaconSeqAdvance, currentTime );
180  return false;
181  }
182  }
183 
184  // compute the beacon period (if we have seen at least two beacons)
185  bool netChange = false;
186  double currentPeriod = currentTime - this->timeStamp;
187 
188  if ( this->averagePeriod < 0.0 ) {
189  double totalRunningTime;
190 
191  this->beaconAnomalyNotify ( guard );
192 
193  /*
194  * this is the 2nd beacon seen. We cant tell about
195  * the change in period at this point so we just
196  * initialize the average period and return.
197  */
198  this->averagePeriod = currentPeriod;
199 
200  logBeacon ( "fp", currentPeriod, currentTime );
201 
202 
203  /*
204  * ignore beacons seen for the first time shortly after
205  * init, but do not ignore beacons arriving with a short
206  * period because the IOC was rebooted soon after the
207  * client starts up.
208  */
209  totalRunningTime = this->timeStamp - programBeginTime;
210  if ( currentPeriod <= totalRunningTime ) {
211  netChange = true;
212  }
213  }
214  else {
215 
216  /*
217  * Is this an IOC seen because of a restored
218  * network segment?
219  *
220  * It may be possible to get false triggers here
221  * if the client is busy, but this does not cause
222  * problems because the echo response will tell us
223  * that the server is available
224  */
225  if ( currentPeriod >= this->averagePeriod * 1.25 ) {
226 
227  /*
228  * trigger on any missing beacon
229  * if connected to this server
230  */
231  this->beaconAnomalyNotify ( guard );
232 
233  if ( currentPeriod >= this->averagePeriod * 3.25 ) {
234  /*
235  * trigger on any 3 contiguous missing beacons
236  * if not connected to this server
237  */
238  netChange = true;
239  }
240  logBeacon ( "bah", currentPeriod, currentTime );
241  }
242 
243  /*
244  * Is this an IOC seen because of an IOC reboot
245  * (beacon come at a higher rate just after the
246  * IOC reboots). Lower tolarance here because we
247  * dont have to worry about lost beacons.
248  *
249  * It may be possible to get false triggers here
250  * if the client is busy, but this does not cause
251  * problems because the echo response will tell us
252  * that the server is available
253  */
254  else if ( currentPeriod <= this->averagePeriod * 0.80 ) {
255  this->beaconAnomalyNotify ( guard );
256  netChange = true;
257  logBeacon ( "bal", currentPeriod, currentTime );
258  }
259  else if ( this->pIIU ) {
260  // update state of health for active virtual circuits
261  // if the beacon looks ok
262  this->pIIU->beaconArrivalNotify ( guard );
263  logBeacon ( "vb", currentPeriod, currentTime );
264  }
265 
266  // update a running average period
267  this->averagePeriod = currentPeriod * 0.125 +
268  this->averagePeriod * 0.875;
269  }
270 
271  this->timeStamp = currentTime;
272 
273  return netChange;
274 }
#define CA_V410(MINOR)
Definition: caProto.h:41
void assertIdenticalMutex(const T &) const
Definition: epicsGuard.h:80
#define ca_uint32_max
Definition: caProto.h:80
void beaconArrivalNotify(epicsGuard< epicsMutex > &)
epicsTime bhe::updateTime ( epicsGuard< epicsMutex > &  guard) const

Definition at line 308 of file bhe.cpp.

309 {
310  guard.assertIdenticalMutex ( this->mutex );
311  return this->timeStamp;
312 }
void assertIdenticalMutex(const T &) const
Definition: epicsGuard.h:80

The documentation for this class was generated from the following files: