blob: fad08fa8de31ef42d6966e693ea4c9a7214dcea6 [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
69 defaultOmciTimeout = 3 * time.Second
Holger Hildebrandtfa074992020-03-27 15:42:06 +000070)
71
72// AdapterFlags represents the set of configurations used by the read-write adaptercore service
73type AdapterFlags struct {
74 // Command line parameters
75 InstanceID string
Matteo Scandolo127c59d2021-01-28 11:31:18 -080076 KafkaAdapterAddress string
77 KafkaClusterAddress string // NOTE this is unused across the adapter
Holger Hildebrandtfa074992020-03-27 15:42:06 +000078 KVStoreType string
mpagenkoaf801632020-07-03 10:00:42 +000079 KVStoreTimeout time.Duration
Matteo Scandolo127c59d2021-01-28 11:31:18 -080080 KVStoreAddress string
Holger Hildebrandtfa074992020-03-27 15:42:06 +000081 Topic string
82 CoreTopic string
83 EventTopic string
84 LogLevel string
85 OnuNumber int
86 Banner bool
87 DisplayVersionOnly bool
mpagenkodff5dda2020-08-28 11:52:01 +000088 AccIncrEvto bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +000089 ProbeHost string
90 ProbePort int
91 LiveProbeInterval time.Duration
92 NotLiveProbeInterval time.Duration
93 HeartbeatCheckInterval time.Duration
94 HeartbeatFailReportInterval time.Duration
95 KafkaReconnectRetries int
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000096 CurrentReplica int
97 TotalReplicas int
Himani Chawlad96df182020-09-28 11:12:02 +053098 MaxTimeoutInterAdapterComm time.Duration
Holger Hildebrandt38985dc2021-02-18 16:25:20 +000099 MaxTimeoutReconciling time.Duration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000100 TraceEnabled bool
101 TraceAgentAddress string
102 LogCorrelationEnabled bool
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100103 OnuVendorIds string
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800104 MetricsEnabled bool
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000105 MibAuditInterval time.Duration
Girish Gowdra0b235842021-03-09 13:06:46 -0800106 OmciTimeout time.Duration
Himani Chawla075f1642021-03-15 19:23:24 +0530107 AlarmAuditInterval time.Duration
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000108}
109
110// NewAdapterFlags returns a new RWCore config
111func NewAdapterFlags() *AdapterFlags {
112 var adapterFlags = AdapterFlags{ // Default values
113 InstanceID: defaultInstanceid,
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800114 KafkaAdapterAddress: defaultKafkaadapteraddress,
115 KafkaClusterAddress: defaultKafkaclusteraddress,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000116 KVStoreType: defaultKvstoretype,
117 KVStoreTimeout: defaultKvstoretimeout,
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800118 KVStoreAddress: defaultKvstoreaddress,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000119 Topic: defaultTopic,
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000120 CoreTopic: defaultCoreTopic,
121 EventTopic: defaultEventTopic,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000122 LogLevel: defaultLoglevel,
123 OnuNumber: defaultOnunumber,
124 Banner: defaultBanner,
125 DisplayVersionOnly: defaultDisplayVersionOnly,
mpagenkodff5dda2020-08-28 11:52:01 +0000126 AccIncrEvto: defaultAccIncrEvto,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000127 ProbeHost: defaultProbeHost,
128 ProbePort: defaultProbePort,
129 LiveProbeInterval: defaultLiveProbeInterval,
130 NotLiveProbeInterval: defaultNotLiveProbeInterval,
131 HeartbeatCheckInterval: defaultHearbeatCheckInterval,
132 HeartbeatFailReportInterval: defaultHearbeatFailReportInterval,
133 KafkaReconnectRetries: defaultKafkaReconnectRetries,
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000134 CurrentReplica: defaultCurrentReplica,
135 TotalReplicas: defaultTotalReplicas,
Himani Chawlad96df182020-09-28 11:12:02 +0530136 MaxTimeoutInterAdapterComm: defaultMaxTimeoutInterAdapterComm,
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000137 MaxTimeoutReconciling: defaultMaxTimeoutReconciling,
dbainbri4d3a0dc2020-12-02 00:33:42 +0000138 TraceEnabled: defaultTraceEnabled,
139 TraceAgentAddress: defaultTraceAgentAddress,
140 LogCorrelationEnabled: defaultLogCorrelationEnabled,
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100141 OnuVendorIds: defaultOnuVendorIds,
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800142 MetricsEnabled: defaultMetricsEnabled,
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000143 MibAuditInterval: defaultMibAuditInterval,
Himani Chawla075f1642021-03-15 19:23:24 +0530144 AlarmAuditInterval: defaultAlarmAuditInterval,
Girish Gowdra0b235842021-03-09 13:06:46 -0800145 OmciTimeout: defaultOmciTimeout,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000146 }
147 return &adapterFlags
148}
149
150// ParseCommandArguments parses the arguments when running read-write adaptercore service
151func (so *AdapterFlags) ParseCommandArguments() {
152
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800153 help := fmt.Sprintf("Kafka - Adapter messaging address")
154 flag.StringVar(&(so.KafkaAdapterAddress), "kafka_adapter_address", defaultKafkaadapteraddress, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000155
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800156 help = fmt.Sprintf("Kafka - Cluster messaging address")
157 flag.StringVar(&(so.KafkaClusterAddress), "kafka_cluster_address", defaultKafkaclusteraddress, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000158
159 help = fmt.Sprintf("Open ONU topic")
Andrea Campanella961734c2021-01-18 11:44:47 +0100160 baseAdapterTopic := flag.String("adapter_topic", defaultTopic, help)
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000161
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000162 help = fmt.Sprintf("Core topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000163 flag.StringVar(&(so.CoreTopic), "core_topic", defaultCoreTopic, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000164
165 help = fmt.Sprintf("Event topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000166 flag.StringVar(&(so.EventTopic), "event_topic", defaultEventTopic, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000167
168 help = fmt.Sprintf("KV store type")
169 flag.StringVar(&(so.KVStoreType), "kv_store_type", defaultKvstoretype, help)
170
171 help = fmt.Sprintf("The default timeout when making a kv store request")
mpagenkoaf801632020-07-03 10:00:42 +0000172 flag.DurationVar(&(so.KVStoreTimeout), "kv_store_request_timeout", defaultKvstoretimeout, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000173
Matteo Scandolo127c59d2021-01-28 11:31:18 -0800174 help = fmt.Sprintf("KV store address")
175 flag.StringVar(&(so.KVStoreAddress), "kv_store_address", defaultKvstoreaddress, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000176
177 help = fmt.Sprintf("Log level")
178 flag.StringVar(&(so.LogLevel), "log_level", defaultLoglevel, help)
179
180 help = fmt.Sprintf("Number of ONUs")
181 flag.IntVar(&(so.OnuNumber), "onu_number", defaultOnunumber, help)
182
183 help = fmt.Sprintf("Show startup banner log lines")
184 flag.BoolVar(&(so.Banner), "banner", defaultBanner, help)
185
186 help = fmt.Sprintf("Show version information and exit")
187 flag.BoolVar(&(so.DisplayVersionOnly), "version", defaultDisplayVersionOnly, help)
188
mpagenkodff5dda2020-08-28 11:52:01 +0000189 help = fmt.Sprintf("Acceptance of incremental EVTOCD configuration")
190 flag.BoolVar(&(so.AccIncrEvto), "accept_incr_evto", defaultAccIncrEvto, help)
191
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000192 help = fmt.Sprintf("The address on which to listen to answer liveness and readiness probe queries over HTTP.")
193 flag.StringVar(&(so.ProbeHost), "probe_host", defaultProbeHost, help)
194
195 help = fmt.Sprintf("The port on which to listen to answer liveness and readiness probe queries over HTTP.")
196 flag.IntVar(&(so.ProbePort), "probe_port", defaultProbePort, help)
197
198 help = fmt.Sprintf("Number of seconds for the default liveliness check")
199 flag.DurationVar(&(so.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, help)
200
201 help = fmt.Sprintf("Number of seconds for liveliness check if probe is not running")
202 flag.DurationVar(&(so.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, help)
203
204 help = fmt.Sprintf("Number of seconds for heartbeat check interval.")
205 flag.DurationVar(&(so.HeartbeatCheckInterval), "hearbeat_check_interval", defaultHearbeatCheckInterval, help)
206
207 help = fmt.Sprintf("Number of seconds adapter has to wait before reporting core on the hearbeat check failure.")
208 flag.DurationVar(&(so.HeartbeatFailReportInterval), "hearbeat_fail_interval", defaultHearbeatFailReportInterval, help)
209
210 help = fmt.Sprintf("Number of retries to connect to Kafka.")
211 flag.IntVar(&(so.KafkaReconnectRetries), "kafka_reconnect_retries", defaultKafkaReconnectRetries, help)
212
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000213 help = "Replica number of this particular instance (default: %s)"
214 flag.IntVar(&(so.CurrentReplica), "current_replica", defaultCurrentReplica, help)
215
216 help = "Total number of instances for this adapter"
217 flag.IntVar(&(so.TotalReplicas), "total_replica", defaultTotalReplicas, help)
218
Himani Chawlad96df182020-09-28 11:12:02 +0530219 help = fmt.Sprintf("Maximum Number of seconds for the default interadapter communication timeout")
220 flag.DurationVar(&(so.MaxTimeoutInterAdapterComm), "max_timeout_interadapter_comm",
221 defaultMaxTimeoutInterAdapterComm, help)
222
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000223 help = fmt.Sprintf("Maximum Number of seconds for the default ONU reconciling timeout")
224 flag.DurationVar(&(so.MaxTimeoutReconciling), "max_timeout_reconciling",
225 defaultMaxTimeoutReconciling, help)
226
dbainbri4d3a0dc2020-12-02 00:33:42 +0000227 help = fmt.Sprintf("Whether to send logs to tracing agent?")
228 flag.BoolVar(&(so.TraceEnabled), "trace_enabled", defaultTraceEnabled, help)
229
230 help = fmt.Sprintf("The address of tracing agent to which span info should be sent.")
231 flag.StringVar(&(so.TraceAgentAddress), "trace_agent_address", defaultTraceAgentAddress, help)
232
233 help = fmt.Sprintf("Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
234 flag.BoolVar(&(so.LogCorrelationEnabled), "log_correlation_enabled", defaultLogCorrelationEnabled, help)
235
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100236 help = fmt.Sprintf("List of Allowed ONU Vendor Ids")
237 flag.StringVar(&(so.OnuVendorIds), "allowed_onu_vendors", defaultOnuVendorIds, help)
238
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800239 help = fmt.Sprintf("Whether to enable metrics collection")
240 flag.BoolVar(&(so.MetricsEnabled), "metrics_enabled", defaultMetricsEnabled, help)
241
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000242 help = fmt.Sprintf("Mib Audit Interval in seconds - the value zero will disable Mib Audit")
243 flag.DurationVar(&(so.MibAuditInterval), "mib_audit_interval", defaultMibAuditInterval, help)
244
Girish Gowdra0b235842021-03-09 13:06:46 -0800245 help = fmt.Sprintf("OMCI timeout duration - this timeout value is used on the OMCI channel for waiting on response from ONU")
246 flag.DurationVar(&(so.OmciTimeout), "omci_timeout", defaultOmciTimeout, help)
247
Himani Chawla075f1642021-03-15 19:23:24 +0530248 help = fmt.Sprintf("Alarm Audit Interval in seconds - the value zero will disable alarm audit")
249 flag.DurationVar(&(so.AlarmAuditInterval), "alarm_audit_interval", defaultAlarmAuditInterval, help)
250
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000251 flag.Parse()
252 containerName := getContainerInfo()
253 if len(containerName) > 0 {
254 so.InstanceID = containerName
255 }
256
Andrea Campanella961734c2021-01-18 11:44:47 +0100257 so.Topic = fmt.Sprintf("%s_%d", *baseAdapterTopic, int32(so.CurrentReplica))
258
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000259}
260
261func getContainerInfo() string {
262 return os.Getenv("HOSTNAME")
263}