blob: e951584c732bd1a56f316f1c4afb2d742c9a5ba7 [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
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +053044 TraceAgentAddress string
45 OnuVendorIds string
46 AdapterEndpoint string
47 GrpcAddress string
48 CoreEndpoint string
49 KVStoreTimeout time.Duration
50 OnuNumber int
Holger Hildebrandtfa074992020-03-27 15:42:06 +000051 ProbePort int
52 LiveProbeInterval time.Duration
53 NotLiveProbeInterval time.Duration
54 HeartbeatCheckInterval time.Duration
55 HeartbeatFailReportInterval time.Duration
56 KafkaReconnectRetries int
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000057 CurrentReplica int
58 TotalReplicas int
Himani Chawlad96df182020-09-28 11:12:02 +053059 MaxTimeoutInterAdapterComm time.Duration
Holger Hildebrandt38985dc2021-02-18 16:25:20 +000060 MaxTimeoutReconciling time.Duration
Holger Hildebrandte3677f12021-02-05 14:50:56 +000061 MibAuditInterval time.Duration
Girish Gowdra0b235842021-03-09 13:06:46 -080062 OmciTimeout time.Duration
Himani Chawla075f1642021-03-15 19:23:24 +053063 AlarmAuditInterval time.Duration
mpagenkoc26d4c02021-05-06 14:27:57 +000064 DownloadToAdapterTimeout time.Duration
65 DownloadToOnuTimeout4MB time.Duration
Matteo Scandolo20d180c2021-06-10 17:20:21 +020066 UniPortMask int
khenaidoo7d3c5582021-08-11 18:09:44 -040067 MinBackoffRetryDelay time.Duration
68 MaxBackoffRetryDelay time.Duration
khenaidoo7d3c5582021-08-11 18:09:44 -040069 RPCTimeout time.Duration
Girish Gowdrae95687a2021-09-08 16:30:58 -070070 MaxConcurrentFlowsPerUni int
nikesh.krishnanca4afa32023-06-28 03:42:16 +053071 PerRPCRetryTimeout time.Duration
72 MaxRetries uint
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +053073 Banner bool
74 DisplayVersionOnly bool
75 AccIncrEvto bool
76 TraceEnabled bool
77 LogCorrelationEnabled bool
78 MetricsEnabled bool
79 ExtendedOmciSupportEnabled bool
Praneeth Kumar Nalmas77ab2f32024-04-17 11:14:27 +053080 SkipOnuConfig bool
Sridhar Ravindraa9cb0442025-07-21 16:55:05 +053081 CheckDeviceTechProfOnReboot bool
akashreddykff176ea2025-09-16 23:20:16 +053082 ProducerRetryMax int
83 MetadataRetryMax int
Holger Hildebrandtfa074992020-03-27 15:42:06 +000084}
85
86// ParseCommandArguments parses the arguments when running read-write adaptercore service
khenaidoo7d3c5582021-08-11 18:09:44 -040087func (so *AdapterFlags) ParseCommandArguments(args []string) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000088
khenaidoo7d3c5582021-08-11 18:09:44 -040089 fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
Holger Hildebrandtfa074992020-03-27 15:42:06 +000090
khenaidoo7d3c5582021-08-11 18:09:44 -040091 fs.StringVar(&(so.KafkaClusterAddress),
92 "kafka_cluster_address",
93 "127.0.0.1:9092",
94 "Kafka - Cluster messaging address")
Holger Hildebrandtfa074992020-03-27 15:42:06 +000095
khenaidoo7d3c5582021-08-11 18:09:44 -040096 fs.StringVar(&(so.EventTopic),
97 "event_topic",
98 "voltha.events",
99 "Event topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000100
khenaidoo7d3c5582021-08-11 18:09:44 -0400101 fs.StringVar(&(so.KVStoreType),
102 "kv_store_type",
Abhay Kumar3282a142024-07-12 06:03:12 +0530103 KVStoreName,
khenaidoo7d3c5582021-08-11 18:09:44 -0400104 "KV store type")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000105
khenaidoo7d3c5582021-08-11 18:09:44 -0400106 fs.DurationVar(&(so.KVStoreTimeout),
107 "kv_store_request_timeout",
108 5*time.Second,
109 "The default timeout when making a kv store request")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000110
khenaidoo7d3c5582021-08-11 18:09:44 -0400111 fs.StringVar(&(so.KVStoreAddress),
112 "kv_store_address",
113 "127.0.0.1:2379",
114 "KV store address")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000115
khenaidoo7d3c5582021-08-11 18:09:44 -0400116 fs.StringVar(&(so.LogLevel),
117 "log_level",
118 "WARN",
119 "Log level")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000120
khenaidoo7d3c5582021-08-11 18:09:44 -0400121 fs.IntVar(&(so.OnuNumber),
122 "onu_number",
123 1,
124 "Number of ONUs")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000125
khenaidoo7d3c5582021-08-11 18:09:44 -0400126 fs.BoolVar(&(so.Banner),
127 "banner",
128 false,
129 "Show startup banner log lines")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000130
khenaidoo7d3c5582021-08-11 18:09:44 -0400131 fs.BoolVar(&(so.DisplayVersionOnly),
132 "version",
133 false,
134 "Show version information and exit")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000135
khenaidoo7d3c5582021-08-11 18:09:44 -0400136 fs.BoolVar(&(so.AccIncrEvto),
137 "accept_incr_evto",
138 false,
139 "Acceptance of incremental EVTOCD configuration")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000140
khenaidoo7d3c5582021-08-11 18:09:44 -0400141 fs.StringVar(&(so.ProbeHost),
142 "probe_host",
143 "",
144 "The address on which to listen to answer liveness and readiness probe queries over HTTP")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000145
khenaidoo7d3c5582021-08-11 18:09:44 -0400146 fs.IntVar(&(so.ProbePort),
147 "probe_port",
148 8080,
149 "The port on which to listen to answer liveness and readiness probe queries over HTTP")
mpagenkodff5dda2020-08-28 11:52:01 +0000150
khenaidoo7d3c5582021-08-11 18:09:44 -0400151 fs.DurationVar(&(so.LiveProbeInterval),
152 "live_probe_interval",
153 60*time.Second,
154 "Number of seconds for the default liveliness check")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000155
khenaidoo7d3c5582021-08-11 18:09:44 -0400156 fs.DurationVar(&(so.NotLiveProbeInterval),
157 "not_live_probe_interval",
158 60*time.Second,
159 "Number of seconds for liveliness check if probe is not running")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000160
khenaidoo7d3c5582021-08-11 18:09:44 -0400161 fs.DurationVar(&(so.HeartbeatCheckInterval),
162 "hearbeat_check_interval",
163 30*time.Second,
164 "Number of seconds for heartbeat check interval")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000165
khenaidoo7d3c5582021-08-11 18:09:44 -0400166 fs.DurationVar(&(so.HeartbeatFailReportInterval),
167 "hearbeat_fail_interval",
168 30*time.Second,
169 "Number of seconds adapter has to wait before reporting core on the hearbeat check failure")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000170
khenaidoo7d3c5582021-08-11 18:09:44 -0400171 fs.IntVar(&(so.KafkaReconnectRetries),
172 "kafka_reconnect_retries",
173 -1,
174 "Number of retries to connect to Kafka")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000175
khenaidoo7d3c5582021-08-11 18:09:44 -0400176 fs.IntVar(&(so.CurrentReplica),
177 "current_replica",
178 1,
179 "Replica number of this particular instance")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000180
khenaidoo7d3c5582021-08-11 18:09:44 -0400181 fs.IntVar(&(so.TotalReplicas),
182 "total_replica",
183 1,
184 "Total number of instances for this adapter")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000185
khenaidoo7d3c5582021-08-11 18:09:44 -0400186 fs.DurationVar(&(so.MaxTimeoutInterAdapterComm),
187 "max_timeout_interadapter_comm",
188 30*time.Second,
189 "Maximum Number of seconds for the default interadapter communication timeout")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000190
khenaidoo7d3c5582021-08-11 18:09:44 -0400191 fs.DurationVar(&(so.MaxTimeoutReconciling),
192 "max_timeout_reconciling",
193 10*time.Second,
194 "Maximum Number of seconds for the default ONU reconciling timeout")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000195
khenaidoo7d3c5582021-08-11 18:09:44 -0400196 fs.BoolVar(&(so.TraceEnabled),
197 "trace_enabled",
198 false,
199 "Whether to send logs to tracing agent")
Himani Chawlad96df182020-09-28 11:12:02 +0530200
khenaidoo7d3c5582021-08-11 18:09:44 -0400201 fs.StringVar(&(so.TraceAgentAddress),
202 "trace_agent_address",
203 "127.0.0.1:6831",
204 "The address of tracing agent to which span info should be sent")
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000205
khenaidoo7d3c5582021-08-11 18:09:44 -0400206 fs.BoolVar(&(so.LogCorrelationEnabled),
207 "log_correlation_enabled",
208 true,
209 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000210
khenaidoo7d3c5582021-08-11 18:09:44 -0400211 fs.StringVar(&(so.OnuVendorIds),
212 "allowed_onu_vendors",
213 OnuVendorIds,
214 "List of Allowed ONU Vendor Ids")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000215
khenaidoo7d3c5582021-08-11 18:09:44 -0400216 fs.BoolVar(&(so.MetricsEnabled),
217 "metrics_enabled",
218 false,
219 "Whether to enable metrics collection")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000220
Holger Hildebrandtc572e622022-06-22 09:19:17 +0000221 fs.BoolVar(&(so.ExtendedOmciSupportEnabled),
222 "extended_omci_support_enabled",
223 false,
224 "Whether to enable extended OMCI support")
225
khenaidoo7d3c5582021-08-11 18:09:44 -0400226 fs.DurationVar(&(so.MibAuditInterval),
227 "mib_audit_interval",
228 300*time.Second,
229 "Mib Audit Interval in seconds - the value zero will disable Mib Audit")
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100230
khenaidoo7d3c5582021-08-11 18:09:44 -0400231 fs.DurationVar(&(so.OmciTimeout),
232 "omci_timeout",
233 3*time.Second,
234 "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 -0800235
khenaidoo7d3c5582021-08-11 18:09:44 -0400236 fs.DurationVar(&(so.AlarmAuditInterval),
237 "alarm_audit_interval",
238 300*time.Second,
239 "Alarm Audit Interval in seconds - the value zero will disable alarm audit")
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000240
khenaidoo7d3c5582021-08-11 18:09:44 -0400241 fs.DurationVar(&(so.DownloadToAdapterTimeout),
242 "download_to_adapter_timeout",
243 10*time.Second,
244 "File download to adapter timeout in seconds")
Girish Gowdra0b235842021-03-09 13:06:46 -0800245
khenaidoo7d3c5582021-08-11 18:09:44 -0400246 fs.DurationVar(&(so.DownloadToOnuTimeout4MB),
247 "download_to_onu_timeout_4MB",
248 60*time.Minute,
249 "File download to ONU timeout in minutes for a block of 4MB")
Himani Chawla075f1642021-03-15 19:23:24 +0530250
khenaidoo7d3c5582021-08-11 18:09:44 -0400251 //Mask to indicate which possibly active ONU UNI state is really reported to the core
252 // compare python code - at the moment restrict active state to the first ONU UNI port
253 // check is limited to max 16 uni ports - cmp above UNI limit!!!
254 fs.IntVar(&(so.UniPortMask),
255 "uni_port_mask",
256 0x0001,
257 "The bitmask to identify UNI ports that need to be enabled")
mpagenkoc26d4c02021-05-06 14:27:57 +0000258
khenaidoo7d3c5582021-08-11 18:09:44 -0400259 fs.StringVar(&(so.GrpcAddress),
260 "grpc_address",
261 ":50060",
262 "Adapter GRPC Server address")
mpagenkoc26d4c02021-05-06 14:27:57 +0000263
khenaidoo7d3c5582021-08-11 18:09:44 -0400264 fs.StringVar(&(so.CoreEndpoint),
265 "core_endpoint",
266 ":55555",
267 "Core endpoint")
Matteo Scandolo20d180c2021-06-10 17:20:21 +0200268
khenaidoo7d3c5582021-08-11 18:09:44 -0400269 fs.StringVar(&(so.AdapterEndpoint),
270 "adapter_endpoint",
271 "",
272 "Adapter Endpoint")
273
274 fs.DurationVar(&(so.RPCTimeout),
275 "rpc_timeout",
276 10*time.Second,
277 "The default timeout when making an RPC request")
278
279 fs.DurationVar(&(so.MinBackoffRetryDelay),
280 "min_retry_delay",
281 500*time.Millisecond,
282 "The minimum number of milliseconds to delay before a connection retry attempt")
283
284 fs.DurationVar(&(so.MaxBackoffRetryDelay),
285 "max_retry_delay",
286 10*time.Second,
287 "The maximum number of milliseconds to delay before a connection retry attempt")
Girish Gowdrae95687a2021-09-08 16:30:58 -0700288 fs.IntVar(&(so.MaxConcurrentFlowsPerUni),
289 "max_concurrent_flows_per_uni",
290 16,
291 "The max number of concurrent flows (add/remove) that can be queued per UNI")
nikesh.krishnanca4afa32023-06-28 03:42:16 +0530292 fs.DurationVar(&(so.PerRPCRetryTimeout),
293 "per_rpc_retry_timeout",
294 0*time.Second,
295 "The default timeout per RPC retry")
Praneeth Kumar Nalmas77ab2f32024-04-17 11:14:27 +0530296 fs.BoolVar(&(so.SkipOnuConfig),
297 "skip_onu_config_enabled",
298 false,
299 "Whether to enable/disable the Skipping of the ONU configuration via OMCI during reconciling")
Sridhar Ravindraa9cb0442025-07-21 16:55:05 +0530300 fs.BoolVar(&(so.CheckDeviceTechProfOnReboot),
301 "check_device_tech_prof_on_reboot_enabled",
302 false,
303 "To check for device tech profile and configure during ONU reboot")
nikesh.krishnanca4afa32023-06-28 03:42:16 +0530304 fs.UintVar(&(so.MaxRetries),
305 "max_grpc_client_retry",
306 0,
307 "The maximum number of times olt adaptor will retry in case grpc request timeouts")
akashreddykff176ea2025-09-16 23:20:16 +0530308 fs.IntVar(&so.ProducerRetryMax,
309 "producer_retry_max",
310 defaultProducerRetryMax,
311 "This option specifies the maximum number of times the producer will retry sending messages before giving up")
312 fs.IntVar(&so.MetadataRetryMax,
313 "metadata_retry_max",
314 defaultMetadataRetryMax,
315 "This option specifies the maximum number of times retry to receive messages before giving up")
khenaidoo7d3c5582021-08-11 18:09:44 -0400316 _ = fs.Parse(args)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000317 containerName := getContainerInfo()
318 if len(containerName) > 0 {
319 so.InstanceID = containerName
khenaidoo7d3c5582021-08-11 18:09:44 -0400320 } else {
321 so.InstanceID = "openonu"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000322 }
323
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000324}
325
326func getContainerInfo() string {
327 return os.Getenv("HOSTNAME")
328}