blob: a7dc890affb97dc676f6a7a71608fc0a2946f92e [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
Girish Gowdru0c588b22019-04-23 23:24:56 -040066)
67
68// AdapterFlags represents the set of configurations used by the read-write adaptercore service
69type AdapterFlags struct {
70 // Command line parameters
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053071 AdapterName string
72 InstanceID string // NOTE what am I used for? why not cli but only ENV? TODO expose in the chart
73 KafkaClusterAddress string
74 KVStoreType string
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053075 KVStoreAddress string
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053076 EventTopic string
77 LogLevel string
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053078 ProbeAddress string
Akash Kankanala041a2122024-10-16 15:49:22 +053079 GrpcAddress string
80 CoreEndpoint string
81 TraceAgentAddress string
82 AdapterEndpoint string
83 KVStoreTimeout time.Duration
84 RPCTimeout time.Duration
85 PerRPCRetryTimeout time.Duration
86 OnuNumber int
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053087 LiveProbeInterval time.Duration
88 NotLiveProbeInterval time.Duration
89 HeartbeatCheckInterval time.Duration
90 HeartbeatFailReportInterval time.Duration
91 GrpcTimeoutInterval time.Duration
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053092 CurrentReplica int
93 TotalReplicas int
Akash Kankanala041a2122024-10-16 15:49:22 +053094 MinBackoffRetryDelay time.Duration
95 MaxBackoffRetryDelay time.Duration
96 MaxRetries uint
97 Banner bool
98 DisplayVersionOnly bool
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053099 TraceEnabled bool
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530100 LogCorrelationEnabled bool
101 OmccEncryption bool
102 EnableONUStats bool
103 EnableGEMStats bool
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530104 CheckOnuDevExistenceAtOnuDiscovery bool
Sridhar Ravindraab785f22025-07-21 17:20:55 +0530105 ForceOnuDiscIndProcessing bool
Girish Gowdru0c588b22019-04-23 23:24:56 -0400106}
107
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700108// NewAdapterFlags returns a new RWCore config
Girish Gowdru0c588b22019-04-23 23:24:56 -0400109func NewAdapterFlags() *AdapterFlags {
110 var adapterFlags = AdapterFlags{ // Default values
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530111 InstanceID: defaultInstanceid,
112 KafkaClusterAddress: defaultKafkaclusteraddress,
113 KVStoreType: defaultKvstoretype,
114 KVStoreTimeout: defaultKvstoretimeout,
115 KVStoreAddress: defaultKvstoreaddress,
116 EventTopic: defaultEventtopic,
117 LogLevel: defaultLoglevel,
118 OnuNumber: defaultOnunumber,
119 Banner: defaultBanner,
120 DisplayVersionOnly: defaultDisplayVersionOnly,
121 ProbeAddress: defaultProbeAddress,
122 LiveProbeInterval: defaultLiveProbeInterval,
123 NotLiveProbeInterval: defaultNotLiveProbeInterval,
124 HeartbeatCheckInterval: defaultHeartbeatCheckInterval,
125 HeartbeatFailReportInterval: defaultHeartbeatFailReportInterval,
126 GrpcAddress: defaultGrpcAddress,
127 CoreEndpoint: defaultCoreEndpoint,
128 GrpcTimeoutInterval: defaultGrpcTimeoutInterval,
129 TraceEnabled: defaultTraceEnabled,
130 TraceAgentAddress: defaultTraceAgentAddress,
131 LogCorrelationEnabled: defaultLogCorrelationEnabled,
132 OmccEncryption: defaultOmccEncryption,
133 EnableONUStats: defaultEnableONUStats,
134 EnableGEMStats: defaultEnableGEMStats,
135 RPCTimeout: defaultRPCTimeout,
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530136 PerRPCRetryTimeout: defaultPerRPCRetryTimeout,
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530137 MinBackoffRetryDelay: defaultMinBackoffRetryDelay,
138 MaxBackoffRetryDelay: defaultMaxBackoffRetryDelay,
139 CheckOnuDevExistenceAtOnuDiscovery: defaultCheckOnuDevExistenceAtOnuDiscovery,
Sridhar Ravindraab785f22025-07-21 17:20:55 +0530140 ForceOnuDiscIndProcessing: defaultForceOnuDiscIndProcessing,
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530141 MaxRetries: defaultMaxRetries,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400142 }
143 return &adapterFlags
144}
145
146// ParseCommandArguments parses the arguments when running read-write adaptercore service
147func (so *AdapterFlags) ParseCommandArguments() {
khenaidoo106c61a2021-08-11 18:05:46 -0400148 flag.StringVar(&(so.KafkaClusterAddress),
149 "kafka_cluster_address",
150 defaultKafkaclusteraddress,
151 "Kafka - Cluster messaging address")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400152
khenaidoo106c61a2021-08-11 18:05:46 -0400153 flag.StringVar(&(so.EventTopic),
154 "event_topic",
155 defaultEventtopic,
156 "Event topic")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400157
khenaidoo106c61a2021-08-11 18:05:46 -0400158 flag.StringVar(&(so.KVStoreType),
159 "kv_store_type",
160 defaultKvstoretype,
161 "KV store type")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400162
khenaidoo106c61a2021-08-11 18:05:46 -0400163 flag.DurationVar(&(so.KVStoreTimeout),
164 "kv_store_request_timeout",
165 defaultKvstoretimeout,
166 "The default timeout when making a kv store request")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400167
khenaidoo106c61a2021-08-11 18:05:46 -0400168 flag.StringVar(&(so.KVStoreAddress),
169 "kv_store_address",
170 defaultKvstoreaddress,
171 "KV store address")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400172
khenaidoo106c61a2021-08-11 18:05:46 -0400173 flag.StringVar(&(so.LogLevel),
174 "log_level",
175 defaultLoglevel,
176 "Log level")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400177
khenaidoo106c61a2021-08-11 18:05:46 -0400178 flag.IntVar(&(so.OnuNumber),
179 "onu_number",
180 defaultOnunumber,
181 "Number of ONUs")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400182
khenaidoo106c61a2021-08-11 18:05:46 -0400183 flag.BoolVar(&(so.Banner),
184 "banner",
185 defaultBanner,
186 "Show startup banner log lines")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400187
khenaidoo106c61a2021-08-11 18:05:46 -0400188 flag.BoolVar(&(so.DisplayVersionOnly),
189 "version",
190 defaultDisplayVersionOnly,
191 "Show version information and exit")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400192
khenaidoo106c61a2021-08-11 18:05:46 -0400193 flag.StringVar(&(so.ProbeAddress),
194 "probe_address",
195 defaultProbeAddress,
196 "The address on which to listen to answer liveness and readiness probe queries over HTTP.")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400197
khenaidoo106c61a2021-08-11 18:05:46 -0400198 flag.DurationVar(&(so.LiveProbeInterval),
199 "live_probe_interval",
200 defaultLiveProbeInterval,
201 "Number of seconds for the default liveliness check")
Matt Jeanneretf880eb62019-07-16 20:08:03 -0400202
khenaidoo106c61a2021-08-11 18:05:46 -0400203 flag.DurationVar(&(so.NotLiveProbeInterval),
204 "not_live_probe_interval",
205 defaultNotLiveProbeInterval,
206 "Number of seconds for liveliness check if probe is not running")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400207
khenaidoo106c61a2021-08-11 18:05:46 -0400208 flag.DurationVar(&(so.HeartbeatCheckInterval),
209 "heartbeat_check_interval",
210 defaultHeartbeatCheckInterval,
211 "Number of seconds for heartbeat check interval")
Rohan Agrawal828bf4e2019-10-22 10:13:19 +0000212
khenaidoo106c61a2021-08-11 18:05:46 -0400213 flag.DurationVar(&(so.HeartbeatFailReportInterval),
214 "heartbeat_fail_interval",
215 defaultHeartbeatFailReportInterval,
216 "Number of seconds adapter has to wait before reporting core on the heartbeat check failure")
cbabu116b73f2019-12-10 17:56:32 +0530217
khenaidoo106c61a2021-08-11 18:05:46 -0400218 flag.DurationVar(&(so.GrpcTimeoutInterval),
219 "grpc_timeout_interval",
220 defaultGrpcTimeoutInterval,
221 "Number of seconds for GRPC timeout")
cbabu116b73f2019-12-10 17:56:32 +0530222
khenaidoo106c61a2021-08-11 18:05:46 -0400223 flag.IntVar(&(so.CurrentReplica),
224 "current_replica",
225 defaultCurrentReplica,
226 "Replica number of this particular instance")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400227
khenaidoo106c61a2021-08-11 18:05:46 -0400228 flag.IntVar(&(so.TotalReplicas),
229 "total_replica",
230 defaultTotalReplicas,
231 "Total number of instances for this adapter")
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530232
khenaidoo106c61a2021-08-11 18:05:46 -0400233 flag.BoolVar(&(so.TraceEnabled),
234 "trace_enabled",
235 defaultTraceEnabled,
236 "Whether to send logs to tracing agent?")
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530237
khenaidoo106c61a2021-08-11 18:05:46 -0400238 flag.StringVar(&(so.TraceAgentAddress),
239 "trace_agent_address",
240 defaultTraceAgentAddress,
241 "The address of tracing agent to which span info should be sent")
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -0700242
khenaidoo106c61a2021-08-11 18:05:46 -0400243 flag.BoolVar(&(so.LogCorrelationEnabled),
244 "log_correlation_enabled",
245 defaultLogCorrelationEnabled,
246 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -0700247
khenaidoo106c61a2021-08-11 18:05:46 -0400248 flag.BoolVar(&(so.OmccEncryption),
249 "omcc_encryption",
250 defaultOmccEncryption,
251 "OMCI Channel encryption status")
Girish Kumar11e15972020-06-15 14:51:10 +0000252
khenaidoo106c61a2021-08-11 18:05:46 -0400253 flag.BoolVar(&(so.EnableONUStats),
254 "enable_onu_stats",
255 defaultEnableONUStats,
256 "Enable ONU Statistics")
Girish Kumar11e15972020-06-15 14:51:10 +0000257
khenaidoo106c61a2021-08-11 18:05:46 -0400258 flag.BoolVar(&(so.EnableGEMStats),
259 "enable_gem_stats",
260 defaultEnableGEMStats,
261 "Enable GEM Statistics")
Girish Kumar11e15972020-06-15 14:51:10 +0000262
khenaidoo106c61a2021-08-11 18:05:46 -0400263 flag.StringVar(&(so.GrpcAddress),
264 "grpc_address",
265 defaultGrpcAddress,
266 "Adapter GRPC Server address")
kesavand494c2082020-08-31 11:16:12 +0530267
khenaidoo106c61a2021-08-11 18:05:46 -0400268 flag.StringVar(&(so.CoreEndpoint),
269 "core_endpoint",
270 defaultCoreEndpoint,
271 "Core endpoint")
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000272
khenaidoo106c61a2021-08-11 18:05:46 -0400273 flag.StringVar(&(so.AdapterEndpoint),
274 "adapter_endpoint",
275 defaultAdapterEndpoint,
276 "Adapter Endpoint")
277
278 flag.DurationVar(&(so.RPCTimeout),
279 "rpc_timeout",
280 defaultRPCTimeout,
281 "The default timeout when making an RPC request")
282
283 flag.DurationVar(&(so.MinBackoffRetryDelay),
284 "min_retry_delay",
285 defaultMinBackoffRetryDelay,
286 "The minimum number of milliseconds to delay before a connection retry attempt")
287
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530288 flag.DurationVar(&(so.PerRPCRetryTimeout),
289 "per_rpc_retry_timeout",
290 defaultPerRPCRetryTimeout,
291 "The default timeout per RPC retry")
292
khenaidoo106c61a2021-08-11 18:05:46 -0400293 flag.DurationVar(&(so.MaxBackoffRetryDelay),
294 "max_retry_delay",
295 defaultMaxBackoffRetryDelay,
296 "The maximum number of milliseconds to delay before a connection retry attempt")
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000297
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530298 flag.UintVar(&(so.MaxRetries),
299 "max_grpc_client_retry",
300 defaultMaxRetries,
301 "The maximum number of times olt adaptor will retry in case grpc request timeouts")
302
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530303 flag.BoolVar(&(so.CheckOnuDevExistenceAtOnuDiscovery),
304 "check_onu_exist_on_discovery",
305 defaultCheckOnuDevExistenceAtOnuDiscovery,
306 "Whether to check for flows only or child device before honoring discovery?")
Sridhar Ravindraab785f22025-07-21 17:20:55 +0530307 flag.BoolVar(&(so.ForceOnuDiscIndProcessing),
308 "force_onu_disc_processing",
309 defaultForceOnuDiscIndProcessing,
310 "Skip the check for onu device existence on onu discovery")
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530311
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530312 flag.Parse()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400313 containerName := getContainerInfo()
314 if len(containerName) > 0 {
315 so.InstanceID = containerName
316 }
Girish Gowdru0c588b22019-04-23 23:24:56 -0400317}
318
319func getContainerInfo() string {
320 return os.Getenv("HOSTNAME")
321}