go.ligato.io/vpp-agent/v3@v3.5.0/proto/ligato/netalloc/models.go (about) 1 // Copyright (c) 2019 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 netalloc 16 17 import ( 18 "net" 19 "strings" 20 21 "go.ligato.io/vpp-agent/v3/pkg/models" 22 ) 23 24 const ( 25 // ModuleName is the module name used for models of the netalloc plugin. 26 ModuleName = "netalloc" 27 28 // AllocRefPrefix is a prefix added in front of references to allocated objects. 29 AllocRefPrefix = "alloc:" 30 31 // AllocRefGWSuffix is a suffix added at the back of the reference when address 32 // of the default gateway is requested (instead of interface IP address). 33 AllocRefGWSuffix = "/GW" 34 ) 35 36 var ( 37 ModelIPAllocation = models.Register(&IPAllocation{}, models.Spec{ 38 Module: ModuleName, 39 Version: "v1", 40 Type: "ip", 41 }, models.WithNameTemplate( 42 "network/{{.NetworkName}}/interface/{{.InterfaceName}}", 43 )) 44 ) 45 46 const ( 47 /* neighbour gateway (derived) */ 48 49 // neighGwKeyTemplate is a template for keys derived from IP allocations 50 // where GW is a neighbour of the interface (addresses are from the same 51 // IP network). 52 neighGwKeyTemplate = "netalloc/neigh-gw/network/{network}/interface/{iface}" 53 ) 54 55 // NeighGwKey returns a derived key used to represent IP allocation where 56 // GW is a neighbour of the interface (addresses are from the same IP network). 57 func NeighGwKey(network, iface string) string { 58 key := strings.Replace(neighGwKeyTemplate, "{network}", network, 1) 59 key = strings.Replace(key, "{iface}", iface, 1) 60 return key 61 } 62 63 // IPAllocMetadata stores allocated IP address already parsed from string. 64 type IPAllocMetadata struct { 65 IfaceAddr *net.IPNet 66 GwAddr *net.IPNet 67 }