blob: 576ae72337f5ea164963503447784abee52bf48f [file] [log] [blame]
Girish Gowdru0c588b22019-04-23 23:24:56 -04001/*
cbabu116b73f2019-12-10 17:56:32 +05302* Copyright 2018-present Open Networking Foundation
Girish Gowdru0c588b22019-04-23 23:24:56 -04003
cbabu116b73f2019-12-10 17:56:32 +05304* 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
Girish Gowdru0c588b22019-04-23 23:24:56 -04007
cbabu116b73f2019-12-10 17:56:32 +05308* http://www.apache.org/licenses/LICENSE-2.0
Girish Gowdru0c588b22019-04-23 23:24:56 -04009
cbabu116b73f2019-12-10 17:56:32 +053010* 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.
Girish Gowdru0c588b22019-04-23 23:24:56 -040015 */
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070016
17//Package config provides the Log, kvstore, Kafka configuration
Girish Gowdru0c588b22019-04-23 23:24:56 -040018package config
19
20import (
21 "flag"
Girish Gowdru0c588b22019-04-23 23:24:56 -040022 "os"
cbabu116b73f2019-12-10 17:56:32 +053023 "time"
Girish Gowdru0c588b22019-04-23 23:24:56 -040024)
25
26// Open OLT default constants
27const (
cbabu116b73f2019-12-10 17:56:32 +053028 EtcdStoreName = "etcd"
29 defaultInstanceid = "openOlt001"
khenaidoo106c61a2021-08-11 18:05:46 -040030 defaultKafkaclusteraddress = "127.0.0.1:9092"
cbabu116b73f2019-12-10 17:56:32 +053031 defaultKvstoretype = EtcdStoreName
Neha Sharma3f221ae2020-04-29 19:02:12 +000032 defaultKvstoretimeout = 5 * time.Second
khenaidoo106c61a2021-08-11 18:05:46 -040033 defaultRPCTimeout = 10 * time.Second
Neha Sharma3f221ae2020-04-29 19:02:12 +000034 defaultKvstoreaddress = "127.0.0.1:2379" // Port: Consul = 8500; Etcd = 2379
David Bainbridge2b3d4882020-03-17 15:06:39 -070035 defaultLoglevel = "WARN"
cbabu116b73f2019-12-10 17:56:32 +053036 defaultBanner = false
37 defaultDisplayVersionOnly = false
cbabu116b73f2019-12-10 17:56:32 +053038 defaultEventtopic = "voltha.events"
39 defaultOnunumber = 1
Neha Sharma3f221ae2020-04-29 19:02:12 +000040 defaultProbeAddress = ":8080"
cbabu116b73f2019-12-10 17:56:32 +053041 defaultLiveProbeInterval = 60 * time.Second
42 defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
Girish Gowdra495dde42021-03-17 14:59:56 -070043 //defaultHeartbeatCheckInterval is the time in seconds the adapter will keep checking the hardware for heartbeat.
44 defaultHeartbeatCheckInterval = 15 * time.Second
45 // defaultHeartbeatFailReportInterval is the time adapter will wait before updating the state to the core.
46 defaultHeartbeatFailReportInterval = 0 * time.Second
khenaidoo106c61a2021-08-11 18:05:46 -040047 defaultGrpcAddress = ":50060"
48 defaultCoreEndpoint = ":55555"
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053049 //defaultGrpcTimeoutInterval is the time in seconds a grpc call will wait before returning error.
Girish Kumar11e15972020-06-15 14:51:10 +000050 defaultGrpcTimeoutInterval = 2 * time.Second
51 defaultCurrentReplica = 1
52 defaultTotalReplicas = 1
53 defaultTraceEnabled = false
54 defaultTraceAgentAddress = "127.0.0.1:6831"
55 defaultLogCorrelationEnabled = true
kesavand494c2082020-08-31 11:16:12 +053056 defaultOmccEncryption = false
Gamze Abakafcbd6e72020-12-17 13:25:16 +000057 defaultEnableONUStats = false
58 defaultEnableGEMStats = false
khenaidoo106c61a2021-08-11 18:05:46 -040059 defaultMinBackoffRetryDelay = 500 * time.Millisecond
60 defaultMaxBackoffRetryDelay = 10 * time.Second
61 defaultAdapterEndpoint = "adapter-open-olt"
Girish Gowdru0c588b22019-04-23 23:24:56 -040062)
63
64// AdapterFlags represents the set of configurations used by the read-write adaptercore service
65type AdapterFlags struct {
66 // Command line parameters
Matteo Scandolodfa7a972020-11-06 13:03:40 -080067 AdapterName string
68 InstanceID string // NOTE what am I used for? why not cli but only ENV? TODO expose in the chart
Neha Sharma3f221ae2020-04-29 19:02:12 +000069 KafkaClusterAddress string
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053070 KVStoreType string
Neha Sharma3f221ae2020-04-29 19:02:12 +000071 KVStoreTimeout time.Duration
72 KVStoreAddress string
khenaidoo106c61a2021-08-11 18:05:46 -040073 RPCTimeout time.Duration
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053074 EventTopic string
Rohan Agrawal2488f192020-01-31 09:26:55 +000075 LogLevel string
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053076 OnuNumber int
77 Banner bool
78 DisplayVersionOnly bool
Neha Sharma3f221ae2020-04-29 19:02:12 +000079 ProbeAddress string
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053080 LiveProbeInterval time.Duration
81 NotLiveProbeInterval time.Duration
82 HeartbeatCheckInterval time.Duration
83 HeartbeatFailReportInterval time.Duration
84 GrpcTimeoutInterval time.Duration
khenaidoo106c61a2021-08-11 18:05:46 -040085 GrpcAddress string
86 CoreEndpoint string
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -070087 CurrentReplica int
88 TotalReplicas int
Girish Kumar11e15972020-06-15 14:51:10 +000089 TraceEnabled bool
90 TraceAgentAddress string
91 LogCorrelationEnabled bool
kesavand494c2082020-08-31 11:16:12 +053092 OmccEncryption bool
Gamze Abakafcbd6e72020-12-17 13:25:16 +000093 EnableONUStats bool
94 EnableGEMStats bool
khenaidoo106c61a2021-08-11 18:05:46 -040095 MinBackoffRetryDelay time.Duration
96 MaxBackoffRetryDelay time.Duration
97 AdapterEndpoint string
Girish Gowdru0c588b22019-04-23 23:24:56 -040098}
99
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700100// NewAdapterFlags returns a new RWCore config
Girish Gowdru0c588b22019-04-23 23:24:56 -0400101func NewAdapterFlags() *AdapterFlags {
102 var adapterFlags = AdapterFlags{ // Default values
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530103 InstanceID: defaultInstanceid,
Neha Sharma3f221ae2020-04-29 19:02:12 +0000104 KafkaClusterAddress: defaultKafkaclusteraddress,
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530105 KVStoreType: defaultKvstoretype,
106 KVStoreTimeout: defaultKvstoretimeout,
Neha Sharma3f221ae2020-04-29 19:02:12 +0000107 KVStoreAddress: defaultKvstoreaddress,
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530108 EventTopic: defaultEventtopic,
109 LogLevel: defaultLoglevel,
110 OnuNumber: defaultOnunumber,
111 Banner: defaultBanner,
112 DisplayVersionOnly: defaultDisplayVersionOnly,
Neha Sharma3f221ae2020-04-29 19:02:12 +0000113 ProbeAddress: defaultProbeAddress,
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530114 LiveProbeInterval: defaultLiveProbeInterval,
115 NotLiveProbeInterval: defaultNotLiveProbeInterval,
Girish Gowdra495dde42021-03-17 14:59:56 -0700116 HeartbeatCheckInterval: defaultHeartbeatCheckInterval,
117 HeartbeatFailReportInterval: defaultHeartbeatFailReportInterval,
khenaidoo106c61a2021-08-11 18:05:46 -0400118 GrpcAddress: defaultGrpcAddress,
119 CoreEndpoint: defaultCoreEndpoint,
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530120 GrpcTimeoutInterval: defaultGrpcTimeoutInterval,
Girish Kumar11e15972020-06-15 14:51:10 +0000121 TraceEnabled: defaultTraceEnabled,
122 TraceAgentAddress: defaultTraceAgentAddress,
123 LogCorrelationEnabled: defaultLogCorrelationEnabled,
kesavand494c2082020-08-31 11:16:12 +0530124 OmccEncryption: defaultOmccEncryption,
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000125 EnableONUStats: defaultEnableONUStats,
126 EnableGEMStats: defaultEnableGEMStats,
khenaidoo106c61a2021-08-11 18:05:46 -0400127 RPCTimeout: defaultRPCTimeout,
128 MinBackoffRetryDelay: defaultMinBackoffRetryDelay,
129 MaxBackoffRetryDelay: defaultMaxBackoffRetryDelay,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400130 }
131 return &adapterFlags
132}
133
134// ParseCommandArguments parses the arguments when running read-write adaptercore service
135func (so *AdapterFlags) ParseCommandArguments() {
136
khenaidoo106c61a2021-08-11 18:05:46 -0400137 flag.StringVar(&(so.KafkaClusterAddress),
138 "kafka_cluster_address",
139 defaultKafkaclusteraddress,
140 "Kafka - Cluster messaging address")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400141
khenaidoo106c61a2021-08-11 18:05:46 -0400142 flag.StringVar(&(so.EventTopic),
143 "event_topic",
144 defaultEventtopic,
145 "Event topic")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400146
khenaidoo106c61a2021-08-11 18:05:46 -0400147 flag.StringVar(&(so.KVStoreType),
148 "kv_store_type",
149 defaultKvstoretype,
150 "KV store type")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400151
khenaidoo106c61a2021-08-11 18:05:46 -0400152 flag.DurationVar(&(so.KVStoreTimeout),
153 "kv_store_request_timeout",
154 defaultKvstoretimeout,
155 "The default timeout when making a kv store request")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400156
khenaidoo106c61a2021-08-11 18:05:46 -0400157 flag.StringVar(&(so.KVStoreAddress),
158 "kv_store_address",
159 defaultKvstoreaddress,
160 "KV store address")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400161
khenaidoo106c61a2021-08-11 18:05:46 -0400162 flag.StringVar(&(so.LogLevel),
163 "log_level",
164 defaultLoglevel,
165 "Log level")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400166
khenaidoo106c61a2021-08-11 18:05:46 -0400167 flag.IntVar(&(so.OnuNumber),
168 "onu_number",
169 defaultOnunumber,
170 "Number of ONUs")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400171
khenaidoo106c61a2021-08-11 18:05:46 -0400172 flag.BoolVar(&(so.Banner),
173 "banner",
174 defaultBanner,
175 "Show startup banner log lines")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400176
khenaidoo106c61a2021-08-11 18:05:46 -0400177 flag.BoolVar(&(so.DisplayVersionOnly),
178 "version",
179 defaultDisplayVersionOnly,
180 "Show version information and exit")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400181
khenaidoo106c61a2021-08-11 18:05:46 -0400182 flag.StringVar(&(so.ProbeAddress),
183 "probe_address",
184 defaultProbeAddress,
185 "The address on which to listen to answer liveness and readiness probe queries over HTTP.")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400186
khenaidoo106c61a2021-08-11 18:05:46 -0400187 flag.DurationVar(&(so.LiveProbeInterval),
188 "live_probe_interval",
189 defaultLiveProbeInterval,
190 "Number of seconds for the default liveliness check")
Matt Jeanneretf880eb62019-07-16 20:08:03 -0400191
khenaidoo106c61a2021-08-11 18:05:46 -0400192 flag.DurationVar(&(so.NotLiveProbeInterval),
193 "not_live_probe_interval",
194 defaultNotLiveProbeInterval,
195 "Number of seconds for liveliness check if probe is not running")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400196
khenaidoo106c61a2021-08-11 18:05:46 -0400197 flag.DurationVar(&(so.HeartbeatCheckInterval),
198 "heartbeat_check_interval",
199 defaultHeartbeatCheckInterval,
200 "Number of seconds for heartbeat check interval")
Rohan Agrawal828bf4e2019-10-22 10:13:19 +0000201
khenaidoo106c61a2021-08-11 18:05:46 -0400202 flag.DurationVar(&(so.HeartbeatFailReportInterval),
203 "heartbeat_fail_interval",
204 defaultHeartbeatFailReportInterval,
205 "Number of seconds adapter has to wait before reporting core on the heartbeat check failure")
cbabu116b73f2019-12-10 17:56:32 +0530206
khenaidoo106c61a2021-08-11 18:05:46 -0400207 flag.DurationVar(&(so.GrpcTimeoutInterval),
208 "grpc_timeout_interval",
209 defaultGrpcTimeoutInterval,
210 "Number of seconds for GRPC timeout")
cbabu116b73f2019-12-10 17:56:32 +0530211
khenaidoo106c61a2021-08-11 18:05:46 -0400212 flag.IntVar(&(so.CurrentReplica),
213 "current_replica",
214 defaultCurrentReplica,
215 "Replica number of this particular instance")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400216
khenaidoo106c61a2021-08-11 18:05:46 -0400217 flag.IntVar(&(so.TotalReplicas),
218 "total_replica",
219 defaultTotalReplicas,
220 "Total number of instances for this adapter")
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530221
khenaidoo106c61a2021-08-11 18:05:46 -0400222 flag.BoolVar(&(so.TraceEnabled),
223 "trace_enabled",
224 defaultTraceEnabled,
225 "Whether to send logs to tracing agent?")
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530226
khenaidoo106c61a2021-08-11 18:05:46 -0400227 flag.StringVar(&(so.TraceAgentAddress),
228 "trace_agent_address",
229 defaultTraceAgentAddress,
230 "The address of tracing agent to which span info should be sent")
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -0700231
khenaidoo106c61a2021-08-11 18:05:46 -0400232 flag.BoolVar(&(so.LogCorrelationEnabled),
233 "log_correlation_enabled",
234 defaultLogCorrelationEnabled,
235 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -0700236
khenaidoo106c61a2021-08-11 18:05:46 -0400237 flag.BoolVar(&(so.OmccEncryption),
238 "omcc_encryption",
239 defaultOmccEncryption,
240 "OMCI Channel encryption status")
Girish Kumar11e15972020-06-15 14:51:10 +0000241
khenaidoo106c61a2021-08-11 18:05:46 -0400242 flag.BoolVar(&(so.EnableONUStats),
243 "enable_onu_stats",
244 defaultEnableONUStats,
245 "Enable ONU Statistics")
Girish Kumar11e15972020-06-15 14:51:10 +0000246
khenaidoo106c61a2021-08-11 18:05:46 -0400247 flag.BoolVar(&(so.EnableGEMStats),
248 "enable_gem_stats",
249 defaultEnableGEMStats,
250 "Enable GEM Statistics")
Girish Kumar11e15972020-06-15 14:51:10 +0000251
khenaidoo106c61a2021-08-11 18:05:46 -0400252 flag.StringVar(&(so.GrpcAddress),
253 "grpc_address",
254 defaultGrpcAddress,
255 "Adapter GRPC Server address")
kesavand494c2082020-08-31 11:16:12 +0530256
khenaidoo106c61a2021-08-11 18:05:46 -0400257 flag.StringVar(&(so.CoreEndpoint),
258 "core_endpoint",
259 defaultCoreEndpoint,
260 "Core endpoint")
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000261
khenaidoo106c61a2021-08-11 18:05:46 -0400262 flag.StringVar(&(so.AdapterEndpoint),
263 "adapter_endpoint",
264 defaultAdapterEndpoint,
265 "Adapter Endpoint")
266
267 flag.DurationVar(&(so.RPCTimeout),
268 "rpc_timeout",
269 defaultRPCTimeout,
270 "The default timeout when making an RPC request")
271
272 flag.DurationVar(&(so.MinBackoffRetryDelay),
273 "min_retry_delay",
274 defaultMinBackoffRetryDelay,
275 "The minimum number of milliseconds to delay before a connection retry attempt")
276
277 flag.DurationVar(&(so.MaxBackoffRetryDelay),
278 "max_retry_delay",
279 defaultMaxBackoffRetryDelay,
280 "The maximum number of milliseconds to delay before a connection retry attempt")
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000281
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530282 flag.Parse()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400283 containerName := getContainerInfo()
284 if len(containerName) > 0 {
285 so.InstanceID = containerName
286 }
287
288}
289
290func getContainerInfo() string {
291 return os.Getenv("HOSTNAME")
292}