From e1681355ba01ed1fd59b55300f46d4dacca2a833 Mon Sep 17 00:00:00 2001 From: Ondrej Fabry Date: Fri, 26 Jul 2019 09:21:26 +0200 Subject: [PATCH] Minor enhancements and code cleanups (#1420) * Minor enhancement for transaction summary log Signed-off-by: Ondrej Fabry * Add make target for remote debugging with delve Signed-off-by: Ondrej Fabry * Minor code cleanup in vpp ifplugin Signed-off-by: Ondrej Fabry * Fix error check when renaming tap and cleanup code Signed-off-by: Ondrej Fabry --- Makefile | 3 + plugins/kvscheduler/api/txn_options.go | 2 +- plugins/kvscheduler/api/txn_record.go | 6 +- plugins/kvscheduler/plugin_scheduler.go | 2 +- plugins/kvscheduler/refresh.go | 2 +- plugins/kvscheduler/txn_process.go | 8 +-- plugins/kvscheduler/txn_record.go | 24 +++---- .../linux/ifplugin/descriptor/interface.go | 71 +++++++++++-------- .../ifplugin/descriptor/interface_tap.go | 19 ++--- .../ifplugin/descriptor/interface_veth.go | 13 ++-- plugins/vpp/ifplugin/descriptor/interface.go | 8 +-- plugins/vpp/ifplugin/descriptor/rx_mode.go | 20 +++--- .../vpp/ifplugin/descriptor/rx_placement.go | 11 ++- 13 files changed, 102 insertions(+), 87 deletions(-) diff --git a/Makefile b/Makefile index 9f670f23fd..97c671a4e7 100644 --- a/Makefile +++ b/Makefile @@ -95,6 +95,9 @@ clean-examples: cd examples/localclient_vpp/nat && go clean cd examples/localclient_vpp/plugins && go clean +debug-remote: + cd ./cmd/vpp-agent && dlv debug --headless --listen=:2345 --api-version=2 --accept-multiclient + # ------------------------------- # Testing # ------------------------------- diff --git a/plugins/kvscheduler/api/txn_options.go b/plugins/kvscheduler/api/txn_options.go index e515824d96..3111ac2a68 100644 --- a/plugins/kvscheduler/api/txn_options.go +++ b/plugins/kvscheduler/api/txn_options.go @@ -268,4 +268,4 @@ func WithSimulation(ctx context.Context) context.Context { func IsWithSimulation(ctx context.Context) bool { _, withSimulation := ctx.Value(txnSimulationCtxKey).(*txnSimulationOpt) return withSimulation -} \ No newline at end of file +} diff --git a/plugins/kvscheduler/api/txn_record.go b/plugins/kvscheduler/api/txn_record.go index 8153ecd736..e333e6b4fa 100644 --- a/plugins/kvscheduler/api/txn_record.go +++ b/plugins/kvscheduler/api/txn_record.go @@ -49,9 +49,9 @@ func (t TxnType) String() string { case NBTransaction: return "NB Transaction" case RetryFailedOps: - return "RETRY" + return "Retry Transaction" } - return "UNKNOWN" + return "UndefinedTxnType" } // RecordedTxn is used to record executed transaction. @@ -128,7 +128,7 @@ func (txn *RecordedTxn) StringWithOpts(resultOnly, verbose bool, indent int) str if !resultOnly { // transaction arguments str += indent1 + "* transaction arguments:\n" - str += indent2 + fmt.Sprintf("- seq-num: %d\n", txn.SeqNum) + str += indent2 + fmt.Sprintf("- seqNum: %d\n", txn.SeqNum) if txn.TxnType == NBTransaction && txn.ResyncType != NotResync { ResyncType := "Full Resync" if txn.ResyncType == DownstreamResync { diff --git a/plugins/kvscheduler/plugin_scheduler.go b/plugins/kvscheduler/plugin_scheduler.go index c5e9bcaaa2..e951bfdb90 100644 --- a/plugins/kvscheduler/plugin_scheduler.go +++ b/plugins/kvscheduler/plugin_scheduler.go @@ -288,7 +288,7 @@ func (s *Scheduler) TransactionBarrier() { // PushSBNotification notifies about a spontaneous value change(s) in the SB // plane (i.e. not triggered by NB transaction). -func (s *Scheduler) PushSBNotification(notif... kvs.KVWithMetadata) error { +func (s *Scheduler) PushSBNotification(notif ...kvs.KVWithMetadata) error { txn := &transaction{ txnType: kvs.SBNotification, } diff --git a/plugins/kvscheduler/refresh.go b/plugins/kvscheduler/refresh.go index 5cd644dcfe..2f14091ed3 100644 --- a/plugins/kvscheduler/refresh.go +++ b/plugins/kvscheduler/refresh.go @@ -571,4 +571,4 @@ func (s *Scheduler) validRetrievedDerivedKV(node graph.Node, descriptor *kvs.KVD // return true -> let's overwrite invalidly retrieved derived value } return true -} \ No newline at end of file +} diff --git a/plugins/kvscheduler/txn_process.go b/plugins/kvscheduler/txn_process.go index fae5ff1ec9..6ad934f2e9 100644 --- a/plugins/kvscheduler/txn_process.go +++ b/plugins/kvscheduler/txn_process.go @@ -207,7 +207,7 @@ func (s *Scheduler) preProcessNBTransaction(txn *transaction) (skip bool) { } // for resync refresh the graph + collect deletes - graphW := s.graph.Write(true,false) + graphW := s.graph.Write(true, false) defer graphW.Release() s.resyncCount++ @@ -344,7 +344,7 @@ func (s *Scheduler) postProcessTransaction(txn *transaction, executed kvs.Record if toRefresh.Length() > 0 { // changes brought by refresh triggered solely for the verification are // not saved into the graph - graphW := s.graph.Write(afterErrRefresh,false) + graphW := s.graph.Write(afterErrRefresh, false) s.refreshGraph(graphW, toRefresh, nil, afterErrRefresh) s.scheduleRetries(txn, graphW, toRetry) @@ -420,7 +420,7 @@ func (s *Scheduler) postProcessTransaction(txn *transaction, executed kvs.Record // delete removed values from the graph after the notifications have been sent if removed.Length() > 0 { - graphW := s.graph.Write(true,true) + graphW := s.graph.Write(true, true) for _, key := range removed.Iterate() { graphW.DeleteNode(key) } @@ -429,7 +429,7 @@ func (s *Scheduler) postProcessTransaction(txn *transaction, executed kvs.Record } // scheduleRetries schedules a series of re-try transactions for failed values -func (s *Scheduler) scheduleRetries(txn *transaction, graphR graph.ReadAccess, toRetry utils.KeySet,) { +func (s *Scheduler) scheduleRetries(txn *transaction, graphR graph.ReadAccess, toRetry utils.KeySet) { // split values based on the retry metadata retryTxns := make(map[retryTxnMeta]*retryTxn) for _, retryKey := range toRetry.Iterate() { diff --git a/plugins/kvscheduler/txn_record.go b/plugins/kvscheduler/txn_record.go index e7e2e81745..04045714fc 100644 --- a/plugins/kvscheduler/txn_record.go +++ b/plugins/kvscheduler/txn_record.go @@ -137,21 +137,16 @@ func (s *Scheduler) preRecordTransaction(txn *transaction, planned kvs.RecordedT // if enabled, print txn summary if s.config.PrintTxnSummary { // build header for the log - txnInfo := txn.txnType.String() + txnInfo := "" if txn.txnType == kvs.NBTransaction && txn.nb.resyncType != kvs.NotResync { - resyncType := "Full Resync" - if txn.nb.resyncType == kvs.DownstreamResync { - resyncType = "SB Sync" - } - if txn.nb.resyncType == kvs.UpstreamResync { - resyncType = "NB Sync" - } - txnInfo = fmt.Sprintf("%s (%s)", txn.txnType.String(), resyncType) + txnInfo = fmt.Sprintf("%s", txn.nb.resyncType.String()) + } else if txn.txnType == kvs.RetryFailedOps && txn.retry != nil { + txnInfo = fmt.Sprintf("retrying TX #%d (attempt %d)", txn.retry.txnSeqNum, txn.retry.attempt) } + msg := fmt.Sprintf("#%d - %s", record.SeqNum, txn.txnType.String()) + n := 115 - len(msg) var buf strings.Builder buf.WriteString("+======================================================================================================================+\n") - msg := fmt.Sprintf("Transaction #%d", record.SeqNum) - n := 115 - len(msg) buf.WriteString(fmt.Sprintf("| %s %"+strconv.Itoa(n)+"s |\n", msg, txnInfo)) buf.WriteString("+======================================================================================================================+\n") buf.WriteString(record.StringWithOpts(false, false, 2)) @@ -172,12 +167,15 @@ func (s *Scheduler) recordTransaction(txn *transaction, txnRecord *kvs.RecordedT txnRecord.Executed = executed if s.config.PrintTxnSummary { + txnType := txn.txnType.String() + msg := fmt.Sprintf("#%d - %s", txnRecord.SeqNum, txnType) + elapsed := stop.Sub(start) + msg2 := fmt.Sprintf("took %v", elapsed.Round(time.Microsecond*100)) + var buf strings.Builder buf.WriteString("o----------------------------------------------------------------------------------------------------------------------o\n") buf.WriteString(txnRecord.StringWithOpts(true, false, 2)) buf.WriteString("x----------------------------------------------------------------------------------------------------------------------x\n") - msg := fmt.Sprintf("#%d", txnRecord.SeqNum) - msg2 := fmt.Sprintf("took %v", stop.Sub(start).Round(time.Microsecond*100)) buf.WriteString(fmt.Sprintf("| %s %"+fmt.Sprint(115-len(msg))+"s |\n", msg, msg2)) buf.WriteString("x----------------------------------------------------------------------------------------------------------------------x\n") fmt.Println(buf.String()) diff --git a/plugins/linux/ifplugin/descriptor/interface.go b/plugins/linux/ifplugin/descriptor/interface.go index 08355df10d..65aff7805d 100644 --- a/plugins/linux/ifplugin/descriptor/interface.go +++ b/plugins/linux/ifplugin/descriptor/interface.go @@ -27,7 +27,6 @@ import ( "github.com/gogo/protobuf/proto" prototypes "github.com/gogo/protobuf/types" "github.com/pkg/errors" - "github.com/vishvananda/netlink" "golang.org/x/sys/unix" "github.com/ligato/cn-infra/idxmap" @@ -249,28 +248,42 @@ func (d *InterfaceDescriptor) MetadataFactory() idxmap.NamedMappingRW { // Validate validates Linux interface configuration. func (d *InterfaceDescriptor) Validate(key string, linuxIf *interfaces.Interface) error { + // validate name (this should never happen, since key is derived from name) if linuxIf.GetName() == "" { return kvs.NewInvalidValueError(ErrInterfaceWithoutName, "name") } - addrs := linuxIf.GetIpAddresses() - for _, a := range addrs { + + // validate IP addresses + for _, a := range linuxIf.GetIpAddresses() { + // TODO: perhaps we could assume default mask if there isnt one? if _, _, err := net.ParseCIDR(a); err != nil { return kvs.NewInvalidValueError(ErrInvalidIPWithMask, "ip_addresses") } } - if linuxIf.GetType() == interfaces.Interface_UNDEFINED { - return kvs.NewInvalidValueError(ErrInterfaceWithoutType, "type") - } - if linuxIf.GetType() == interfaces.Interface_TAP_TO_VPP && d.vppIfPlugin == nil { - return ErrTAPRequiresVPPIfPlugin + // validate namespace + if ns := linuxIf.GetNamespace(); ns != nil { + if ns.GetType() == namespace.NetNamespace_UNDEFINED || ns.GetReference() == "" { + return kvs.NewInvalidValueError(ErrNamespaceWithoutReference, "namespace") + } } - if linuxIf.GetNamespace() != nil && - (linuxIf.GetNamespace().GetType() == namespace.NetNamespace_UNDEFINED || - linuxIf.GetNamespace().GetReference() == "") { - return kvs.NewInvalidValueError(ErrNamespaceWithoutReference, "namespace") + + // validate type + switch linuxIf.GetType() { + case interfaces.Interface_LOOPBACK: + if linuxIf.GetLink() != nil { + return kvs.NewInvalidValueError(ErrInterfaceReferenceMismatch, "link") + } + case interfaces.Interface_TAP_TO_VPP: + if d.vppIfPlugin == nil { + return ErrTAPRequiresVPPIfPlugin + } + case interfaces.Interface_UNDEFINED: + return kvs.NewInvalidValueError(ErrInterfaceWithoutType, "type") } - switch linuxIf.Link.(type) { + + // validate link + switch linuxIf.GetLink().(type) { case *interfaces.Interface_Tap: if linuxIf.GetType() != interfaces.Interface_TAP_TO_VPP { return kvs.NewInvalidValueError(ErrInterfaceReferenceMismatch, "link") @@ -723,6 +736,7 @@ func (d *InterfaceDescriptor) Retrieve(correlate []adapter.InterfaceKVWithMetada // receive results from the go routines ifaces := make(map[string]adapter.InterfaceKVWithMetadata) // interface logical name -> interface data indexes := make(map[int]struct{}) // already retrieved interfaces by their Linux indexes + for idx := 0; idx < goRoutinesCnt; idx++ { retrieved := <-ch if retrieved.err != nil { @@ -732,7 +746,7 @@ func (d *InterfaceDescriptor) Retrieve(correlate []adapter.InterfaceKVWithMetada // skip if this interface was already retrieved and this is not the expected // namespace from correlation - remember, the same namespace may have // multiple different references - rewrite := false + var rewrite bool if _, alreadyRetrieved := indexes[kv.Metadata.LinuxIfIndex]; alreadyRetrieved { if expCfg, hasExpCfg := ifCfg[kv.Value.Name]; hasExpCfg { if proto.Equal(expCfg.Namespace, kv.Value.Namespace) { @@ -857,19 +871,23 @@ func (d *InterfaceDescriptor) retrieveInterfaces(nsList []*namespace.NetNamespac alias = strings.TrimPrefix(alias, agentPrefix) // parse alias to obtain logical references - var vppTapIfName string - if link.Type() == (&netlink.Veth{}).Type() { - var vethPeerIfName string + if link.Type() == "veth" { iface.Type = interfaces.Interface_VETH + var vethPeerIfName string iface.Name, vethPeerIfName = parseVethAlias(alias) iface.Link = &interfaces.Interface_Veth{ - Veth: &interfaces.VethLink{PeerIfName: vethPeerIfName}, + Veth: &interfaces.VethLink{ + PeerIfName: vethPeerIfName, + }, } - } else if link.Type() == (&netlink.Tuntap{}).Type() || link.Type() == "tun" /* not defined in vishvananda */ { + } else if link.Type() == "tuntap" || link.Type() == "tun" /* not defined in vishvananda */ { iface.Type = interfaces.Interface_TAP_TO_VPP + var vppTapIfName string iface.Name, vppTapIfName, _ = parseTapAlias(alias) iface.Link = &interfaces.Interface_Tap{ - Tap: &interfaces.TapLink{VppTapIfName: vppTapIfName}, + Tap: &interfaces.TapLink{ + VppTapIfName: vppTapIfName, + }, } } else if link.Attrs().Name == defaultLoopbackName { iface.Type = interfaces.Interface_LOOPBACK @@ -878,9 +896,8 @@ func (d *InterfaceDescriptor) retrieveInterfaces(nsList []*namespace.NetNamespac // unsupported interface type supposedly configured by agent => print warning d.log.WithFields(logging.Fields{ "if-host-name": link.Attrs().Name, - "if-type": link.Type(), "namespace": nsRef, - }).Warn("Managed interface of unsupported type") + }).Warnf("Managed interface of unsupported type: %s", link.Type()) continue } @@ -941,7 +958,7 @@ func (d *InterfaceDescriptor) retrieveInterfaces(nsList []*namespace.NetNamespac Origin: kvs.FromNB, Metadata: &ifaceidx.LinuxIfMetadata{ LinuxIfIndex: link.Attrs().Index, - VPPTapName: vppTapIfName, + VPPTapName: iface.GetTap().GetVppTapIfName(), Namespace: nsRef, }, }) @@ -983,8 +1000,7 @@ func (d *InterfaceDescriptor) setInterfaceNamespace(ctx nslinuxcalls.NamespaceMg } // Move the interface into the namespace. - err = d.ifHandler.SetLinkNamespace(link, ns) - if err != nil { + if err := d.ifHandler.SetLinkNamespace(link, ns); err != nil { return errors.Errorf("failed to set interface %s file descriptor: %v", link.Attrs().Name, err) } @@ -1009,8 +1025,7 @@ func (d *InterfaceDescriptor) setInterfaceNamespace(ctx nslinuxcalls.NamespaceMg if !isIPv6 && address.IP.IsLinkLocalUnicast() { continue } - err = d.ifHandler.AddInterfaceIP(ifName, address) - if err != nil { + if err := d.ifHandler.AddInterfaceIP(ifName, address); err != nil { if err.Error() == "file exists" { continue } @@ -1098,7 +1113,6 @@ func getSysctl(name string) (string, error) { if err != nil { return "", err } - return string(data[:len(data)-1]), nil } @@ -1108,6 +1122,5 @@ func setSysctl(name, value string) (string, error) { if err := ioutil.WriteFile(fullName, []byte(value), 0644); err != nil { return "", err } - return getSysctl(name) } diff --git a/plugins/linux/ifplugin/descriptor/interface_tap.go b/plugins/linux/ifplugin/descriptor/interface_tap.go index f6833b49c4..aa2dc87dfe 100644 --- a/plugins/linux/ifplugin/descriptor/interface_tap.go +++ b/plugins/linux/ifplugin/descriptor/interface_tap.go @@ -27,8 +27,10 @@ import ( // createTAPToVPP moves Linux-side of the VPP-TAP interface to the destination namespace // and sets the requested host name, IP addresses, etc. -func (d *InterfaceDescriptor) createTAPToVPP(nsCtx nslinuxcalls.NamespaceMgmtCtx, key string, - linuxIf *interfaces.Interface) (metadata *ifaceidx.LinuxIfMetadata, err error) { +func (d *InterfaceDescriptor) createTAPToVPP( + nsCtx nslinuxcalls.NamespaceMgmtCtx, key string, linuxIf *interfaces.Interface, +) ( + md *ifaceidx.LinuxIfMetadata, err error) { // determine TAP interface name as set by VPP ifplugin vppTapName := linuxIf.GetTap().GetVppTapIfName() @@ -45,7 +47,8 @@ func (d *InterfaceDescriptor) createTAPToVPP(nsCtx nslinuxcalls.NamespaceMgmtCtx agentPrefix := d.serviceLabel.GetAgentPrefix() // add alias to associate TAP with the logical name and VPP-TAP reference - err = d.ifHandler.SetInterfaceAlias(vppTapHostName, agentPrefix+getTapAlias(linuxIf, vppTapHostName)) + alias := agentPrefix + getTapAlias(linuxIf, vppTapHostName) + err = d.ifHandler.SetInterfaceAlias(vppTapHostName, alias) if err != nil { d.log.Error(err) return nil, err @@ -67,8 +70,7 @@ func (d *InterfaceDescriptor) createTAPToVPP(nsCtx nslinuxcalls.NamespaceMgmtCtx defer revert() // rename from temporary host name to the request host name - d.ifHandler.RenameInterface(vppTapHostName, hostName) - if err != nil { + if err := d.ifHandler.RenameInterface(vppTapHostName, hostName); err != nil { d.log.Error(err) return nil, err } @@ -79,13 +81,12 @@ func (d *InterfaceDescriptor) createTAPToVPP(nsCtx nslinuxcalls.NamespaceMgmtCtx d.log.Error(err) return nil, err } - metadata = &ifaceidx.LinuxIfMetadata{ + + return &ifaceidx.LinuxIfMetadata{ VPPTapName: vppTapName, Namespace: linuxIf.Namespace, LinuxIfIndex: link.Attrs().Index, - } - - return metadata, nil + }, nil } // deleteAutoTAP returns TAP interface back to the default namespace and renames diff --git a/plugins/linux/ifplugin/descriptor/interface_veth.go b/plugins/linux/ifplugin/descriptor/interface_veth.go index 630c9f3521..fc9a94140f 100644 --- a/plugins/linux/ifplugin/descriptor/interface_veth.go +++ b/plugins/linux/ifplugin/descriptor/interface_veth.go @@ -26,8 +26,10 @@ import ( // createVETH creates a new VETH pair if neither of VETH-ends are configured, or just // applies configuration to the unfinished VETH-end with a temporary host name. -func (d *InterfaceDescriptor) createVETH(nsCtx nslinuxcalls.NamespaceMgmtCtx, key string, - linuxIf *interfaces.Interface) (metadata *ifaceidx.LinuxIfMetadata, err error) { +func (d *InterfaceDescriptor) createVETH( + nsCtx nslinuxcalls.NamespaceMgmtCtx, key string, linuxIf *interfaces.Interface, +) ( + md *ifaceidx.LinuxIfMetadata, err error) { // determine host/logical/temporary interface names hostName := getHostIfName(linuxIf) @@ -92,12 +94,11 @@ func (d *InterfaceDescriptor) createVETH(nsCtx nslinuxcalls.NamespaceMgmtCtx, ke d.log.Error(err) return nil, err } - metadata = &ifaceidx.LinuxIfMetadata{ + + return &ifaceidx.LinuxIfMetadata{ Namespace: linuxIf.Namespace, LinuxIfIndex: link.Attrs().Index, - } - - return metadata, nil + }, nil } // deleteVETH either un-configures one VETH-end if the other end is still configured, or diff --git a/plugins/vpp/ifplugin/descriptor/interface.go b/plugins/vpp/ifplugin/descriptor/interface.go index 6fc00d59d0..f9c92a2edc 100644 --- a/plugins/vpp/ifplugin/descriptor/interface.go +++ b/plugins/vpp/ifplugin/descriptor/interface.go @@ -360,13 +360,13 @@ func (d *InterfaceDescriptor) Validate(key string, intf *interfaces.Interface) e } // validate interface type defined - if intf.Type == interfaces.Interface_UNDEFINED_TYPE { + if intf.GetType() == interfaces.Interface_UNDEFINED_TYPE { return kvs.NewInvalidValueError(ErrInterfaceWithoutType, "type") } // validate link with interface type linkMismatchErr := kvs.NewInvalidValueError(ErrInterfaceLinkMismatch, "link") - switch intf.Link.(type) { + switch intf.GetLink().(type) { case *interfaces.Interface_Sub: if intf.Type != interfaces.Interface_SUB_INTERFACE { return linkMismatchErr @@ -433,7 +433,7 @@ func (d *InterfaceDescriptor) Validate(key string, intf *interfaces.Interface) e } } - // validate Rx Placement before it gets derived out + // validate rx placements before before deriving for i, rxPlacement1 := range intf.GetRxPlacements() { for j := i + 1; j < len(intf.GetRxPlacements()); j++ { rxPlacement2 := intf.GetRxPlacements()[j] @@ -607,7 +607,7 @@ func (d *InterfaceDescriptor) DerivedValues(key string, intf *interfaces.Interfa // Rx mode if len(intf.GetRxModes()) > 0 { derValues = append(derValues, kvs.KeyValuePair{ - Key: interfaces.RxModesKey(intf.GetName()), + Key: interfaces.RxModesKey(intf.GetName()), Value: &interfaces.Interface{ Name: intf.GetName(), Type: intf.GetType(), diff --git a/plugins/vpp/ifplugin/descriptor/rx_mode.go b/plugins/vpp/ifplugin/descriptor/rx_mode.go index 59130aafc5..3a9a6ccd68 100644 --- a/plugins/vpp/ifplugin/descriptor/rx_mode.go +++ b/plugins/vpp/ifplugin/descriptor/rx_mode.go @@ -68,16 +68,16 @@ func NewRxModeDescriptor(ifHandler vppcalls.InterfaceVppAPI, ifIndex ifaceidx.If } typedDescr := &adapter.RxModeDescriptor{ - Name: RxModeDescriptorName, - KeySelector: ctx.IsInterfaceRxModeKey, + Name: RxModeDescriptorName, + KeySelector: ctx.IsInterfaceRxModeKey, // proto message Interface is only used as container for RxMode - ValueTypeName: proto.MessageName(&interfaces.Interface{}), + ValueTypeName: proto.MessageName(&interfaces.Interface{}), ValueComparator: ctx.EquivalentRxMode, - Validate: ctx.Validate, - Create: ctx.Create, - Update: ctx.Update, - Delete: ctx.Delete, - Dependencies: ctx.Dependencies, + Validate: ctx.Validate, + Create: ctx.Create, + Update: ctx.Update, + Delete: ctx.Delete, + Dependencies: ctx.Dependencies, } return adapter.NewRxModeDescriptor(typedDescr) @@ -131,7 +131,7 @@ func (d *RxModeDescriptor) Validate(key string, ifaceWithRxMode *interfaces.Inte for i, rxMode1 := range ifaceWithRxMode.GetRxModes() { if rxMode1.Mode == interfaces.Interface_RxMode_UNKNOWN { if rxMode1.DefaultMode { - return kvs.NewInvalidValueError(ErrUndefinedRxMode,"rx_mode[default]") + return kvs.NewInvalidValueError(ErrUndefinedRxMode, "rx_mode[default]") } return kvs.NewInvalidValueError(ErrUndefinedRxMode, fmt.Sprintf("rx_mode[.queue=%d]", rxMode1.Queue)) @@ -142,7 +142,7 @@ func (d *RxModeDescriptor) Validate(key string, ifaceWithRxMode *interfaces.Inte continue } if rxMode1.DefaultMode { - return kvs.NewInvalidValueError(ErrRedefinedRxMode,"rx_mode[default]") + return kvs.NewInvalidValueError(ErrRedefinedRxMode, "rx_mode[default]") } if rxMode1.Queue == rxMode2.Queue { return kvs.NewInvalidValueError(ErrRedefinedRxMode, diff --git a/plugins/vpp/ifplugin/descriptor/rx_placement.go b/plugins/vpp/ifplugin/descriptor/rx_placement.go index 393e3b51ac..e51e416bd5 100644 --- a/plugins/vpp/ifplugin/descriptor/rx_placement.go +++ b/plugins/vpp/ifplugin/descriptor/rx_placement.go @@ -15,9 +15,9 @@ package descriptor import ( - "github.com/pkg/errors" "github.com/gogo/protobuf/proto" "github.com/ligato/cn-infra/logging" + "github.com/pkg/errors" interfaces "github.com/ligato/vpp-agent/api/models/vpp/interfaces" kvs "github.com/ligato/vpp-agent/plugins/kvscheduler/api" @@ -70,8 +70,7 @@ func (d *RxPlacementDescriptor) IsInterfaceRxPlacementKey(key string) bool { } // EquivalentRxMode compares Rx placements for equivalency. -func (d *RxPlacementDescriptor) EquivalentRxPlacement(key string, - oldRxPl, newRxPl *interfaces.Interface_RxPlacement) bool { +func (d *RxPlacementDescriptor) EquivalentRxPlacement(key string, oldRxPl, newRxPl *interfaces.Interface_RxPlacement) bool { if (oldRxPl.MainThread != newRxPl.MainThread) || (!oldRxPl.MainThread && oldRxPl.Worker != newRxPl.Worker) { @@ -83,7 +82,7 @@ func (d *RxPlacementDescriptor) EquivalentRxPlacement(key string, // Create configures RxPlacement for a given interface queue. // Please note the proto message Interface is only used as container for RxMode. // Only interface name, type and Rx mode are set. -func (d *RxPlacementDescriptor) Create(key string, rxPlacement *interfaces.Interface_RxPlacement) (metadata interface{}, err error) { +func (d *RxPlacementDescriptor) Create(key string, rxPlacement *interfaces.Interface_RxPlacement) (md interface{}, err error) { ifaceName, _, _ := interfaces.ParseRxPlacementKey(key) ifMeta, found := d.ifIndex.LookupByName(ifaceName) if !found { @@ -108,7 +107,7 @@ func (d *RxPlacementDescriptor) Delete(key string, rxPlacement *interfaces.Inter // Dependencies informs scheduler that Rx placement configuration cannot be applied // until the interface link is UP. -func (d *RxPlacementDescriptor) Dependencies(key string, rxPlacement *interfaces.Interface_RxPlacement) (deps []kvs.Dependency) { +func (d *RxPlacementDescriptor) Dependencies(key string, rxPlacement *interfaces.Interface_RxPlacement) []kvs.Dependency { ifaceName, _, _ := interfaces.ParseRxPlacementKey(key) return []kvs.Dependency{ { @@ -116,4 +115,4 @@ func (d *RxPlacementDescriptor) Dependencies(key string, rxPlacement *interfaces Key: interfaces.LinkStateKey(ifaceName, true), }, } -} \ No newline at end of file +}