blob: 628c689c5e53343ebeb791b14d004fc32f1ab10e [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001/*
2* Copyright 2018-present Open Networking Foundation
3
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7
8* http://www.apache.org/licenses/LICENSE-2.0
9
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15 */
16
17//Package config provides the Log, kvstore, Kafka configuration
18package config
19
20import (
21 "flag"
22 "fmt"
23 "os"
24 "time"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000025)
26
27// Open ONU default constants
28const (
Himani Chawla6d2ae152020-09-02 13:11:20 +053029 etcdStoreName = "etcd"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000030 defaultInstanceid = "openonu"
Matteo Scandolo127c59d2021-01-28 11:31:18 -080031 defaultKafkaadapteraddress = "127.0.0.1:9092"
32 defaultKafkaclusteraddress = "127.0.0.1:9092"
Himani Chawla6d2ae152020-09-02 13:11:20 +053033 defaultKvstoretype = etcdStoreName
mpagenkoaf801632020-07-03 10:00:42 +000034 defaultKvstoretimeout = 5 * time.Second
Matteo Scandolo127c59d2021-01-28 11:31:18 -080035 defaultKvstoreaddress = "127.0.0.1:2379"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000036 defaultLoglevel = "WARN"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000037 defaultBanner = false
38 defaultDisplayVersionOnly = false
mpagenkodff5dda2020-08-28 11:52:01 +000039 defaultAccIncrEvto = false
Holger Hildebrandtfa074992020-03-27 15:42:06 +000040 defaultTopic = "openonu"
Holger Hildebrandta768fe92020-10-01 13:06:21 +000041 defaultCoreTopic = "rwcore"
42 defaultEventTopic = "voltha.events"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000043 defaultOnunumber = 1
44 defaultProbeHost = ""
45 defaultProbePort = 8080
46 defaultLiveProbeInterval = 60 * time.Second
47 defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
48 //defaultHearbeatFailReportInterval is the time in seconds the adapter will keep checking the hardware for heartbeat.
49 defaultHearbeatCheckInterval = 30 * time.Second
50 // defaultHearbeatFailReportInterval is the time adapter will wait before updating the state to the core.
51 defaultHearbeatFailReportInterval = 180 * time.Second
52 //defaultKafkaReconnectRetries -1: reconnect endlessly.
Himani Chawlad96df182020-09-28 11:12:02 +053053 defaultKafkaReconnectRetries = -1
54 defaultCurrentReplica = 1
55 defaultTotalReplicas = 1
56 defaultMaxTimeoutInterAdapterComm = 30 * time.Second
Andrea Campanella3d7c9312021-01-19 09:20:49 +010057 defaultOnuVendorIds = "OPEN,ALCL,BRCM,TWSH,ALPH,ISKT,SFAA,BBSM,SCOM,ARPX,DACM,ERSN,HWTC,CIGG,ADTN,ARCA,AVMG"
dbainbri4d3a0dc2020-12-02 00:33:42 +000058
59 // For Tracing
60 defaultTraceEnabled = false
61 defaultTraceAgentAddress = "127.0.0.1:6831"
62 defaultLogCorrelationEnabled = true
Girish Gowdraaf0ad632021-01-27 13:00:01 -080063
Holger Hildebrandte3677f12021-02-05 14:50:56 +000064 defaultMetricsEnabled = false
65 defaultMibAuditInterval = 0
Holger Hildebrandtfa074992020-03-27 15:42:06 +000066)
67
68// AdapterFlags represents the set of configurations used by the read-write adaptercore service
69type AdapterFlags struct {
70 // Command line parameters
71 InstanceID string
Matteo Scandolo127c59d2021-01-28 11:31:18 -080072 KafkaAdapterAddress string
73 KafkaClusterAddress string // NOTE this is unused across the adapter
Holger Hildebrandtfa074992020-03-27 15:42:06 +000074 KVStoreType string
mpagenkoaf801632020-07-03 10:00:42 +000075 KVStoreTimeout time.Duration
Matteo Scandolo127c59d2021-01-28 11:31:18 -080076 KVStoreAddress string
Holger Hildebrandtfa074992020-03-27 15:42:06 +000077 Topic string
78 CoreTopic string
79 EventTopic string
80 LogLevel string
81 OnuNumber int
82 Banner bool
83 DisplayVersionOnly bool
mpagenkodff5dda2020-08-28 11:52:01 +000084 AccIncrEvto bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +000085 ProbeHost string
86 ProbePort int
87 LiveProbeInterval time.Duration
88 NotLiveProbeInterval time.Duration
89 HeartbeatCheckInterval time.Duration
90 HeartbeatFailReportInterval time.Duration
91 KafkaReconnectRetries int
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000092 CurrentReplica int
93 TotalReplicas int
Himani Chawlad96df182020-09-28 11:12:02 +053094 MaxTimeoutInterAdapterComm time.Duration
dbainbri4d3a0dc2020-12-02 00:33:42 +000095 TraceEnabled bool
96 TraceAgentAddress string
97 LogCorrelationEnabled bool
Andrea Campanella3d7c9312021-01-19 09:20:49 +010098 OnuVendorIds string
Girish Gowdraaf0ad632021-01-27 13:00:01 -080099 MetricsEnabled bool
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000100 MibAuditInterval time.Duration
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000101}
102
103// NewAdapterFlags returns a new RWCore config
104func NewAdapterFlags() *AdapterFlags {
105 var adapterFlags = AdapterFlags{ // Default values
106 InstanceID: defaultInstanceid,
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800107 KafkaAdapterAddress: defaultKafkaadapteraddress,
108 KafkaClusterAddress: defaultKafkaclusteraddress,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000109 KVStoreType: defaultKvstoretype,
110 KVStoreTimeout: defaultKvstoretimeout,
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800111 KVStoreAddress: defaultKvstoreaddress,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000112 Topic: defaultTopic,
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000113 CoreTopic: defaultCoreTopic,
114 EventTopic: defaultEventTopic,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000115 LogLevel: defaultLoglevel,
116 OnuNumber: defaultOnunumber,
117 Banner: defaultBanner,
118 DisplayVersionOnly: defaultDisplayVersionOnly,
mpagenkodff5dda2020-08-28 11:52:01 +0000119 AccIncrEvto: defaultAccIncrEvto,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000120 ProbeHost: defaultProbeHost,
121 ProbePort: defaultProbePort,
122 LiveProbeInterval: defaultLiveProbeInterval,
123 NotLiveProbeInterval: defaultNotLiveProbeInterval,
124 HeartbeatCheckInterval: defaultHearbeatCheckInterval,
125 HeartbeatFailReportInterval: defaultHearbeatFailReportInterval,
126 KafkaReconnectRetries: defaultKafkaReconnectRetries,
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000127 CurrentReplica: defaultCurrentReplica,
128 TotalReplicas: defaultTotalReplicas,
Himani Chawlad96df182020-09-28 11:12:02 +0530129 MaxTimeoutInterAdapterComm: defaultMaxTimeoutInterAdapterComm,
dbainbri4d3a0dc2020-12-02 00:33:42 +0000130 TraceEnabled: defaultTraceEnabled,
131 TraceAgentAddress: defaultTraceAgentAddress,
132 LogCorrelationEnabled: defaultLogCorrelationEnabled,
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100133 OnuVendorIds: defaultOnuVendorIds,
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800134 MetricsEnabled: defaultMetricsEnabled,
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000135 MibAuditInterval: defaultMibAuditInterval,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000136 }
137 return &adapterFlags
138}
139
140// ParseCommandArguments parses the arguments when running read-write adaptercore service
141func (so *AdapterFlags) ParseCommandArguments() {
142
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800143 help := fmt.Sprintf("Kafka - Adapter messaging address")
144 flag.StringVar(&(so.KafkaAdapterAddress), "kafka_adapter_address", defaultKafkaadapteraddress, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000145
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800146 help = fmt.Sprintf("Kafka - Cluster messaging address")
147 flag.StringVar(&(so.KafkaClusterAddress), "kafka_cluster_address", defaultKafkaclusteraddress, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000148
149 help = fmt.Sprintf("Open ONU topic")
Andrea Campanella961734c2021-01-18 11:44:47 +0100150 baseAdapterTopic := flag.String("adapter_topic", defaultTopic, help)
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000151
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000152 help = fmt.Sprintf("Core topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000153 flag.StringVar(&(so.CoreTopic), "core_topic", defaultCoreTopic, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000154
155 help = fmt.Sprintf("Event topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000156 flag.StringVar(&(so.EventTopic), "event_topic", defaultEventTopic, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000157
158 help = fmt.Sprintf("KV store type")
159 flag.StringVar(&(so.KVStoreType), "kv_store_type", defaultKvstoretype, help)
160
161 help = fmt.Sprintf("The default timeout when making a kv store request")
mpagenkoaf801632020-07-03 10:00:42 +0000162 flag.DurationVar(&(so.KVStoreTimeout), "kv_store_request_timeout", defaultKvstoretimeout, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000163
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800164 help = fmt.Sprintf("KV store address")
165 flag.StringVar(&(so.KVStoreAddress), "kv_store_address", defaultKvstoreaddress, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000166
167 help = fmt.Sprintf("Log level")
168 flag.StringVar(&(so.LogLevel), "log_level", defaultLoglevel, help)
169
170 help = fmt.Sprintf("Number of ONUs")
171 flag.IntVar(&(so.OnuNumber), "onu_number", defaultOnunumber, help)
172
173 help = fmt.Sprintf("Show startup banner log lines")
174 flag.BoolVar(&(so.Banner), "banner", defaultBanner, help)
175
176 help = fmt.Sprintf("Show version information and exit")
177 flag.BoolVar(&(so.DisplayVersionOnly), "version", defaultDisplayVersionOnly, help)
178
mpagenkodff5dda2020-08-28 11:52:01 +0000179 help = fmt.Sprintf("Acceptance of incremental EVTOCD configuration")
180 flag.BoolVar(&(so.AccIncrEvto), "accept_incr_evto", defaultAccIncrEvto, help)
181
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000182 help = fmt.Sprintf("The address on which to listen to answer liveness and readiness probe queries over HTTP.")
183 flag.StringVar(&(so.ProbeHost), "probe_host", defaultProbeHost, help)
184
185 help = fmt.Sprintf("The port on which to listen to answer liveness and readiness probe queries over HTTP.")
186 flag.IntVar(&(so.ProbePort), "probe_port", defaultProbePort, help)
187
188 help = fmt.Sprintf("Number of seconds for the default liveliness check")
189 flag.DurationVar(&(so.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, help)
190
191 help = fmt.Sprintf("Number of seconds for liveliness check if probe is not running")
192 flag.DurationVar(&(so.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, help)
193
194 help = fmt.Sprintf("Number of seconds for heartbeat check interval.")
195 flag.DurationVar(&(so.HeartbeatCheckInterval), "hearbeat_check_interval", defaultHearbeatCheckInterval, help)
196
197 help = fmt.Sprintf("Number of seconds adapter has to wait before reporting core on the hearbeat check failure.")
198 flag.DurationVar(&(so.HeartbeatFailReportInterval), "hearbeat_fail_interval", defaultHearbeatFailReportInterval, help)
199
200 help = fmt.Sprintf("Number of retries to connect to Kafka.")
201 flag.IntVar(&(so.KafkaReconnectRetries), "kafka_reconnect_retries", defaultKafkaReconnectRetries, help)
202
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000203 help = "Replica number of this particular instance (default: %s)"
204 flag.IntVar(&(so.CurrentReplica), "current_replica", defaultCurrentReplica, help)
205
206 help = "Total number of instances for this adapter"
207 flag.IntVar(&(so.TotalReplicas), "total_replica", defaultTotalReplicas, help)
208
Himani Chawlad96df182020-09-28 11:12:02 +0530209 help = fmt.Sprintf("Maximum Number of seconds for the default interadapter communication timeout")
210 flag.DurationVar(&(so.MaxTimeoutInterAdapterComm), "max_timeout_interadapter_comm",
211 defaultMaxTimeoutInterAdapterComm, help)
212
dbainbri4d3a0dc2020-12-02 00:33:42 +0000213 help = fmt.Sprintf("Whether to send logs to tracing agent?")
214 flag.BoolVar(&(so.TraceEnabled), "trace_enabled", defaultTraceEnabled, help)
215
216 help = fmt.Sprintf("The address of tracing agent to which span info should be sent.")
217 flag.StringVar(&(so.TraceAgentAddress), "trace_agent_address", defaultTraceAgentAddress, help)
218
219 help = fmt.Sprintf("Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
220 flag.BoolVar(&(so.LogCorrelationEnabled), "log_correlation_enabled", defaultLogCorrelationEnabled, help)
221
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100222 help = fmt.Sprintf("List of Allowed ONU Vendor Ids")
223 flag.StringVar(&(so.OnuVendorIds), "allowed_onu_vendors", defaultOnuVendorIds, help)
224
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800225 help = fmt.Sprintf("Whether to enable metrics collection")
226 flag.BoolVar(&(so.MetricsEnabled), "metrics_enabled", defaultMetricsEnabled, help)
227
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000228 help = fmt.Sprintf("Mib Audit Interval in seconds - the value zero will disable Mib Audit")
229 flag.DurationVar(&(so.MibAuditInterval), "mib_audit_interval", defaultMibAuditInterval, help)
230
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000231 flag.Parse()
232 containerName := getContainerInfo()
233 if len(containerName) > 0 {
234 so.InstanceID = containerName
235 }
236
Andrea Campanella961734c2021-01-18 11:44:47 +0100237 so.Topic = fmt.Sprintf("%s_%d", *baseAdapterTopic, int32(so.CurrentReplica))
238
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000239}
240
241func getContainerInfo() string {
242 return os.Getenv("HOSTNAME")
243}