blob: 08ecfa3317a1521eefbce5208eeea7269d54b14d [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 (
khenaidoo7d3c5582021-08-11 18:09:44 -040028 EtcdStoreName = "etcd"
Mahir Gunyel691beaf2023-12-21 23:52:47 -080029 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
mpagenkoaf801632020-07-03 10:00:42 +000038 KVStoreTimeout time.Duration
Matteo Scandolo127c59d2021-01-28 11:31:18 -080039 KVStoreAddress string
Holger Hildebrandtfa074992020-03-27 15:42:06 +000040 EventTopic string
41 LogLevel string
42 OnuNumber int
43 Banner bool
44 DisplayVersionOnly bool
mpagenkodff5dda2020-08-28 11:52:01 +000045 AccIncrEvto bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +000046 ProbeHost string
47 ProbePort int
48 LiveProbeInterval time.Duration
49 NotLiveProbeInterval time.Duration
50 HeartbeatCheckInterval time.Duration
51 HeartbeatFailReportInterval time.Duration
52 KafkaReconnectRetries int
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000053 CurrentReplica int
54 TotalReplicas int
Himani Chawlad96df182020-09-28 11:12:02 +053055 MaxTimeoutInterAdapterComm time.Duration
Holger Hildebrandt38985dc2021-02-18 16:25:20 +000056 MaxTimeoutReconciling time.Duration
dbainbri4d3a0dc2020-12-02 00:33:42 +000057 TraceEnabled bool
58 TraceAgentAddress string
59 LogCorrelationEnabled bool
Andrea Campanella3d7c9312021-01-19 09:20:49 +010060 OnuVendorIds string
Girish Gowdraaf0ad632021-01-27 13:00:01 -080061 MetricsEnabled bool
Holger Hildebrandtc572e622022-06-22 09:19:17 +000062 ExtendedOmciSupportEnabled bool
Holger Hildebrandte3677f12021-02-05 14:50:56 +000063 MibAuditInterval time.Duration
Girish Gowdra0b235842021-03-09 13:06:46 -080064 OmciTimeout time.Duration
Himani Chawla075f1642021-03-15 19:23:24 +053065 AlarmAuditInterval time.Duration
mpagenkoc26d4c02021-05-06 14:27:57 +000066 DownloadToAdapterTimeout time.Duration
67 DownloadToOnuTimeout4MB time.Duration
Matteo Scandolo20d180c2021-06-10 17:20:21 +020068 UniPortMask int
khenaidoo7d3c5582021-08-11 18:09:44 -040069 MinBackoffRetryDelay time.Duration
70 MaxBackoffRetryDelay time.Duration
71 AdapterEndpoint string
72 GrpcAddress string
73 CoreEndpoint string
74 RPCTimeout time.Duration
Girish Gowdrae95687a2021-09-08 16:30:58 -070075 MaxConcurrentFlowsPerUni int
nikesh.krishnanca4afa32023-06-28 03:42:16 +053076 PerRPCRetryTimeout time.Duration
77 MaxRetries uint
Praneeth Kumar Nalmas77ab2f32024-04-17 11:14:27 +053078 SkipOnuConfig bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +000079}
80
81// ParseCommandArguments parses the arguments when running read-write adaptercore service
khenaidoo7d3c5582021-08-11 18:09:44 -040082func (so *AdapterFlags) ParseCommandArguments(args []string) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000083
khenaidoo7d3c5582021-08-11 18:09:44 -040084 fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
Holger Hildebrandtfa074992020-03-27 15:42:06 +000085
khenaidoo7d3c5582021-08-11 18:09:44 -040086 fs.StringVar(&(so.KafkaClusterAddress),
87 "kafka_cluster_address",
88 "127.0.0.1:9092",
89 "Kafka - Cluster messaging address")
Holger Hildebrandtfa074992020-03-27 15:42:06 +000090
khenaidoo7d3c5582021-08-11 18:09:44 -040091 fs.StringVar(&(so.EventTopic),
92 "event_topic",
93 "voltha.events",
94 "Event topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +000095
khenaidoo7d3c5582021-08-11 18:09:44 -040096 fs.StringVar(&(so.KVStoreType),
97 "kv_store_type",
98 EtcdStoreName,
99 "KV store type")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000100
khenaidoo7d3c5582021-08-11 18:09:44 -0400101 fs.DurationVar(&(so.KVStoreTimeout),
102 "kv_store_request_timeout",
103 5*time.Second,
104 "The default timeout when making a kv store request")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000105
khenaidoo7d3c5582021-08-11 18:09:44 -0400106 fs.StringVar(&(so.KVStoreAddress),
107 "kv_store_address",
108 "127.0.0.1:2379",
109 "KV store address")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000110
khenaidoo7d3c5582021-08-11 18:09:44 -0400111 fs.StringVar(&(so.LogLevel),
112 "log_level",
113 "WARN",
114 "Log level")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000115
khenaidoo7d3c5582021-08-11 18:09:44 -0400116 fs.IntVar(&(so.OnuNumber),
117 "onu_number",
118 1,
119 "Number of ONUs")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000120
khenaidoo7d3c5582021-08-11 18:09:44 -0400121 fs.BoolVar(&(so.Banner),
122 "banner",
123 false,
124 "Show startup banner log lines")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000125
khenaidoo7d3c5582021-08-11 18:09:44 -0400126 fs.BoolVar(&(so.DisplayVersionOnly),
127 "version",
128 false,
129 "Show version information and exit")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000130
khenaidoo7d3c5582021-08-11 18:09:44 -0400131 fs.BoolVar(&(so.AccIncrEvto),
132 "accept_incr_evto",
133 false,
134 "Acceptance of incremental EVTOCD configuration")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000135
khenaidoo7d3c5582021-08-11 18:09:44 -0400136 fs.StringVar(&(so.ProbeHost),
137 "probe_host",
138 "",
139 "The address on which to listen to answer liveness and readiness probe queries over HTTP")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000140
khenaidoo7d3c5582021-08-11 18:09:44 -0400141 fs.IntVar(&(so.ProbePort),
142 "probe_port",
143 8080,
144 "The port on which to listen to answer liveness and readiness probe queries over HTTP")
mpagenkodff5dda2020-08-28 11:52:01 +0000145
khenaidoo7d3c5582021-08-11 18:09:44 -0400146 fs.DurationVar(&(so.LiveProbeInterval),
147 "live_probe_interval",
148 60*time.Second,
149 "Number of seconds for the default liveliness check")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000150
khenaidoo7d3c5582021-08-11 18:09:44 -0400151 fs.DurationVar(&(so.NotLiveProbeInterval),
152 "not_live_probe_interval",
153 60*time.Second,
154 "Number of seconds for liveliness check if probe is not running")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000155
khenaidoo7d3c5582021-08-11 18:09:44 -0400156 fs.DurationVar(&(so.HeartbeatCheckInterval),
157 "hearbeat_check_interval",
158 30*time.Second,
159 "Number of seconds for heartbeat check interval")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000160
khenaidoo7d3c5582021-08-11 18:09:44 -0400161 fs.DurationVar(&(so.HeartbeatFailReportInterval),
162 "hearbeat_fail_interval",
163 30*time.Second,
164 "Number of seconds adapter has to wait before reporting core on the hearbeat check failure")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000165
khenaidoo7d3c5582021-08-11 18:09:44 -0400166 fs.IntVar(&(so.KafkaReconnectRetries),
167 "kafka_reconnect_retries",
168 -1,
169 "Number of retries to connect to Kafka")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000170
khenaidoo7d3c5582021-08-11 18:09:44 -0400171 fs.IntVar(&(so.CurrentReplica),
172 "current_replica",
173 1,
174 "Replica number of this particular instance")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000175
khenaidoo7d3c5582021-08-11 18:09:44 -0400176 fs.IntVar(&(so.TotalReplicas),
177 "total_replica",
178 1,
179 "Total number of instances for this adapter")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000180
khenaidoo7d3c5582021-08-11 18:09:44 -0400181 fs.DurationVar(&(so.MaxTimeoutInterAdapterComm),
182 "max_timeout_interadapter_comm",
183 30*time.Second,
184 "Maximum Number of seconds for the default interadapter communication timeout")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000185
khenaidoo7d3c5582021-08-11 18:09:44 -0400186 fs.DurationVar(&(so.MaxTimeoutReconciling),
187 "max_timeout_reconciling",
188 10*time.Second,
189 "Maximum Number of seconds for the default ONU reconciling timeout")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000190
khenaidoo7d3c5582021-08-11 18:09:44 -0400191 fs.BoolVar(&(so.TraceEnabled),
192 "trace_enabled",
193 false,
194 "Whether to send logs to tracing agent")
Himani Chawlad96df182020-09-28 11:12:02 +0530195
khenaidoo7d3c5582021-08-11 18:09:44 -0400196 fs.StringVar(&(so.TraceAgentAddress),
197 "trace_agent_address",
198 "127.0.0.1:6831",
199 "The address of tracing agent to which span info should be sent")
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000200
khenaidoo7d3c5582021-08-11 18:09:44 -0400201 fs.BoolVar(&(so.LogCorrelationEnabled),
202 "log_correlation_enabled",
203 true,
204 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000205
khenaidoo7d3c5582021-08-11 18:09:44 -0400206 fs.StringVar(&(so.OnuVendorIds),
207 "allowed_onu_vendors",
208 OnuVendorIds,
209 "List of Allowed ONU Vendor Ids")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000210
khenaidoo7d3c5582021-08-11 18:09:44 -0400211 fs.BoolVar(&(so.MetricsEnabled),
212 "metrics_enabled",
213 false,
214 "Whether to enable metrics collection")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000215
Holger Hildebrandtc572e622022-06-22 09:19:17 +0000216 fs.BoolVar(&(so.ExtendedOmciSupportEnabled),
217 "extended_omci_support_enabled",
218 false,
219 "Whether to enable extended OMCI support")
220
khenaidoo7d3c5582021-08-11 18:09:44 -0400221 fs.DurationVar(&(so.MibAuditInterval),
222 "mib_audit_interval",
223 300*time.Second,
224 "Mib Audit Interval in seconds - the value zero will disable Mib Audit")
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100225
khenaidoo7d3c5582021-08-11 18:09:44 -0400226 fs.DurationVar(&(so.OmciTimeout),
227 "omci_timeout",
228 3*time.Second,
229 "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 -0800230
khenaidoo7d3c5582021-08-11 18:09:44 -0400231 fs.DurationVar(&(so.AlarmAuditInterval),
232 "alarm_audit_interval",
233 300*time.Second,
234 "Alarm Audit Interval in seconds - the value zero will disable alarm audit")
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000235
khenaidoo7d3c5582021-08-11 18:09:44 -0400236 fs.DurationVar(&(so.DownloadToAdapterTimeout),
237 "download_to_adapter_timeout",
238 10*time.Second,
239 "File download to adapter timeout in seconds")
Girish Gowdra0b235842021-03-09 13:06:46 -0800240
khenaidoo7d3c5582021-08-11 18:09:44 -0400241 fs.DurationVar(&(so.DownloadToOnuTimeout4MB),
242 "download_to_onu_timeout_4MB",
243 60*time.Minute,
244 "File download to ONU timeout in minutes for a block of 4MB")
Himani Chawla075f1642021-03-15 19:23:24 +0530245
khenaidoo7d3c5582021-08-11 18:09:44 -0400246 //Mask to indicate which possibly active ONU UNI state is really reported to the core
247 // compare python code - at the moment restrict active state to the first ONU UNI port
248 // check is limited to max 16 uni ports - cmp above UNI limit!!!
249 fs.IntVar(&(so.UniPortMask),
250 "uni_port_mask",
251 0x0001,
252 "The bitmask to identify UNI ports that need to be enabled")
mpagenkoc26d4c02021-05-06 14:27:57 +0000253
khenaidoo7d3c5582021-08-11 18:09:44 -0400254 fs.StringVar(&(so.GrpcAddress),
255 "grpc_address",
256 ":50060",
257 "Adapter GRPC Server address")
mpagenkoc26d4c02021-05-06 14:27:57 +0000258
khenaidoo7d3c5582021-08-11 18:09:44 -0400259 fs.StringVar(&(so.CoreEndpoint),
260 "core_endpoint",
261 ":55555",
262 "Core endpoint")
Matteo Scandolo20d180c2021-06-10 17:20:21 +0200263
khenaidoo7d3c5582021-08-11 18:09:44 -0400264 fs.StringVar(&(so.AdapterEndpoint),
265 "adapter_endpoint",
266 "",
267 "Adapter Endpoint")
268
269 fs.DurationVar(&(so.RPCTimeout),
270 "rpc_timeout",
271 10*time.Second,
272 "The default timeout when making an RPC request")
273
274 fs.DurationVar(&(so.MinBackoffRetryDelay),
275 "min_retry_delay",
276 500*time.Millisecond,
277 "The minimum number of milliseconds to delay before a connection retry attempt")
278
279 fs.DurationVar(&(so.MaxBackoffRetryDelay),
280 "max_retry_delay",
281 10*time.Second,
282 "The maximum number of milliseconds to delay before a connection retry attempt")
Girish Gowdrae95687a2021-09-08 16:30:58 -0700283 fs.IntVar(&(so.MaxConcurrentFlowsPerUni),
284 "max_concurrent_flows_per_uni",
285 16,
286 "The max number of concurrent flows (add/remove) that can be queued per UNI")
nikesh.krishnanca4afa32023-06-28 03:42:16 +0530287 fs.DurationVar(&(so.PerRPCRetryTimeout),
288 "per_rpc_retry_timeout",
289 0*time.Second,
290 "The default timeout per RPC retry")
Praneeth Kumar Nalmas77ab2f32024-04-17 11:14:27 +0530291 fs.BoolVar(&(so.SkipOnuConfig),
292 "skip_onu_config_enabled",
293 false,
294 "Whether to enable/disable the Skipping of the ONU configuration via OMCI during reconciling")
nikesh.krishnanca4afa32023-06-28 03:42:16 +0530295 fs.UintVar(&(so.MaxRetries),
296 "max_grpc_client_retry",
297 0,
298 "The maximum number of times olt adaptor will retry in case grpc request timeouts")
khenaidoo7d3c5582021-08-11 18:09:44 -0400299 _ = fs.Parse(args)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000300 containerName := getContainerInfo()
301 if len(containerName) > 0 {
302 so.InstanceID = containerName
khenaidoo7d3c5582021-08-11 18:09:44 -0400303 } else {
304 so.InstanceID = "openonu"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000305 }
306
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000307}
308
309func getContainerInfo() string {
310 return os.Getenv("HOSTNAME")
311}