go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/abfplugin/vppcalls/abf_vppcalls_api.go (about)

     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 vppcalls
    16  
    17  import (
    18  	govppapi "go.fd.io/govpp/api"
    19  	"go.ligato.io/cn-infra/v2/logging"
    20  
    21  	"go.ligato.io/vpp-agent/v3/plugins/vpp"
    22  	"go.ligato.io/vpp-agent/v3/plugins/vpp/aclplugin/aclidx"
    23  	"go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/ifaceidx"
    24  	abf "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/abf"
    25  )
    26  
    27  // ABFDetails contains proto-modeled ABF data together with VPP-related metadata
    28  type ABFDetails struct {
    29  	ABF  *abf.ABF `json:"abf"`
    30  	Meta *ABFMeta `json:"abf_meta"`
    31  }
    32  
    33  // ABFMeta contains policy ID (ABF index)
    34  type ABFMeta struct {
    35  	PolicyID uint32 `json:"policy_id"`
    36  }
    37  
    38  // ABFVppAPI provides read/write methods required to handle VPP ACL-based forwarding
    39  type ABFVppAPI interface {
    40  	ABFVppRead
    41  
    42  	// AddAbfPolicy creates new ABF entry together with a list of forwarding paths
    43  	AddAbfPolicy(policyID, aclID uint32, abfPaths []*abf.ABF_ForwardingPath) error
    44  	// DeleteAbfPolicy removes existing ABF entry
    45  	DeleteAbfPolicy(policyID uint32, abfPaths []*abf.ABF_ForwardingPath) error
    46  	// AbfAttachInterfaceIPv4 attaches IPv4 interface to the ABF
    47  	AbfAttachInterfaceIPv4(policyID, ifIdx, priority uint32) error
    48  	// AbfDetachInterfaceIPv4 detaches IPV4 interface from the ABF
    49  	AbfDetachInterfaceIPv4(policyID, ifIdx, priority uint32) error
    50  	// AbfAttachInterfaceIPv6 attaches IPv6 interface to the ABF
    51  	AbfAttachInterfaceIPv6(policyID, ifIdx, priority uint32) error
    52  	// AbfDetachInterfaceIPv6 detaches IPv6 interface from the ABF
    53  	AbfDetachInterfaceIPv6(policyID, ifIdx, priority uint32) error
    54  }
    55  
    56  // ABFVppRead provides read methods for ABF plugin
    57  type ABFVppRead interface {
    58  	// GetAbfVersion retrieves version of the VPP ABF plugin
    59  	GetAbfVersion() (ver string, err error)
    60  	// DumpABFPolicy retrieves VPP ABF configuration.
    61  	DumpABFPolicy() ([]*ABFDetails, error)
    62  }
    63  
    64  var Handler = vpp.RegisterHandler(vpp.HandlerDesc{
    65  	Name:       "abf",
    66  	HandlerAPI: (*ABFVppAPI)(nil),
    67  })
    68  
    69  type NewHandlerFunc func(ch govppapi.Channel, aclIdx aclidx.ACLMetadataIndex, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) ABFVppAPI
    70  
    71  func AddABFHandlerVersion(version vpp.Version, msgs []govppapi.Message, h NewHandlerFunc) {
    72  	Handler.AddVersion(vpp.HandlerVersion{
    73  		Version: version,
    74  		Check: func(c vpp.Client) error {
    75  			ch, err := c.NewAPIChannel()
    76  			if err != nil {
    77  				return err
    78  			}
    79  			return ch.CheckCompatiblity(msgs...)
    80  		},
    81  		NewHandler: func(c vpp.Client, a ...interface{}) vpp.HandlerAPI {
    82  			ch, err := c.NewAPIChannel()
    83  			if err != nil {
    84  				return err
    85  			}
    86  			var aclIdx aclidx.ACLMetadataIndex
    87  			if a[0] != nil {
    88  				aclIdx = a[0].(aclidx.ACLMetadataIndex)
    89  			}
    90  			return h(ch, aclIdx, a[1].(ifaceidx.IfaceMetadataIndex), a[2].(logging.Logger))
    91  		},
    92  	})
    93  }
    94  
    95  func CompatibleABFHandler(c vpp.Client, aclIdx aclidx.ACLMetadataIndex, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) ABFVppAPI {
    96  	if v := Handler.FindCompatibleVersion(c); v != nil {
    97  		return v.NewHandler(c, aclIdx, ifIdx, log).(ABFVppAPI)
    98  	}
    99  	return nil
   100  }