Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: vppcalls and handler version registration #1572

Merged
merged 21 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,9 @@ dep-update:
@echo "# updating all dependencies"
@echo "Warning: 'go get' desired new modules by hand"

# FIXME: 'go mod verify' might be used here, but tidy and verify disagree.
dep-check:
@echo "# checking dependencies"
go mod tidy -v
go mod verify -v
@if ! git diff --quiet go.mod go.sum ; then \
echo "go mod tidy check failed"; \
exit 1 ; \
Expand Down
2 changes: 1 addition & 1 deletion cmd/agentctl/commands/models.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package commands

import (
_ "go.ligato.io/vpp-agent/v2/plugins/govppmux"
_ "go.ligato.io/vpp-agent/v2/proto/ligato/govppmux"
_ "go.ligato.io/vpp-agent/v2/proto/ligato/linux"
_ "go.ligato.io/vpp-agent/v2/proto/ligato/netalloc"
_ "go.ligato.io/vpp-agent/v2/proto/ligato/vpp"
Expand Down
34 changes: 34 additions & 0 deletions cmd/vpp-agent/app/app_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2019 Cisco and/or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package app

import (
"log"
"strings"
"testing"

"go.ligato.io/vpp-agent/v2/plugins/vpp"
)

func TestHandlers(t *testing.T) {
handlers := vpp.GetHandlers()

log.Printf("listing %d handlers:", len(handlers))

for h, handler := range handlers {
versions := strings.Join(handler.Versions(), ", ")
log.Printf(" - %s (%v)", h, versions)
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module go.ligato.io/vpp-agent/v2
go 1.12

require (
git.fd.io/govpp.git v0.1.1-0.20191017045426-cc80dbcaaaca
git.fd.io/govpp.git v0.2.1-0.20191115113328-e45d8802fd8d
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/DataDog/zstd v1.3.5 // indirect
github.com/Microsoft/go-winio v0.4.7 // indirect
Expand Down Expand Up @@ -54,7 +54,7 @@ require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jhump/protoreflect v1.5.0
github.com/ligato/cn-infra v2.2.1-0.20191030081411-42c7431fdca1+incompatible
github.com/lunixbochs/struc v0.0.0-20180408203800-02e4c2afbb2a
github.com/lunixbochs/struc v0.0.0-20190916212049-a5c72983bc42
github.com/mattn/goveralls v0.0.3
github.com/mitchellh/go-homedir v0.0.0-20180523094522-3864e76763d9 // indirect
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cloud.google.com/go v0.26.0 h1:e0WKqKTd5BnrG8aKH3J3h+QvEIQtSUcf2n5UZ5ZgLtQ=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
git.fd.io/govpp.git v0.1.1-0.20191017045426-cc80dbcaaaca h1:BKr2iuczYUKDrfEbxMcaNDw0hP/h7EM0MwQ3W/oBrj4=
git.fd.io/govpp.git v0.1.1-0.20191017045426-cc80dbcaaaca/go.mod h1:eW8f/z6ki4GL3Yl8cjGAdoZ+R0lTEHny11PxVFLYfsI=
git.fd.io/govpp.git v0.2.1-0.20191115113328-e45d8802fd8d h1:fyfPeiO3NHRkBAo7JsX1O+rxJkWun9RXoM3qvZRvi78=
git.fd.io/govpp.git v0.2.1-0.20191115113328-e45d8802fd8d/go.mod h1:cJ7XSNm8O4jeU1dLgOacRoHt5MxlL+XPgas1yBC53gc=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
Expand Down Expand Up @@ -197,8 +197,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/ligato/cn-infra v2.2.1-0.20191030081411-42c7431fdca1+incompatible h1:o4bJ+B9h9JvoF94T2zY3amXuR1Mryjkkfnvey8FOicg=
github.com/ligato/cn-infra v2.2.1-0.20191030081411-42c7431fdca1+incompatible/go.mod h1:wBXHMbKAlgOc/MkJMy/25284ri77duvS0XlIImme7z0=
github.com/lunixbochs/struc v0.0.0-20180408203800-02e4c2afbb2a h1:axFx97V2Lyke5LbeygrJlzc07mwVhHt2ZHeI/Nv8Aq4=
github.com/lunixbochs/struc v0.0.0-20180408203800-02e4c2afbb2a/go.mod h1:iOJu9pApjjmEmNq7PqlA5R9mDu/HMF5EM3llWKX/TyA=
github.com/lunixbochs/struc v0.0.0-20190916212049-a5c72983bc42 h1:PzBD7QuxXSgSu61TKXxRwVGzWO5d9QZ0HxFFpndZMCg=
github.com/lunixbochs/struc v0.0.0-20190916212049-a5c72983bc42/go.mod h1:vy1vK6wD6j7xX6O6hXe621WabdtNkou2h7uRtTfRMyg=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mattn/goveralls v0.0.3 h1:GnFhBAK0wJmxZBum88FqDzcDPLjAk9sL0HzhmW+9bo8=
Expand Down
13 changes: 6 additions & 7 deletions plugins/configurator/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
package configurator

import (
"context"
"errors"

linux_l3 "go.ligato.io/vpp-agent/v2/proto/ligato/linux/l3"

"github.com/ligato/cn-infra/logging"
"golang.org/x/net/context"

iflinuxcalls "go.ligato.io/vpp-agent/v2/plugins/linux/ifplugin/linuxcalls"
l3linuxcalls "go.ligato.io/vpp-agent/v2/plugins/linux/l3plugin/linuxcalls"
Expand All @@ -34,6 +32,7 @@ import (
"go.ligato.io/vpp-agent/v2/plugins/vpp/puntplugin/vppcalls"
rpc "go.ligato.io/vpp-agent/v2/proto/ligato/configurator"
linux_interfaces "go.ligato.io/vpp-agent/v2/proto/ligato/linux/interfaces"
linux_l3 "go.ligato.io/vpp-agent/v2/proto/ligato/linux/l3"
vpp_abf "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/abf"
vpp_acl "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/acl"
vpp_interfaces "go.ligato.io/vpp-agent/v2/proto/ligato/vpp/interfaces"
Expand Down Expand Up @@ -66,7 +65,7 @@ type dumpService struct {
}

// Dump implements Dump method for Configurator
func (svc *dumpService) Dump(context.Context, *rpc.DumpRequest) (*rpc.DumpResponse, error) {
func (svc *dumpService) Dump(ctx context.Context, req *rpc.DumpRequest) (*rpc.DumpResponse, error) {
defer trackOperation("Dump")()

svc.log.Debugf("Received Dump request..")
Expand All @@ -76,7 +75,7 @@ func (svc *dumpService) Dump(context.Context, *rpc.DumpRequest) (*rpc.DumpRespon
var err error

// core
dump.VppConfig.Interfaces, err = svc.DumpInterfaces()
dump.VppConfig.Interfaces, err = svc.DumpInterfaces(ctx)
if err != nil {
svc.log.Errorf("DumpInterfaces failed: %v", err)
return nil, err
Expand Down Expand Up @@ -172,13 +171,13 @@ func (svc *dumpService) Dump(context.Context, *rpc.DumpRequest) (*rpc.DumpRespon

// DumpInterfaces reads interfaces and returns them as an *InterfaceResponse. If reading ends up with error,
// only error is send back in response
func (svc *dumpService) DumpInterfaces() (ifs []*vpp_interfaces.Interface, err error) {
func (svc *dumpService) DumpInterfaces(ctx context.Context) (ifs []*vpp_interfaces.Interface, err error) {
if svc.ifHandler == nil {
// handler is not available
return nil, nil
}

ifDetails, err := svc.ifHandler.DumpInterfaces()
ifDetails, err := svc.ifHandler.DumpInterfaces(ctx)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/configurator/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewPlugin(opts ...Option) *Plugin {
p.PluginName = "configurator"
p.GRPCServer = &grpc.DefaultPlugin
p.Dispatch = &orchestrator.DefaultPlugin
p.GoVppmux = &govppmux.DefaultPlugin
p.VPP = &govppmux.DefaultPlugin
p.ServiceLabel = &servicelabel.DefaultPlugin
p.AddrAlloc = &netalloc.DefaultPlugin
p.VPPACLPlugin = &aclplugin.DefaultPlugin
Expand Down
12 changes: 6 additions & 6 deletions plugins/configurator/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type Deps struct {
infra.PluginDeps
GRPCServer grpc.Server
Dispatch orchestrator.Dispatcher
GoVppmux govppmux.StatsAPI
VPP govppmux.API
ServiceLabel servicelabel.ReaderAPI
AddrAlloc netalloc.AddressAllocator
VPPACLPlugin aclplugin.API
Expand Down Expand Up @@ -113,7 +113,7 @@ func (p *Plugin) Close() error {
// helper method initializes all VPP/Linux plugin handlers
func (p *Plugin) initHandlers() (err error) {
// VPP channels
if p.vppChan, err = p.GoVppmux.NewAPIChannel(); err != nil {
if p.vppChan, err = p.VPP.NewAPIChannel(); err != nil {
return err
}

Expand All @@ -130,7 +130,7 @@ func (p *Plugin) initHandlers() (err error) {
// VPP handlers

// core
p.configurator.ifHandler = ifvppcalls.CompatibleInterfaceVppHandler(p.vppChan, p.Log)
p.configurator.ifHandler = ifvppcalls.CompatibleInterfaceVppHandler(p.VPP, p.Log)
if p.configurator.ifHandler == nil {
p.Log.Info("VPP Interface handler is not available, it will be skipped")
}
Expand All @@ -148,15 +148,15 @@ func (p *Plugin) initHandlers() (err error) {
}

// plugins
p.configurator.abfHandler = abfvppcalls.CompatibleABFVppHandler(p.vppChan, aclIndexes, ifIndexes, p.Log)
p.configurator.abfHandler = abfvppcalls.CompatibleABFHandler(p.VPP, aclIndexes, ifIndexes, p.Log)
if p.configurator.abfHandler == nil {
p.Log.Info("VPP ABF handler is not available, it will be skipped")
}
p.configurator.aclHandler = aclvppcalls.CompatibleACLVppHandler(p.vppChan, ifIndexes, p.Log)
p.configurator.aclHandler = aclvppcalls.CompatibleACLHandler(p.VPP, ifIndexes)
if p.configurator.aclHandler == nil {
p.Log.Info("VPP ACL handler is not available, it will be skipped")
}
p.configurator.natHandler = natvppcalls.CompatibleNatVppHandler(p.vppChan, ifIndexes, dhcpIndexes, p.Log)
p.configurator.natHandler = natvppcalls.CompatibleNatVppHandler(p.VPP, ifIndexes, dhcpIndexes, p.Log)
if p.configurator.natHandler == nil {
p.Log.Info("VPP NAT handler is not available, it will be skipped")
}
Expand Down
20 changes: 10 additions & 10 deletions plugins/govppmux/adapter_stubs.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright (c) 2017 Cisco and/or its affiliates.
// Copyright (c) 2019 Cisco and/or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// +build mockvpp

Expand Down
20 changes: 10 additions & 10 deletions plugins/govppmux/adapter_vppapiclient.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright (c) 2017 Cisco and/or its affiliates.
// Copyright (c) 2019 Cisco and/or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !mockvpp,vppapiclient

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
govppapi "git.fd.io/govpp.git/api"
"git.fd.io/govpp.git/core"
"github.com/ligato/cn-infra/logging"
"github.com/ligato/cn-infra/logging/measure"
)

// NewAPIChannel returns a new API channel for communication with VPP via govpp core.
Expand All @@ -41,7 +40,7 @@ func (p *Plugin) NewAPIChannel() (govppapi.Channel, error) {
p.config.RetryRequestCount,
p.config.RetryRequestTimeout,
}
return newGovppChan(ch, retryCfg, p.tracer), nil
return newGovppChan(ch, retryCfg), nil
}

// NewAPIChannelBuffered returns a new API channel for communication with VPP via govpp core.
Expand All @@ -59,7 +58,7 @@ func (p *Plugin) NewAPIChannelBuffered(reqChanBufSize, replyChanBufSize int) (go
p.config.RetryRequestCount,
p.config.RetryRequestTimeout,
}
return newGovppChan(ch, retryCfg, p.tracer), nil
return newGovppChan(ch, retryCfg), nil
}

// goVppChan implements govpp channel interface. Instance is returned by NewAPIChannel() or NewAPIChannelBuffered(),
Expand All @@ -69,15 +68,12 @@ type goVppChan struct {
govppapi.Channel
// Retry data
retry retryConfig
// tracer used to measure binary api call duration
tracer measure.Tracer
}

func newGovppChan(ch govppapi.Channel, retryCfg retryConfig, tracer measure.Tracer) *goVppChan {
func newGovppChan(ch govppapi.Channel, retryCfg retryConfig) *goVppChan {
govppChan := &goVppChan{
Channel: ch,
retry: retryCfg,
tracer: tracer,
}
atomic.AddUint64(&stats.ChannelsCreated, 1)
atomic.AddUint64(&stats.ChannelsOpen, 1)
Expand All @@ -99,31 +95,28 @@ type retryConfig struct {
type govppRequestCtx struct {
ctx context.Context
task *trace.Task

// Original request context
requestCtx govppapi.RequestCtx
// Function allowing to re-send request in case it's granted by the config file
sendRequest func(govppapi.Message) govppapi.RequestCtx
// Parameter for sendRequest
requestMsg govppapi.Message
// Retry data

retry retryConfig
// Tracer object
tracer measure.Tracer
// Start time
start time.Time
}

// govppMultirequestCtx is custom govpp MultiRequestCtx.
type govppMultirequestCtx struct {
ctx context.Context
task *trace.Task

// Original multi request context
requestCtx govppapi.MultiRequestCtx
// Parameter for sendRequest
requestMsg govppapi.Message
// Tracer object
tracer measure.Tracer
// Start time

start time.Time
}

Expand All @@ -147,19 +140,13 @@ func (c *goVppChan) SendRequest(request govppapi.Message) govppapi.RequestCtx {
sendRequest: c.Channel.SendRequest,
requestMsg: request,
retry: c.retry,
tracer: c.tracer,
start: start,
}
}

// ReceiveReply handles request and returns error if occurred. Also does retry if this option is available.
func (r *govppRequestCtx) ReceiveReply(reply govppapi.Message) error {
defer func() {
r.task.End()
if r.tracer != nil {
r.tracer.LogTime(r.requestMsg.GetMessageName(), r.start)
}
}()
defer r.task.End()

var timeout time.Duration
maxRetries := r.retry.attempts
Expand Down Expand Up @@ -213,7 +200,6 @@ func (c *goVppChan) SendMultiRequest(request govppapi.Message) govppapi.MultiReq
task: task,
requestCtx: requestCtx,
requestMsg: request,
tracer: c.tracer,
start: start,
}
}
Expand All @@ -232,12 +218,7 @@ func (r *govppMultirequestCtx) ReceiveReply(reply govppapi.Message) (bool, error
atomic.AddUint64(&stats.RequestsFail, 1)
}

defer func() {
r.task.End()
if r.tracer != nil {
r.tracer.LogTime(r.requestMsg.GetMessageName(), r.start)
}
}()
defer r.task.End()
} else {
atomic.AddUint64(&stats.RequestReplies, 1)
trackMsgReply(reply.GetMessageName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"git.fd.io/govpp.git/core"
. "github.com/onsi/gomega"

"go.ligato.io/vpp-agent/v2/plugins/vpp/vppcallmock"
)

Expand Down Expand Up @@ -75,7 +76,7 @@ func TestRequestRetry(t *testing.T) {
defer ctx.TeardownTestCtx()

retryCfg := retryConfig{test.attempts, test.timeout}
ch := newGovppChan(ctx.MockChannel, retryCfg, nil)
ch := newGovppChan(ctx.MockChannel, retryCfg)

ctx.MockChannel.RetErrs = test.retErrs

Expand Down
File renamed without changes.
Loading