blob: 98c7eac9eba3e24b05b18468c9449b29c1c2302a [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001/*
2* Copyright 2018-present Open Networking Foundation
3
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"
29 OnuVendorIds = "OPEN,ALCL,BRCM,TWSH,ALPH,ISKT,SFAA,BBSM,SCOM,ARPX,DACM,ERSN,HWTC,CIGG,ADTN,ARCA,AVMG"
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 Hildebrandte3677f12021-02-05 14:50:56 +000062 MibAuditInterval time.Duration
Girish Gowdra0b235842021-03-09 13:06:46 -080063 OmciTimeout time.Duration
Himani Chawla075f1642021-03-15 19:23:24 +053064 AlarmAuditInterval time.Duration
mpagenkoc26d4c02021-05-06 14:27:57 +000065 DownloadToAdapterTimeout time.Duration
66 DownloadToOnuTimeout4MB time.Duration
Matteo Scandolo20d180c2021-06-10 17:20:21 +020067 UniPortMask int
khenaidoo7d3c5582021-08-11 18:09:44 -040068 MinBackoffRetryDelay time.Duration
69 MaxBackoffRetryDelay time.Duration
70 AdapterEndpoint string
71 GrpcAddress string
72 CoreEndpoint string
73 RPCTimeout time.Duration
Girish Gowdrae95687a2021-09-08 16:30:58 -070074 MaxConcurrentFlowsPerUni int
Holger Hildebrandtfa074992020-03-27 15:42:06 +000075}
76
77// ParseCommandArguments parses the arguments when running read-write adaptercore service
khenaidoo7d3c5582021-08-11 18:09:44 -040078func (so *AdapterFlags) ParseCommandArguments(args []string) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000079
khenaidoo7d3c5582021-08-11 18:09:44 -040080 fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
Holger Hildebrandtfa074992020-03-27 15:42:06 +000081
khenaidoo7d3c5582021-08-11 18:09:44 -040082 fs.StringVar(&(so.KafkaClusterAddress),
83 "kafka_cluster_address",
84 "127.0.0.1:9092",
85 "Kafka - Cluster messaging address")
Holger Hildebrandtfa074992020-03-27 15:42:06 +000086
khenaidoo7d3c5582021-08-11 18:09:44 -040087 fs.StringVar(&(so.EventTopic),
88 "event_topic",
89 "voltha.events",
90 "Event topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +000091
khenaidoo7d3c5582021-08-11 18:09:44 -040092 fs.StringVar(&(so.KVStoreType),
93 "kv_store_type",
94 EtcdStoreName,
95 "KV store type")
Holger Hildebrandtfa074992020-03-27 15:42:06 +000096
khenaidoo7d3c5582021-08-11 18:09:44 -040097 fs.DurationVar(&(so.KVStoreTimeout),
98 "kv_store_request_timeout",
99 5*time.Second,
100 "The default timeout when making a kv store request")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000101
khenaidoo7d3c5582021-08-11 18:09:44 -0400102 fs.StringVar(&(so.KVStoreAddress),
103 "kv_store_address",
104 "127.0.0.1:2379",
105 "KV store address")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000106
khenaidoo7d3c5582021-08-11 18:09:44 -0400107 fs.StringVar(&(so.LogLevel),
108 "log_level",
109 "WARN",
110 "Log level")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000111
khenaidoo7d3c5582021-08-11 18:09:44 -0400112 fs.IntVar(&(so.OnuNumber),
113 "onu_number",
114 1,
115 "Number of ONUs")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000116
khenaidoo7d3c5582021-08-11 18:09:44 -0400117 fs.BoolVar(&(so.Banner),
118 "banner",
119 false,
120 "Show startup banner log lines")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000121
khenaidoo7d3c5582021-08-11 18:09:44 -0400122 fs.BoolVar(&(so.DisplayVersionOnly),
123 "version",
124 false,
125 "Show version information and exit")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000126
khenaidoo7d3c5582021-08-11 18:09:44 -0400127 fs.BoolVar(&(so.AccIncrEvto),
128 "accept_incr_evto",
129 false,
130 "Acceptance of incremental EVTOCD configuration")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000131
khenaidoo7d3c5582021-08-11 18:09:44 -0400132 fs.StringVar(&(so.ProbeHost),
133 "probe_host",
134 "",
135 "The address on which to listen to answer liveness and readiness probe queries over HTTP")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000136
khenaidoo7d3c5582021-08-11 18:09:44 -0400137 fs.IntVar(&(so.ProbePort),
138 "probe_port",
139 8080,
140 "The port on which to listen to answer liveness and readiness probe queries over HTTP")
mpagenkodff5dda2020-08-28 11:52:01 +0000141
khenaidoo7d3c5582021-08-11 18:09:44 -0400142 fs.DurationVar(&(so.LiveProbeInterval),
143 "live_probe_interval",
144 60*time.Second,
145 "Number of seconds for the default liveliness check")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000146
khenaidoo7d3c5582021-08-11 18:09:44 -0400147 fs.DurationVar(&(so.NotLiveProbeInterval),
148 "not_live_probe_interval",
149 60*time.Second,
150 "Number of seconds for liveliness check if probe is not running")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000151
khenaidoo7d3c5582021-08-11 18:09:44 -0400152 fs.DurationVar(&(so.HeartbeatCheckInterval),
153 "hearbeat_check_interval",
154 30*time.Second,
155 "Number of seconds for heartbeat check interval")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000156
khenaidoo7d3c5582021-08-11 18:09:44 -0400157 fs.DurationVar(&(so.HeartbeatFailReportInterval),
158 "hearbeat_fail_interval",
159 30*time.Second,
160 "Number of seconds adapter has to wait before reporting core on the hearbeat check failure")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000161
khenaidoo7d3c5582021-08-11 18:09:44 -0400162 fs.IntVar(&(so.KafkaReconnectRetries),
163 "kafka_reconnect_retries",
164 -1,
165 "Number of retries to connect to Kafka")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000166
khenaidoo7d3c5582021-08-11 18:09:44 -0400167 fs.IntVar(&(so.CurrentReplica),
168 "current_replica",
169 1,
170 "Replica number of this particular instance")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000171
khenaidoo7d3c5582021-08-11 18:09:44 -0400172 fs.IntVar(&(so.TotalReplicas),
173 "total_replica",
174 1,
175 "Total number of instances for this adapter")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000176
khenaidoo7d3c5582021-08-11 18:09:44 -0400177 fs.DurationVar(&(so.MaxTimeoutInterAdapterComm),
178 "max_timeout_interadapter_comm",
179 30*time.Second,
180 "Maximum Number of seconds for the default interadapter communication timeout")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000181
khenaidoo7d3c5582021-08-11 18:09:44 -0400182 fs.DurationVar(&(so.MaxTimeoutReconciling),
183 "max_timeout_reconciling",
184 10*time.Second,
185 "Maximum Number of seconds for the default ONU reconciling timeout")
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000186
khenaidoo7d3c5582021-08-11 18:09:44 -0400187 fs.BoolVar(&(so.TraceEnabled),
188 "trace_enabled",
189 false,
190 "Whether to send logs to tracing agent")
Himani Chawlad96df182020-09-28 11:12:02 +0530191
khenaidoo7d3c5582021-08-11 18:09:44 -0400192 fs.StringVar(&(so.TraceAgentAddress),
193 "trace_agent_address",
194 "127.0.0.1:6831",
195 "The address of tracing agent to which span info should be sent")
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000196
khenaidoo7d3c5582021-08-11 18:09:44 -0400197 fs.BoolVar(&(so.LogCorrelationEnabled),
198 "log_correlation_enabled",
199 true,
200 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000201
khenaidoo7d3c5582021-08-11 18:09:44 -0400202 fs.StringVar(&(so.OnuVendorIds),
203 "allowed_onu_vendors",
204 OnuVendorIds,
205 "List of Allowed ONU Vendor Ids")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000206
khenaidoo7d3c5582021-08-11 18:09:44 -0400207 fs.BoolVar(&(so.MetricsEnabled),
208 "metrics_enabled",
209 false,
210 "Whether to enable metrics collection")
dbainbri4d3a0dc2020-12-02 00:33:42 +0000211
khenaidoo7d3c5582021-08-11 18:09:44 -0400212 fs.DurationVar(&(so.MibAuditInterval),
213 "mib_audit_interval",
214 300*time.Second,
215 "Mib Audit Interval in seconds - the value zero will disable Mib Audit")
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100216
khenaidoo7d3c5582021-08-11 18:09:44 -0400217 fs.DurationVar(&(so.OmciTimeout),
218 "omci_timeout",
219 3*time.Second,
220 "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 -0800221
khenaidoo7d3c5582021-08-11 18:09:44 -0400222 fs.DurationVar(&(so.AlarmAuditInterval),
223 "alarm_audit_interval",
224 300*time.Second,
225 "Alarm Audit Interval in seconds - the value zero will disable alarm audit")
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000226
khenaidoo7d3c5582021-08-11 18:09:44 -0400227 fs.DurationVar(&(so.DownloadToAdapterTimeout),
228 "download_to_adapter_timeout",
229 10*time.Second,
230 "File download to adapter timeout in seconds")
Girish Gowdra0b235842021-03-09 13:06:46 -0800231
khenaidoo7d3c5582021-08-11 18:09:44 -0400232 fs.DurationVar(&(so.DownloadToOnuTimeout4MB),
233 "download_to_onu_timeout_4MB",
234 60*time.Minute,
235 "File download to ONU timeout in minutes for a block of 4MB")
Himani Chawla075f1642021-03-15 19:23:24 +0530236
khenaidoo7d3c5582021-08-11 18:09:44 -0400237 //Mask to indicate which possibly active ONU UNI state is really reported to the core
238 // compare python code - at the moment restrict active state to the first ONU UNI port
239 // check is limited to max 16 uni ports - cmp above UNI limit!!!
240 fs.IntVar(&(so.UniPortMask),
241 "uni_port_mask",
242 0x0001,
243 "The bitmask to identify UNI ports that need to be enabled")
mpagenkoc26d4c02021-05-06 14:27:57 +0000244
khenaidoo7d3c5582021-08-11 18:09:44 -0400245 fs.StringVar(&(so.GrpcAddress),
246 "grpc_address",
247 ":50060",
248 "Adapter GRPC Server address")
mpagenkoc26d4c02021-05-06 14:27:57 +0000249
khenaidoo7d3c5582021-08-11 18:09:44 -0400250 fs.StringVar(&(so.CoreEndpoint),
251 "core_endpoint",
252 ":55555",
253 "Core endpoint")
Matteo Scandolo20d180c2021-06-10 17:20:21 +0200254
khenaidoo7d3c5582021-08-11 18:09:44 -0400255 fs.StringVar(&(so.AdapterEndpoint),
256 "adapter_endpoint",
257 "",
258 "Adapter Endpoint")
259
260 fs.DurationVar(&(so.RPCTimeout),
261 "rpc_timeout",
262 10*time.Second,
263 "The default timeout when making an RPC request")
264
265 fs.DurationVar(&(so.MinBackoffRetryDelay),
266 "min_retry_delay",
267 500*time.Millisecond,
268 "The minimum number of milliseconds to delay before a connection retry attempt")
269
270 fs.DurationVar(&(so.MaxBackoffRetryDelay),
271 "max_retry_delay",
272 10*time.Second,
273 "The maximum number of milliseconds to delay before a connection retry attempt")
Girish Gowdrae95687a2021-09-08 16:30:58 -0700274 fs.IntVar(&(so.MaxConcurrentFlowsPerUni),
275 "max_concurrent_flows_per_uni",
276 16,
277 "The max number of concurrent flows (add/remove) that can be queued per UNI")
khenaidoo7d3c5582021-08-11 18:09:44 -0400278
279 _ = fs.Parse(args)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000280 containerName := getContainerInfo()
281 if len(containerName) > 0 {
282 so.InstanceID = containerName
khenaidoo7d3c5582021-08-11 18:09:44 -0400283 } else {
284 so.InstanceID = "openonu"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000285 }
286
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000287}
288
289func getContainerInfo() string {
290 return os.Getenv("HOSTNAME")
291}