notificationChannelBufSize = 100 // default size of the notification channel buffers
)
-const (
+var (
healthCheckProbeInterval = time.Second * 1 // default health check probe interval
healthCheckReplyTimeout = time.Millisecond * 100 // timeout for reply to a health check probe
+ healthCheckThreshold = 1 // number of failed healthProbe until the error is reported
)
// ConnectionState holds the current state of the connection to VPP.
log = l
}
+// SetHealthCheckProbeInterval sets health check probe interval.
+// Beware: Function is not thread-safe. It is recommended to setup this parameter
+// before connecting to vpp.
+func SetHealthCheckProbeInterval(interval time.Duration) {
+ healthCheckProbeInterval = interval
+}
+
+// SetHealthCheckReplyTimeout sets timeout for reply to a health check probe.
+// If reply arrives after the timeout, check is considered as failed.
+// Beware: Function is not thread-safe. It is recommended to setup this parameter
+// before connecting to vpp.
+func SetHealthCheckReplyTimeout(timeout time.Duration) {
+ healthCheckReplyTimeout = timeout
+}
+
+// SetHealthCheckThreshold sets the number of failed healthProbe checks until the error is reported.
+// Beware: Function is not thread-safe. It is recommended to setup this parameter
+// before connecting to vpp.
+func SetHealthCheckThreshold(threshold int) {
+ healthCheckThreshold = threshold
+}
+
// Connect connects to VPP using specified VPP adapter and returns the connection handle.
// This call blocks until VPP is connected, or an error occurs. Only one connection attempt will be performed.
func Connect(vppAdapter adapter.VppAdapter) (*Connection, error) {
return
}
+ failedChecks := 0
// send health check probes until an error occurs
for {
// wait for healthCheckProbeInterval
err = errors.New("probe reply not received within the timeout period")
}
- // in case of error, break & disconnect
if err != nil {
+ failedChecks++
+ } else {
+ failedChecks = 0
+ }
+
+ if failedChecks >= healthCheckThreshold {
+ // in case of error, break & disconnect
log.Errorf("VPP health check failed: %v", err)
// signal disconnected event via channel
connChan <- ConnectionEvent{Timestamp: time.Now(), State: Disconnected}