go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/natplugin/vppcalls/vpp2101/vppcalls_handler.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 vpp2101
    16  
    17  import (
    18  	govppapi "go.fd.io/govpp/api"
    19  	"go.ligato.io/cn-infra/v2/idxmap"
    20  	"go.ligato.io/cn-infra/v2/logging"
    21  
    22  	"go.ligato.io/vpp-agent/v3/plugins/vpp"
    23  	"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101"
    24  	vpp_ip "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/ip"
    25  	vpp_nat "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/nat44"
    26  	"go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/ifaceidx"
    27  	"go.ligato.io/vpp-agent/v3/plugins/vpp/natplugin/vppcalls"
    28  )
    29  
    30  func init() {
    31  	var msgs []govppapi.Message
    32  	msgs = append(msgs, vpp_nat.AllMessages()...)
    33  
    34  	vppcalls.AddNatHandlerVersion(vpp2101.Version, msgs, NewNatVppHandler)
    35  }
    36  
    37  // NatVppHandler is accessor for NAT-related vppcalls methods.
    38  type NatVppHandler struct {
    39  	callsChannel govppapi.Channel
    40  	ip           vpp_ip.RPCService
    41  	nat          vpp_nat.RPCService
    42  	ifIndexes    ifaceidx.IfaceMetadataIndex
    43  	dhcpIndex    idxmap.NamedMapping
    44  	log          logging.Logger
    45  }
    46  
    47  // NewNatVppHandler creates new instance of NAT vppcalls handler.
    48  func NewNatVppHandler(c vpp.Client,
    49  	ifIndexes ifaceidx.IfaceMetadataIndex, dhcpIndex idxmap.NamedMapping, log logging.Logger,
    50  ) vppcalls.NatVppAPI {
    51  	callsChan, _ := c.NewAPIChannel()
    52  	return &NatVppHandler{
    53  		callsChannel: callsChan,
    54  		ip:           vpp_ip.NewServiceClient(c),
    55  		nat:          vpp_nat.NewServiceClient(c),
    56  		ifIndexes:    ifIndexes,
    57  		dhcpIndex:    dhcpIndex,
    58  		log:          log,
    59  	}
    60  }