go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/l3plugin/vppcalls/vpp2202/vrrp_dump.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 vpp2202 16 17 import ( 18 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2202/vrrp" 19 "go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin/vppcalls" 20 l3 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/l3" 21 ) 22 23 // DumpVrrpEntries dumps all configured VRRP entries. 24 func (h *VrrpVppHandler) DumpVrrpEntries() (entries []*vppcalls.VrrpDetails, err error) { 25 req := &vrrp.VrrpVrDump{ 26 SwIfIndex: 0xffffffff, // Send multirequest to get all VRRP entries 27 } 28 reqCtx := h.callsChannel.SendMultiRequest(req) 29 for { 30 vrrpDetails := &vrrp.VrrpVrDetails{} 31 stop, err := reqCtx.ReceiveReply(vrrpDetails) 32 if stop { 33 break 34 } 35 if err != nil { 36 return nil, err 37 } 38 39 // VRRP interface 40 ifName, _, exists := h.ifIndexes.LookupBySwIfIndex(uint32(vrrpDetails.Config.SwIfIndex)) 41 if !exists { 42 h.log.Warnf("VRRP dump: interface name not found for index %d", vrrpDetails.Config.SwIfIndex) 43 } 44 45 var isEnabled bool 46 if vrrpDetails.Runtime.State != vrrp.VRRP_API_VR_STATE_INIT { 47 isEnabled = true 48 } 49 50 isPreempt := (vrrpDetails.Config.Flags & vrrp.VRRP_API_VR_PREEMPT) == vrrp.VRRP_API_VR_PREEMPT 51 isAccept := (vrrpDetails.Config.Flags & vrrp.VRRP_API_VR_ACCEPT) == vrrp.VRRP_API_VR_ACCEPT 52 isUnicast := (vrrpDetails.Config.Flags & vrrp.VRRP_API_VR_UNICAST) == vrrp.VRRP_API_VR_UNICAST 53 54 ipStrs := make([]string, 0, len(vrrpDetails.Addrs)) 55 for _, v := range vrrpDetails.Addrs { 56 ipStrs = append(ipStrs, v.String()) 57 } 58 59 // VRRP entry 60 vrrp := &vppcalls.VrrpDetails{ 61 Vrrp: &l3.VRRPEntry{ 62 Interface: ifName, 63 VrId: uint32(vrrpDetails.Config.VrID), 64 Priority: uint32(vrrpDetails.Config.Priority), 65 Interval: uint32(vrrpDetails.Config.Interval) * centiMilliRatio, 66 Preempt: isPreempt, 67 Accept: isAccept, 68 Unicast: isUnicast, 69 IpAddresses: ipStrs, 70 Enabled: isEnabled, 71 }, 72 Meta: &vppcalls.VrrpMeta{}, 73 } 74 75 entries = append(entries, vrrp) 76 } 77 78 return entries, nil 79 }