blob: ba0e5640509b8d188b8d3a82dd485db063c680ae [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"
cbabu116b73f2019-12-10 17:56:32 +053042 defaultLiveProbeInterval = 60 * time.Second
43 defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
Akash Kankanala041a2122024-10-16 15:49:22 +053044 // defaultHeartbeatCheckInterval is the time in seconds the adapter will keep checking the hardware for heartbeat.
Girish Gowdra495dde42021-03-17 14:59:56 -070045 defaultHeartbeatCheckInterval = 15 * time.Second
46 // defaultHeartbeatFailReportInterval is the time adapter will wait before updating the state to the core.
47 defaultHeartbeatFailReportInterval = 0 * time.Second
khenaidoo106c61a2021-08-11 18:05:46 -040048 defaultGrpcAddress = ":50060"
49 defaultCoreEndpoint = ":55555"
Akash Kankanala041a2122024-10-16 15:49:22 +053050 // defaultGrpcTimeoutInterval is the time in seconds a grpc call will wait before returning error.
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053051 defaultGrpcTimeoutInterval = 2 * time.Second
52 defaultCurrentReplica = 1
53 defaultTotalReplicas = 1
54 defaultTraceEnabled = false
55 defaultTraceAgentAddress = "127.0.0.1:6831"
56 defaultLogCorrelationEnabled = true
57 defaultOmccEncryption = false
58 defaultEnableONUStats = false
59 defaultEnableGEMStats = false
60 defaultMinBackoffRetryDelay = 500 * time.Millisecond
61 defaultMaxBackoffRetryDelay = 10 * time.Second
62 defaultAdapterEndpoint = "adapter-open-olt"
63 defaultCheckOnuDevExistenceAtOnuDiscovery = false
Sridhar Ravindraab785f22025-07-21 17:20:55 +053064 defaultForceOnuDiscIndProcessing = false
nikesh.krishnan6dd882b2023-03-14 10:02:41 +053065 defaultMaxRetries = 10
akashreddyk02b2bfe2025-09-05 10:37:40 +053066 defaultProducerRetryMax = 10
67 defaultMetadataRetryMax = 15
Girish Gowdru0c588b22019-04-23 23:24:56 -040068)
69
70// AdapterFlags represents the set of configurations used by the read-write adaptercore service
71type AdapterFlags struct {
72 // Command line parameters
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053073 AdapterName string
74 InstanceID string // NOTE what am I used for? why not cli but only ENV? TODO expose in the chart
75 KafkaClusterAddress string
76 KVStoreType string
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053077 KVStoreAddress string
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053078 EventTopic string
79 LogLevel string
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053080 ProbeAddress string
Akash Kankanala041a2122024-10-16 15:49:22 +053081 GrpcAddress string
82 CoreEndpoint string
83 TraceAgentAddress string
84 AdapterEndpoint string
85 KVStoreTimeout time.Duration
86 RPCTimeout time.Duration
87 PerRPCRetryTimeout time.Duration
88 OnuNumber int
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053089 LiveProbeInterval time.Duration
90 NotLiveProbeInterval time.Duration
91 HeartbeatCheckInterval time.Duration
92 HeartbeatFailReportInterval time.Duration
93 GrpcTimeoutInterval time.Duration
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053094 CurrentReplica int
95 TotalReplicas int
Akash Kankanala041a2122024-10-16 15:49:22 +053096 MinBackoffRetryDelay time.Duration
97 MaxBackoffRetryDelay time.Duration
98 MaxRetries uint
99 Banner bool
100 DisplayVersionOnly bool
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530101 TraceEnabled bool
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530102 LogCorrelationEnabled bool
103 OmccEncryption bool
104 EnableONUStats bool
105 EnableGEMStats bool
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530106 CheckOnuDevExistenceAtOnuDiscovery bool
Sridhar Ravindraab785f22025-07-21 17:20:55 +0530107 ForceOnuDiscIndProcessing bool
akashreddyk02b2bfe2025-09-05 10:37:40 +0530108 ProducerRetryMax int
109 MetadataRetryMax int
Girish Gowdru0c588b22019-04-23 23:24:56 -0400110}
111
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700112// NewAdapterFlags returns a new RWCore config
Girish Gowdru0c588b22019-04-23 23:24:56 -0400113func NewAdapterFlags() *AdapterFlags {
114 var adapterFlags = AdapterFlags{ // Default values
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530115 InstanceID: defaultInstanceid,
116 KafkaClusterAddress: defaultKafkaclusteraddress,
117 KVStoreType: defaultKvstoretype,
118 KVStoreTimeout: defaultKvstoretimeout,
119 KVStoreAddress: defaultKvstoreaddress,
120 EventTopic: defaultEventtopic,
121 LogLevel: defaultLoglevel,
122 OnuNumber: defaultOnunumber,
123 Banner: defaultBanner,
124 DisplayVersionOnly: defaultDisplayVersionOnly,
125 ProbeAddress: defaultProbeAddress,
126 LiveProbeInterval: defaultLiveProbeInterval,
127 NotLiveProbeInterval: defaultNotLiveProbeInterval,
128 HeartbeatCheckInterval: defaultHeartbeatCheckInterval,
129 HeartbeatFailReportInterval: defaultHeartbeatFailReportInterval,
130 GrpcAddress: defaultGrpcAddress,
131 CoreEndpoint: defaultCoreEndpoint,
132 GrpcTimeoutInterval: defaultGrpcTimeoutInterval,
133 TraceEnabled: defaultTraceEnabled,
134 TraceAgentAddress: defaultTraceAgentAddress,
135 LogCorrelationEnabled: defaultLogCorrelationEnabled,
136 OmccEncryption: defaultOmccEncryption,
137 EnableONUStats: defaultEnableONUStats,
138 EnableGEMStats: defaultEnableGEMStats,
139 RPCTimeout: defaultRPCTimeout,
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530140 PerRPCRetryTimeout: defaultPerRPCRetryTimeout,
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530141 MinBackoffRetryDelay: defaultMinBackoffRetryDelay,
142 MaxBackoffRetryDelay: defaultMaxBackoffRetryDelay,
143 CheckOnuDevExistenceAtOnuDiscovery: defaultCheckOnuDevExistenceAtOnuDiscovery,
Sridhar Ravindraab785f22025-07-21 17:20:55 +0530144 ForceOnuDiscIndProcessing: defaultForceOnuDiscIndProcessing,
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530145 MaxRetries: defaultMaxRetries,
akashreddyk02b2bfe2025-09-05 10:37:40 +0530146 ProducerRetryMax: defaultProducerRetryMax,
147 MetadataRetryMax: defaultMetadataRetryMax,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400148 }
149 return &adapterFlags
150}
151
152// ParseCommandArguments parses the arguments when running read-write adaptercore service
153func (so *AdapterFlags) ParseCommandArguments() {
khenaidoo106c61a2021-08-11 18:05:46 -0400154 flag.StringVar(&(so.KafkaClusterAddress),
155 "kafka_cluster_address",
156 defaultKafkaclusteraddress,
157 "Kafka - Cluster messaging address")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400158
khenaidoo106c61a2021-08-11 18:05:46 -0400159 flag.StringVar(&(so.EventTopic),
160 "event_topic",
161 defaultEventtopic,
162 "Event topic")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400163
khenaidoo106c61a2021-08-11 18:05:46 -0400164 flag.StringVar(&(so.KVStoreType),
165 "kv_store_type",
166 defaultKvstoretype,
167 "KV store type")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400168
khenaidoo106c61a2021-08-11 18:05:46 -0400169 flag.DurationVar(&(so.KVStoreTimeout),
170 "kv_store_request_timeout",
171 defaultKvstoretimeout,
172 "The default timeout when making a kv store request")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400173
khenaidoo106c61a2021-08-11 18:05:46 -0400174 flag.StringVar(&(so.KVStoreAddress),
175 "kv_store_address",
176 defaultKvstoreaddress,
177 "KV store address")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400178
khenaidoo106c61a2021-08-11 18:05:46 -0400179 flag.StringVar(&(so.LogLevel),
180 "log_level",
181 defaultLoglevel,
182 "Log level")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400183
khenaidoo106c61a2021-08-11 18:05:46 -0400184 flag.IntVar(&(so.OnuNumber),
185 "onu_number",
186 defaultOnunumber,
187 "Number of ONUs")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400188
khenaidoo106c61a2021-08-11 18:05:46 -0400189 flag.BoolVar(&(so.Banner),
190 "banner",
191 defaultBanner,
192 "Show startup banner log lines")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400193
khenaidoo106c61a2021-08-11 18:05:46 -0400194 flag.BoolVar(&(so.DisplayVersionOnly),
195 "version",
196 defaultDisplayVersionOnly,
197 "Show version information and exit")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400198
khenaidoo106c61a2021-08-11 18:05:46 -0400199 flag.StringVar(&(so.ProbeAddress),
200 "probe_address",
201 defaultProbeAddress,
202 "The address on which to listen to answer liveness and readiness probe queries over HTTP.")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400203
khenaidoo106c61a2021-08-11 18:05:46 -0400204 flag.DurationVar(&(so.LiveProbeInterval),
205 "live_probe_interval",
206 defaultLiveProbeInterval,
207 "Number of seconds for the default liveliness check")
Matt Jeanneretf880eb62019-07-16 20:08:03 -0400208
khenaidoo106c61a2021-08-11 18:05:46 -0400209 flag.DurationVar(&(so.NotLiveProbeInterval),
210 "not_live_probe_interval",
211 defaultNotLiveProbeInterval,
212 "Number of seconds for liveliness check if probe is not running")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400213
khenaidoo106c61a2021-08-11 18:05:46 -0400214 flag.DurationVar(&(so.HeartbeatCheckInterval),
215 "heartbeat_check_interval",
216 defaultHeartbeatCheckInterval,
217 "Number of seconds for heartbeat check interval")
Rohan Agrawal828bf4e2019-10-22 10:13:19 +0000218
khenaidoo106c61a2021-08-11 18:05:46 -0400219 flag.DurationVar(&(so.HeartbeatFailReportInterval),
220 "heartbeat_fail_interval",
221 defaultHeartbeatFailReportInterval,
222 "Number of seconds adapter has to wait before reporting core on the heartbeat check failure")
cbabu116b73f2019-12-10 17:56:32 +0530223
khenaidoo106c61a2021-08-11 18:05:46 -0400224 flag.DurationVar(&(so.GrpcTimeoutInterval),
225 "grpc_timeout_interval",
226 defaultGrpcTimeoutInterval,
227 "Number of seconds for GRPC timeout")
cbabu116b73f2019-12-10 17:56:32 +0530228
khenaidoo106c61a2021-08-11 18:05:46 -0400229 flag.IntVar(&(so.CurrentReplica),
230 "current_replica",
231 defaultCurrentReplica,
232 "Replica number of this particular instance")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400233
khenaidoo106c61a2021-08-11 18:05:46 -0400234 flag.IntVar(&(so.TotalReplicas),
235 "total_replica",
236 defaultTotalReplicas,
237 "Total number of instances for this adapter")
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530238
khenaidoo106c61a2021-08-11 18:05:46 -0400239 flag.BoolVar(&(so.TraceEnabled),
240 "trace_enabled",
241 defaultTraceEnabled,
242 "Whether to send logs to tracing agent?")
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530243
khenaidoo106c61a2021-08-11 18:05:46 -0400244 flag.StringVar(&(so.TraceAgentAddress),
245 "trace_agent_address",
246 defaultTraceAgentAddress,
247 "The address of tracing agent to which span info should be sent")
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -0700248
khenaidoo106c61a2021-08-11 18:05:46 -0400249 flag.BoolVar(&(so.LogCorrelationEnabled),
250 "log_correlation_enabled",
251 defaultLogCorrelationEnabled,
252 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -0700253
khenaidoo106c61a2021-08-11 18:05:46 -0400254 flag.BoolVar(&(so.OmccEncryption),
255 "omcc_encryption",
256 defaultOmccEncryption,
257 "OMCI Channel encryption status")
Girish Kumar11e15972020-06-15 14:51:10 +0000258
khenaidoo106c61a2021-08-11 18:05:46 -0400259 flag.BoolVar(&(so.EnableONUStats),
260 "enable_onu_stats",
261 defaultEnableONUStats,
262 "Enable ONU Statistics")
Girish Kumar11e15972020-06-15 14:51:10 +0000263
khenaidoo106c61a2021-08-11 18:05:46 -0400264 flag.BoolVar(&(so.EnableGEMStats),
265 "enable_gem_stats",
266 defaultEnableGEMStats,
267 "Enable GEM Statistics")
Girish Kumar11e15972020-06-15 14:51:10 +0000268
khenaidoo106c61a2021-08-11 18:05:46 -0400269 flag.StringVar(&(so.GrpcAddress),
270 "grpc_address",
271 defaultGrpcAddress,
272 "Adapter GRPC Server address")
kesavand494c2082020-08-31 11:16:12 +0530273
khenaidoo106c61a2021-08-11 18:05:46 -0400274 flag.StringVar(&(so.CoreEndpoint),
275 "core_endpoint",
276 defaultCoreEndpoint,
277 "Core endpoint")
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000278
khenaidoo106c61a2021-08-11 18:05:46 -0400279 flag.StringVar(&(so.AdapterEndpoint),
280 "adapter_endpoint",
281 defaultAdapterEndpoint,
282 "Adapter Endpoint")
283
284 flag.DurationVar(&(so.RPCTimeout),
285 "rpc_timeout",
286 defaultRPCTimeout,
287 "The default timeout when making an RPC request")
288
289 flag.DurationVar(&(so.MinBackoffRetryDelay),
290 "min_retry_delay",
291 defaultMinBackoffRetryDelay,
292 "The minimum number of milliseconds to delay before a connection retry attempt")
293
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530294 flag.DurationVar(&(so.PerRPCRetryTimeout),
295 "per_rpc_retry_timeout",
296 defaultPerRPCRetryTimeout,
297 "The default timeout per RPC retry")
298
khenaidoo106c61a2021-08-11 18:05:46 -0400299 flag.DurationVar(&(so.MaxBackoffRetryDelay),
300 "max_retry_delay",
301 defaultMaxBackoffRetryDelay,
302 "The maximum number of milliseconds to delay before a connection retry attempt")
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000303
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530304 flag.UintVar(&(so.MaxRetries),
305 "max_grpc_client_retry",
306 defaultMaxRetries,
307 "The maximum number of times olt adaptor will retry in case grpc request timeouts")
308
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530309 flag.BoolVar(&(so.CheckOnuDevExistenceAtOnuDiscovery),
310 "check_onu_exist_on_discovery",
311 defaultCheckOnuDevExistenceAtOnuDiscovery,
312 "Whether to check for flows only or child device before honoring discovery?")
Sridhar Ravindraab785f22025-07-21 17:20:55 +0530313 flag.BoolVar(&(so.ForceOnuDiscIndProcessing),
314 "force_onu_disc_processing",
315 defaultForceOnuDiscIndProcessing,
316 "Skip the check for onu device existence on onu discovery")
akashreddyk02b2bfe2025-09-05 10:37:40 +0530317 flag.IntVar(&(so.ProducerRetryMax),
318 "producer_retry_max",
319 defaultProducerRetryMax,
320 "This option specifies the maximum number of times the producer will retry sending messages before giving up")
321 flag.IntVar(&(so.MetadataRetryMax),
322 "metadata_retry_max",
323 defaultMetadataRetryMax,
324 "This option specifies the maximum number of times retry to receive messages before giving up")
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530325
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530326 flag.Parse()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400327 containerName := getContainerInfo()
328 if len(containerName) > 0 {
329 so.InstanceID = containerName
330 }
Girish Gowdru0c588b22019-04-23 23:24:56 -0400331}
332
333func getContainerInfo() string {
334 return os.Getenv("HOSTNAME")
335}