go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/l3plugin/vppcalls/vpp2210/vrf_vppcalls.go (about) 1 // Copyright (c) 2022 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 vpp2210 16 17 import ( 18 vpp_ip "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2210/ip" 19 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2210/ip_types" 20 l3 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/l3" 21 ) 22 23 // AddVrfTable adds new VRF table. 24 func (h *VrfTableHandler) AddVrfTable(table *l3.VrfTable) error { 25 return h.addDelVrfTable(table, true) 26 } 27 28 // DelVrfTable deletes existing VRF table. 29 func (h *VrfTableHandler) DelVrfTable(table *l3.VrfTable) error { 30 return h.addDelVrfTable(table, false) 31 } 32 33 func (h *VrfTableHandler) addDelVrfTable(table *l3.VrfTable, isAdd bool) error { 34 req := &vpp_ip.IPTableAddDel{ 35 Table: vpp_ip.IPTable{ 36 TableID: table.Id, 37 IsIP6: table.GetProtocol() == l3.VrfTable_IPV6, 38 Name: table.Label, 39 }, 40 IsAdd: isAdd, 41 } 42 reply := &vpp_ip.IPTableAddDelReply{} 43 44 if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil { 45 return err 46 } 47 48 return nil 49 } 50 51 // SetVrfFlowHashSettings sets IP flow hash settings for a VRF table. 52 func (h *VrfTableHandler) SetVrfFlowHashSettings(vrfID uint32, isIPv6 bool, hashFields *l3.VrfTable_FlowHashSettings) error { 53 af := ip_types.ADDRESS_IP4 54 if isIPv6 { 55 af = ip_types.ADDRESS_IP6 56 } 57 req := &vpp_ip.SetIPFlowHashV2{ 58 TableID: vrfID, 59 Af: af, 60 FlowHashConfig: setFlowHashConfig(hashFields), 61 } 62 reply := &vpp_ip.SetIPFlowHashV2Reply{} 63 64 err := h.callsChannel.SendRequest(req).ReceiveReply(reply) 65 return err 66 } 67 68 func setFlowHashConfig(fields *l3.VrfTable_FlowHashSettings) vpp_ip.IPFlowHashConfig { 69 var config vpp_ip.IPFlowHashConfig 70 if fields.UseSrcIp { 71 config |= vpp_ip.IP_API_FLOW_HASH_SRC_IP 72 } 73 if fields.UseDstIp { 74 config |= vpp_ip.IP_API_FLOW_HASH_DST_IP 75 } 76 if fields.UseSrcPort { 77 config |= vpp_ip.IP_API_FLOW_HASH_SRC_PORT 78 } 79 if fields.UseDstPort { 80 config |= vpp_ip.IP_API_FLOW_HASH_DST_PORT 81 } 82 if fields.UseProtocol { 83 config |= vpp_ip.IP_API_FLOW_HASH_PROTO 84 } 85 if fields.Reverse { 86 config |= vpp_ip.IP_API_FLOW_HASH_REVERSE 87 } 88 if fields.Symmetric { 89 config |= vpp_ip.IP_API_FLOW_HASH_SYMETRIC 90 } 91 return config 92 }