Skip to content

Commit 804992b

Browse files
authored
Update GoVPP and use pure Go client adapters by default (#1401)
* Update GoVPP and use pure Go client adapters by default Signed-off-by: Ondrej Fabry <[email protected]> * Update GoVPP with fix for duplicate objects Signed-off-by: Ondrej Fabry <[email protected]>
1 parent 14f91ed commit 804992b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+12843
-2975
lines changed

Gopkg.lock

+12-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) 2019 Cisco and/or its affiliates.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at:
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// +build !mockvpp,!vppapiclient
16+
17+
package govppmux
18+
19+
import (
20+
"git.fd.io/govpp.git/adapter"
21+
"git.fd.io/govpp.git/adapter/socketclient"
22+
"git.fd.io/govpp.git/adapter/statsclient"
23+
"github.com/ligato/cn-infra/logging"
24+
)
25+
26+
// NewVppAdapter returns VPP binary API adapter, implemented as pure Go client.
27+
func NewVppAdapter(addr string, useShm bool) adapter.VppAPI {
28+
if useShm {
29+
logging.Warnf(`Using shared memory for VPP binary API is not currently supported in pure Go client!
30+
31+
To use socket client for VPP binary API:
32+
- unset GOVPPMUX_NOSOCK environment variable
33+
- remove these settings from govpp.conf config: shm-prefix, connect-via-shm
34+
35+
If you still want to use shared memory for VPP binary API (not recommended):
36+
- compile your agent with this build tag: vppapiclient
37+
`)
38+
panic("No implementation for shared memory in pure Go client!")
39+
}
40+
// addr is used as socket path
41+
return socketclient.NewVppClient(addr)
42+
43+
}
44+
45+
// NewStatsAdapter returns VPP stats API adapter, implemented as pure Go client.
46+
func NewStatsAdapter(socketName string) adapter.StatsAPI {
47+
return statsclient.NewStatsClient(socketName)
48+
}

plugins/govppmux/adapter_stubs.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ import (
2121
govppmock "git.fd.io/govpp.git/adapter/mock"
2222
)
2323

24-
// NewVppAdapter returns mock adapter, used for building without vppapiclient library.
24+
// NewVppAdapter returns mock adapter for VPP binary API.
2525
func NewVppAdapter(shmPrefix string, useShm bool) adapter.VppAPI {
2626
return govppmock.NewVppAdapter()
2727
}
2828

29-
// NewStatsAdapter returns stats vpp api adapter, used for reading statistics with vppapiclient library.
29+
// NewStatsAdapter returns mock adapter for VPP stats API.
3030
func NewStatsAdapter(socketName string) adapter.StatsAPI {
3131
return govppmock.NewStatsAdapter()
3232
}

plugins/govppmux/adapter_vppapiclient.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// +build !mockvpp
15+
// +build !mockvpp,vppapiclient
1616

1717
package govppmux
1818

@@ -22,18 +22,17 @@ import (
2222
"git.fd.io/govpp.git/adapter/vppapiclient"
2323
)
2424

25-
// NewVppAdapter returns real vpp api adapter, used for building with vppapiclient library.
25+
// NewVppAdapter returns VPP binary API adapter, implemented as wrapper for vppapiclient library.
2626
func NewVppAdapter(addr string, useShm bool) adapter.VppAPI {
2727
if useShm {
2828
// addr is used as shm prefix
2929
return vppapiclient.NewVppClient(addr)
3030
}
3131
// addr is used as socket path
3232
return socketclient.NewVppClient(addr)
33-
3433
}
3534

36-
// NewStatsAdapter returns stats vpp api adapter, used for reading statistics with vppapiclient library.
35+
// NewStatsAdapter returns VPP stats API adapter, implemented as wrapper for vppapiclient library.
3736
func NewStatsAdapter(socketName string) adapter.StatsAPI {
3837
return vppapiclient.NewStatClient(socketName)
3938
}

plugins/govppmux/govpp_channel.go renamed to plugins/govppmux/binapi_client.go

+46-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
// Copyright (c) 2018 Cisco and/or its affiliates.
1+
// Copyright (c) 2019 Cisco and/or its affiliates.
22
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at:
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at:
66
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
7+
// http://www.apache.org/licenses/LICENSE-2.0
88
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
1414

1515
package govppmux
1616

@@ -26,6 +26,42 @@ import (
2626
"github.com/ligato/cn-infra/logging/measure"
2727
)
2828

29+
// NewAPIChannel returns a new API channel for communication with VPP via govpp core.
30+
// It uses default buffer sizes for the request and reply Go channels.
31+
//
32+
// Example of binary API call from some plugin using GOVPP:
33+
// ch, _ := govpp_mux.NewAPIChannel()
34+
// ch.SendRequest(req).ReceiveReply
35+
func (p *Plugin) NewAPIChannel() (govppapi.Channel, error) {
36+
ch, err := p.vppConn.NewAPIChannel()
37+
if err != nil {
38+
return nil, err
39+
}
40+
retryCfg := retryConfig{
41+
p.config.RetryRequestCount,
42+
p.config.RetryRequestTimeout,
43+
}
44+
return newGovppChan(ch, retryCfg, p.tracer), nil
45+
}
46+
47+
// NewAPIChannelBuffered returns a new API channel for communication with VPP via govpp core.
48+
// It allows to specify custom buffer sizes for the request and reply Go channels.
49+
//
50+
// Example of binary API call from some plugin using GOVPP:
51+
// ch, _ := govpp_mux.NewAPIChannelBuffered(100, 100)
52+
// ch.SendRequest(req).ReceiveReply
53+
func (p *Plugin) NewAPIChannelBuffered(reqChanBufSize, replyChanBufSize int) (govppapi.Channel, error) {
54+
ch, err := p.vppConn.NewAPIChannelBuffered(reqChanBufSize, replyChanBufSize)
55+
if err != nil {
56+
return nil, err
57+
}
58+
retryCfg := retryConfig{
59+
p.config.RetryRequestCount,
60+
p.config.RetryRequestTimeout,
61+
}
62+
return newGovppChan(ch, retryCfg, p.tracer), nil
63+
}
64+
2965
// goVppChan implements govpp channel interface. Instance is returned by NewAPIChannel() or NewAPIChannelBuffered(),
3066
// and contains *govpp.channel dynamic type (vppChan field). Implemented methods allow custom handling of low-level
3167
// govpp.

plugins/govppmux/config.go

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) 2019 Cisco and/or its affiliates.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at:
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package govppmux
16+
17+
import "time"
18+
19+
// Config groups the configurable parameter of GoVpp.
20+
type Config struct {
21+
TraceEnabled bool `json:"trace-enabled"`
22+
ReconnectResync bool `json:"resync-after-reconnect"`
23+
HealthCheckProbeInterval time.Duration `json:"health-check-probe-interval"`
24+
HealthCheckReplyTimeout time.Duration `json:"health-check-reply-timeout"`
25+
HealthCheckThreshold int `json:"health-check-threshold"`
26+
ReplyTimeout time.Duration `json:"reply-timeout"`
27+
// Connect to VPP for configuration requests via the shared memory instead of through the socket.
28+
ConnectViaShm bool `json:"connect-via-shm"`
29+
// The prefix prepended to the name used for shared memory (SHM) segments. If not set,
30+
// shared memory segments are created directly in the SHM directory /dev/shm.
31+
ShmPrefix string `json:"shm-prefix"`
32+
BinAPISocketPath string `json:"binapi-socket-path"`
33+
StatsSocketPath string `json:"stats-socket-path"`
34+
// How many times can be request resent in case vpp is suddenly disconnected.
35+
RetryRequestCount int `json:"retry-request-count"`
36+
// Time between request resend attempts. Default is 500ms.
37+
RetryRequestTimeout time.Duration `json:"retry-request-timeout"`
38+
// How many times can be connection request resent in case the vpp is not reachable.
39+
RetryConnectCount int `json:"retry-connect-count"`
40+
// Time between connection request resend attempts. Default is 1s.
41+
RetryConnectTimeout time.Duration `json:"retry-connect-timeout"`
42+
}
43+
44+
func defaultConfig() *Config {
45+
return &Config{
46+
HealthCheckProbeInterval: time.Second,
47+
HealthCheckReplyTimeout: 250 * time.Millisecond,
48+
HealthCheckThreshold: 1,
49+
ReplyTimeout: time.Second,
50+
RetryRequestTimeout: 500 * time.Millisecond,
51+
RetryConnectTimeout: time.Second,
52+
}
53+
}
54+
55+
func (p *Plugin) loadConfig() (*Config, error) {
56+
cfg := defaultConfig()
57+
58+
found, err := p.Cfg.LoadValue(cfg)
59+
if err != nil {
60+
return nil, err
61+
} else if found {
62+
p.Log.Debugf("config loaded from file %q", p.Cfg.GetConfigName())
63+
} else {
64+
p.Log.Debugf("config file %q not found, using default config", p.Cfg.GetConfigName())
65+
}
66+
67+
return cfg, nil
68+
}

0 commit comments

Comments
 (0)