blob: b61a9097ac12c81c39a60b671a8b58d4f4d68d75 [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"
22 "fmt"
23 "os"
24 "time"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000025)
26
27// Open ONU default constants
28const (
Himani Chawla6d2ae152020-09-02 13:11:20 +053029 etcdStoreName = "etcd"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000030 defaultInstanceid = "openonu"
Matteo Scandolo127c59d2021-01-28 11:31:18 -080031 defaultKafkaadapteraddress = "127.0.0.1:9092"
32 defaultKafkaclusteraddress = "127.0.0.1:9092"
Himani Chawla6d2ae152020-09-02 13:11:20 +053033 defaultKvstoretype = etcdStoreName
mpagenkoaf801632020-07-03 10:00:42 +000034 defaultKvstoretimeout = 5 * time.Second
Matteo Scandolo127c59d2021-01-28 11:31:18 -080035 defaultKvstoreaddress = "127.0.0.1:2379"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000036 defaultLoglevel = "WARN"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000037 defaultBanner = false
38 defaultDisplayVersionOnly = false
mpagenkodff5dda2020-08-28 11:52:01 +000039 defaultAccIncrEvto = false
Holger Hildebrandtfa074992020-03-27 15:42:06 +000040 defaultTopic = "openonu"
Holger Hildebrandta768fe92020-10-01 13:06:21 +000041 defaultCoreTopic = "rwcore"
42 defaultEventTopic = "voltha.events"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000043 defaultOnunumber = 1
44 defaultProbeHost = ""
45 defaultProbePort = 8080
46 defaultLiveProbeInterval = 60 * time.Second
47 defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
48 //defaultHearbeatFailReportInterval is the time in seconds the adapter will keep checking the hardware for heartbeat.
49 defaultHearbeatCheckInterval = 30 * time.Second
50 // defaultHearbeatFailReportInterval is the time adapter will wait before updating the state to the core.
51 defaultHearbeatFailReportInterval = 180 * time.Second
52 //defaultKafkaReconnectRetries -1: reconnect endlessly.
Himani Chawlad96df182020-09-28 11:12:02 +053053 defaultKafkaReconnectRetries = -1
54 defaultCurrentReplica = 1
55 defaultTotalReplicas = 1
56 defaultMaxTimeoutInterAdapterComm = 30 * time.Second
Holger Hildebrandt38985dc2021-02-18 16:25:20 +000057 defaultMaxTimeoutReconciling = 10 * time.Second
Andrea Campanella3d7c9312021-01-19 09:20:49 +010058 defaultOnuVendorIds = "OPEN,ALCL,BRCM,TWSH,ALPH,ISKT,SFAA,BBSM,SCOM,ARPX,DACM,ERSN,HWTC,CIGG,ADTN,ARCA,AVMG"
dbainbri4d3a0dc2020-12-02 00:33:42 +000059
60 // For Tracing
61 defaultTraceEnabled = false
62 defaultTraceAgentAddress = "127.0.0.1:6831"
63 defaultLogCorrelationEnabled = true
Girish Gowdraaf0ad632021-01-27 13:00:01 -080064
Himani Chawla075f1642021-03-15 19:23:24 +053065 defaultMetricsEnabled = false
66 defaultMibAuditInterval = 0
67 defaultAlarmAuditInterval = 300 * time.Second
Girish Gowdra0b235842021-03-09 13:06:46 -080068
mpagenkoc26d4c02021-05-06 14:27:57 +000069 defaultOmciTimeout = 3 * time.Second
70 defaultDlToAdapterTimeout = 10 * time.Second
71 defaultDlToOnuTimeoutPer4MB = 60 * time.Minute //assumed for 4 MB of the image
Matteo Scandolo20d180c2021-06-10 17:20:21 +020072 //Mask to indicate which possibly active ONU UNI state is really reported to the core
73 // compare python code - at the moment restrict active state to the first ONU UNI port
74 // check is limited to max 16 uni ports - cmp above UNI limit!!!
75 defaultUniPortMask = 0x0001
Holger Hildebrandtfa074992020-03-27 15:42:06 +000076)
77
78// AdapterFlags represents the set of configurations used by the read-write adaptercore service
79type AdapterFlags struct {
80 // Command line parameters
81 InstanceID string
Matteo Scandolo127c59d2021-01-28 11:31:18 -080082 KafkaAdapterAddress string
83 KafkaClusterAddress string // NOTE this is unused across the adapter
Holger Hildebrandtfa074992020-03-27 15:42:06 +000084 KVStoreType string
mpagenkoaf801632020-07-03 10:00:42 +000085 KVStoreTimeout time.Duration
Matteo Scandolo127c59d2021-01-28 11:31:18 -080086 KVStoreAddress string
Holger Hildebrandtfa074992020-03-27 15:42:06 +000087 Topic string
88 CoreTopic string
89 EventTopic string
90 LogLevel string
91 OnuNumber int
92 Banner bool
93 DisplayVersionOnly bool
mpagenkodff5dda2020-08-28 11:52:01 +000094 AccIncrEvto bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +000095 ProbeHost string
96 ProbePort int
97 LiveProbeInterval time.Duration
98 NotLiveProbeInterval time.Duration
99 HeartbeatCheckInterval time.Duration
100 HeartbeatFailReportInterval time.Duration
101 KafkaReconnectRetries int
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000102 CurrentReplica int
103 TotalReplicas int
Himani Chawlad96df182020-09-28 11:12:02 +0530104 MaxTimeoutInterAdapterComm time.Duration
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000105 MaxTimeoutReconciling time.Duration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000106 TraceEnabled bool
107 TraceAgentAddress string
108 LogCorrelationEnabled bool
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100109 OnuVendorIds string
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800110 MetricsEnabled bool
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000111 MibAuditInterval time.Duration
Girish Gowdra0b235842021-03-09 13:06:46 -0800112 OmciTimeout time.Duration
Himani Chawla075f1642021-03-15 19:23:24 +0530113 AlarmAuditInterval time.Duration
mpagenkoc26d4c02021-05-06 14:27:57 +0000114 DownloadToAdapterTimeout time.Duration
115 DownloadToOnuTimeout4MB time.Duration
Matteo Scandolo20d180c2021-06-10 17:20:21 +0200116 UniPortMask int
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000117}
118
119// NewAdapterFlags returns a new RWCore config
120func NewAdapterFlags() *AdapterFlags {
121 var adapterFlags = AdapterFlags{ // Default values
122 InstanceID: defaultInstanceid,
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800123 KafkaAdapterAddress: defaultKafkaadapteraddress,
124 KafkaClusterAddress: defaultKafkaclusteraddress,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000125 KVStoreType: defaultKvstoretype,
126 KVStoreTimeout: defaultKvstoretimeout,
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800127 KVStoreAddress: defaultKvstoreaddress,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000128 Topic: defaultTopic,
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000129 CoreTopic: defaultCoreTopic,
130 EventTopic: defaultEventTopic,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000131 LogLevel: defaultLoglevel,
132 OnuNumber: defaultOnunumber,
133 Banner: defaultBanner,
134 DisplayVersionOnly: defaultDisplayVersionOnly,
mpagenkodff5dda2020-08-28 11:52:01 +0000135 AccIncrEvto: defaultAccIncrEvto,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000136 ProbeHost: defaultProbeHost,
137 ProbePort: defaultProbePort,
138 LiveProbeInterval: defaultLiveProbeInterval,
139 NotLiveProbeInterval: defaultNotLiveProbeInterval,
140 HeartbeatCheckInterval: defaultHearbeatCheckInterval,
141 HeartbeatFailReportInterval: defaultHearbeatFailReportInterval,
142 KafkaReconnectRetries: defaultKafkaReconnectRetries,
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000143 CurrentReplica: defaultCurrentReplica,
144 TotalReplicas: defaultTotalReplicas,
Himani Chawlad96df182020-09-28 11:12:02 +0530145 MaxTimeoutInterAdapterComm: defaultMaxTimeoutInterAdapterComm,
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000146 MaxTimeoutReconciling: defaultMaxTimeoutReconciling,
dbainbri4d3a0dc2020-12-02 00:33:42 +0000147 TraceEnabled: defaultTraceEnabled,
148 TraceAgentAddress: defaultTraceAgentAddress,
149 LogCorrelationEnabled: defaultLogCorrelationEnabled,
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100150 OnuVendorIds: defaultOnuVendorIds,
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800151 MetricsEnabled: defaultMetricsEnabled,
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000152 MibAuditInterval: defaultMibAuditInterval,
Himani Chawla075f1642021-03-15 19:23:24 +0530153 AlarmAuditInterval: defaultAlarmAuditInterval,
Girish Gowdra0b235842021-03-09 13:06:46 -0800154 OmciTimeout: defaultOmciTimeout,
mpagenkoc26d4c02021-05-06 14:27:57 +0000155 DownloadToAdapterTimeout: defaultDlToAdapterTimeout,
156 DownloadToOnuTimeout4MB: defaultDlToOnuTimeoutPer4MB,
Matteo Scandolo20d180c2021-06-10 17:20:21 +0200157 UniPortMask: defaultUniPortMask,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000158 }
159 return &adapterFlags
160}
161
162// ParseCommandArguments parses the arguments when running read-write adaptercore service
163func (so *AdapterFlags) ParseCommandArguments() {
164
mpagenkoc26d4c02021-05-06 14:27:57 +0000165 help := "Kafka - Adapter messaging address"
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800166 flag.StringVar(&(so.KafkaAdapterAddress), "kafka_adapter_address", defaultKafkaadapteraddress, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000167
mpagenkoc26d4c02021-05-06 14:27:57 +0000168 help = "Kafka - Cluster messaging address"
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800169 flag.StringVar(&(so.KafkaClusterAddress), "kafka_cluster_address", defaultKafkaclusteraddress, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000170
mpagenkoc26d4c02021-05-06 14:27:57 +0000171 help = "Open ONU topic"
Andrea Campanella961734c2021-01-18 11:44:47 +0100172 baseAdapterTopic := flag.String("adapter_topic", defaultTopic, help)
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000173
mpagenkoc26d4c02021-05-06 14:27:57 +0000174 help = "Core topic"
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000175 flag.StringVar(&(so.CoreTopic), "core_topic", defaultCoreTopic, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000176
mpagenkoc26d4c02021-05-06 14:27:57 +0000177 help = "Event topic"
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000178 flag.StringVar(&(so.EventTopic), "event_topic", defaultEventTopic, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000179
mpagenkoc26d4c02021-05-06 14:27:57 +0000180 help = "KV store type"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000181 flag.StringVar(&(so.KVStoreType), "kv_store_type", defaultKvstoretype, help)
182
mpagenkoc26d4c02021-05-06 14:27:57 +0000183 help = "The default timeout when making a kv store request"
mpagenkoaf801632020-07-03 10:00:42 +0000184 flag.DurationVar(&(so.KVStoreTimeout), "kv_store_request_timeout", defaultKvstoretimeout, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000185
mpagenkoc26d4c02021-05-06 14:27:57 +0000186 help = "KV store address"
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800187 flag.StringVar(&(so.KVStoreAddress), "kv_store_address", defaultKvstoreaddress, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000188
mpagenkoc26d4c02021-05-06 14:27:57 +0000189 help = "Log level"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000190 flag.StringVar(&(so.LogLevel), "log_level", defaultLoglevel, help)
191
mpagenkoc26d4c02021-05-06 14:27:57 +0000192 help = "Number of ONUs"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000193 flag.IntVar(&(so.OnuNumber), "onu_number", defaultOnunumber, help)
194
mpagenkoc26d4c02021-05-06 14:27:57 +0000195 help = "Show startup banner log lines"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000196 flag.BoolVar(&(so.Banner), "banner", defaultBanner, help)
197
mpagenkoc26d4c02021-05-06 14:27:57 +0000198 help = "Show version information and exit"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000199 flag.BoolVar(&(so.DisplayVersionOnly), "version", defaultDisplayVersionOnly, help)
200
mpagenkoc26d4c02021-05-06 14:27:57 +0000201 help = "Acceptance of incremental EVTOCD configuration"
mpagenkodff5dda2020-08-28 11:52:01 +0000202 flag.BoolVar(&(so.AccIncrEvto), "accept_incr_evto", defaultAccIncrEvto, help)
203
mpagenkoc26d4c02021-05-06 14:27:57 +0000204 help = "The address on which to listen to answer liveness and readiness probe queries over HTTP"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000205 flag.StringVar(&(so.ProbeHost), "probe_host", defaultProbeHost, help)
206
mpagenkoc26d4c02021-05-06 14:27:57 +0000207 help = "The port on which to listen to answer liveness and readiness probe queries over HTTP"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000208 flag.IntVar(&(so.ProbePort), "probe_port", defaultProbePort, help)
209
mpagenkoc26d4c02021-05-06 14:27:57 +0000210 help = "Number of seconds for the default liveliness check"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000211 flag.DurationVar(&(so.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, help)
212
mpagenkoc26d4c02021-05-06 14:27:57 +0000213 help = "Number of seconds for liveliness check if probe is not running"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000214 flag.DurationVar(&(so.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, help)
215
mpagenkoc26d4c02021-05-06 14:27:57 +0000216 help = "Number of seconds for heartbeat check interval"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000217 flag.DurationVar(&(so.HeartbeatCheckInterval), "hearbeat_check_interval", defaultHearbeatCheckInterval, help)
218
mpagenkoc26d4c02021-05-06 14:27:57 +0000219 help = "Number of seconds adapter has to wait before reporting core on the hearbeat check failure"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000220 flag.DurationVar(&(so.HeartbeatFailReportInterval), "hearbeat_fail_interval", defaultHearbeatFailReportInterval, help)
221
mpagenkoc26d4c02021-05-06 14:27:57 +0000222 help = "Number of retries to connect to Kafka"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000223 flag.IntVar(&(so.KafkaReconnectRetries), "kafka_reconnect_retries", defaultKafkaReconnectRetries, help)
224
mpagenkoc26d4c02021-05-06 14:27:57 +0000225 help = "Replica number of this particular instance"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000226 flag.IntVar(&(so.CurrentReplica), "current_replica", defaultCurrentReplica, help)
227
228 help = "Total number of instances for this adapter"
229 flag.IntVar(&(so.TotalReplicas), "total_replica", defaultTotalReplicas, help)
230
mpagenkoc26d4c02021-05-06 14:27:57 +0000231 help = "Maximum Number of seconds for the default interadapter communication timeout"
Himani Chawlad96df182020-09-28 11:12:02 +0530232 flag.DurationVar(&(so.MaxTimeoutInterAdapterComm), "max_timeout_interadapter_comm",
233 defaultMaxTimeoutInterAdapterComm, help)
234
mpagenkoc26d4c02021-05-06 14:27:57 +0000235 help = "Maximum Number of seconds for the default ONU reconciling timeout"
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000236 flag.DurationVar(&(so.MaxTimeoutReconciling), "max_timeout_reconciling",
237 defaultMaxTimeoutReconciling, help)
238
mpagenkoc26d4c02021-05-06 14:27:57 +0000239 help = "Whether to send logs to tracing agent"
dbainbri4d3a0dc2020-12-02 00:33:42 +0000240 flag.BoolVar(&(so.TraceEnabled), "trace_enabled", defaultTraceEnabled, help)
241
mpagenkoc26d4c02021-05-06 14:27:57 +0000242 help = "The address of tracing agent to which span info should be sent"
dbainbri4d3a0dc2020-12-02 00:33:42 +0000243 flag.StringVar(&(so.TraceAgentAddress), "trace_agent_address", defaultTraceAgentAddress, help)
244
mpagenkoc26d4c02021-05-06 14:27:57 +0000245 help = "Whether to enrich log statements with fields denoting operation being executed for achieving correlation"
dbainbri4d3a0dc2020-12-02 00:33:42 +0000246 flag.BoolVar(&(so.LogCorrelationEnabled), "log_correlation_enabled", defaultLogCorrelationEnabled, help)
247
mpagenkoc26d4c02021-05-06 14:27:57 +0000248 help = "List of Allowed ONU Vendor Ids"
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100249 flag.StringVar(&(so.OnuVendorIds), "allowed_onu_vendors", defaultOnuVendorIds, help)
250
mpagenkoc26d4c02021-05-06 14:27:57 +0000251 help = "Whether to enable metrics collection"
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800252 flag.BoolVar(&(so.MetricsEnabled), "metrics_enabled", defaultMetricsEnabled, help)
253
mpagenkoc26d4c02021-05-06 14:27:57 +0000254 help = "Mib Audit Interval in seconds - the value zero will disable Mib Audit"
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000255 flag.DurationVar(&(so.MibAuditInterval), "mib_audit_interval", defaultMibAuditInterval, help)
256
mpagenkoc26d4c02021-05-06 14:27:57 +0000257 help = "OMCI timeout duration - this timeout value is used on the OMCI channel for waiting on response from ONU"
Girish Gowdra0b235842021-03-09 13:06:46 -0800258 flag.DurationVar(&(so.OmciTimeout), "omci_timeout", defaultOmciTimeout, help)
259
mpagenkoc26d4c02021-05-06 14:27:57 +0000260 help = "Alarm Audit Interval in seconds - the value zero will disable alarm audit"
Himani Chawla075f1642021-03-15 19:23:24 +0530261 flag.DurationVar(&(so.AlarmAuditInterval), "alarm_audit_interval", defaultAlarmAuditInterval, help)
262
mpagenkoc26d4c02021-05-06 14:27:57 +0000263 help = "File download to adapter timeout in seconds"
264 flag.DurationVar(&(so.DownloadToAdapterTimeout), "download_to_adapter_timeout", defaultDlToAdapterTimeout, help)
265
266 help = "File download to ONU timeout in minutes for a block of 4MB"
267 flag.DurationVar(&(so.DownloadToOnuTimeout4MB), "download_to_onu_timeout_4MB", defaultDlToOnuTimeoutPer4MB, help)
268
Matteo Scandolo20d180c2021-06-10 17:20:21 +0200269 help = "The bitmask to identify UNI ports that need to be enabled"
270 flag.IntVar(&(so.UniPortMask), "uni_port_mask", defaultUniPortMask, help)
271
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000272 flag.Parse()
273 containerName := getContainerInfo()
274 if len(containerName) > 0 {
275 so.InstanceID = containerName
276 }
277
Andrea Campanella961734c2021-01-18 11:44:47 +0100278 so.Topic = fmt.Sprintf("%s_%d", *baseAdapterTopic, int32(so.CurrentReplica))
279
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000280}
281
282func getContainerInfo() string {
283 return os.Getenv("HOSTNAME")
284}