var (
RequestChanBufSize = 100 // default size of the request channel buffer
ReplyChanBufSize = 100 // default size of the reply channel buffer
var (
RequestChanBufSize = 100 // default size of the request channel buffer
ReplyChanBufSize = 100 // default size of the reply channel buffer
HealthCheckReplyTimeout = time.Millisecond * 100 // timeout for reply to a health check probe
HealthCheckThreshold = 1 // number of failed health checks until the error is reported
HealthCheckReplyTimeout = time.Millisecond * 100 // timeout for reply to a health check probe
HealthCheckThreshold = 1 // number of failed health checks until the error is reported
- DefaultReplyTimeout = time.Second * 1 // default timeout for replies from VPP
- ReconnectInterval = time.Second * 1 // default interval for reconnect attempts
- MaxReconnectAttempts = 3 // maximum number of reconnect attempts
+ DefaultReplyTimeout = time.Second // default timeout for replies from VPP
vppClient adapter.VppAPI // VPP binary API client
//statsClient adapter.StatsAPI // VPP stats API client
vppClient adapter.VppAPI // VPP binary API client
//statsClient adapter.StatsAPI // VPP stats API client
vppConnected uint32 // non-zero if the adapter is connected to VPP
codec *codec.MsgCodec // message codec
vppConnected uint32 // non-zero if the adapter is connected to VPP
codec *codec.MsgCodec // message codec
-func newConnection(binapi adapter.VppAPI) *Connection {
+func newConnection(binapi adapter.VppAPI, attempts int, interval time.Duration) *Connection {
+ if attempts == 0 {
+ attempts = DefaultMaxReconnectAttempts
+ }
+ if interval == 0 {
+ interval = DefaultReconnectInterval
+ }
+
codec: &codec.MsgCodec{},
msgIDs: make(map[string]uint16),
msgMap: make(map[uint16]api.Message),
codec: &codec.MsgCodec{},
msgIDs: make(map[string]uint16),
msgMap: make(map[uint16]api.Message),
// Only one connection attempt will be performed.
func Connect(binapi adapter.VppAPI) (*Connection, error) {
// create new connection handle
// Only one connection attempt will be performed.
func Connect(binapi adapter.VppAPI) (*Connection, error) {
// create new connection handle
// and ConnectionState channel. This call does not block until connection is established, it
// returns immediately. The caller is supposed to watch the returned ConnectionState channel for
// Connected/Disconnected events. In case of disconnect, the library will asynchronously try to reconnect.
// and ConnectionState channel. This call does not block until connection is established, it
// returns immediately. The caller is supposed to watch the returned ConnectionState channel for
// Connected/Disconnected events. In case of disconnect, the library will asynchronously try to reconnect.
-func AsyncConnect(binapi adapter.VppAPI) (*Connection, chan ConnectionEvent, error) {
+func AsyncConnect(binapi adapter.VppAPI, attempts int, interval time.Duration) (*Connection, chan ConnectionEvent, error) {
// asynchronously attempt to connect to VPP
connChan := make(chan ConnectionEvent, NotificationChanBufSize)
// asynchronously attempt to connect to VPP
connChan := make(chan ConnectionEvent, NotificationChanBufSize)
// signal connected event
connChan <- ConnectionEvent{Timestamp: time.Now(), State: Connected}
break
// signal connected event
connChan <- ConnectionEvent{Timestamp: time.Now(), State: Connected}
break
- log.Errorf("connecting failed (attempt %d/%d): %v", reconnectAttempts, MaxReconnectAttempts, err)
- time.Sleep(ReconnectInterval)
+ log.Errorf("connecting failed (attempt %d/%d): %v", reconnectAttempts, c.maxAttempts, err)
+ time.Sleep(c.recInterval)