blob: 8413bc86e0b5eb9a9c6a1aca7b55c84f8a790e09 [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
Holger Hildebrandtfa074992020-03-27 15:42:06 +000078}
79
80// ParseCommandArguments parses the arguments when running read-write adaptercore service
khenaidoo7d3c5582021-08-11 18:09:44 -040081func (so *AdapterFlags) ParseCommandArguments(args []string) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000082
khenaidoo7d3c5582021-08-11 18:09:44 -040083 fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
Holger Hildebrandtfa074992020-03-27 15:42:06 +000084
khenaidoo7d3c5582021-08-11 18:09:44 -040085 fs.StringVar(&(so.KafkaClusterAddress),
86 "kafka_cluster_address",
87 "127.0.0.1:9092",
88 "Kafka - Cluster messaging address")
Holger Hildebrandtfa074992020-03-27 15:42:06 +000089
khenaidoo7d3c5582021-08-11 18:09:44 -040090 fs.StringVar(&(so.EventTopic),
91 "event_topic",
92 "voltha.events",
93 "Event topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +000094
khenaidoo7d3c5582021-08-11 18:09:44 -040095 fs.StringVar(&(so.KVStoreType),
96 "kv_store_type",
97 EtcdStoreName,
98 "KV store type")
Holger Hildebrandtfa074992020-03-27 15:42:06 +000099
khenaidoo7d3c5582021-08-11 18:09:44 -0400100 fs.DurationVar(&(so.KVStoreTimeout),
101 "kv_store_request_timeout",
102 5*time.Second,
103 "The default timeout when making a kv store request")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000104
khenaidoo7d3c5582021-08-11 18:09:44 -0400105 fs.StringVar(&(so.KVStoreAddress),
106 "kv_store_address",
107 "127.0.0.1:2379",
108 "KV store address")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000109
khenaidoo7d3c5582021-08-11 18:09:44 -0400110 fs.StringVar(&(so.LogLevel),
111 "log_level",
112 "WARN",
113 "Log level")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000114
khenaidoo7d3c5582021-08-11 18:09:44 -0400115 fs.IntVar(&(so.OnuNumber),
116 "onu_number",
117 1,
118 "Number of ONUs")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000119
khenaidoo7d3c5582021-08-11 18:09:44 -0400120 fs.BoolVar(&(so.Banner),
121 "banner",
122 false,
123 "Show startup banner log lines")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000124
khenaidoo7d3c5582021-08-11 18:09:44 -0400125 fs.BoolVar(&(so.DisplayVersionOnly),
126 "version",
127 false,
128 "Show version information and exit")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000129
khenaidoo7d3c5582021-08-11 18:09:44 -0400130 fs.BoolVar(&(so.AccIncrEvto),
131 "accept_incr_evto",
132 false,
133 "Acceptance of incremental EVTOCD configuration")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000134
khenaidoo7d3c5582021-08-11 18:09:44 -0400135 fs.StringVar(&(so.ProbeHost),
136 "probe_host",
137 "",
138 "The address on which to listen to answer liveness and readiness probe queries over HTTP")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000139
khenaidoo7d3c5582021-08-11 18:09:44 -0400140 fs.IntVar(&(so.ProbePort),
141 "probe_port",
142 8080,
143 "The port on which to listen to answer liveness and readiness probe queries over HTTP")
mpagenkodff5dda2020-08-28 11:52:01 +0000144
khenaidoo7d3c5582021-08-11 18:09:44 -0400145 fs.DurationVar(&(so.LiveProbeInterval),
146 "live_probe_interval",
147 60*time.Second,
148 "Number of seconds for the default liveliness check")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000149
khenaidoo7d3c5582021-08-11 18:09:44 -0400150 fs.DurationVar(&(so.NotLiveProbeInterval),
151 "not_live_probe_interval",
152 60*time.Second,
153 "Number of seconds for liveliness check if probe is not running")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000154
khenaidoo7d3c5582021-08-11 18:09:44 -0400155 fs.DurationVar(&(so.HeartbeatCheckInterval),
156 "hearbeat_check_interval",
157 30*time.Second,
158 "Number of seconds for heartbeat check interval")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000159
khenaidoo7d3c5582021-08-11 18:09:44 -0400160 fs.DurationVar(&(so.HeartbeatFailReportInterval),
161 "hearbeat_fail_interval",
162 30*time.Second,
163 "Number of seconds adapter has to wait before reporting core on the hearbeat check failure")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000164
khenaidoo7d3c5582021-08-11 18:09:44 -0400165 fs.IntVar(&(so.KafkaReconnectRetries),
166 "kafka_reconnect_retries",
167 -1,
168 "Number of retries to connect to Kafka")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000169
khenaidoo7d3c5582021-08-11 18:09:44 -0400170 fs.IntVar(&(so.CurrentReplica),
171 "current_replica",
172 1,
173 "Replica number of this particular instance")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000174
khenaidoo7d3c5582021-08-11 18:09:44 -0400175 fs.IntVar(&(so.TotalReplicas),
176 "total_replica",
177 1,
178 "Total number of instances for this adapter")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000179
khenaidoo7d3c5582021-08-11 18:09:44 -0400180 fs.DurationVar(&(so.MaxTimeoutInterAdapterComm),
181 "max_timeout_interadapter_comm",
182 30*time.Second,
183 "Maximum Number of seconds for the default interadapter communication timeout")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000184
khenaidoo7d3c5582021-08-11 18:09:44 -0400185 fs.DurationVar(&(so.MaxTimeoutReconciling),
186 "max_timeout_reconciling",
187 10*time.Second,
188 "Maximum Number of seconds for the default ONU reconciling timeout")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000189
khenaidoo7d3c5582021-08-11 18:09:44 -0400190 fs.BoolVar(&(so.TraceEnabled),
191 "trace_enabled",
192 false,
193 "Whether to send logs to tracing agent")
Himani Chawlad96df182020-09-28 11:12:02 +0530194
khenaidoo7d3c5582021-08-11 18:09:44 -0400195 fs.StringVar(&(so.TraceAgentAddress),
196 "trace_agent_address",
197 "127.0.0.1:6831",
198 "The address of tracing agent to which span info should be sent")
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000199
khenaidoo7d3c5582021-08-11 18:09:44 -0400200 fs.BoolVar(&(so.LogCorrelationEnabled),
201 "log_correlation_enabled",
202 true,
203 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000204
khenaidoo7d3c5582021-08-11 18:09:44 -0400205 fs.StringVar(&(so.OnuVendorIds),
206 "allowed_onu_vendors",
207 OnuVendorIds,
208 "List of Allowed ONU Vendor Ids")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000209
khenaidoo7d3c5582021-08-11 18:09:44 -0400210 fs.BoolVar(&(so.MetricsEnabled),
211 "metrics_enabled",
212 false,
213 "Whether to enable metrics collection")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000214
Holger Hildebrandtc572e622022-06-22 09:19:17 +0000215 fs.BoolVar(&(so.ExtendedOmciSupportEnabled),
216 "extended_omci_support_enabled",
217 false,
218 "Whether to enable extended OMCI support")
219
khenaidoo7d3c5582021-08-11 18:09:44 -0400220 fs.DurationVar(&(so.MibAuditInterval),
221 "mib_audit_interval",
222 300*time.Second,
223 "Mib Audit Interval in seconds - the value zero will disable Mib Audit")
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100224
khenaidoo7d3c5582021-08-11 18:09:44 -0400225 fs.DurationVar(&(so.OmciTimeout),
226 "omci_timeout",
227 3*time.Second,
228 "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 -0800229
khenaidoo7d3c5582021-08-11 18:09:44 -0400230 fs.DurationVar(&(so.AlarmAuditInterval),
231 "alarm_audit_interval",
232 300*time.Second,
233 "Alarm Audit Interval in seconds - the value zero will disable alarm audit")
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000234
khenaidoo7d3c5582021-08-11 18:09:44 -0400235 fs.DurationVar(&(so.DownloadToAdapterTimeout),
236 "download_to_adapter_timeout",
237 10*time.Second,
238 "File download to adapter timeout in seconds")
Girish Gowdra0b235842021-03-09 13:06:46 -0800239
khenaidoo7d3c5582021-08-11 18:09:44 -0400240 fs.DurationVar(&(so.DownloadToOnuTimeout4MB),
241 "download_to_onu_timeout_4MB",
242 60*time.Minute,
243 "File download to ONU timeout in minutes for a block of 4MB")
Himani Chawla075f1642021-03-15 19:23:24 +0530244
khenaidoo7d3c5582021-08-11 18:09:44 -0400245 //Mask to indicate which possibly active ONU UNI state is really reported to the core
246 // compare python code - at the moment restrict active state to the first ONU UNI port
247 // check is limited to max 16 uni ports - cmp above UNI limit!!!
248 fs.IntVar(&(so.UniPortMask),
249 "uni_port_mask",
250 0x0001,
251 "The bitmask to identify UNI ports that need to be enabled")
mpagenkoc26d4c02021-05-06 14:27:57 +0000252
khenaidoo7d3c5582021-08-11 18:09:44 -0400253 fs.StringVar(&(so.GrpcAddress),
254 "grpc_address",
255 ":50060",
256 "Adapter GRPC Server address")
mpagenkoc26d4c02021-05-06 14:27:57 +0000257
khenaidoo7d3c5582021-08-11 18:09:44 -0400258 fs.StringVar(&(so.CoreEndpoint),
259 "core_endpoint",
260 ":55555",
261 "Core endpoint")
Matteo Scandolo20d180c2021-06-10 17:20:21 +0200262
khenaidoo7d3c5582021-08-11 18:09:44 -0400263 fs.StringVar(&(so.AdapterEndpoint),
264 "adapter_endpoint",
265 "",
266 "Adapter Endpoint")
267
268 fs.DurationVar(&(so.RPCTimeout),
269 "rpc_timeout",
270 10*time.Second,
271 "The default timeout when making an RPC request")
272
273 fs.DurationVar(&(so.MinBackoffRetryDelay),
274 "min_retry_delay",
275 500*time.Millisecond,
276 "The minimum number of milliseconds to delay before a connection retry attempt")
277
278 fs.DurationVar(&(so.MaxBackoffRetryDelay),
279 "max_retry_delay",
280 10*time.Second,
281 "The maximum number of milliseconds to delay before a connection retry attempt")
Girish Gowdrae95687a2021-09-08 16:30:58 -0700282 fs.IntVar(&(so.MaxConcurrentFlowsPerUni),
283 "max_concurrent_flows_per_uni",
284 16,
285 "The max number of concurrent flows (add/remove) that can be queued per UNI")
nikesh.krishnanca4afa32023-06-28 03:42:16 +0530286 fs.DurationVar(&(so.PerRPCRetryTimeout),
287 "per_rpc_retry_timeout",
288 0*time.Second,
289 "The default timeout per RPC retry")
290 fs.UintVar(&(so.MaxRetries),
291 "max_grpc_client_retry",
292 0,
293 "The maximum number of times olt adaptor will retry in case grpc request timeouts")
khenaidoo7d3c5582021-08-11 18:09:44 -0400294 _ = fs.Parse(args)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000295 containerName := getContainerInfo()
296 if len(containerName) > 0 {
297 so.InstanceID = containerName
khenaidoo7d3c5582021-08-11 18:09:44 -0400298 } else {
299 so.InstanceID = "openonu"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000300 }
301
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000302}
303
304func getContainerInfo() string {
305 return os.Getenv("HOSTNAME")
306}