go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/l3plugin/vppcalls/l3_vppcalls.go (about) 1 // Copyright (c) 2018 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 vppcalls 16 17 import ( 18 "context" 19 "errors" 20 "net" 21 22 govppapi "go.fd.io/govpp/api" 23 "go.ligato.io/cn-infra/v2/logging" 24 25 "go.ligato.io/vpp-agent/v3/plugins/netalloc" 26 "go.ligato.io/vpp-agent/v3/plugins/vpp" 27 "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/ifaceidx" 28 "go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin/vrfidx" 29 l3 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/l3" 30 ) 31 32 var ( 33 // ErrIPNeighborNotImplemented is used for IPScanNeighAPI handlers that are missing implementation. 34 ErrIPNeighborNotImplemented = errors.New("ip neighbor config not implemented") 35 36 // ErrTeibUnsupported error is returned if TEIB is not supported on given VPP version. 37 ErrTeibUnsupported = errors.New("TEIB is not supported") 38 39 // ErrVRRPUnsupported error is returned if VRRP is not supported on given VPP version. 40 ErrVRRPUnsupported = errors.New("VRRP is not supported") 41 ) 42 43 // L3VppAPI groups L3 Vpp APIs. 44 type L3VppAPI interface { 45 ArpVppAPI 46 ProxyArpVppAPI 47 RouteVppAPI 48 IPNeighVppAPI 49 VrfTableVppAPI 50 DHCPProxyAPI 51 L3XCVppAPI 52 TeibVppAPI 53 VrrpVppAPI 54 } 55 56 // ArpDetails holds info about ARP entry as a proto model 57 type ArpDetails struct { 58 Arp *l3.ARPEntry 59 Meta *ArpMeta 60 } 61 62 // ArpMeta contains interface index of the ARP interface 63 type ArpMeta struct { 64 SwIfIndex uint32 65 } 66 67 // DHCPProxyAPI provides methods for managing ARP entries 68 type DHCPProxyAPI interface { 69 DHCPProxyRead 70 71 // CreateDHCPProxy creates dhcp proxy according to provided input 72 CreateDHCPProxy(entry *l3.DHCPProxy) error 73 // DeleteDHCPProxy deletes created dhcp proxy 74 DeleteDHCPProxy(entry *l3.DHCPProxy) error 75 } 76 77 // DHCPProxyRead provides read methods for routes 78 type DHCPProxyRead interface { 79 // DumpDHCPProxy returns configured DHCP proxy 80 DumpDHCPProxy() ([]*DHCPProxyDetails, error) 81 } 82 83 // DHCPProxyDetails holds info about DHCP proxy entry as a proto model 84 type DHCPProxyDetails struct { 85 DHCPProxy *l3.DHCPProxy 86 } 87 88 // ArpVppAPI provides methods for managing ARP entries 89 type ArpVppAPI interface { 90 ArpVppRead 91 92 // VppAddArp adds ARP entry according to provided input 93 VppAddArp(entry *l3.ARPEntry) error 94 // VppDelArp removes old ARP entry according to provided input 95 VppDelArp(entry *l3.ARPEntry) error 96 } 97 98 // ArpVppRead provides read methods for ARPs 99 type ArpVppRead interface { 100 // DumpArpEntries dumps ARPs from VPP and fills them into the provided static route map. 101 DumpArpEntries() ([]*ArpDetails, error) 102 } 103 104 // ProxyArpRangesDetails holds info about proxy ARP range as a proto modeled data 105 type ProxyArpRangesDetails struct { 106 Range *l3.ProxyARP_Range 107 } 108 109 // ProxyArpInterfaceDetails holds info about proxy ARP interfaces as a proto modeled data 110 type ProxyArpInterfaceDetails struct { 111 Interface *l3.ProxyARP_Interface 112 Meta *ProxyArpInterfaceMeta 113 } 114 115 // ProxyArpInterfaceMeta contains interface vpp index 116 type ProxyArpInterfaceMeta struct { 117 SwIfIndex uint32 118 } 119 120 // ProxyArpVppAPI provides methods for managing proxy ARP entries 121 type ProxyArpVppAPI interface { 122 ProxyArpVppRead 123 124 // EnableProxyArpInterface enables interface for proxy ARP 125 EnableProxyArpInterface(ifName string) error 126 // DisableProxyArpInterface disables interface for proxy ARP 127 DisableProxyArpInterface(ifName string) error 128 // AddProxyArpRange adds new IP range for proxy ARP 129 AddProxyArpRange(firstIP, lastIP []byte, vrfID uint32) error 130 // DeleteProxyArpRange removes proxy ARP IP range 131 DeleteProxyArpRange(firstIP, lastIP []byte, vrfID uint32) error 132 } 133 134 // ProxyArpVppRead provides read methods for proxy ARPs 135 type ProxyArpVppRead interface { 136 // DumpProxyArpRanges returns configured proxy ARP ranges 137 DumpProxyArpRanges() ([]*ProxyArpRangesDetails, error) 138 // DumpProxyArpInterfaces returns configured proxy ARP interfaces 139 DumpProxyArpInterfaces() ([]*ProxyArpInterfaceDetails, error) 140 } 141 142 // RouteDetails is object returned as a VPP dump. It contains static route data in proto format, and VPP-specific 143 // metadata 144 type RouteDetails struct { 145 Route *l3.Route 146 Meta *RouteMeta 147 } 148 149 // VrrpDetails is object returned as a VRRP dump. 150 type VrrpDetails struct { 151 Vrrp *l3.VRRPEntry 152 Meta *VrrpMeta 153 } 154 155 // FibMplsLabel is object returned with route dump. 156 type FibMplsLabel struct { 157 IsUniform bool 158 Label uint32 159 TTL uint8 160 Exp uint8 161 } 162 163 // RouteMeta holds fields returned from the VPP as details which are not in the model 164 type RouteMeta struct { 165 TableName string 166 OutgoingIfIdx uint32 167 IsIPv6 bool 168 Afi uint8 169 IsLocal bool 170 IsUDPEncap bool 171 IsUnreach bool 172 IsProhibit bool 173 IsResolveHost bool 174 IsResolveAttached bool 175 IsDvr bool 176 IsSourceLookup bool 177 NextHopID uint32 178 RpfID uint32 179 LabelStack []FibMplsLabel 180 } 181 182 // VrrpMeta holds fields returned from the VPP as details which are not in the model 183 type VrrpMeta struct{} 184 185 // RouteVppAPI provides methods for managing routes 186 type RouteVppAPI interface { 187 RouteVppRead 188 189 // VppAddRoute adds new route, according to provided input. 190 // Every route has to contain VRF ID (default is 0). 191 VppAddRoute(ctx context.Context, route *l3.Route) error 192 // VppDelRoute removes old route, according to provided input. 193 // Every route has to contain VRF ID (default is 0). 194 VppDelRoute(ctx context.Context, route *l3.Route) error 195 } 196 197 // RouteVppRead provides read methods for routes 198 type RouteVppRead interface { 199 // DumpRoutes dumps l3 routes from VPP and fills them 200 // into the provided static route map. 201 DumpRoutes() ([]*RouteDetails, error) 202 } 203 204 // VrfTableVppAPI provides methods for managing VRF tables. 205 type VrfTableVppAPI interface { 206 VrfTableVppRead 207 208 // AddVrfTable adds new VRF table. 209 AddVrfTable(table *l3.VrfTable) error 210 // DelVrfTable deletes existing VRF table. 211 DelVrfTable(table *l3.VrfTable) error 212 // SetVrfFlowHashSettings sets IP flow hash settings for a VRF table. 213 SetVrfFlowHashSettings(vrfID uint32, isIPv6 bool, hashFields *l3.VrfTable_FlowHashSettings) error 214 } 215 216 // VrfTableVppRead provides read methods for VRF tables. 217 type VrfTableVppRead interface { 218 // DumpVrfTables dumps all configured VRF tables. 219 DumpVrfTables() ([]*l3.VrfTable, error) 220 } 221 222 // IPNeighVppAPI provides methods for managing IP scan neighbor configuration 223 type IPNeighVppAPI interface { 224 // SetIPScanNeighbor configures IP scan neighbor to the VPP 225 SetIPScanNeighbor(data *l3.IPScanNeighbor) error 226 // GetIPScanNeighbor returns IP scan neighbor configuration from the VPP 227 GetIPScanNeighbor() (*l3.IPScanNeighbor, error) 228 // DefaultIPScanNeighbor returns default IP scan neighbor configuration 229 DefaultIPScanNeighbor() *l3.IPScanNeighbor 230 } 231 232 // TeibVppAPI provides methods for managing VPP tunnel information base. 233 type TeibVppAPI interface { 234 TeibVppRead 235 236 // VppAddTeibEntry adds a new TEIB entry. 237 VppAddTeibEntry(ctx context.Context, entry *l3.TeibEntry) error 238 // VppDelTeibEntry removes an existing TEIB entry. 239 VppDelTeibEntry(ctx context.Context, entry *l3.TeibEntry) error 240 } 241 242 // TeibVppRead provides read methods VPP tunnel information base. 243 type TeibVppRead interface { 244 // DumpTeib dumps TEIB entries from VPP and fills them into the provided TEIB entry map. 245 DumpTeib() ([]*l3.TeibEntry, error) 246 } 247 248 // VrrpVppAPI provides methods for managing VPP VRRP. 249 type VrrpVppAPI interface { 250 VppAddVrrp(entry *l3.VRRPEntry) error 251 VppDelVrrp(entry *l3.VRRPEntry) error 252 VppStartVrrp(entry *l3.VRRPEntry) error 253 VppStopVrrp(entry *l3.VRRPEntry) error 254 DumpVrrpEntries() ([]*VrrpDetails, error) 255 } 256 257 // Path represents FIB path entry. 258 type Path struct { 259 SwIfIndex uint32 260 NextHop net.IP 261 Weight uint8 262 Preference uint8 263 } 264 265 // L3XC represents configuration for L3XC. 266 type L3XC struct { 267 SwIfIndex uint32 268 IsIPv6 bool 269 Paths []Path 270 } 271 272 // L3XCVppRead provides read methods for L3XC configuration. 273 type L3XCVppRead interface { 274 DumpAllL3XC(ctx context.Context) ([]L3XC, error) 275 DumpL3XC(ctx context.Context, index uint32) ([]L3XC, error) 276 } 277 278 // L3XCVppAPI provides methods for managing L3XC configuration. 279 type L3XCVppAPI interface { 280 L3XCVppRead 281 282 UpdateL3XC(ctx context.Context, l3xc *L3XC) error 283 DeleteL3XC(ctx context.Context, index uint32, ipv6 bool) error 284 } 285 286 var Handler = vpp.RegisterHandler(vpp.HandlerDesc{ 287 Name: "l3", 288 HandlerAPI: (*L3VppAPI)(nil), 289 }) 290 291 type NewHandlerFunc func(c vpp.Client, idx ifaceidx.IfaceMetadataIndex, vrfIdx vrfidx.VRFMetadataIndex, addrAlloc netalloc.AddressAllocator, log logging.Logger) L3VppAPI 292 293 func AddHandlerVersion(version vpp.Version, msgs []govppapi.Message, h NewHandlerFunc) { 294 Handler.AddVersion(vpp.HandlerVersion{ 295 Version: version, 296 Check: func(c vpp.Client) error { 297 ch, err := c.NewAPIChannel() 298 if err != nil { 299 return err 300 } 301 return ch.CheckCompatiblity(msgs...) 302 }, 303 NewHandler: func(c vpp.Client, a ...interface{}) vpp.HandlerAPI { 304 var vrfIdx vrfidx.VRFMetadataIndex 305 if a[1] != nil { 306 vrfIdx = a[1].(vrfidx.VRFMetadataIndex) 307 } 308 return h(c, a[0].(ifaceidx.IfaceMetadataIndex), vrfIdx, a[2].(netalloc.AddressAllocator), a[3].(logging.Logger)) 309 }, 310 }) 311 } 312 313 func CompatibleL3VppHandler( 314 c vpp.Client, 315 ifIdx ifaceidx.IfaceMetadataIndex, 316 vrfIdx vrfidx.VRFMetadataIndex, 317 addrAlloc netalloc.AddressAllocator, 318 log logging.Logger, 319 ) L3VppAPI { 320 if v := Handler.FindCompatibleVersion(c); v != nil { 321 return v.NewHandler(c, ifIdx, vrfIdx, addrAlloc, log).(L3VppAPI) 322 } 323 return nil 324 }