go.ligato.io/vpp-agent/v3@v3.5.0/plugins/govppmux/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 govppmux 16 17 import "time" 18 19 // Config defines configurable parameters for govppmux plugin. 20 type Config struct { 21 // ReconnectResync enables resync after reconnect to VPP. 22 ReconnectResync bool `json:"resync-after-reconnect"` 23 24 // ReplyTimeout defines timeout period for replies in channels from VPP. 25 ReplyTimeout time.Duration `json:"reply-timeout"` 26 27 // Connect to VPP for configuration requests via the shared memory instead of through the socket. 28 ConnectViaShm bool `json:"connect-via-shm"` 29 30 // ShmPrefix defines prefix prepended to the name used for shared memory (SHM) segments. 31 // If not set, shared memory segments are created directly in the SHM directory /dev/shm. 32 ShmPrefix string `json:"shm-prefix"` 33 34 // BinAPISocketPath defines path to the binapi socket file. 35 BinAPISocketPath string `json:"binapi-socket-path"` 36 37 // StatsSocketPath defines path to the stats socket file. 38 StatsSocketPath string `json:"stats-socket-path"` 39 40 // How many times can be request resent in case vpp is suddenly disconnected. 41 RetryRequestCount int `json:"retry-request-count"` 42 43 // Time between request resend attempts. Default is 500ms. 44 RetryRequestTimeout time.Duration `json:"retry-request-timeout"` 45 46 // How many times can be connection request resent in case the vpp is not reachable. 47 RetryConnectCount int `json:"retry-connect-count"` 48 49 // Time between connection request resend attempts. Default is 1s. 50 RetryConnectTimeout time.Duration `json:"retry-connect-timeout"` 51 52 // Enable VPP proxy. 53 ProxyEnabled bool `json:"proxy-enabled"` 54 55 // Below are options used for VPP connection health checking. 56 HealthCheckProbeInterval time.Duration `json:"health-check-probe-interval"` 57 HealthCheckReplyTimeout time.Duration `json:"health-check-reply-timeout"` 58 HealthCheckThreshold int `json:"health-check-threshold"` 59 60 // DEPRECATED: TraceEnabled is obsolete and used only in older versions. 61 TraceEnabled bool `json:"trace-enabled"` 62 } 63 64 func DefaultConfig() *Config { 65 return &Config{ 66 ReconnectResync: true, 67 HealthCheckProbeInterval: time.Second, 68 HealthCheckReplyTimeout: 250 * time.Millisecond, 69 HealthCheckThreshold: 1, 70 ReplyTimeout: time.Second, 71 RetryRequestTimeout: 500 * time.Millisecond, 72 RetryConnectTimeout: time.Second, 73 ProxyEnabled: true, 74 } 75 } 76 77 func (p *Plugin) loadConfig() (*Config, error) { 78 cfg := DefaultConfig() 79 found, err := p.Cfg.LoadValue(cfg) 80 if err != nil { 81 return nil, err 82 } else if found { 83 p.Log.Debugf("config loaded from file %q", p.Cfg.GetConfigName()) 84 } else { 85 p.Log.Debugf("config file %q not found, using default config", p.Cfg.GetConfigName()) 86 } 87 return cfg, nil 88 }