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

     1  // Copyright (c) 2017 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/pkg/idxvpp"
    22  	"go.ligato.io/vpp-agent/v3/plugins/vpp"
    23  	"go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/ifaceidx"
    24  	l2 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/l2"
    25  )
    26  
    27  // BridgeDomainDetails is the wrapper structure for the bridge domain northbound API structure.
    28  // NOTE: Interfaces in BridgeDomains_BridgeDomain is overridden by the local Interfaces member.
    29  type BridgeDomainDetails struct {
    30  	Bd   *l2.BridgeDomain  `json:"bridge_domain"`
    31  	Meta *BridgeDomainMeta `json:"bridge_domain_meta"`
    32  }
    33  
    34  // BridgeDomainMeta contains bridge domain interface name/index map
    35  type BridgeDomainMeta struct {
    36  	BdID uint32 `json:"bridge_domain_id"`
    37  }
    38  
    39  // L2VppAPI groups L2 Vpp APIs.
    40  type L2VppAPI interface {
    41  	BridgeDomainVppAPI
    42  	FIBVppAPI
    43  	XConnectVppAPI
    44  }
    45  
    46  // BridgeDomainVppAPI provides methods for managing bridge domains.
    47  type BridgeDomainVppAPI interface {
    48  	BridgeDomainVppRead
    49  
    50  	// AddBridgeDomain adds new bridge domain.
    51  	AddBridgeDomain(bdIdx uint32, bd *l2.BridgeDomain) error
    52  	// DeleteBridgeDomain removes existing bridge domain.
    53  	DeleteBridgeDomain(bdIdx uint32) error
    54  	// AddInterfaceToBridgeDomain puts interface into bridge domain.
    55  	AddInterfaceToBridgeDomain(bdIdx uint32, ifaceCfg *l2.BridgeDomain_Interface) error
    56  	// DeleteInterfaceFromBridgeDomain removes interface from bridge domain.
    57  	DeleteInterfaceFromBridgeDomain(bdIdx uint32, ifaceCfg *l2.BridgeDomain_Interface) error
    58  	// AddArpTerminationTableEntry creates ARP termination entry for bridge domain.
    59  	AddArpTerminationTableEntry(bdID uint32, mac string, ip string) error
    60  	// RemoveArpTerminationTableEntry removes ARP termination entry from bridge domain.
    61  	RemoveArpTerminationTableEntry(bdID uint32, mac string, ip string) error
    62  }
    63  
    64  // BridgeDomainVppRead provides read methods for bridge domains.
    65  type BridgeDomainVppRead interface {
    66  	// DumpBridgeDomains dumps VPP bridge domain data into the northbound API data structure
    67  	// map indexed by bridge domain ID.
    68  	DumpBridgeDomains() ([]*BridgeDomainDetails, error)
    69  }
    70  
    71  // FibTableDetails is the wrapper structure for the FIB table entry northbound API structure.
    72  type FibTableDetails struct {
    73  	Fib  *l2.FIBEntry `json:"fib"`
    74  	Meta *FibMeta     `json:"fib_meta"`
    75  }
    76  
    77  // FibMeta contains FIB interface and bridge domain name/index map
    78  type FibMeta struct {
    79  	BdID  uint32 `json:"bridge_domain_id"`
    80  	IfIdx uint32 `json:"outgoing_interface_sw_if_idx"`
    81  }
    82  
    83  // FIBVppAPI provides methods for managing FIBs.
    84  type FIBVppAPI interface {
    85  	FIBVppRead
    86  
    87  	// AddL2FIB creates L2 FIB table entry.
    88  	AddL2FIB(fib *l2.FIBEntry) error
    89  	// DeleteL2FIB removes existing L2 FIB table entry.
    90  	DeleteL2FIB(fib *l2.FIBEntry) error
    91  }
    92  
    93  // FIBVppRead provides read methods for FIBs.
    94  type FIBVppRead interface {
    95  	// DumpL2FIBs dumps VPP L2 FIB table entries into the northbound API
    96  	// data structure map indexed by destination MAC address.
    97  	DumpL2FIBs() (map[string]*FibTableDetails, error)
    98  }
    99  
   100  // XConnectDetails is the wrapper structure for the l2 xconnect northbound API structure.
   101  type XConnectDetails struct {
   102  	Xc   *l2.XConnectPair `json:"x_connect"`
   103  	Meta *XcMeta          `json:"x_connect_meta"`
   104  }
   105  
   106  // XcMeta contains cross connect rx/tx interface indexes
   107  type XcMeta struct {
   108  	ReceiveInterfaceSwIfIdx  uint32 `json:"receive_interface_sw_if_idx"`
   109  	TransmitInterfaceSwIfIdx uint32 `json:"transmit_interface_sw_if_idx"`
   110  }
   111  
   112  // XConnectVppAPI provides methods for managing cross connects.
   113  type XConnectVppAPI interface {
   114  	XConnectVppRead
   115  
   116  	// AddL2XConnect creates xConnect between two existing interfaces.
   117  	AddL2XConnect(rxIface, txIface string) error
   118  	// DeleteL2XConnect removes xConnect between two interfaces.
   119  	DeleteL2XConnect(rxIface, txIface string) error
   120  }
   121  
   122  // XConnectVppRead provides read methods for cross connects.
   123  type XConnectVppRead interface {
   124  	// DumpXConnectPairs dumps VPP xconnect pair data into the northbound API
   125  	// data structure map indexed by rx interface index.
   126  	DumpXConnectPairs() (map[uint32]*XConnectDetails, error)
   127  }
   128  
   129  var Handler = vpp.RegisterHandler(vpp.HandlerDesc{
   130  	Name:       "l2",
   131  	HandlerAPI: (*L2VppAPI)(nil),
   132  })
   133  
   134  type NewHandlerFunc func(ch govppapi.Channel, ifDdx ifaceidx.IfaceMetadataIndex, bdIdx idxvpp.NameToIndex, log logging.Logger) L2VppAPI
   135  
   136  func AddHandlerVersion(version vpp.Version, msgs []govppapi.Message, h NewHandlerFunc) {
   137  	Handler.AddVersion(vpp.HandlerVersion{
   138  		Version: version,
   139  		Check: func(c vpp.Client) error {
   140  			ch, err := c.NewAPIChannel()
   141  			if err != nil {
   142  				return err
   143  			}
   144  			return ch.CheckCompatiblity(msgs...)
   145  		},
   146  		NewHandler: func(c vpp.Client, a ...interface{}) vpp.HandlerAPI {
   147  			ch, err := c.NewAPIChannel()
   148  			if err != nil {
   149  				return err
   150  			}
   151  			var bdIdx idxvpp.NameToIndex
   152  			if a[1] != nil {
   153  				bdIdx = a[1].(idxvpp.NameToIndex)
   154  			}
   155  			return h(ch, a[0].(ifaceidx.IfaceMetadataIndex), bdIdx, a[2].(logging.Logger))
   156  		},
   157  	})
   158  }
   159  
   160  func CompatibleL2VppHandler(c vpp.Client, ifIdx ifaceidx.IfaceMetadataIndex, bdIdx idxvpp.NameToIndex, log logging.Logger) L2VppAPI {
   161  	if v := Handler.FindCompatibleVersion(c); v != nil {
   162  		return v.NewHandler(c, ifIdx, bdIdx, log).(L2VppAPI)
   163  	}
   164  	return nil
   165  }