blob: e23e0773e60b1e0a5e18799f649d2c9106cb2619 [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001/*
Joey Armstrong89c812c2024-01-12 19:00:20 -05002* Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors
Holger Hildebrandtfa074992020-03-27 15:42:06 +00003
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
Mahir Gunyel691beaf2023-12-21 23:52:47 -080017// Package config provides the Log, kvstore, Kafka configuration
Holger Hildebrandtfa074992020-03-27 15:42:06 +000018package config
19
20import (
21 "flag"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000022 "os"
23 "time"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000024)
25
26// Open ONU default constants
27const (
akashreddykff176ea2025-09-16 23:20:16 +053028 KVStoreName = "etcd"
29 OnuVendorIds = "OPEN,ALCL,BRCM,TWSH,ALPH,ISKT,SFAA,BBSM,SCOM,ARPX,DACM,ERSN,HWTC,CIGG,ADTN,ARCA,AVMG,LEOX,ZYXE"
30 defaultProducerRetryMax = 10
31 defaultMetadataRetryMax = 15
Holger Hildebrandtfa074992020-03-27 15:42:06 +000032)
33
34// AdapterFlags represents the set of configurations used by the read-write adaptercore service
35type AdapterFlags struct {
36 // Command line parameters
37 InstanceID string
Matteo Scandolo127c59d2021-01-28 11:31:18 -080038 KafkaClusterAddress string // NOTE this is unused across the adapter
Holger Hildebrandtfa074992020-03-27 15:42:06 +000039 KVStoreType string
Matteo Scandolo127c59d2021-01-28 11:31:18 -080040 KVStoreAddress string
Holger Hildebrandtfa074992020-03-27 15:42:06 +000041 EventTopic string
42 LogLevel string
Holger Hildebrandtfa074992020-03-27 15:42:06 +000043 ProbeHost string
Abhay Kumarb5c1d7a2025-12-09 08:10:00 +000044 PrometheusAddress string
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +053045 TraceAgentAddress string
46 OnuVendorIds string
47 AdapterEndpoint string
48 GrpcAddress string
49 CoreEndpoint string
50 KVStoreTimeout time.Duration
51 OnuNumber int
Holger Hildebrandtfa074992020-03-27 15:42:06 +000052 ProbePort int
53 LiveProbeInterval time.Duration
54 NotLiveProbeInterval time.Duration
55 HeartbeatCheckInterval time.Duration
56 HeartbeatFailReportInterval time.Duration
57 KafkaReconnectRetries int
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000058 CurrentReplica int
59 TotalReplicas int
Himani Chawlad96df182020-09-28 11:12:02 +053060 MaxTimeoutInterAdapterComm time.Duration
Holger Hildebrandt38985dc2021-02-18 16:25:20 +000061 MaxTimeoutReconciling time.Duration
Holger Hildebrandte3677f12021-02-05 14:50:56 +000062 MibAuditInterval time.Duration
Girish Gowdra0b235842021-03-09 13:06:46 -080063 OmciTimeout time.Duration
Himani Chawla075f1642021-03-15 19:23:24 +053064 AlarmAuditInterval time.Duration
mpagenkoc26d4c02021-05-06 14:27:57 +000065 DownloadToAdapterTimeout time.Duration
66 DownloadToOnuTimeout4MB time.Duration
Matteo Scandolo20d180c2021-06-10 17:20:21 +020067 UniPortMask int
khenaidoo7d3c5582021-08-11 18:09:44 -040068 MinBackoffRetryDelay time.Duration
69 MaxBackoffRetryDelay time.Duration
khenaidoo7d3c5582021-08-11 18:09:44 -040070 RPCTimeout time.Duration
bseeniva0b4286b2026-01-30 13:05:42 +053071 ONUSwUpgradeTimeout time.Duration
Girish Gowdrae95687a2021-09-08 16:30:58 -070072 MaxConcurrentFlowsPerUni int
nikesh.krishnanca4afa32023-06-28 03:42:16 +053073 PerRPCRetryTimeout time.Duration
74 MaxRetries uint
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +053075 Banner bool
76 DisplayVersionOnly bool
77 AccIncrEvto bool
78 TraceEnabled bool
79 LogCorrelationEnabled bool
80 MetricsEnabled bool
81 ExtendedOmciSupportEnabled bool
Praneeth Kumar Nalmas77ab2f32024-04-17 11:14:27 +053082 SkipOnuConfig bool
Sridhar Ravindraa9cb0442025-07-21 16:55:05 +053083 CheckDeviceTechProfOnReboot bool
akashreddykff176ea2025-09-16 23:20:16 +053084 ProducerRetryMax int
85 MetadataRetryMax int
Holger Hildebrandtfa074992020-03-27 15:42:06 +000086}
87
88// ParseCommandArguments parses the arguments when running read-write adaptercore service
khenaidoo7d3c5582021-08-11 18:09:44 -040089func (so *AdapterFlags) ParseCommandArguments(args []string) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000090
khenaidoo7d3c5582021-08-11 18:09:44 -040091 fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
Holger Hildebrandtfa074992020-03-27 15:42:06 +000092
khenaidoo7d3c5582021-08-11 18:09:44 -040093 fs.StringVar(&(so.KafkaClusterAddress),
94 "kafka_cluster_address",
95 "127.0.0.1:9092",
96 "Kafka - Cluster messaging address")
Holger Hildebrandtfa074992020-03-27 15:42:06 +000097
khenaidoo7d3c5582021-08-11 18:09:44 -040098 fs.StringVar(&(so.EventTopic),
99 "event_topic",
100 "voltha.events",
101 "Event topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000102
khenaidoo7d3c5582021-08-11 18:09:44 -0400103 fs.StringVar(&(so.KVStoreType),
104 "kv_store_type",
Abhay Kumar3282a142024-07-12 06:03:12 +0530105 KVStoreName,
khenaidoo7d3c5582021-08-11 18:09:44 -0400106 "KV store type")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000107
khenaidoo7d3c5582021-08-11 18:09:44 -0400108 fs.DurationVar(&(so.KVStoreTimeout),
109 "kv_store_request_timeout",
110 5*time.Second,
111 "The default timeout when making a kv store request")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000112
khenaidoo7d3c5582021-08-11 18:09:44 -0400113 fs.StringVar(&(so.KVStoreAddress),
114 "kv_store_address",
115 "127.0.0.1:2379",
116 "KV store address")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000117
khenaidoo7d3c5582021-08-11 18:09:44 -0400118 fs.StringVar(&(so.LogLevel),
119 "log_level",
120 "WARN",
121 "Log level")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000122
khenaidoo7d3c5582021-08-11 18:09:44 -0400123 fs.IntVar(&(so.OnuNumber),
124 "onu_number",
125 1,
126 "Number of ONUs")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000127
khenaidoo7d3c5582021-08-11 18:09:44 -0400128 fs.BoolVar(&(so.Banner),
129 "banner",
130 false,
131 "Show startup banner log lines")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000132
khenaidoo7d3c5582021-08-11 18:09:44 -0400133 fs.BoolVar(&(so.DisplayVersionOnly),
134 "version",
135 false,
136 "Show version information and exit")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000137
khenaidoo7d3c5582021-08-11 18:09:44 -0400138 fs.BoolVar(&(so.AccIncrEvto),
139 "accept_incr_evto",
140 false,
141 "Acceptance of incremental EVTOCD configuration")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000142
khenaidoo7d3c5582021-08-11 18:09:44 -0400143 fs.StringVar(&(so.ProbeHost),
144 "probe_host",
145 "",
146 "The address on which to listen to answer liveness and readiness probe queries over HTTP")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000147
khenaidoo7d3c5582021-08-11 18:09:44 -0400148 fs.IntVar(&(so.ProbePort),
149 "probe_port",
150 8080,
151 "The port on which to listen to answer liveness and readiness probe queries over HTTP")
mpagenkodff5dda2020-08-28 11:52:01 +0000152
Abhay Kumarb5c1d7a2025-12-09 08:10:00 +0000153 fs.StringVar(&(so.PrometheusAddress),
154 "prometheus_port",
155 ":8081",
156 "Used for exposing the metrics to prometheus.")
157
khenaidoo7d3c5582021-08-11 18:09:44 -0400158 fs.DurationVar(&(so.LiveProbeInterval),
159 "live_probe_interval",
160 60*time.Second,
161 "Number of seconds for the default liveliness check")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000162
khenaidoo7d3c5582021-08-11 18:09:44 -0400163 fs.DurationVar(&(so.NotLiveProbeInterval),
164 "not_live_probe_interval",
165 60*time.Second,
166 "Number of seconds for liveliness check if probe is not running")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000167
khenaidoo7d3c5582021-08-11 18:09:44 -0400168 fs.DurationVar(&(so.HeartbeatCheckInterval),
169 "hearbeat_check_interval",
170 30*time.Second,
171 "Number of seconds for heartbeat check interval")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000172
khenaidoo7d3c5582021-08-11 18:09:44 -0400173 fs.DurationVar(&(so.HeartbeatFailReportInterval),
174 "hearbeat_fail_interval",
175 30*time.Second,
176 "Number of seconds adapter has to wait before reporting core on the hearbeat check failure")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000177
khenaidoo7d3c5582021-08-11 18:09:44 -0400178 fs.IntVar(&(so.KafkaReconnectRetries),
179 "kafka_reconnect_retries",
180 -1,
181 "Number of retries to connect to Kafka")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000182
khenaidoo7d3c5582021-08-11 18:09:44 -0400183 fs.IntVar(&(so.CurrentReplica),
184 "current_replica",
185 1,
186 "Replica number of this particular instance")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000187
khenaidoo7d3c5582021-08-11 18:09:44 -0400188 fs.IntVar(&(so.TotalReplicas),
189 "total_replica",
190 1,
191 "Total number of instances for this adapter")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000192
khenaidoo7d3c5582021-08-11 18:09:44 -0400193 fs.DurationVar(&(so.MaxTimeoutInterAdapterComm),
194 "max_timeout_interadapter_comm",
195 30*time.Second,
196 "Maximum Number of seconds for the default interadapter communication timeout")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000197
khenaidoo7d3c5582021-08-11 18:09:44 -0400198 fs.DurationVar(&(so.MaxTimeoutReconciling),
199 "max_timeout_reconciling",
200 10*time.Second,
201 "Maximum Number of seconds for the default ONU reconciling timeout")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000202
khenaidoo7d3c5582021-08-11 18:09:44 -0400203 fs.BoolVar(&(so.TraceEnabled),
204 "trace_enabled",
205 false,
206 "Whether to send logs to tracing agent")
Himani Chawlad96df182020-09-28 11:12:02 +0530207
khenaidoo7d3c5582021-08-11 18:09:44 -0400208 fs.StringVar(&(so.TraceAgentAddress),
209 "trace_agent_address",
210 "127.0.0.1:6831",
211 "The address of tracing agent to which span info should be sent")
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000212
khenaidoo7d3c5582021-08-11 18:09:44 -0400213 fs.BoolVar(&(so.LogCorrelationEnabled),
214 "log_correlation_enabled",
215 true,
216 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000217
khenaidoo7d3c5582021-08-11 18:09:44 -0400218 fs.StringVar(&(so.OnuVendorIds),
219 "allowed_onu_vendors",
220 OnuVendorIds,
221 "List of Allowed ONU Vendor Ids")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000222
khenaidoo7d3c5582021-08-11 18:09:44 -0400223 fs.BoolVar(&(so.MetricsEnabled),
224 "metrics_enabled",
225 false,
226 "Whether to enable metrics collection")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000227
Holger Hildebrandtc572e622022-06-22 09:19:17 +0000228 fs.BoolVar(&(so.ExtendedOmciSupportEnabled),
229 "extended_omci_support_enabled",
230 false,
231 "Whether to enable extended OMCI support")
232
khenaidoo7d3c5582021-08-11 18:09:44 -0400233 fs.DurationVar(&(so.MibAuditInterval),
234 "mib_audit_interval",
235 300*time.Second,
236 "Mib Audit Interval in seconds - the value zero will disable Mib Audit")
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100237
khenaidoo7d3c5582021-08-11 18:09:44 -0400238 fs.DurationVar(&(so.OmciTimeout),
239 "omci_timeout",
240 3*time.Second,
241 "OMCI timeout duration - this timeout value is used on the OMCI channel for waiting on response from ONU")
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800242
khenaidoo7d3c5582021-08-11 18:09:44 -0400243 fs.DurationVar(&(so.AlarmAuditInterval),
244 "alarm_audit_interval",
245 300*time.Second,
246 "Alarm Audit Interval in seconds - the value zero will disable alarm audit")
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000247
khenaidoo7d3c5582021-08-11 18:09:44 -0400248 fs.DurationVar(&(so.DownloadToAdapterTimeout),
249 "download_to_adapter_timeout",
250 10*time.Second,
251 "File download to adapter timeout in seconds")
Girish Gowdra0b235842021-03-09 13:06:46 -0800252
khenaidoo7d3c5582021-08-11 18:09:44 -0400253 fs.DurationVar(&(so.DownloadToOnuTimeout4MB),
254 "download_to_onu_timeout_4MB",
255 60*time.Minute,
256 "File download to ONU timeout in minutes for a block of 4MB")
Himani Chawla075f1642021-03-15 19:23:24 +0530257
khenaidoo7d3c5582021-08-11 18:09:44 -0400258 //Mask to indicate which possibly active ONU UNI state is really reported to the core
259 // compare python code - at the moment restrict active state to the first ONU UNI port
260 // check is limited to max 16 uni ports - cmp above UNI limit!!!
261 fs.IntVar(&(so.UniPortMask),
262 "uni_port_mask",
263 0x0001,
264 "The bitmask to identify UNI ports that need to be enabled")
mpagenkoc26d4c02021-05-06 14:27:57 +0000265
khenaidoo7d3c5582021-08-11 18:09:44 -0400266 fs.StringVar(&(so.GrpcAddress),
267 "grpc_address",
268 ":50060",
269 "Adapter GRPC Server address")
mpagenkoc26d4c02021-05-06 14:27:57 +0000270
khenaidoo7d3c5582021-08-11 18:09:44 -0400271 fs.StringVar(&(so.CoreEndpoint),
272 "core_endpoint",
273 ":55555",
274 "Core endpoint")
Matteo Scandolo20d180c2021-06-10 17:20:21 +0200275
khenaidoo7d3c5582021-08-11 18:09:44 -0400276 fs.StringVar(&(so.AdapterEndpoint),
277 "adapter_endpoint",
278 "",
279 "Adapter Endpoint")
280
281 fs.DurationVar(&(so.RPCTimeout),
282 "rpc_timeout",
283 10*time.Second,
284 "The default timeout when making an RPC request")
285
bseeniva0b4286b2026-01-30 13:05:42 +0530286 fs.DurationVar(&(so.ONUSwUpgradeTimeout),
287 "onu_sw_upgrade_timeout",
288 3*time.Hour,
289 "The default timeout for ONU software upgrade")
290
khenaidoo7d3c5582021-08-11 18:09:44 -0400291 fs.DurationVar(&(so.MinBackoffRetryDelay),
292 "min_retry_delay",
293 500*time.Millisecond,
294 "The minimum number of milliseconds to delay before a connection retry attempt")
295
296 fs.DurationVar(&(so.MaxBackoffRetryDelay),
297 "max_retry_delay",
298 10*time.Second,
299 "The maximum number of milliseconds to delay before a connection retry attempt")
Girish Gowdrae95687a2021-09-08 16:30:58 -0700300 fs.IntVar(&(so.MaxConcurrentFlowsPerUni),
301 "max_concurrent_flows_per_uni",
302 16,
303 "The max number of concurrent flows (add/remove) that can be queued per UNI")
nikesh.krishnanca4afa32023-06-28 03:42:16 +0530304 fs.DurationVar(&(so.PerRPCRetryTimeout),
305 "per_rpc_retry_timeout",
306 0*time.Second,
307 "The default timeout per RPC retry")
Praneeth Kumar Nalmas77ab2f32024-04-17 11:14:27 +0530308 fs.BoolVar(&(so.SkipOnuConfig),
309 "skip_onu_config_enabled",
310 false,
311 "Whether to enable/disable the Skipping of the ONU configuration via OMCI during reconciling")
Sridhar Ravindraa9cb0442025-07-21 16:55:05 +0530312 fs.BoolVar(&(so.CheckDeviceTechProfOnReboot),
313 "check_device_tech_prof_on_reboot_enabled",
314 false,
315 "To check for device tech profile and configure during ONU reboot")
nikesh.krishnanca4afa32023-06-28 03:42:16 +0530316 fs.UintVar(&(so.MaxRetries),
317 "max_grpc_client_retry",
318 0,
319 "The maximum number of times olt adaptor will retry in case grpc request timeouts")
akashreddykff176ea2025-09-16 23:20:16 +0530320 fs.IntVar(&so.ProducerRetryMax,
321 "producer_retry_max",
322 defaultProducerRetryMax,
323 "This option specifies the maximum number of times the producer will retry sending messages before giving up")
324 fs.IntVar(&so.MetadataRetryMax,
325 "metadata_retry_max",
326 defaultMetadataRetryMax,
327 "This option specifies the maximum number of times retry to receive messages before giving up")
khenaidoo7d3c5582021-08-11 18:09:44 -0400328 _ = fs.Parse(args)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000329 containerName := getContainerInfo()
330 if len(containerName) > 0 {
331 so.InstanceID = containerName
khenaidoo7d3c5582021-08-11 18:09:44 -0400332 } else {
333 so.InstanceID = "openonu"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000334 }
335
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000336}
337
338func getContainerInfo() string {
339 return os.Getenv("HOSTNAME")
340}