From 539d3478c8f15dffd15037a051f545aa2f6b3a7d Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Wed, 11 Sep 2002 23:30:12 +0000 Subject: [PATCH] fixed beacon detect logic does not detect reconnected servers --- src/ca/bhe.cpp | 25 +++++++++++++++++++++---- src/ca/bhe.h | 6 +++--- src/ca/caProto.h | 2 ++ src/ca/cac.cpp | 2 +- src/ca/cac.h | 2 +- src/ca/casw.cpp | 2 +- src/ca/udpiiu.cpp | 2 +- 7 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/ca/bhe.cpp b/src/ca/bhe.cpp index 094444ff7..c7aae430e 100644 --- a/src/ca/bhe.cpp +++ b/src/ca/bhe.cpp @@ -89,7 +89,7 @@ void bhe::beaconAnomalyNotify () * updates beacon period, and looks for beacon anomalies */ bool bhe::updatePeriod ( const epicsTime & programBeginTime, - const epicsTime & currentTime, unsigned beaconNumber, + const epicsTime & currentTime, ca_uint32_t beaconNumber, unsigned protocolRevision ) { // @@ -115,11 +115,28 @@ bool bhe::updatePeriod ( const epicsTime & programBeginTime, return false; } - // detect beacon duplications due to IP redundant packet routes + // 1) detect beacon duplications due to redundant routes + // 2) detect lost beacons due to input queue overrun or damage if ( CA_V410 ( protocolRevision ) ) { - unsigned lastBeaconNumberSave = this->lastBeaconNumber; + unsigned beaconSeqAdvance; + if ( beaconNumber > this->lastBeaconNumber ) { + beaconSeqAdvance = beaconNumber - this->lastBeaconNumber; + } + else { + beaconSeqAdvance = ( ca_uint32_max - this->lastBeaconNumber ) + beaconNumber; + } this->lastBeaconNumber = beaconNumber; - if ( beaconNumber != lastBeaconNumberSave + 1 ) { + + // throw out sequence numbers just prior to, or the same as, the last one received + // (this situation is probably caused by a temporary duplicate route ) + if ( beaconSeqAdvance == 0 || beaconSeqAdvance > ca_uint32_max - 256 ) { + return false; + } + + // throw out sequence numbers that jump forward by only a few numbers + // (this situation is probably caused by a duplicate route + // or a beacon due to input queue overun) + if ( beaconSeqAdvance > 1 && beaconSeqAdvance < 4 ) { return false; } } diff --git a/src/ca/bhe.h b/src/ca/bhe.h index f57823fa6..33591e71f 100644 --- a/src/ca/bhe.h +++ b/src/ca/bhe.h @@ -39,7 +39,7 @@ #endif #include "inetAddrID.h" - +#include "caProto.h" class tcpiiu; @@ -50,7 +50,7 @@ public: epicsShareFunc ~bhe (); epicsShareFunc void destroy (); epicsShareFunc bool updatePeriod ( const epicsTime & programBeginTime, - const epicsTime & currentTime, unsigned beaconNumber, + const epicsTime & currentTime, ca_uint32_t beaconNumber, unsigned protocolRevision ); epicsShareFunc double period () const; epicsShareFunc epicsTime updateTime () const; @@ -63,7 +63,7 @@ private: tsDLList < tcpiiu > iiuList; epicsTime timeStamp; double averagePeriod; - unsigned lastBeaconNumber; + ca_uint32_t lastBeaconNumber; void beaconAnomalyNotify (); static epicsSingleton < tsFreeList < class bhe, 1024 > > pFreeList; bhe ( const bhe & ); diff --git a/src/ca/caProto.h b/src/ca/caProto.h index b051b50b0..f750e0acc 100644 --- a/src/ca/caProto.h +++ b/src/ca/caProto.h @@ -101,6 +101,8 @@ typedef unsigned int ca_uint32_t; typedef float ca_float32_t; typedef ca_uint32_t caResId; +#define ca_uint32_max 0xffffffff + /* values for m_cmmd */ #define CA_PROTO_VERSION 0u /* set minor version and priority (used to be NOOP cmd) */ #define CA_PROTO_EVENT_ADD 1u /* add an event */ diff --git a/src/ca/cac.cpp b/src/ca/cac.cpp index 9384c285e..28c3f616b 100644 --- a/src/ca/cac.cpp +++ b/src/ca/cac.cpp @@ -372,7 +372,7 @@ void cac::show ( unsigned level ) const * cac::beaconNotify */ void cac::beaconNotify ( const inetAddrID & addr, const epicsTime & currentTime, - unsigned beaconNumber, unsigned protocolRevision ) + ca_uint32_t beaconNumber, unsigned protocolRevision ) { epicsGuard < cacMutex > guard ( this->mutex ); diff --git a/src/ca/cac.h b/src/ca/cac.h index 5da51062e..bd87fcbc8 100644 --- a/src/ca/cac.h +++ b/src/ca/cac.h @@ -108,7 +108,7 @@ public: // beacon management void beaconNotify ( const inetAddrID & addr, const epicsTime & currentTime, - unsigned beaconNumber, unsigned protocolRevision ); + ca_uint32_t beaconNumber, unsigned protocolRevision ); void repeaterSubscribeConfirmNotify (); // IO management diff --git a/src/ca/casw.cpp b/src/ca/casw.cpp index 60ba22b93..e719bbce4 100644 --- a/src/ca/casw.cpp +++ b/src/ca/casw.cpp @@ -195,7 +195,7 @@ int main ( int argc, char ** argv ) ina.sin_port = epicsNTOH16 ( serverPort ); } - unsigned beaconNumber = ntohl ( pCurMsg->m_cid ); + ca_uint32_t beaconNumber = ntohl ( pCurMsg->m_cid ); unsigned protocolRevision = ntohs ( pCurMsg->m_dataType ); epicsTime currentTime = epicsTime::getCurrent(); diff --git a/src/ca/udpiiu.cpp b/src/ca/udpiiu.cpp index 4a7951fee..6f360edcf 100644 --- a/src/ca/udpiiu.cpp +++ b/src/ca/udpiiu.cpp @@ -684,7 +684,7 @@ bool udpiiu::beaconAction ( epicsGuard < callbackMutex > &, const caHdr &msg, ina.sin_port = epicsHTON16 ( this->serverPort ); } unsigned protocolRevision = msg.m_dataType; - unsigned beaconNumber = msg.m_cid; + ca_uint32_t beaconNumber = msg.m_cid; this->cacRef.beaconNotify ( ina, currentTime, beaconNumber, protocolRevision );