blob: c4ab24901224adea6c9001f8bee56f57c7a37c28 [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
Holger Hildebrandtfa074992020-03-27 15:42:06 +000072)
73
74// AdapterFlags represents the set of configurations used by the read-write adaptercore service
75type AdapterFlags struct {
76 // Command line parameters
77 InstanceID string
Matteo Scandolo127c59d2021-01-28 11:31:18 -080078 KafkaAdapterAddress string
79 KafkaClusterAddress string // NOTE this is unused across the adapter
Holger Hildebrandtfa074992020-03-27 15:42:06 +000080 KVStoreType string
mpagenkoaf801632020-07-03 10:00:42 +000081 KVStoreTimeout time.Duration
Matteo Scandolo127c59d2021-01-28 11:31:18 -080082 KVStoreAddress string
Holger Hildebrandtfa074992020-03-27 15:42:06 +000083 Topic string
84 CoreTopic string
85 EventTopic string
86 LogLevel string
87 OnuNumber int
88 Banner bool
89 DisplayVersionOnly bool
mpagenkodff5dda2020-08-28 11:52:01 +000090 AccIncrEvto bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +000091 ProbeHost string
92 ProbePort int
93 LiveProbeInterval time.Duration
94 NotLiveProbeInterval time.Duration
95 HeartbeatCheckInterval time.Duration
96 HeartbeatFailReportInterval time.Duration
97 KafkaReconnectRetries int
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000098 CurrentReplica int
99 TotalReplicas int
Himani Chawlad96df182020-09-28 11:12:02 +0530100 MaxTimeoutInterAdapterComm time.Duration
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000101 MaxTimeoutReconciling time.Duration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000102 TraceEnabled bool
103 TraceAgentAddress string
104 LogCorrelationEnabled bool
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100105 OnuVendorIds string
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800106 MetricsEnabled bool
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000107 MibAuditInterval time.Duration
Girish Gowdra0b235842021-03-09 13:06:46 -0800108 OmciTimeout time.Duration
Himani Chawla075f1642021-03-15 19:23:24 +0530109 AlarmAuditInterval time.Duration
mpagenkoc26d4c02021-05-06 14:27:57 +0000110 DownloadToAdapterTimeout time.Duration
111 DownloadToOnuTimeout4MB time.Duration
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000112}
113
114// NewAdapterFlags returns a new RWCore config
115func NewAdapterFlags() *AdapterFlags {
116 var adapterFlags = AdapterFlags{ // Default values
117 InstanceID: defaultInstanceid,
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800118 KafkaAdapterAddress: defaultKafkaadapteraddress,
119 KafkaClusterAddress: defaultKafkaclusteraddress,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000120 KVStoreType: defaultKvstoretype,
121 KVStoreTimeout: defaultKvstoretimeout,
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800122 KVStoreAddress: defaultKvstoreaddress,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000123 Topic: defaultTopic,
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000124 CoreTopic: defaultCoreTopic,
125 EventTopic: defaultEventTopic,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000126 LogLevel: defaultLoglevel,
127 OnuNumber: defaultOnunumber,
128 Banner: defaultBanner,
129 DisplayVersionOnly: defaultDisplayVersionOnly,
mpagenkodff5dda2020-08-28 11:52:01 +0000130 AccIncrEvto: defaultAccIncrEvto,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000131 ProbeHost: defaultProbeHost,
132 ProbePort: defaultProbePort,
133 LiveProbeInterval: defaultLiveProbeInterval,
134 NotLiveProbeInterval: defaultNotLiveProbeInterval,
135 HeartbeatCheckInterval: defaultHearbeatCheckInterval,
136 HeartbeatFailReportInterval: defaultHearbeatFailReportInterval,
137 KafkaReconnectRetries: defaultKafkaReconnectRetries,
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000138 CurrentReplica: defaultCurrentReplica,
139 TotalReplicas: defaultTotalReplicas,
Himani Chawlad96df182020-09-28 11:12:02 +0530140 MaxTimeoutInterAdapterComm: defaultMaxTimeoutInterAdapterComm,
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000141 MaxTimeoutReconciling: defaultMaxTimeoutReconciling,
dbainbri4d3a0dc2020-12-02 00:33:42 +0000142 TraceEnabled: defaultTraceEnabled,
143 TraceAgentAddress: defaultTraceAgentAddress,
144 LogCorrelationEnabled: defaultLogCorrelationEnabled,
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100145 OnuVendorIds: defaultOnuVendorIds,
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800146 MetricsEnabled: defaultMetricsEnabled,
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000147 MibAuditInterval: defaultMibAuditInterval,
Himani Chawla075f1642021-03-15 19:23:24 +0530148 AlarmAuditInterval: defaultAlarmAuditInterval,
Girish Gowdra0b235842021-03-09 13:06:46 -0800149 OmciTimeout: defaultOmciTimeout,
mpagenkoc26d4c02021-05-06 14:27:57 +0000150 DownloadToAdapterTimeout: defaultDlToAdapterTimeout,
151 DownloadToOnuTimeout4MB: defaultDlToOnuTimeoutPer4MB,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000152 }
153 return &adapterFlags
154}
155
156// ParseCommandArguments parses the arguments when running read-write adaptercore service
157func (so *AdapterFlags) ParseCommandArguments() {
158
mpagenkoc26d4c02021-05-06 14:27:57 +0000159 help := "Kafka - Adapter messaging address"
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800160 flag.StringVar(&(so.KafkaAdapterAddress), "kafka_adapter_address", defaultKafkaadapteraddress, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000161
mpagenkoc26d4c02021-05-06 14:27:57 +0000162 help = "Kafka - Cluster messaging address"
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800163 flag.StringVar(&(so.KafkaClusterAddress), "kafka_cluster_address", defaultKafkaclusteraddress, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000164
mpagenkoc26d4c02021-05-06 14:27:57 +0000165 help = "Open ONU topic"
Andrea Campanella961734c2021-01-18 11:44:47 +0100166 baseAdapterTopic := flag.String("adapter_topic", defaultTopic, help)
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000167
mpagenkoc26d4c02021-05-06 14:27:57 +0000168 help = "Core topic"
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000169 flag.StringVar(&(so.CoreTopic), "core_topic", defaultCoreTopic, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000170
mpagenkoc26d4c02021-05-06 14:27:57 +0000171 help = "Event topic"
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000172 flag.StringVar(&(so.EventTopic), "event_topic", defaultEventTopic, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000173
mpagenkoc26d4c02021-05-06 14:27:57 +0000174 help = "KV store type"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000175 flag.StringVar(&(so.KVStoreType), "kv_store_type", defaultKvstoretype, help)
176
mpagenkoc26d4c02021-05-06 14:27:57 +0000177 help = "The default timeout when making a kv store request"
mpagenkoaf801632020-07-03 10:00:42 +0000178 flag.DurationVar(&(so.KVStoreTimeout), "kv_store_request_timeout", defaultKvstoretimeout, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000179
mpagenkoc26d4c02021-05-06 14:27:57 +0000180 help = "KV store address"
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800181 flag.StringVar(&(so.KVStoreAddress), "kv_store_address", defaultKvstoreaddress, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000182
mpagenkoc26d4c02021-05-06 14:27:57 +0000183 help = "Log level"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000184 flag.StringVar(&(so.LogLevel), "log_level", defaultLoglevel, help)
185
mpagenkoc26d4c02021-05-06 14:27:57 +0000186 help = "Number of ONUs"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000187 flag.IntVar(&(so.OnuNumber), "onu_number", defaultOnunumber, help)
188
mpagenkoc26d4c02021-05-06 14:27:57 +0000189 help = "Show startup banner log lines"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000190 flag.BoolVar(&(so.Banner), "banner", defaultBanner, help)
191
mpagenkoc26d4c02021-05-06 14:27:57 +0000192 help = "Show version information and exit"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000193 flag.BoolVar(&(so.DisplayVersionOnly), "version", defaultDisplayVersionOnly, help)
194
mpagenkoc26d4c02021-05-06 14:27:57 +0000195 help = "Acceptance of incremental EVTOCD configuration"
mpagenkodff5dda2020-08-28 11:52:01 +0000196 flag.BoolVar(&(so.AccIncrEvto), "accept_incr_evto", defaultAccIncrEvto, help)
197
mpagenkoc26d4c02021-05-06 14:27:57 +0000198 help = "The address on which to listen to answer liveness and readiness probe queries over HTTP"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000199 flag.StringVar(&(so.ProbeHost), "probe_host", defaultProbeHost, help)
200
mpagenkoc26d4c02021-05-06 14:27:57 +0000201 help = "The port on which to listen to answer liveness and readiness probe queries over HTTP"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000202 flag.IntVar(&(so.ProbePort), "probe_port", defaultProbePort, help)
203
mpagenkoc26d4c02021-05-06 14:27:57 +0000204 help = "Number of seconds for the default liveliness check"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000205 flag.DurationVar(&(so.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, help)
206
mpagenkoc26d4c02021-05-06 14:27:57 +0000207 help = "Number of seconds for liveliness check if probe is not running"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000208 flag.DurationVar(&(so.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, help)
209
mpagenkoc26d4c02021-05-06 14:27:57 +0000210 help = "Number of seconds for heartbeat check interval"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000211 flag.DurationVar(&(so.HeartbeatCheckInterval), "hearbeat_check_interval", defaultHearbeatCheckInterval, help)
212
mpagenkoc26d4c02021-05-06 14:27:57 +0000213 help = "Number of seconds adapter has to wait before reporting core on the hearbeat check failure"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000214 flag.DurationVar(&(so.HeartbeatFailReportInterval), "hearbeat_fail_interval", defaultHearbeatFailReportInterval, help)
215
mpagenkoc26d4c02021-05-06 14:27:57 +0000216 help = "Number of retries to connect to Kafka"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000217 flag.IntVar(&(so.KafkaReconnectRetries), "kafka_reconnect_retries", defaultKafkaReconnectRetries, help)
218
mpagenkoc26d4c02021-05-06 14:27:57 +0000219 help = "Replica number of this particular instance"
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000220 flag.IntVar(&(so.CurrentReplica), "current_replica", defaultCurrentReplica, help)
221
222 help = "Total number of instances for this adapter"
223 flag.IntVar(&(so.TotalReplicas), "total_replica", defaultTotalReplicas, help)
224
mpagenkoc26d4c02021-05-06 14:27:57 +0000225 help = "Maximum Number of seconds for the default interadapter communication timeout"
Himani Chawlad96df182020-09-28 11:12:02 +0530226 flag.DurationVar(&(so.MaxTimeoutInterAdapterComm), "max_timeout_interadapter_comm",
227 defaultMaxTimeoutInterAdapterComm, help)
228
mpagenkoc26d4c02021-05-06 14:27:57 +0000229 help = "Maximum Number of seconds for the default ONU reconciling timeout"
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000230 flag.DurationVar(&(so.MaxTimeoutReconciling), "max_timeout_reconciling",
231 defaultMaxTimeoutReconciling, help)
232
mpagenkoc26d4c02021-05-06 14:27:57 +0000233 help = "Whether to send logs to tracing agent"
dbainbri4d3a0dc2020-12-02 00:33:42 +0000234 flag.BoolVar(&(so.TraceEnabled), "trace_enabled", defaultTraceEnabled, help)
235
mpagenkoc26d4c02021-05-06 14:27:57 +0000236 help = "The address of tracing agent to which span info should be sent"
dbainbri4d3a0dc2020-12-02 00:33:42 +0000237 flag.StringVar(&(so.TraceAgentAddress), "trace_agent_address", defaultTraceAgentAddress, help)
238
mpagenkoc26d4c02021-05-06 14:27:57 +0000239 help = "Whether to enrich log statements with fields denoting operation being executed for achieving correlation"
dbainbri4d3a0dc2020-12-02 00:33:42 +0000240 flag.BoolVar(&(so.LogCorrelationEnabled), "log_correlation_enabled", defaultLogCorrelationEnabled, help)
241
mpagenkoc26d4c02021-05-06 14:27:57 +0000242 help = "List of Allowed ONU Vendor Ids"
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100243 flag.StringVar(&(so.OnuVendorIds), "allowed_onu_vendors", defaultOnuVendorIds, help)
244
mpagenkoc26d4c02021-05-06 14:27:57 +0000245 help = "Whether to enable metrics collection"
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800246 flag.BoolVar(&(so.MetricsEnabled), "metrics_enabled", defaultMetricsEnabled, help)
247
mpagenkoc26d4c02021-05-06 14:27:57 +0000248 help = "Mib Audit Interval in seconds - the value zero will disable Mib Audit"
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000249 flag.DurationVar(&(so.MibAuditInterval), "mib_audit_interval", defaultMibAuditInterval, help)
250
mpagenkoc26d4c02021-05-06 14:27:57 +0000251 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 -0800252 flag.DurationVar(&(so.OmciTimeout), "omci_timeout", defaultOmciTimeout, help)
253
mpagenkoc26d4c02021-05-06 14:27:57 +0000254 help = "Alarm Audit Interval in seconds - the value zero will disable alarm audit"
Himani Chawla075f1642021-03-15 19:23:24 +0530255 flag.DurationVar(&(so.AlarmAuditInterval), "alarm_audit_interval", defaultAlarmAuditInterval, help)
256
mpagenkoc26d4c02021-05-06 14:27:57 +0000257 help = "File download to adapter timeout in seconds"
258 flag.DurationVar(&(so.DownloadToAdapterTimeout), "download_to_adapter_timeout", defaultDlToAdapterTimeout, help)
259
260 help = "File download to ONU timeout in minutes for a block of 4MB"
261 flag.DurationVar(&(so.DownloadToOnuTimeout4MB), "download_to_onu_timeout_4MB", defaultDlToOnuTimeoutPer4MB, help)
262
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000263 flag.Parse()
264 containerName := getContainerInfo()
265 if len(containerName) > 0 {
266 so.InstanceID = containerName
267 }
268
Andrea Campanella961734c2021-01-18 11:44:47 +0100269 so.Topic = fmt.Sprintf("%s_%d", *baseAdapterTopic, int32(so.CurrentReplica))
270
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000271}
272
273func getContainerInfo() string {
274 return os.Getenv("HOSTNAME")
275}