blob: 704aa772bffa4c69b1686769710171089afb2359 [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
Girish Gowdrae95687a2021-09-08 16:30:58 -070071 MaxConcurrentFlowsPerUni int
nikesh.krishnanca4afa32023-06-28 03:42:16 +053072 PerRPCRetryTimeout time.Duration
73 MaxRetries uint
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +053074 Banner bool
75 DisplayVersionOnly bool
76 AccIncrEvto bool
77 TraceEnabled bool
78 LogCorrelationEnabled bool
79 MetricsEnabled bool
80 ExtendedOmciSupportEnabled bool
Praneeth Kumar Nalmas77ab2f32024-04-17 11:14:27 +053081 SkipOnuConfig bool
Sridhar Ravindraa9cb0442025-07-21 16:55:05 +053082 CheckDeviceTechProfOnReboot bool
akashreddykff176ea2025-09-16 23:20:16 +053083 ProducerRetryMax int
84 MetadataRetryMax int
Holger Hildebrandtfa074992020-03-27 15:42:06 +000085}
86
87// ParseCommandArguments parses the arguments when running read-write adaptercore service
khenaidoo7d3c5582021-08-11 18:09:44 -040088func (so *AdapterFlags) ParseCommandArguments(args []string) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000089
khenaidoo7d3c5582021-08-11 18:09:44 -040090 fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
Holger Hildebrandtfa074992020-03-27 15:42:06 +000091
khenaidoo7d3c5582021-08-11 18:09:44 -040092 fs.StringVar(&(so.KafkaClusterAddress),
93 "kafka_cluster_address",
94 "127.0.0.1:9092",
95 "Kafka - Cluster messaging address")
Holger Hildebrandtfa074992020-03-27 15:42:06 +000096
khenaidoo7d3c5582021-08-11 18:09:44 -040097 fs.StringVar(&(so.EventTopic),
98 "event_topic",
99 "voltha.events",
100 "Event topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000101
khenaidoo7d3c5582021-08-11 18:09:44 -0400102 fs.StringVar(&(so.KVStoreType),
103 "kv_store_type",
Abhay Kumar3282a142024-07-12 06:03:12 +0530104 KVStoreName,
khenaidoo7d3c5582021-08-11 18:09:44 -0400105 "KV store type")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000106
khenaidoo7d3c5582021-08-11 18:09:44 -0400107 fs.DurationVar(&(so.KVStoreTimeout),
108 "kv_store_request_timeout",
109 5*time.Second,
110 "The default timeout when making a kv store request")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000111
khenaidoo7d3c5582021-08-11 18:09:44 -0400112 fs.StringVar(&(so.KVStoreAddress),
113 "kv_store_address",
114 "127.0.0.1:2379",
115 "KV store address")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000116
khenaidoo7d3c5582021-08-11 18:09:44 -0400117 fs.StringVar(&(so.LogLevel),
118 "log_level",
119 "WARN",
120 "Log level")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000121
khenaidoo7d3c5582021-08-11 18:09:44 -0400122 fs.IntVar(&(so.OnuNumber),
123 "onu_number",
124 1,
125 "Number of ONUs")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000126
khenaidoo7d3c5582021-08-11 18:09:44 -0400127 fs.BoolVar(&(so.Banner),
128 "banner",
129 false,
130 "Show startup banner log lines")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000131
khenaidoo7d3c5582021-08-11 18:09:44 -0400132 fs.BoolVar(&(so.DisplayVersionOnly),
133 "version",
134 false,
135 "Show version information and exit")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000136
khenaidoo7d3c5582021-08-11 18:09:44 -0400137 fs.BoolVar(&(so.AccIncrEvto),
138 "accept_incr_evto",
139 false,
140 "Acceptance of incremental EVTOCD configuration")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000141
khenaidoo7d3c5582021-08-11 18:09:44 -0400142 fs.StringVar(&(so.ProbeHost),
143 "probe_host",
144 "",
145 "The address on which to listen to answer liveness and readiness probe queries over HTTP")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000146
khenaidoo7d3c5582021-08-11 18:09:44 -0400147 fs.IntVar(&(so.ProbePort),
148 "probe_port",
149 8080,
150 "The port on which to listen to answer liveness and readiness probe queries over HTTP")
mpagenkodff5dda2020-08-28 11:52:01 +0000151
Abhay Kumarb5c1d7a2025-12-09 08:10:00 +0000152 fs.StringVar(&(so.PrometheusAddress),
153 "prometheus_port",
154 ":8081",
155 "Used for exposing the metrics to prometheus.")
156
khenaidoo7d3c5582021-08-11 18:09:44 -0400157 fs.DurationVar(&(so.LiveProbeInterval),
158 "live_probe_interval",
159 60*time.Second,
160 "Number of seconds for the default liveliness check")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000161
khenaidoo7d3c5582021-08-11 18:09:44 -0400162 fs.DurationVar(&(so.NotLiveProbeInterval),
163 "not_live_probe_interval",
164 60*time.Second,
165 "Number of seconds for liveliness check if probe is not running")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000166
khenaidoo7d3c5582021-08-11 18:09:44 -0400167 fs.DurationVar(&(so.HeartbeatCheckInterval),
168 "hearbeat_check_interval",
169 30*time.Second,
170 "Number of seconds for heartbeat check interval")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000171
khenaidoo7d3c5582021-08-11 18:09:44 -0400172 fs.DurationVar(&(so.HeartbeatFailReportInterval),
173 "hearbeat_fail_interval",
174 30*time.Second,
175 "Number of seconds adapter has to wait before reporting core on the hearbeat check failure")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000176
khenaidoo7d3c5582021-08-11 18:09:44 -0400177 fs.IntVar(&(so.KafkaReconnectRetries),
178 "kafka_reconnect_retries",
179 -1,
180 "Number of retries to connect to Kafka")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000181
khenaidoo7d3c5582021-08-11 18:09:44 -0400182 fs.IntVar(&(so.CurrentReplica),
183 "current_replica",
184 1,
185 "Replica number of this particular instance")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000186
khenaidoo7d3c5582021-08-11 18:09:44 -0400187 fs.IntVar(&(so.TotalReplicas),
188 "total_replica",
189 1,
190 "Total number of instances for this adapter")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000191
khenaidoo7d3c5582021-08-11 18:09:44 -0400192 fs.DurationVar(&(so.MaxTimeoutInterAdapterComm),
193 "max_timeout_interadapter_comm",
194 30*time.Second,
195 "Maximum Number of seconds for the default interadapter communication timeout")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000196
khenaidoo7d3c5582021-08-11 18:09:44 -0400197 fs.DurationVar(&(so.MaxTimeoutReconciling),
198 "max_timeout_reconciling",
199 10*time.Second,
200 "Maximum Number of seconds for the default ONU reconciling timeout")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000201
khenaidoo7d3c5582021-08-11 18:09:44 -0400202 fs.BoolVar(&(so.TraceEnabled),
203 "trace_enabled",
204 false,
205 "Whether to send logs to tracing agent")
Himani Chawlad96df182020-09-28 11:12:02 +0530206
khenaidoo7d3c5582021-08-11 18:09:44 -0400207 fs.StringVar(&(so.TraceAgentAddress),
208 "trace_agent_address",
209 "127.0.0.1:6831",
210 "The address of tracing agent to which span info should be sent")
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000211
khenaidoo7d3c5582021-08-11 18:09:44 -0400212 fs.BoolVar(&(so.LogCorrelationEnabled),
213 "log_correlation_enabled",
214 true,
215 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000216
khenaidoo7d3c5582021-08-11 18:09:44 -0400217 fs.StringVar(&(so.OnuVendorIds),
218 "allowed_onu_vendors",
219 OnuVendorIds,
220 "List of Allowed ONU Vendor Ids")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000221
khenaidoo7d3c5582021-08-11 18:09:44 -0400222 fs.BoolVar(&(so.MetricsEnabled),
223 "metrics_enabled",
224 false,
225 "Whether to enable metrics collection")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000226
Holger Hildebrandtc572e622022-06-22 09:19:17 +0000227 fs.BoolVar(&(so.ExtendedOmciSupportEnabled),
228 "extended_omci_support_enabled",
229 false,
230 "Whether to enable extended OMCI support")
231
khenaidoo7d3c5582021-08-11 18:09:44 -0400232 fs.DurationVar(&(so.MibAuditInterval),
233 "mib_audit_interval",
234 300*time.Second,
235 "Mib Audit Interval in seconds - the value zero will disable Mib Audit")
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100236
khenaidoo7d3c5582021-08-11 18:09:44 -0400237 fs.DurationVar(&(so.OmciTimeout),
238 "omci_timeout",
239 3*time.Second,
240 "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 -0800241
khenaidoo7d3c5582021-08-11 18:09:44 -0400242 fs.DurationVar(&(so.AlarmAuditInterval),
243 "alarm_audit_interval",
244 300*time.Second,
245 "Alarm Audit Interval in seconds - the value zero will disable alarm audit")
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000246
khenaidoo7d3c5582021-08-11 18:09:44 -0400247 fs.DurationVar(&(so.DownloadToAdapterTimeout),
248 "download_to_adapter_timeout",
249 10*time.Second,
250 "File download to adapter timeout in seconds")
Girish Gowdra0b235842021-03-09 13:06:46 -0800251
khenaidoo7d3c5582021-08-11 18:09:44 -0400252 fs.DurationVar(&(so.DownloadToOnuTimeout4MB),
253 "download_to_onu_timeout_4MB",
254 60*time.Minute,
255 "File download to ONU timeout in minutes for a block of 4MB")
Himani Chawla075f1642021-03-15 19:23:24 +0530256
khenaidoo7d3c5582021-08-11 18:09:44 -0400257 //Mask to indicate which possibly active ONU UNI state is really reported to the core
258 // compare python code - at the moment restrict active state to the first ONU UNI port
259 // check is limited to max 16 uni ports - cmp above UNI limit!!!
260 fs.IntVar(&(so.UniPortMask),
261 "uni_port_mask",
262 0x0001,
263 "The bitmask to identify UNI ports that need to be enabled")
mpagenkoc26d4c02021-05-06 14:27:57 +0000264
khenaidoo7d3c5582021-08-11 18:09:44 -0400265 fs.StringVar(&(so.GrpcAddress),
266 "grpc_address",
267 ":50060",
268 "Adapter GRPC Server address")
mpagenkoc26d4c02021-05-06 14:27:57 +0000269
khenaidoo7d3c5582021-08-11 18:09:44 -0400270 fs.StringVar(&(so.CoreEndpoint),
271 "core_endpoint",
272 ":55555",
273 "Core endpoint")
Matteo Scandolo20d180c2021-06-10 17:20:21 +0200274
khenaidoo7d3c5582021-08-11 18:09:44 -0400275 fs.StringVar(&(so.AdapterEndpoint),
276 "adapter_endpoint",
277 "",
278 "Adapter Endpoint")
279
280 fs.DurationVar(&(so.RPCTimeout),
281 "rpc_timeout",
282 10*time.Second,
283 "The default timeout when making an RPC request")
284
285 fs.DurationVar(&(so.MinBackoffRetryDelay),
286 "min_retry_delay",
287 500*time.Millisecond,
288 "The minimum number of milliseconds to delay before a connection retry attempt")
289
290 fs.DurationVar(&(so.MaxBackoffRetryDelay),
291 "max_retry_delay",
292 10*time.Second,
293 "The maximum number of milliseconds to delay before a connection retry attempt")
Girish Gowdrae95687a2021-09-08 16:30:58 -0700294 fs.IntVar(&(so.MaxConcurrentFlowsPerUni),
295 "max_concurrent_flows_per_uni",
296 16,
297 "The max number of concurrent flows (add/remove) that can be queued per UNI")
nikesh.krishnanca4afa32023-06-28 03:42:16 +0530298 fs.DurationVar(&(so.PerRPCRetryTimeout),
299 "per_rpc_retry_timeout",
300 0*time.Second,
301 "The default timeout per RPC retry")
Praneeth Kumar Nalmas77ab2f32024-04-17 11:14:27 +0530302 fs.BoolVar(&(so.SkipOnuConfig),
303 "skip_onu_config_enabled",
304 false,
305 "Whether to enable/disable the Skipping of the ONU configuration via OMCI during reconciling")
Sridhar Ravindraa9cb0442025-07-21 16:55:05 +0530306 fs.BoolVar(&(so.CheckDeviceTechProfOnReboot),
307 "check_device_tech_prof_on_reboot_enabled",
308 false,
309 "To check for device tech profile and configure during ONU reboot")
nikesh.krishnanca4afa32023-06-28 03:42:16 +0530310 fs.UintVar(&(so.MaxRetries),
311 "max_grpc_client_retry",
312 0,
313 "The maximum number of times olt adaptor will retry in case grpc request timeouts")
akashreddykff176ea2025-09-16 23:20:16 +0530314 fs.IntVar(&so.ProducerRetryMax,
315 "producer_retry_max",
316 defaultProducerRetryMax,
317 "This option specifies the maximum number of times the producer will retry sending messages before giving up")
318 fs.IntVar(&so.MetadataRetryMax,
319 "metadata_retry_max",
320 defaultMetadataRetryMax,
321 "This option specifies the maximum number of times retry to receive messages before giving up")
khenaidoo7d3c5582021-08-11 18:09:44 -0400322 _ = fs.Parse(args)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000323 containerName := getContainerInfo()
324 if len(containerName) > 0 {
325 so.InstanceID = containerName
khenaidoo7d3c5582021-08-11 18:09:44 -0400326 } else {
327 so.InstanceID = "openonu"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000328 }
329
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000330}
331
332func getContainerInfo() string {
333 return os.Getenv("HOSTNAME")
334}