blob: d06607e480a7b2c7834ac196331f1b9552103085 [file] [log] [blame]
Girish Gowdru0c588b22019-04-23 23:24:56 -04001/*
Joey Armstrong11f5a572024-01-12 19:11:32 -05002* Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors
Girish Gowdru0c588b22019-04-23 23:24:56 -04003
cbabu116b73f2019-12-10 17:56:32 +05304* 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
Girish Gowdru0c588b22019-04-23 23:24:56 -04007
cbabu116b73f2019-12-10 17:56:32 +05308* http://www.apache.org/licenses/LICENSE-2.0
Girish Gowdru0c588b22019-04-23 23:24:56 -04009
cbabu116b73f2019-12-10 17:56:32 +053010* 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.
Girish Gowdru0c588b22019-04-23 23:24:56 -040015 */
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070016
Joey Armstrong3f0e2422023-07-05 18:25:41 -040017// Package config provides the Log, kvstore, Kafka configuration
Girish Gowdru0c588b22019-04-23 23:24:56 -040018package config
19
20import (
21 "flag"
Girish Gowdru0c588b22019-04-23 23:24:56 -040022 "os"
cbabu116b73f2019-12-10 17:56:32 +053023 "time"
Girish Gowdru0c588b22019-04-23 23:24:56 -040024)
25
26// Open OLT default constants
27const (
Abhay Kumar9bcfeb22024-07-12 09:14:25 +053028 KVStoreName = "etcd"
cbabu116b73f2019-12-10 17:56:32 +053029 defaultInstanceid = "openOlt001"
khenaidoo106c61a2021-08-11 18:05:46 -040030 defaultKafkaclusteraddress = "127.0.0.1:9092"
Abhay Kumar9bcfeb22024-07-12 09:14:25 +053031 defaultKvstoretype = KVStoreName
Neha Sharma3f221ae2020-04-29 19:02:12 +000032 defaultKvstoretimeout = 5 * time.Second
khenaidoo106c61a2021-08-11 18:05:46 -040033 defaultRPCTimeout = 10 * time.Second
nikesh.krishnan6dd882b2023-03-14 10:02:41 +053034 defaultPerRPCRetryTimeout = 2 * time.Second
Neha Sharma3f221ae2020-04-29 19:02:12 +000035 defaultKvstoreaddress = "127.0.0.1:2379" // Port: Consul = 8500; Etcd = 2379
David Bainbridge2b3d4882020-03-17 15:06:39 -070036 defaultLoglevel = "WARN"
cbabu116b73f2019-12-10 17:56:32 +053037 defaultBanner = false
38 defaultDisplayVersionOnly = false
cbabu116b73f2019-12-10 17:56:32 +053039 defaultEventtopic = "voltha.events"
40 defaultOnunumber = 1
Neha Sharma3f221ae2020-04-29 19:02:12 +000041 defaultProbeAddress = ":8080"
Abhay Kumard3f18512025-12-09 07:51:12 +000042 defaultPrometheusPort = ":8081"
cbabu116b73f2019-12-10 17:56:32 +053043 defaultLiveProbeInterval = 60 * time.Second
44 defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
Akash Kankanala041a2122024-10-16 15:49:22 +053045 // defaultHeartbeatCheckInterval is the time in seconds the adapter will keep checking the hardware for heartbeat.
Girish Gowdra495dde42021-03-17 14:59:56 -070046 defaultHeartbeatCheckInterval = 15 * time.Second
47 // defaultHeartbeatFailReportInterval is the time adapter will wait before updating the state to the core.
48 defaultHeartbeatFailReportInterval = 0 * time.Second
khenaidoo106c61a2021-08-11 18:05:46 -040049 defaultGrpcAddress = ":50060"
50 defaultCoreEndpoint = ":55555"
Akash Kankanala041a2122024-10-16 15:49:22 +053051 // defaultGrpcTimeoutInterval is the time in seconds a grpc call will wait before returning error.
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053052 defaultGrpcTimeoutInterval = 2 * time.Second
53 defaultCurrentReplica = 1
54 defaultTotalReplicas = 1
55 defaultTraceEnabled = false
56 defaultTraceAgentAddress = "127.0.0.1:6831"
57 defaultLogCorrelationEnabled = true
58 defaultOmccEncryption = false
59 defaultEnableONUStats = false
60 defaultEnableGEMStats = false
61 defaultMinBackoffRetryDelay = 500 * time.Millisecond
62 defaultMaxBackoffRetryDelay = 10 * time.Second
63 defaultAdapterEndpoint = "adapter-open-olt"
64 defaultCheckOnuDevExistenceAtOnuDiscovery = false
Sridhar Ravindraab785f22025-07-21 17:20:55 +053065 defaultForceOnuDiscIndProcessing = false
nikesh.krishnan6dd882b2023-03-14 10:02:41 +053066 defaultMaxRetries = 10
akashreddyk02b2bfe2025-09-05 10:37:40 +053067 defaultProducerRetryMax = 10
68 defaultMetadataRetryMax = 15
Girish Gowdru0c588b22019-04-23 23:24:56 -040069)
70
71// AdapterFlags represents the set of configurations used by the read-write adaptercore service
72type AdapterFlags struct {
73 // Command line parameters
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053074 AdapterName string
75 InstanceID string // NOTE what am I used for? why not cli but only ENV? TODO expose in the chart
76 KafkaClusterAddress string
77 KVStoreType string
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053078 KVStoreAddress string
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053079 EventTopic string
80 LogLevel string
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053081 ProbeAddress string
Abhay Kumard3f18512025-12-09 07:51:12 +000082 PrometheusAddress string
Akash Kankanala041a2122024-10-16 15:49:22 +053083 GrpcAddress string
84 CoreEndpoint string
85 TraceAgentAddress string
86 AdapterEndpoint string
87 KVStoreTimeout time.Duration
88 RPCTimeout time.Duration
89 PerRPCRetryTimeout time.Duration
90 OnuNumber int
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053091 LiveProbeInterval time.Duration
92 NotLiveProbeInterval time.Duration
93 HeartbeatCheckInterval time.Duration
94 HeartbeatFailReportInterval time.Duration
95 GrpcTimeoutInterval time.Duration
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053096 CurrentReplica int
97 TotalReplicas int
Akash Kankanala041a2122024-10-16 15:49:22 +053098 MinBackoffRetryDelay time.Duration
99 MaxBackoffRetryDelay time.Duration
100 MaxRetries uint
101 Banner bool
102 DisplayVersionOnly bool
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530103 TraceEnabled bool
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530104 LogCorrelationEnabled bool
105 OmccEncryption bool
106 EnableONUStats bool
107 EnableGEMStats bool
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530108 CheckOnuDevExistenceAtOnuDiscovery bool
Sridhar Ravindraab785f22025-07-21 17:20:55 +0530109 ForceOnuDiscIndProcessing bool
akashreddyk02b2bfe2025-09-05 10:37:40 +0530110 ProducerRetryMax int
111 MetadataRetryMax int
Girish Gowdru0c588b22019-04-23 23:24:56 -0400112}
113
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700114// NewAdapterFlags returns a new RWCore config
Girish Gowdru0c588b22019-04-23 23:24:56 -0400115func NewAdapterFlags() *AdapterFlags {
116 var adapterFlags = AdapterFlags{ // Default values
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530117 InstanceID: defaultInstanceid,
118 KafkaClusterAddress: defaultKafkaclusteraddress,
119 KVStoreType: defaultKvstoretype,
120 KVStoreTimeout: defaultKvstoretimeout,
121 KVStoreAddress: defaultKvstoreaddress,
122 EventTopic: defaultEventtopic,
123 LogLevel: defaultLoglevel,
124 OnuNumber: defaultOnunumber,
125 Banner: defaultBanner,
126 DisplayVersionOnly: defaultDisplayVersionOnly,
127 ProbeAddress: defaultProbeAddress,
Abhay Kumard3f18512025-12-09 07:51:12 +0000128 PrometheusAddress: defaultPrometheusPort,
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530129 LiveProbeInterval: defaultLiveProbeInterval,
130 NotLiveProbeInterval: defaultNotLiveProbeInterval,
131 HeartbeatCheckInterval: defaultHeartbeatCheckInterval,
132 HeartbeatFailReportInterval: defaultHeartbeatFailReportInterval,
133 GrpcAddress: defaultGrpcAddress,
134 CoreEndpoint: defaultCoreEndpoint,
135 GrpcTimeoutInterval: defaultGrpcTimeoutInterval,
136 TraceEnabled: defaultTraceEnabled,
137 TraceAgentAddress: defaultTraceAgentAddress,
138 LogCorrelationEnabled: defaultLogCorrelationEnabled,
139 OmccEncryption: defaultOmccEncryption,
140 EnableONUStats: defaultEnableONUStats,
141 EnableGEMStats: defaultEnableGEMStats,
142 RPCTimeout: defaultRPCTimeout,
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530143 PerRPCRetryTimeout: defaultPerRPCRetryTimeout,
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530144 MinBackoffRetryDelay: defaultMinBackoffRetryDelay,
145 MaxBackoffRetryDelay: defaultMaxBackoffRetryDelay,
146 CheckOnuDevExistenceAtOnuDiscovery: defaultCheckOnuDevExistenceAtOnuDiscovery,
Sridhar Ravindraab785f22025-07-21 17:20:55 +0530147 ForceOnuDiscIndProcessing: defaultForceOnuDiscIndProcessing,
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530148 MaxRetries: defaultMaxRetries,
akashreddyk02b2bfe2025-09-05 10:37:40 +0530149 ProducerRetryMax: defaultProducerRetryMax,
150 MetadataRetryMax: defaultMetadataRetryMax,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400151 }
152 return &adapterFlags
153}
154
155// ParseCommandArguments parses the arguments when running read-write adaptercore service
156func (so *AdapterFlags) ParseCommandArguments() {
khenaidoo106c61a2021-08-11 18:05:46 -0400157 flag.StringVar(&(so.KafkaClusterAddress),
158 "kafka_cluster_address",
159 defaultKafkaclusteraddress,
160 "Kafka - Cluster messaging address")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400161
khenaidoo106c61a2021-08-11 18:05:46 -0400162 flag.StringVar(&(so.EventTopic),
163 "event_topic",
164 defaultEventtopic,
165 "Event topic")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400166
khenaidoo106c61a2021-08-11 18:05:46 -0400167 flag.StringVar(&(so.KVStoreType),
168 "kv_store_type",
169 defaultKvstoretype,
170 "KV store type")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400171
khenaidoo106c61a2021-08-11 18:05:46 -0400172 flag.DurationVar(&(so.KVStoreTimeout),
173 "kv_store_request_timeout",
174 defaultKvstoretimeout,
175 "The default timeout when making a kv store request")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400176
khenaidoo106c61a2021-08-11 18:05:46 -0400177 flag.StringVar(&(so.KVStoreAddress),
178 "kv_store_address",
179 defaultKvstoreaddress,
180 "KV store address")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400181
khenaidoo106c61a2021-08-11 18:05:46 -0400182 flag.StringVar(&(so.LogLevel),
183 "log_level",
184 defaultLoglevel,
185 "Log level")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400186
khenaidoo106c61a2021-08-11 18:05:46 -0400187 flag.IntVar(&(so.OnuNumber),
188 "onu_number",
189 defaultOnunumber,
190 "Number of ONUs")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400191
khenaidoo106c61a2021-08-11 18:05:46 -0400192 flag.BoolVar(&(so.Banner),
193 "banner",
194 defaultBanner,
195 "Show startup banner log lines")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400196
khenaidoo106c61a2021-08-11 18:05:46 -0400197 flag.BoolVar(&(so.DisplayVersionOnly),
198 "version",
199 defaultDisplayVersionOnly,
200 "Show version information and exit")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400201
khenaidoo106c61a2021-08-11 18:05:46 -0400202 flag.StringVar(&(so.ProbeAddress),
203 "probe_address",
204 defaultProbeAddress,
205 "The address on which to listen to answer liveness and readiness probe queries over HTTP.")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400206
Abhay Kumard3f18512025-12-09 07:51:12 +0000207 flag.StringVar(&(so.PrometheusAddress),
208 "prometheus_address",
209 defaultPrometheusPort,
210 "Used for exposing the metrics to prometheus.")
211
khenaidoo106c61a2021-08-11 18:05:46 -0400212 flag.DurationVar(&(so.LiveProbeInterval),
213 "live_probe_interval",
214 defaultLiveProbeInterval,
215 "Number of seconds for the default liveliness check")
Matt Jeanneretf880eb62019-07-16 20:08:03 -0400216
khenaidoo106c61a2021-08-11 18:05:46 -0400217 flag.DurationVar(&(so.NotLiveProbeInterval),
218 "not_live_probe_interval",
219 defaultNotLiveProbeInterval,
220 "Number of seconds for liveliness check if probe is not running")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400221
khenaidoo106c61a2021-08-11 18:05:46 -0400222 flag.DurationVar(&(so.HeartbeatCheckInterval),
223 "heartbeat_check_interval",
224 defaultHeartbeatCheckInterval,
225 "Number of seconds for heartbeat check interval")
Rohan Agrawal828bf4e2019-10-22 10:13:19 +0000226
khenaidoo106c61a2021-08-11 18:05:46 -0400227 flag.DurationVar(&(so.HeartbeatFailReportInterval),
228 "heartbeat_fail_interval",
229 defaultHeartbeatFailReportInterval,
230 "Number of seconds adapter has to wait before reporting core on the heartbeat check failure")
cbabu116b73f2019-12-10 17:56:32 +0530231
khenaidoo106c61a2021-08-11 18:05:46 -0400232 flag.DurationVar(&(so.GrpcTimeoutInterval),
233 "grpc_timeout_interval",
234 defaultGrpcTimeoutInterval,
235 "Number of seconds for GRPC timeout")
cbabu116b73f2019-12-10 17:56:32 +0530236
khenaidoo106c61a2021-08-11 18:05:46 -0400237 flag.IntVar(&(so.CurrentReplica),
238 "current_replica",
239 defaultCurrentReplica,
240 "Replica number of this particular instance")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400241
khenaidoo106c61a2021-08-11 18:05:46 -0400242 flag.IntVar(&(so.TotalReplicas),
243 "total_replica",
244 defaultTotalReplicas,
245 "Total number of instances for this adapter")
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530246
khenaidoo106c61a2021-08-11 18:05:46 -0400247 flag.BoolVar(&(so.TraceEnabled),
248 "trace_enabled",
249 defaultTraceEnabled,
250 "Whether to send logs to tracing agent?")
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530251
khenaidoo106c61a2021-08-11 18:05:46 -0400252 flag.StringVar(&(so.TraceAgentAddress),
253 "trace_agent_address",
254 defaultTraceAgentAddress,
255 "The address of tracing agent to which span info should be sent")
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -0700256
khenaidoo106c61a2021-08-11 18:05:46 -0400257 flag.BoolVar(&(so.LogCorrelationEnabled),
258 "log_correlation_enabled",
259 defaultLogCorrelationEnabled,
260 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -0700261
khenaidoo106c61a2021-08-11 18:05:46 -0400262 flag.BoolVar(&(so.OmccEncryption),
263 "omcc_encryption",
264 defaultOmccEncryption,
265 "OMCI Channel encryption status")
Girish Kumar11e15972020-06-15 14:51:10 +0000266
khenaidoo106c61a2021-08-11 18:05:46 -0400267 flag.BoolVar(&(so.EnableONUStats),
268 "enable_onu_stats",
269 defaultEnableONUStats,
270 "Enable ONU Statistics")
Girish Kumar11e15972020-06-15 14:51:10 +0000271
khenaidoo106c61a2021-08-11 18:05:46 -0400272 flag.BoolVar(&(so.EnableGEMStats),
273 "enable_gem_stats",
274 defaultEnableGEMStats,
275 "Enable GEM Statistics")
Girish Kumar11e15972020-06-15 14:51:10 +0000276
khenaidoo106c61a2021-08-11 18:05:46 -0400277 flag.StringVar(&(so.GrpcAddress),
278 "grpc_address",
279 defaultGrpcAddress,
280 "Adapter GRPC Server address")
kesavand494c2082020-08-31 11:16:12 +0530281
khenaidoo106c61a2021-08-11 18:05:46 -0400282 flag.StringVar(&(so.CoreEndpoint),
283 "core_endpoint",
284 defaultCoreEndpoint,
285 "Core endpoint")
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000286
khenaidoo106c61a2021-08-11 18:05:46 -0400287 flag.StringVar(&(so.AdapterEndpoint),
288 "adapter_endpoint",
289 defaultAdapterEndpoint,
290 "Adapter Endpoint")
291
292 flag.DurationVar(&(so.RPCTimeout),
293 "rpc_timeout",
294 defaultRPCTimeout,
295 "The default timeout when making an RPC request")
296
297 flag.DurationVar(&(so.MinBackoffRetryDelay),
298 "min_retry_delay",
299 defaultMinBackoffRetryDelay,
300 "The minimum number of milliseconds to delay before a connection retry attempt")
301
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530302 flag.DurationVar(&(so.PerRPCRetryTimeout),
303 "per_rpc_retry_timeout",
304 defaultPerRPCRetryTimeout,
305 "The default timeout per RPC retry")
306
khenaidoo106c61a2021-08-11 18:05:46 -0400307 flag.DurationVar(&(so.MaxBackoffRetryDelay),
308 "max_retry_delay",
309 defaultMaxBackoffRetryDelay,
310 "The maximum number of milliseconds to delay before a connection retry attempt")
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000311
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530312 flag.UintVar(&(so.MaxRetries),
313 "max_grpc_client_retry",
314 defaultMaxRetries,
315 "The maximum number of times olt adaptor will retry in case grpc request timeouts")
316
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530317 flag.BoolVar(&(so.CheckOnuDevExistenceAtOnuDiscovery),
318 "check_onu_exist_on_discovery",
319 defaultCheckOnuDevExistenceAtOnuDiscovery,
320 "Whether to check for flows only or child device before honoring discovery?")
Sridhar Ravindraab785f22025-07-21 17:20:55 +0530321 flag.BoolVar(&(so.ForceOnuDiscIndProcessing),
322 "force_onu_disc_processing",
323 defaultForceOnuDiscIndProcessing,
324 "Skip the check for onu device existence on onu discovery")
akashreddyk02b2bfe2025-09-05 10:37:40 +0530325 flag.IntVar(&(so.ProducerRetryMax),
326 "producer_retry_max",
327 defaultProducerRetryMax,
328 "This option specifies the maximum number of times the producer will retry sending messages before giving up")
329 flag.IntVar(&(so.MetadataRetryMax),
330 "metadata_retry_max",
331 defaultMetadataRetryMax,
332 "This option specifies the maximum number of times retry to receive messages before giving up")
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530333
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530334 flag.Parse()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400335 containerName := getContainerInfo()
336 if len(containerName) > 0 {
337 so.InstanceID = containerName
338 }
Girish Gowdru0c588b22019-04-23 23:24:56 -0400339}
340
341func getContainerInfo() string {
342 return os.Getenv("HOSTNAME")
343}