go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/config.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 ifplugin 16 17 import ( 18 "os" 19 "time" 20 ) 21 22 var ( 23 // PeriodicPollingPeriod between statistics reads 24 // TODO should be configurable 25 PeriodicPollingPeriod = time.Second * 5 26 27 // StateUpdateDelay defines delay before dumping states 28 StateUpdateDelay = time.Second * 3 29 30 disableInterfaceStats = os.Getenv("DISABLE_INTERFACE_STATS") != "" 31 disableStatusPublishing = os.Getenv("DISABLE_STATUS_PUBLISHING") != "" 32 ) 33 34 // Config defines configuration for VPP ifplugin. 35 type Config struct { 36 MTU uint32 `json:"mtu"` 37 StatusPublishers []string `json:"status-publishers"` 38 } 39 40 // DefaultConfig returns Config with default values. 41 func DefaultConfig() Config { 42 return Config{ 43 MTU: 0, 44 } 45 } 46 47 func (p *IfPlugin) loadConfig() (*Config, error) { 48 cfg := DefaultConfig() 49 50 found, err := p.Cfg.LoadValue(&cfg) 51 if err != nil { 52 return nil, err 53 } else if !found { 54 p.Log.Debugf("config %s not found", p.Cfg.GetConfigName()) 55 return nil, nil 56 } 57 p.Log.Debugf("config %s found: %+v", p.Cfg.GetConfigName(), cfg) 58 59 // vppStatusPublishers can override state publishers from the configuration file. 60 if pubs := os.Getenv("VPP_STATUS_PUBLISHERS"); pubs != "" { 61 p.Log.Debugf("status publishers from env: %v", pubs) 62 cfg.StatusPublishers = append(cfg.StatusPublishers, pubs) 63 } 64 65 return &cfg, err 66 }