go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/srplugin/vppcalls/api_vppcalls.go (about) 1 // Copyright (c) 2019 Bell Canada, Pantheon Technologies 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 "net" 19 20 govppapi "go.fd.io/govpp/api" 21 "go.ligato.io/cn-infra/v2/logging" 22 23 "go.ligato.io/vpp-agent/v3/plugins/vpp" 24 "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/ifaceidx" 25 srv6 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/srv6" 26 ) 27 28 // SRv6VppAPI is API boundary for vppcall package access, introduced to properly test code dependent on vppcalls package 29 type SRv6VppAPI interface { 30 SRv6VPPWrite 31 SRv6VPPRead 32 } 33 34 // SRv6VPPWrite provides write methods for segment routing 35 type SRv6VPPWrite interface { 36 // AddLocalSid adds local sid <localSID> into VPP 37 AddLocalSid(localSID *srv6.LocalSID) error 38 // DeleteLocalSid deletes local sid <localSID> in VPP 39 DeleteLocalSid(localSID *srv6.LocalSID) error 40 // SetEncapsSourceAddress sets for SRv6 in VPP the source address used for encapsulated packet 41 SetEncapsSourceAddress(address string) error 42 // AddPolicy adds SRv6 policy <policy> into VPP (including all policy's segment lists). 43 AddPolicy(policy *srv6.Policy) error 44 // DeletePolicy deletes SRv6 policy given by binding SID <bindingSid> (including all policy's segment lists). 45 DeletePolicy(bindingSid net.IP) error 46 // AddPolicySegmentList adds segment list <segmentList> to SRv6 policy <policy> in VPP 47 AddPolicySegmentList(segmentList *srv6.Policy_SegmentList, policy *srv6.Policy) error 48 // DeletePolicySegmentList removes segment list <segmentList> (with VPP-internal index <segmentVPPIndex>) from SRv6 policy <policy> in VPP 49 DeletePolicySegmentList(segmentList *srv6.Policy_SegmentList, segmentVPPIndex uint32, policy *srv6.Policy) error 50 // AddSteering sets in VPP steering into SRv6 policy. 51 AddSteering(steering *srv6.Steering) error 52 // RemoveSteering removes in VPP steering into SRv6 policy. 53 RemoveSteering(steering *srv6.Steering) error 54 } 55 56 // SRv6VPPRead provides read methods for segment routing 57 type SRv6VPPRead interface { 58 // TODO: implement other dump methods 59 60 // DumpLocalSids retrieves all localsids 61 DumpLocalSids() (localsids []*srv6.LocalSID, err error) 62 63 // RetrievePolicyIndexInfo retrieves index of policy <policy> and its segment lists 64 RetrievePolicyIndexInfo(policy *srv6.Policy) (policyIndex uint32, segmentListIndexes map[*srv6.Policy_SegmentList]uint32, err error) 65 } 66 67 var Handler = vpp.RegisterHandler(vpp.HandlerDesc{ 68 Name: "srv6", 69 HandlerAPI: (*SRv6VppAPI)(nil), 70 }) 71 72 type NewHandlerFunc func(vpp.Client, ifaceidx.IfaceMetadataIndex, logging.Logger) SRv6VppAPI 73 74 func AddHandlerVersion(version vpp.Version, msgs []govppapi.Message, h NewHandlerFunc) { 75 Handler.AddVersion(vpp.HandlerVersion{ 76 Version: version, 77 Check: func(c vpp.Client) error { 78 return c.CheckCompatiblity(msgs...) 79 }, 80 NewHandler: func(c vpp.Client, a ...interface{}) vpp.HandlerAPI { 81 return h(c, a[0].(ifaceidx.IfaceMetadataIndex), a[1].(logging.Logger)) 82 }, 83 }) 84 } 85 86 func CompatibleSRv6Handler(c vpp.Client, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) SRv6VppAPI { 87 if v := Handler.FindCompatibleVersion(c); v != nil { 88 return v.NewHandler(c, ifIdx, log).(SRv6VppAPI) 89 } 90 return nil 91 }