blob: 14342a4225d7d45de277ac9d64fc6f00c8799238 [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001/*
Joey Armstronge8c091f2023-01-17 16:56:26 -05002* Copyright 2018-2023 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
17//Package config provides the Log, kvstore, Kafka configuration
18package 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"
Girish Gowdra21bbf052022-02-17 16:08:22 -080029 OnuVendorIds = "OPEN,ALCL,BRCM,TWSH,ALPH,ISKT,SFAA,BBSM,SCOM,ARPX,DACM,ERSN,HWTC,CIGG,ADTN,ARCA,AVMG,LEOX"
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
Holger Hildebrandtfa074992020-03-27 15:42:06 +000076}
77
78// ParseCommandArguments parses the arguments when running read-write adaptercore service
khenaidoo7d3c5582021-08-11 18:09:44 -040079func (so *AdapterFlags) ParseCommandArguments(args []string) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000080
khenaidoo7d3c5582021-08-11 18:09:44 -040081 fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
Holger Hildebrandtfa074992020-03-27 15:42:06 +000082
khenaidoo7d3c5582021-08-11 18:09:44 -040083 fs.StringVar(&(so.KafkaClusterAddress),
84 "kafka_cluster_address",
85 "127.0.0.1:9092",
86 "Kafka - Cluster messaging address")
Holger Hildebrandtfa074992020-03-27 15:42:06 +000087
khenaidoo7d3c5582021-08-11 18:09:44 -040088 fs.StringVar(&(so.EventTopic),
89 "event_topic",
90 "voltha.events",
91 "Event topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +000092
khenaidoo7d3c5582021-08-11 18:09:44 -040093 fs.StringVar(&(so.KVStoreType),
94 "kv_store_type",
95 EtcdStoreName,
96 "KV store type")
Holger Hildebrandtfa074992020-03-27 15:42:06 +000097
khenaidoo7d3c5582021-08-11 18:09:44 -040098 fs.DurationVar(&(so.KVStoreTimeout),
99 "kv_store_request_timeout",
100 5*time.Second,
101 "The default timeout when making a kv store request")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000102
khenaidoo7d3c5582021-08-11 18:09:44 -0400103 fs.StringVar(&(so.KVStoreAddress),
104 "kv_store_address",
105 "127.0.0.1:2379",
106 "KV store address")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000107
khenaidoo7d3c5582021-08-11 18:09:44 -0400108 fs.StringVar(&(so.LogLevel),
109 "log_level",
110 "WARN",
111 "Log level")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000112
khenaidoo7d3c5582021-08-11 18:09:44 -0400113 fs.IntVar(&(so.OnuNumber),
114 "onu_number",
115 1,
116 "Number of ONUs")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000117
khenaidoo7d3c5582021-08-11 18:09:44 -0400118 fs.BoolVar(&(so.Banner),
119 "banner",
120 false,
121 "Show startup banner log lines")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000122
khenaidoo7d3c5582021-08-11 18:09:44 -0400123 fs.BoolVar(&(so.DisplayVersionOnly),
124 "version",
125 false,
126 "Show version information and exit")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000127
khenaidoo7d3c5582021-08-11 18:09:44 -0400128 fs.BoolVar(&(so.AccIncrEvto),
129 "accept_incr_evto",
130 false,
131 "Acceptance of incremental EVTOCD configuration")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000132
khenaidoo7d3c5582021-08-11 18:09:44 -0400133 fs.StringVar(&(so.ProbeHost),
134 "probe_host",
135 "",
136 "The address on which to listen to answer liveness and readiness probe queries over HTTP")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000137
khenaidoo7d3c5582021-08-11 18:09:44 -0400138 fs.IntVar(&(so.ProbePort),
139 "probe_port",
140 8080,
141 "The port on which to listen to answer liveness and readiness probe queries over HTTP")
mpagenkodff5dda2020-08-28 11:52:01 +0000142
khenaidoo7d3c5582021-08-11 18:09:44 -0400143 fs.DurationVar(&(so.LiveProbeInterval),
144 "live_probe_interval",
145 60*time.Second,
146 "Number of seconds for the default liveliness check")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000147
khenaidoo7d3c5582021-08-11 18:09:44 -0400148 fs.DurationVar(&(so.NotLiveProbeInterval),
149 "not_live_probe_interval",
150 60*time.Second,
151 "Number of seconds for liveliness check if probe is not running")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000152
khenaidoo7d3c5582021-08-11 18:09:44 -0400153 fs.DurationVar(&(so.HeartbeatCheckInterval),
154 "hearbeat_check_interval",
155 30*time.Second,
156 "Number of seconds for heartbeat check interval")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000157
khenaidoo7d3c5582021-08-11 18:09:44 -0400158 fs.DurationVar(&(so.HeartbeatFailReportInterval),
159 "hearbeat_fail_interval",
160 30*time.Second,
161 "Number of seconds adapter has to wait before reporting core on the hearbeat check failure")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000162
khenaidoo7d3c5582021-08-11 18:09:44 -0400163 fs.IntVar(&(so.KafkaReconnectRetries),
164 "kafka_reconnect_retries",
165 -1,
166 "Number of retries to connect to Kafka")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000167
khenaidoo7d3c5582021-08-11 18:09:44 -0400168 fs.IntVar(&(so.CurrentReplica),
169 "current_replica",
170 1,
171 "Replica number of this particular instance")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000172
khenaidoo7d3c5582021-08-11 18:09:44 -0400173 fs.IntVar(&(so.TotalReplicas),
174 "total_replica",
175 1,
176 "Total number of instances for this adapter")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000177
khenaidoo7d3c5582021-08-11 18:09:44 -0400178 fs.DurationVar(&(so.MaxTimeoutInterAdapterComm),
179 "max_timeout_interadapter_comm",
180 30*time.Second,
181 "Maximum Number of seconds for the default interadapter communication timeout")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000182
khenaidoo7d3c5582021-08-11 18:09:44 -0400183 fs.DurationVar(&(so.MaxTimeoutReconciling),
184 "max_timeout_reconciling",
185 10*time.Second,
186 "Maximum Number of seconds for the default ONU reconciling timeout")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000187
khenaidoo7d3c5582021-08-11 18:09:44 -0400188 fs.BoolVar(&(so.TraceEnabled),
189 "trace_enabled",
190 false,
191 "Whether to send logs to tracing agent")
Himani Chawlad96df182020-09-28 11:12:02 +0530192
khenaidoo7d3c5582021-08-11 18:09:44 -0400193 fs.StringVar(&(so.TraceAgentAddress),
194 "trace_agent_address",
195 "127.0.0.1:6831",
196 "The address of tracing agent to which span info should be sent")
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000197
khenaidoo7d3c5582021-08-11 18:09:44 -0400198 fs.BoolVar(&(so.LogCorrelationEnabled),
199 "log_correlation_enabled",
200 true,
201 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000202
khenaidoo7d3c5582021-08-11 18:09:44 -0400203 fs.StringVar(&(so.OnuVendorIds),
204 "allowed_onu_vendors",
205 OnuVendorIds,
206 "List of Allowed ONU Vendor Ids")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000207
khenaidoo7d3c5582021-08-11 18:09:44 -0400208 fs.BoolVar(&(so.MetricsEnabled),
209 "metrics_enabled",
210 false,
211 "Whether to enable metrics collection")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000212
Holger Hildebrandtc572e622022-06-22 09:19:17 +0000213 fs.BoolVar(&(so.ExtendedOmciSupportEnabled),
214 "extended_omci_support_enabled",
215 false,
216 "Whether to enable extended OMCI support")
217
khenaidoo7d3c5582021-08-11 18:09:44 -0400218 fs.DurationVar(&(so.MibAuditInterval),
219 "mib_audit_interval",
220 300*time.Second,
221 "Mib Audit Interval in seconds - the value zero will disable Mib Audit")
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100222
khenaidoo7d3c5582021-08-11 18:09:44 -0400223 fs.DurationVar(&(so.OmciTimeout),
224 "omci_timeout",
225 3*time.Second,
226 "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 -0800227
khenaidoo7d3c5582021-08-11 18:09:44 -0400228 fs.DurationVar(&(so.AlarmAuditInterval),
229 "alarm_audit_interval",
230 300*time.Second,
231 "Alarm Audit Interval in seconds - the value zero will disable alarm audit")
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000232
khenaidoo7d3c5582021-08-11 18:09:44 -0400233 fs.DurationVar(&(so.DownloadToAdapterTimeout),
234 "download_to_adapter_timeout",
235 10*time.Second,
236 "File download to adapter timeout in seconds")
Girish Gowdra0b235842021-03-09 13:06:46 -0800237
khenaidoo7d3c5582021-08-11 18:09:44 -0400238 fs.DurationVar(&(so.DownloadToOnuTimeout4MB),
239 "download_to_onu_timeout_4MB",
240 60*time.Minute,
241 "File download to ONU timeout in minutes for a block of 4MB")
Himani Chawla075f1642021-03-15 19:23:24 +0530242
khenaidoo7d3c5582021-08-11 18:09:44 -0400243 //Mask to indicate which possibly active ONU UNI state is really reported to the core
244 // compare python code - at the moment restrict active state to the first ONU UNI port
245 // check is limited to max 16 uni ports - cmp above UNI limit!!!
246 fs.IntVar(&(so.UniPortMask),
247 "uni_port_mask",
248 0x0001,
249 "The bitmask to identify UNI ports that need to be enabled")
mpagenkoc26d4c02021-05-06 14:27:57 +0000250
khenaidoo7d3c5582021-08-11 18:09:44 -0400251 fs.StringVar(&(so.GrpcAddress),
252 "grpc_address",
253 ":50060",
254 "Adapter GRPC Server address")
mpagenkoc26d4c02021-05-06 14:27:57 +0000255
khenaidoo7d3c5582021-08-11 18:09:44 -0400256 fs.StringVar(&(so.CoreEndpoint),
257 "core_endpoint",
258 ":55555",
259 "Core endpoint")
Matteo Scandolo20d180c2021-06-10 17:20:21 +0200260
khenaidoo7d3c5582021-08-11 18:09:44 -0400261 fs.StringVar(&(so.AdapterEndpoint),
262 "adapter_endpoint",
263 "",
264 "Adapter Endpoint")
265
266 fs.DurationVar(&(so.RPCTimeout),
267 "rpc_timeout",
268 10*time.Second,
269 "The default timeout when making an RPC request")
270
271 fs.DurationVar(&(so.MinBackoffRetryDelay),
272 "min_retry_delay",
273 500*time.Millisecond,
274 "The minimum number of milliseconds to delay before a connection retry attempt")
275
276 fs.DurationVar(&(so.MaxBackoffRetryDelay),
277 "max_retry_delay",
278 10*time.Second,
279 "The maximum number of milliseconds to delay before a connection retry attempt")
Girish Gowdrae95687a2021-09-08 16:30:58 -0700280 fs.IntVar(&(so.MaxConcurrentFlowsPerUni),
281 "max_concurrent_flows_per_uni",
282 16,
283 "The max number of concurrent flows (add/remove) that can be queued per UNI")
khenaidoo7d3c5582021-08-11 18:09:44 -0400284
285 _ = fs.Parse(args)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000286 containerName := getContainerInfo()
287 if len(containerName) > 0 {
288 so.InstanceID = containerName
khenaidoo7d3c5582021-08-11 18:09:44 -0400289 } else {
290 so.InstanceID = "openonu"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000291 }
292
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000293}
294
295func getContainerInfo() string {
296 return os.Getenv("HOSTNAME")
297}