go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/descriptor/interface_with_address.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 descriptor 16 17 import ( 18 "go.ligato.io/cn-infra/v2/logging" 19 "google.golang.org/protobuf/proto" 20 21 kvs "go.ligato.io/vpp-agent/v3/plugins/kvscheduler/api" 22 interfaces "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces" 23 ) 24 25 const ( 26 // InterfaceWithAddressDescriptorName is the name of the descriptor for marking 27 // interfaces with at least one IP address assigned. 28 InterfaceWithAddressDescriptorName = "vpp-interface-has-address" 29 30 // dependency labels 31 interfaceHasIPDep = "interface-has-IP" 32 ) 33 34 // InterfaceWithAddrDescriptor assigns property key-value pairs to interfaces 35 // with at least one IP address. 36 type InterfaceWithAddrDescriptor struct { 37 log logging.Logger 38 } 39 40 // NewInterfaceWithAddrDescriptor creates a new instance of InterfaceWithAddrDescriptor. 41 func NewInterfaceWithAddrDescriptor(log logging.PluginLogger) *kvs.KVDescriptor { 42 43 descrCtx := &InterfaceWithAddrDescriptor{ 44 log: log.NewLogger("interface-has-address-descriptor"), 45 } 46 return &kvs.KVDescriptor{ 47 Name: InterfaceWithAddressDescriptorName, 48 KeySelector: descrCtx.IsInterfaceWithAddressKey, 49 Create: descrCtx.Create, 50 Delete: descrCtx.Delete, 51 Dependencies: descrCtx.Dependencies, 52 } 53 } 54 55 // IsInterfaceWithAddressKey returns true if the key is a property assigned to interface 56 // with at least one IP address. 57 func (d *InterfaceWithAddrDescriptor) IsInterfaceWithAddressKey(key string) bool { 58 _, isIfaceWithIPKey := interfaces.ParseInterfaceWithIPKey(key) 59 return isIfaceWithIPKey 60 } 61 62 // Create is NOOP (the key-value pair is a property). 63 func (d *InterfaceWithAddrDescriptor) Create(key string, emptyVal proto.Message) (metadata kvs.Metadata, err error) { 64 return nil, nil 65 } 66 67 // Delete is NOOP (the key-value pair is a property) 68 func (d *InterfaceWithAddrDescriptor) Delete(key string, emptyVal proto.Message, metadata kvs.Metadata) (err error) { 69 return nil 70 } 71 72 // Dependencies ensures that the property is created only after at least one IP 73 // address is successfully assigned to the interface. 74 func (d *InterfaceWithAddrDescriptor) Dependencies(key string, emptyVal proto.Message) (deps []kvs.Dependency) { 75 ifaceName, _ := interfaces.ParseInterfaceWithIPKey(key) 76 return []kvs.Dependency{ 77 { 78 Label: interfaceHasIPDep, 79 AnyOf: kvs.AnyOfDependency{ 80 KeyPrefixes: []string{interfaces.InterfaceAddressPrefix(ifaceName)}, 81 }, 82 }, 83 } 84 }