go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/l3plugin/vppcalls/vpp2106/ipneigh_vppcalls.go (about) 1 // Copyright (c) 2021 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 vpp2106 16 17 import ( 18 //vpp_ip_neighbor "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2106/ip_neighbor" 19 //"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2106/ip_types" 20 "go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin/vppcalls" 21 l3 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/l3" 22 ) 23 24 /* 25 FIXME: IP neighbor configuraton is not implemented for 20.01, because 26 of breaking change in the API. 27 New proto model must be defined to support configuring this properly. 28 The current model does not allow separated config for IPv4 and IPv6. 29 */ 30 31 // DefaultIPScanNeighbor implements ip neigh handler. 32 func (h *IPNeighHandler) DefaultIPScanNeighbor() *l3.IPScanNeighbor { 33 return nil 34 35 /*return &l3.IPScanNeighbor{ 36 Mode: l3.IPScanNeighbor_DISABLED, 37 MaxProcTime: 0, 38 MaxUpdate: 50000, 39 ScanInterval: 0, 40 ScanIntDelay: 0, 41 StaleThreshold: 0, 42 }*/ 43 } 44 45 // SetIPScanNeighbor implements ip neigh handler. 46 func (h *IPNeighHandler) SetIPScanNeighbor(data *l3.IPScanNeighbor) (err error) { 47 return vppcalls.ErrIPNeighborNotImplemented 48 49 /*switch data.Mode { 50 case l3.IPScanNeighbor_IPV4: 51 return h.setIPScanNeighbor(ip_types.ADDRESS_IP4, data.MaxUpdate, data.MaxProcTime, recycle) 52 case l3.IPScanNeighbor_IPV6: 53 return h.setIPScanNeighbor(ip_types.ADDRESS_IP6, data.MaxUpdate, data.MaxProcTime, recycle) 54 case l3.IPScanNeighbor_BOTH: 55 err = h.setIPScanNeighbor(ip_types.ADDRESS_IP4, data.MaxUpdate, data.MaxProcTime, recycle) 56 if err != nil { 57 return err 58 } 59 err = h.setIPScanNeighbor(ip_types.ADDRESS_IP6, data.MaxUpdate, data.MaxProcTime, recycle) 60 if err != nil { 61 return err 62 } 63 case l3.IPScanNeighbor_DISABLED: 64 err = h.setIPScanNeighbor(ip_types.ADDRESS_IP4, 0, 0, false) 65 if err != nil { 66 return err 67 } 68 err = h.setIPScanNeighbor(ip_types.ADDRESS_IP6, 0, 0, false) 69 if err != nil { 70 return err 71 } 72 default: 73 return fmt.Errorf("unknown IP Scan Neighbor mode: %v", data.Mode) 74 } 75 return nil*/ 76 } 77 78 /*func (h *IPNeighHandler) setIPScanNeighbor(af ip_types.AddressFamily, maxNum, maxAge uint32, recycle bool) error { 79 req := &vpp_ip_neighbor.IPNeighborConfig{ 80 Af: af, 81 MaxNumber: maxNum, 82 MaxAge: maxAge, 83 Recycle: recycle, 84 } 85 reply := &vpp_ip_neighbor.IPNeighborConfigReply{} 86 87 if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil { 88 return err 89 } 90 91 return nil 92 }*/ 93 94 var ( 95 /* 96 Sample outputs for VPP CLI 'show ip neighbor-config' 97 --- 98 ip4: 99 limit:50000, age:0, recycle:0 100 ip6: 101 limit:50000, age:0, recycle:0 102 --- 103 */ 104 //cliIPScanNeighRe = regexp.MustCompile(`(ip4|ip6):\n\s+limit:([0-9]+),\s+age:([0-9]+),\s+recycle:([0-9]+)\s+`) 105 ) 106 107 // GetIPScanNeighbor dumps current IP Scan Neighbor configuration. 108 func (h *IPNeighHandler) GetIPScanNeighbor() (*l3.IPScanNeighbor, error) { 109 return nil, vppcalls.ErrIPNeighborNotImplemented 110 111 /*data, err := h.RunCli(context.TODO(), "show ip neighbor-config") 112 if err != nil { 113 return nil, err 114 } 115 116 allMatches := cliIPScanNeighRe.FindAllStringSubmatch(data, 2) 117 118 fmt.Printf("%d MATCHES:\n%q\n", len(allMatches), allMatches) 119 120 if len(allMatches) != 2 || len(allMatches[0]) != 5 || len(allMatches[1]) != 5 { 121 h.log.Warnf("invalid 'show ip neighbor-config' output: %q", data) 122 return nil, errors.Errorf("invalid VPP CLI output for ip neighbor config") 123 } 124 125 ipScanNeigh := &l3.IPScanNeighbor{} 126 127 for _, matches := range allMatches { 128 switch matches[1] { 129 case "ip4": 130 ipScanNeigh.Mode = l3.IPScanNeighbor_IPV4 131 case "ip6": 132 ipScanNeigh.Mode = l3.IPScanNeighbor_IPV6 133 } 134 ipScanNeigh.MaxUpdate = h.strToUint32(matches[2]) 135 ipScanNeigh.MaxProcTime = h.strToUint32(matches[3]) 136 ipScanNeigh.ScanInterval = h.strToUint32(matches[4]) 137 } 138 139 return ipScanNeigh, nil*/ 140 } 141 142 // func (h *IPNeighHandler) strToUint32(s string) uint32 { 143 // if s == "" { 144 // return 0 145 // } 146 // n, err := strconv.ParseUint(s, 10, 32) 147 // if err != nil { 148 // h.log.Error(err) 149 // } 150 // return uint32(n) 151 // }