blob: 04e4293af2ac8d35951e9832d78fc7d8b070b213 [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 (
Abhay Kumar3282a142024-07-12 06:03:12 +053028 KVStoreName = "etcd"
29 OnuVendorIds = "OPEN,ALCL,BRCM,TWSH,ALPH,ISKT,SFAA,BBSM,SCOM,ARPX,DACM,ERSN,HWTC,CIGG,ADTN,ARCA,AVMG,LEOX,ZYXE"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000030)
31
32// AdapterFlags represents the set of configurations used by the read-write adaptercore service
33type AdapterFlags struct {
34 // Command line parameters
35 InstanceID string
Matteo Scandolo127c59d2021-01-28 11:31:18 -080036 KafkaClusterAddress string // NOTE this is unused across the adapter
Holger Hildebrandtfa074992020-03-27 15:42:06 +000037 KVStoreType string
Matteo Scandolo127c59d2021-01-28 11:31:18 -080038 KVStoreAddress string
Holger Hildebrandtfa074992020-03-27 15:42:06 +000039 EventTopic string
40 LogLevel string
Holger Hildebrandtfa074992020-03-27 15:42:06 +000041 ProbeHost string
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +053042 TraceAgentAddress string
43 OnuVendorIds string
44 AdapterEndpoint string
45 GrpcAddress string
46 CoreEndpoint string
47 KVStoreTimeout time.Duration
48 OnuNumber int
Holger Hildebrandtfa074992020-03-27 15:42:06 +000049 ProbePort int
50 LiveProbeInterval time.Duration
51 NotLiveProbeInterval time.Duration
52 HeartbeatCheckInterval time.Duration
53 HeartbeatFailReportInterval time.Duration
54 KafkaReconnectRetries int
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000055 CurrentReplica int
56 TotalReplicas int
Himani Chawlad96df182020-09-28 11:12:02 +053057 MaxTimeoutInterAdapterComm time.Duration
Holger Hildebrandt38985dc2021-02-18 16:25:20 +000058 MaxTimeoutReconciling time.Duration
Holger Hildebrandte3677f12021-02-05 14:50:56 +000059 MibAuditInterval time.Duration
Girish Gowdra0b235842021-03-09 13:06:46 -080060 OmciTimeout time.Duration
Himani Chawla075f1642021-03-15 19:23:24 +053061 AlarmAuditInterval time.Duration
mpagenkoc26d4c02021-05-06 14:27:57 +000062 DownloadToAdapterTimeout time.Duration
63 DownloadToOnuTimeout4MB time.Duration
Matteo Scandolo20d180c2021-06-10 17:20:21 +020064 UniPortMask int
khenaidoo7d3c5582021-08-11 18:09:44 -040065 MinBackoffRetryDelay time.Duration
66 MaxBackoffRetryDelay time.Duration
khenaidoo7d3c5582021-08-11 18:09:44 -040067 RPCTimeout time.Duration
Girish Gowdrae95687a2021-09-08 16:30:58 -070068 MaxConcurrentFlowsPerUni int
nikesh.krishnanca4afa32023-06-28 03:42:16 +053069 PerRPCRetryTimeout time.Duration
70 MaxRetries uint
Akash Reddy Kankanala92dfdf82025-03-23 22:07:09 +053071 Banner bool
72 DisplayVersionOnly bool
73 AccIncrEvto bool
74 TraceEnabled bool
75 LogCorrelationEnabled bool
76 MetricsEnabled bool
77 ExtendedOmciSupportEnabled bool
Praneeth Kumar Nalmas77ab2f32024-04-17 11:14:27 +053078 SkipOnuConfig bool
Sridhar Ravindraa9cb0442025-07-21 16:55:05 +053079 CheckDeviceTechProfOnReboot bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +000080}
81
82// ParseCommandArguments parses the arguments when running read-write adaptercore service
khenaidoo7d3c5582021-08-11 18:09:44 -040083func (so *AdapterFlags) ParseCommandArguments(args []string) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000084
khenaidoo7d3c5582021-08-11 18:09:44 -040085 fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
Holger Hildebrandtfa074992020-03-27 15:42:06 +000086
khenaidoo7d3c5582021-08-11 18:09:44 -040087 fs.StringVar(&(so.KafkaClusterAddress),
88 "kafka_cluster_address",
89 "127.0.0.1:9092",
90 "Kafka - Cluster messaging address")
Holger Hildebrandtfa074992020-03-27 15:42:06 +000091
khenaidoo7d3c5582021-08-11 18:09:44 -040092 fs.StringVar(&(so.EventTopic),
93 "event_topic",
94 "voltha.events",
95 "Event topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +000096
khenaidoo7d3c5582021-08-11 18:09:44 -040097 fs.StringVar(&(so.KVStoreType),
98 "kv_store_type",
Abhay Kumar3282a142024-07-12 06:03:12 +053099 KVStoreName,
khenaidoo7d3c5582021-08-11 18:09:44 -0400100 "KV store type")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000101
khenaidoo7d3c5582021-08-11 18:09:44 -0400102 fs.DurationVar(&(so.KVStoreTimeout),
103 "kv_store_request_timeout",
104 5*time.Second,
105 "The default timeout when making a kv store request")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000106
khenaidoo7d3c5582021-08-11 18:09:44 -0400107 fs.StringVar(&(so.KVStoreAddress),
108 "kv_store_address",
109 "127.0.0.1:2379",
110 "KV store address")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000111
khenaidoo7d3c5582021-08-11 18:09:44 -0400112 fs.StringVar(&(so.LogLevel),
113 "log_level",
114 "WARN",
115 "Log level")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000116
khenaidoo7d3c5582021-08-11 18:09:44 -0400117 fs.IntVar(&(so.OnuNumber),
118 "onu_number",
119 1,
120 "Number of ONUs")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000121
khenaidoo7d3c5582021-08-11 18:09:44 -0400122 fs.BoolVar(&(so.Banner),
123 "banner",
124 false,
125 "Show startup banner log lines")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000126
khenaidoo7d3c5582021-08-11 18:09:44 -0400127 fs.BoolVar(&(so.DisplayVersionOnly),
128 "version",
129 false,
130 "Show version information and exit")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000131
khenaidoo7d3c5582021-08-11 18:09:44 -0400132 fs.BoolVar(&(so.AccIncrEvto),
133 "accept_incr_evto",
134 false,
135 "Acceptance of incremental EVTOCD configuration")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000136
khenaidoo7d3c5582021-08-11 18:09:44 -0400137 fs.StringVar(&(so.ProbeHost),
138 "probe_host",
139 "",
140 "The address on which to listen to answer liveness and readiness probe queries over HTTP")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000141
khenaidoo7d3c5582021-08-11 18:09:44 -0400142 fs.IntVar(&(so.ProbePort),
143 "probe_port",
144 8080,
145 "The port on which to listen to answer liveness and readiness probe queries over HTTP")
mpagenkodff5dda2020-08-28 11:52:01 +0000146
khenaidoo7d3c5582021-08-11 18:09:44 -0400147 fs.DurationVar(&(so.LiveProbeInterval),
148 "live_probe_interval",
149 60*time.Second,
150 "Number of seconds for the default liveliness check")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000151
khenaidoo7d3c5582021-08-11 18:09:44 -0400152 fs.DurationVar(&(so.NotLiveProbeInterval),
153 "not_live_probe_interval",
154 60*time.Second,
155 "Number of seconds for liveliness check if probe is not running")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000156
khenaidoo7d3c5582021-08-11 18:09:44 -0400157 fs.DurationVar(&(so.HeartbeatCheckInterval),
158 "hearbeat_check_interval",
159 30*time.Second,
160 "Number of seconds for heartbeat check interval")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000161
khenaidoo7d3c5582021-08-11 18:09:44 -0400162 fs.DurationVar(&(so.HeartbeatFailReportInterval),
163 "hearbeat_fail_interval",
164 30*time.Second,
165 "Number of seconds adapter has to wait before reporting core on the hearbeat check failure")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000166
khenaidoo7d3c5582021-08-11 18:09:44 -0400167 fs.IntVar(&(so.KafkaReconnectRetries),
168 "kafka_reconnect_retries",
169 -1,
170 "Number of retries to connect to Kafka")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000171
khenaidoo7d3c5582021-08-11 18:09:44 -0400172 fs.IntVar(&(so.CurrentReplica),
173 "current_replica",
174 1,
175 "Replica number of this particular instance")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000176
khenaidoo7d3c5582021-08-11 18:09:44 -0400177 fs.IntVar(&(so.TotalReplicas),
178 "total_replica",
179 1,
180 "Total number of instances for this adapter")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000181
khenaidoo7d3c5582021-08-11 18:09:44 -0400182 fs.DurationVar(&(so.MaxTimeoutInterAdapterComm),
183 "max_timeout_interadapter_comm",
184 30*time.Second,
185 "Maximum Number of seconds for the default interadapter communication timeout")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000186
khenaidoo7d3c5582021-08-11 18:09:44 -0400187 fs.DurationVar(&(so.MaxTimeoutReconciling),
188 "max_timeout_reconciling",
189 10*time.Second,
190 "Maximum Number of seconds for the default ONU reconciling timeout")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000191
khenaidoo7d3c5582021-08-11 18:09:44 -0400192 fs.BoolVar(&(so.TraceEnabled),
193 "trace_enabled",
194 false,
195 "Whether to send logs to tracing agent")
Himani Chawlad96df182020-09-28 11:12:02 +0530196
khenaidoo7d3c5582021-08-11 18:09:44 -0400197 fs.StringVar(&(so.TraceAgentAddress),
198 "trace_agent_address",
199 "127.0.0.1:6831",
200 "The address of tracing agent to which span info should be sent")
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000201
khenaidoo7d3c5582021-08-11 18:09:44 -0400202 fs.BoolVar(&(so.LogCorrelationEnabled),
203 "log_correlation_enabled",
204 true,
205 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000206
khenaidoo7d3c5582021-08-11 18:09:44 -0400207 fs.StringVar(&(so.OnuVendorIds),
208 "allowed_onu_vendors",
209 OnuVendorIds,
210 "List of Allowed ONU Vendor Ids")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000211
khenaidoo7d3c5582021-08-11 18:09:44 -0400212 fs.BoolVar(&(so.MetricsEnabled),
213 "metrics_enabled",
214 false,
215 "Whether to enable metrics collection")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000216
Holger Hildebrandtc572e622022-06-22 09:19:17 +0000217 fs.BoolVar(&(so.ExtendedOmciSupportEnabled),
218 "extended_omci_support_enabled",
219 false,
220 "Whether to enable extended OMCI support")
221
khenaidoo7d3c5582021-08-11 18:09:44 -0400222 fs.DurationVar(&(so.MibAuditInterval),
223 "mib_audit_interval",
224 300*time.Second,
225 "Mib Audit Interval in seconds - the value zero will disable Mib Audit")
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100226
khenaidoo7d3c5582021-08-11 18:09:44 -0400227 fs.DurationVar(&(so.OmciTimeout),
228 "omci_timeout",
229 3*time.Second,
230 "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 -0800231
khenaidoo7d3c5582021-08-11 18:09:44 -0400232 fs.DurationVar(&(so.AlarmAuditInterval),
233 "alarm_audit_interval",
234 300*time.Second,
235 "Alarm Audit Interval in seconds - the value zero will disable alarm audit")
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000236
khenaidoo7d3c5582021-08-11 18:09:44 -0400237 fs.DurationVar(&(so.DownloadToAdapterTimeout),
238 "download_to_adapter_timeout",
239 10*time.Second,
240 "File download to adapter timeout in seconds")
Girish Gowdra0b235842021-03-09 13:06:46 -0800241
khenaidoo7d3c5582021-08-11 18:09:44 -0400242 fs.DurationVar(&(so.DownloadToOnuTimeout4MB),
243 "download_to_onu_timeout_4MB",
244 60*time.Minute,
245 "File download to ONU timeout in minutes for a block of 4MB")
Himani Chawla075f1642021-03-15 19:23:24 +0530246
khenaidoo7d3c5582021-08-11 18:09:44 -0400247 //Mask to indicate which possibly active ONU UNI state is really reported to the core
248 // compare python code - at the moment restrict active state to the first ONU UNI port
249 // check is limited to max 16 uni ports - cmp above UNI limit!!!
250 fs.IntVar(&(so.UniPortMask),
251 "uni_port_mask",
252 0x0001,
253 "The bitmask to identify UNI ports that need to be enabled")
mpagenkoc26d4c02021-05-06 14:27:57 +0000254
khenaidoo7d3c5582021-08-11 18:09:44 -0400255 fs.StringVar(&(so.GrpcAddress),
256 "grpc_address",
257 ":50060",
258 "Adapter GRPC Server address")
mpagenkoc26d4c02021-05-06 14:27:57 +0000259
khenaidoo7d3c5582021-08-11 18:09:44 -0400260 fs.StringVar(&(so.CoreEndpoint),
261 "core_endpoint",
262 ":55555",
263 "Core endpoint")
Matteo Scandolo20d180c2021-06-10 17:20:21 +0200264
khenaidoo7d3c5582021-08-11 18:09:44 -0400265 fs.StringVar(&(so.AdapterEndpoint),
266 "adapter_endpoint",
267 "",
268 "Adapter Endpoint")
269
270 fs.DurationVar(&(so.RPCTimeout),
271 "rpc_timeout",
272 10*time.Second,
273 "The default timeout when making an RPC request")
274
275 fs.DurationVar(&(so.MinBackoffRetryDelay),
276 "min_retry_delay",
277 500*time.Millisecond,
278 "The minimum number of milliseconds to delay before a connection retry attempt")
279
280 fs.DurationVar(&(so.MaxBackoffRetryDelay),
281 "max_retry_delay",
282 10*time.Second,
283 "The maximum number of milliseconds to delay before a connection retry attempt")
Girish Gowdrae95687a2021-09-08 16:30:58 -0700284 fs.IntVar(&(so.MaxConcurrentFlowsPerUni),
285 "max_concurrent_flows_per_uni",
286 16,
287 "The max number of concurrent flows (add/remove) that can be queued per UNI")
nikesh.krishnanca4afa32023-06-28 03:42:16 +0530288 fs.DurationVar(&(so.PerRPCRetryTimeout),
289 "per_rpc_retry_timeout",
290 0*time.Second,
291 "The default timeout per RPC retry")
Praneeth Kumar Nalmas77ab2f32024-04-17 11:14:27 +0530292 fs.BoolVar(&(so.SkipOnuConfig),
293 "skip_onu_config_enabled",
294 false,
295 "Whether to enable/disable the Skipping of the ONU configuration via OMCI during reconciling")
Sridhar Ravindraa9cb0442025-07-21 16:55:05 +0530296 fs.BoolVar(&(so.CheckDeviceTechProfOnReboot),
297 "check_device_tech_prof_on_reboot_enabled",
298 false,
299 "To check for device tech profile and configure during ONU reboot")
nikesh.krishnanca4afa32023-06-28 03:42:16 +0530300 fs.UintVar(&(so.MaxRetries),
301 "max_grpc_client_retry",
302 0,
303 "The maximum number of times olt adaptor will retry in case grpc request timeouts")
khenaidoo7d3c5582021-08-11 18:09:44 -0400304 _ = fs.Parse(args)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000305 containerName := getContainerInfo()
306 if len(containerName) > 0 {
307 so.InstanceID = containerName
khenaidoo7d3c5582021-08-11 18:09:44 -0400308 } else {
309 so.InstanceID = "openonu"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000310 }
311
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000312}
313
314func getContainerInfo() string {
315 return os.Getenv("HOSTNAME")
316}