blob: abd3617ca6e1ff37c35d11b64138569e193944b6 [file] [log] [blame]
Girish Gowdru0c588b22019-04-23 23:24:56 -04001/*
Joey Armstrong11f5a572024-01-12 19:11:32 -05002* Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors
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
Joey Armstrong3f0e2422023-07-05 18:25:41 -040017// 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 (
Abhay Kumar9bcfeb22024-07-12 09:14:25 +053028 KVStoreName = "etcd"
cbabu116b73f2019-12-10 17:56:32 +053029 defaultInstanceid = "openOlt001"
khenaidoo106c61a2021-08-11 18:05:46 -040030 defaultKafkaclusteraddress = "127.0.0.1:9092"
Abhay Kumar9bcfeb22024-07-12 09:14:25 +053031 defaultKvstoretype = KVStoreName
Neha Sharma3f221ae2020-04-29 19:02:12 +000032 defaultKvstoretimeout = 5 * time.Second
khenaidoo106c61a2021-08-11 18:05:46 -040033 defaultRPCTimeout = 10 * time.Second
nikesh.krishnan6dd882b2023-03-14 10:02:41 +053034 defaultPerRPCRetryTimeout = 2 * time.Second
Neha Sharma3f221ae2020-04-29 19:02:12 +000035 defaultKvstoreaddress = "127.0.0.1:2379" // Port: Consul = 8500; Etcd = 2379
David Bainbridge2b3d4882020-03-17 15:06:39 -070036 defaultLoglevel = "WARN"
cbabu116b73f2019-12-10 17:56:32 +053037 defaultBanner = false
38 defaultDisplayVersionOnly = false
cbabu116b73f2019-12-10 17:56:32 +053039 defaultEventtopic = "voltha.events"
40 defaultOnunumber = 1
Neha Sharma3f221ae2020-04-29 19:02:12 +000041 defaultProbeAddress = ":8080"
cbabu116b73f2019-12-10 17:56:32 +053042 defaultLiveProbeInterval = 60 * time.Second
43 defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
Girish Gowdra495dde42021-03-17 14:59:56 -070044 //defaultHeartbeatCheckInterval is the time in seconds the adapter will keep checking the hardware for heartbeat.
45 defaultHeartbeatCheckInterval = 15 * time.Second
46 // defaultHeartbeatFailReportInterval is the time adapter will wait before updating the state to the core.
47 defaultHeartbeatFailReportInterval = 0 * time.Second
khenaidoo106c61a2021-08-11 18:05:46 -040048 defaultGrpcAddress = ":50060"
49 defaultCoreEndpoint = ":55555"
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053050 //defaultGrpcTimeoutInterval is the time in seconds a grpc call will wait before returning error.
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053051 defaultGrpcTimeoutInterval = 2 * time.Second
52 defaultCurrentReplica = 1
53 defaultTotalReplicas = 1
54 defaultTraceEnabled = false
55 defaultTraceAgentAddress = "127.0.0.1:6831"
56 defaultLogCorrelationEnabled = true
57 defaultOmccEncryption = false
58 defaultEnableONUStats = false
59 defaultEnableGEMStats = false
60 defaultMinBackoffRetryDelay = 500 * time.Millisecond
61 defaultMaxBackoffRetryDelay = 10 * time.Second
62 defaultAdapterEndpoint = "adapter-open-olt"
63 defaultCheckOnuDevExistenceAtOnuDiscovery = false
nikesh.krishnan6dd882b2023-03-14 10:02:41 +053064 defaultMaxRetries = 10
Girish Gowdru0c588b22019-04-23 23:24:56 -040065)
66
67// AdapterFlags represents the set of configurations used by the read-write adaptercore service
68type AdapterFlags struct {
69 // Command line parameters
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053070 AdapterName string
71 InstanceID string // NOTE what am I used for? why not cli but only ENV? TODO expose in the chart
72 KafkaClusterAddress string
73 KVStoreType string
74 KVStoreTimeout time.Duration
75 KVStoreAddress string
76 RPCTimeout time.Duration
nikesh.krishnan6dd882b2023-03-14 10:02:41 +053077 PerRPCRetryTimeout time.Duration
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053078 EventTopic string
79 LogLevel string
80 OnuNumber int
81 Banner bool
82 DisplayVersionOnly bool
83 ProbeAddress string
84 LiveProbeInterval time.Duration
85 NotLiveProbeInterval time.Duration
86 HeartbeatCheckInterval time.Duration
87 HeartbeatFailReportInterval time.Duration
88 GrpcTimeoutInterval time.Duration
89 GrpcAddress string
90 CoreEndpoint string
91 CurrentReplica int
92 TotalReplicas int
93 TraceEnabled bool
94 TraceAgentAddress string
95 LogCorrelationEnabled bool
96 OmccEncryption bool
97 EnableONUStats bool
98 EnableGEMStats bool
99 MinBackoffRetryDelay time.Duration
100 MaxBackoffRetryDelay time.Duration
101 AdapterEndpoint string
102 CheckOnuDevExistenceAtOnuDiscovery bool
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530103 MaxRetries uint
Girish Gowdru0c588b22019-04-23 23:24:56 -0400104}
105
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700106// NewAdapterFlags returns a new RWCore config
Girish Gowdru0c588b22019-04-23 23:24:56 -0400107func NewAdapterFlags() *AdapterFlags {
108 var adapterFlags = AdapterFlags{ // Default values
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530109 InstanceID: defaultInstanceid,
110 KafkaClusterAddress: defaultKafkaclusteraddress,
111 KVStoreType: defaultKvstoretype,
112 KVStoreTimeout: defaultKvstoretimeout,
113 KVStoreAddress: defaultKvstoreaddress,
114 EventTopic: defaultEventtopic,
115 LogLevel: defaultLoglevel,
116 OnuNumber: defaultOnunumber,
117 Banner: defaultBanner,
118 DisplayVersionOnly: defaultDisplayVersionOnly,
119 ProbeAddress: defaultProbeAddress,
120 LiveProbeInterval: defaultLiveProbeInterval,
121 NotLiveProbeInterval: defaultNotLiveProbeInterval,
122 HeartbeatCheckInterval: defaultHeartbeatCheckInterval,
123 HeartbeatFailReportInterval: defaultHeartbeatFailReportInterval,
124 GrpcAddress: defaultGrpcAddress,
125 CoreEndpoint: defaultCoreEndpoint,
126 GrpcTimeoutInterval: defaultGrpcTimeoutInterval,
127 TraceEnabled: defaultTraceEnabled,
128 TraceAgentAddress: defaultTraceAgentAddress,
129 LogCorrelationEnabled: defaultLogCorrelationEnabled,
130 OmccEncryption: defaultOmccEncryption,
131 EnableONUStats: defaultEnableONUStats,
132 EnableGEMStats: defaultEnableGEMStats,
133 RPCTimeout: defaultRPCTimeout,
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530134 PerRPCRetryTimeout: defaultPerRPCRetryTimeout,
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530135 MinBackoffRetryDelay: defaultMinBackoffRetryDelay,
136 MaxBackoffRetryDelay: defaultMaxBackoffRetryDelay,
137 CheckOnuDevExistenceAtOnuDiscovery: defaultCheckOnuDevExistenceAtOnuDiscovery,
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530138 MaxRetries: defaultMaxRetries,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400139 }
140 return &adapterFlags
141}
142
143// ParseCommandArguments parses the arguments when running read-write adaptercore service
144func (so *AdapterFlags) ParseCommandArguments() {
145
khenaidoo106c61a2021-08-11 18:05:46 -0400146 flag.StringVar(&(so.KafkaClusterAddress),
147 "kafka_cluster_address",
148 defaultKafkaclusteraddress,
149 "Kafka - Cluster messaging address")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400150
khenaidoo106c61a2021-08-11 18:05:46 -0400151 flag.StringVar(&(so.EventTopic),
152 "event_topic",
153 defaultEventtopic,
154 "Event topic")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400155
khenaidoo106c61a2021-08-11 18:05:46 -0400156 flag.StringVar(&(so.KVStoreType),
157 "kv_store_type",
158 defaultKvstoretype,
159 "KV store type")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400160
khenaidoo106c61a2021-08-11 18:05:46 -0400161 flag.DurationVar(&(so.KVStoreTimeout),
162 "kv_store_request_timeout",
163 defaultKvstoretimeout,
164 "The default timeout when making a kv store request")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400165
khenaidoo106c61a2021-08-11 18:05:46 -0400166 flag.StringVar(&(so.KVStoreAddress),
167 "kv_store_address",
168 defaultKvstoreaddress,
169 "KV store address")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400170
khenaidoo106c61a2021-08-11 18:05:46 -0400171 flag.StringVar(&(so.LogLevel),
172 "log_level",
173 defaultLoglevel,
174 "Log level")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400175
khenaidoo106c61a2021-08-11 18:05:46 -0400176 flag.IntVar(&(so.OnuNumber),
177 "onu_number",
178 defaultOnunumber,
179 "Number of ONUs")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400180
khenaidoo106c61a2021-08-11 18:05:46 -0400181 flag.BoolVar(&(so.Banner),
182 "banner",
183 defaultBanner,
184 "Show startup banner log lines")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400185
khenaidoo106c61a2021-08-11 18:05:46 -0400186 flag.BoolVar(&(so.DisplayVersionOnly),
187 "version",
188 defaultDisplayVersionOnly,
189 "Show version information and exit")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400190
khenaidoo106c61a2021-08-11 18:05:46 -0400191 flag.StringVar(&(so.ProbeAddress),
192 "probe_address",
193 defaultProbeAddress,
194 "The address on which to listen to answer liveness and readiness probe queries over HTTP.")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400195
khenaidoo106c61a2021-08-11 18:05:46 -0400196 flag.DurationVar(&(so.LiveProbeInterval),
197 "live_probe_interval",
198 defaultLiveProbeInterval,
199 "Number of seconds for the default liveliness check")
Matt Jeanneretf880eb62019-07-16 20:08:03 -0400200
khenaidoo106c61a2021-08-11 18:05:46 -0400201 flag.DurationVar(&(so.NotLiveProbeInterval),
202 "not_live_probe_interval",
203 defaultNotLiveProbeInterval,
204 "Number of seconds for liveliness check if probe is not running")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400205
khenaidoo106c61a2021-08-11 18:05:46 -0400206 flag.DurationVar(&(so.HeartbeatCheckInterval),
207 "heartbeat_check_interval",
208 defaultHeartbeatCheckInterval,
209 "Number of seconds for heartbeat check interval")
Rohan Agrawal828bf4e2019-10-22 10:13:19 +0000210
khenaidoo106c61a2021-08-11 18:05:46 -0400211 flag.DurationVar(&(so.HeartbeatFailReportInterval),
212 "heartbeat_fail_interval",
213 defaultHeartbeatFailReportInterval,
214 "Number of seconds adapter has to wait before reporting core on the heartbeat check failure")
cbabu116b73f2019-12-10 17:56:32 +0530215
khenaidoo106c61a2021-08-11 18:05:46 -0400216 flag.DurationVar(&(so.GrpcTimeoutInterval),
217 "grpc_timeout_interval",
218 defaultGrpcTimeoutInterval,
219 "Number of seconds for GRPC timeout")
cbabu116b73f2019-12-10 17:56:32 +0530220
khenaidoo106c61a2021-08-11 18:05:46 -0400221 flag.IntVar(&(so.CurrentReplica),
222 "current_replica",
223 defaultCurrentReplica,
224 "Replica number of this particular instance")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400225
khenaidoo106c61a2021-08-11 18:05:46 -0400226 flag.IntVar(&(so.TotalReplicas),
227 "total_replica",
228 defaultTotalReplicas,
229 "Total number of instances for this adapter")
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530230
khenaidoo106c61a2021-08-11 18:05:46 -0400231 flag.BoolVar(&(so.TraceEnabled),
232 "trace_enabled",
233 defaultTraceEnabled,
234 "Whether to send logs to tracing agent?")
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530235
khenaidoo106c61a2021-08-11 18:05:46 -0400236 flag.StringVar(&(so.TraceAgentAddress),
237 "trace_agent_address",
238 defaultTraceAgentAddress,
239 "The address of tracing agent to which span info should be sent")
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -0700240
khenaidoo106c61a2021-08-11 18:05:46 -0400241 flag.BoolVar(&(so.LogCorrelationEnabled),
242 "log_correlation_enabled",
243 defaultLogCorrelationEnabled,
244 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -0700245
khenaidoo106c61a2021-08-11 18:05:46 -0400246 flag.BoolVar(&(so.OmccEncryption),
247 "omcc_encryption",
248 defaultOmccEncryption,
249 "OMCI Channel encryption status")
Girish Kumar11e15972020-06-15 14:51:10 +0000250
khenaidoo106c61a2021-08-11 18:05:46 -0400251 flag.BoolVar(&(so.EnableONUStats),
252 "enable_onu_stats",
253 defaultEnableONUStats,
254 "Enable ONU Statistics")
Girish Kumar11e15972020-06-15 14:51:10 +0000255
khenaidoo106c61a2021-08-11 18:05:46 -0400256 flag.BoolVar(&(so.EnableGEMStats),
257 "enable_gem_stats",
258 defaultEnableGEMStats,
259 "Enable GEM Statistics")
Girish Kumar11e15972020-06-15 14:51:10 +0000260
khenaidoo106c61a2021-08-11 18:05:46 -0400261 flag.StringVar(&(so.GrpcAddress),
262 "grpc_address",
263 defaultGrpcAddress,
264 "Adapter GRPC Server address")
kesavand494c2082020-08-31 11:16:12 +0530265
khenaidoo106c61a2021-08-11 18:05:46 -0400266 flag.StringVar(&(so.CoreEndpoint),
267 "core_endpoint",
268 defaultCoreEndpoint,
269 "Core endpoint")
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000270
khenaidoo106c61a2021-08-11 18:05:46 -0400271 flag.StringVar(&(so.AdapterEndpoint),
272 "adapter_endpoint",
273 defaultAdapterEndpoint,
274 "Adapter Endpoint")
275
276 flag.DurationVar(&(so.RPCTimeout),
277 "rpc_timeout",
278 defaultRPCTimeout,
279 "The default timeout when making an RPC request")
280
281 flag.DurationVar(&(so.MinBackoffRetryDelay),
282 "min_retry_delay",
283 defaultMinBackoffRetryDelay,
284 "The minimum number of milliseconds to delay before a connection retry attempt")
285
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530286 flag.DurationVar(&(so.PerRPCRetryTimeout),
287 "per_rpc_retry_timeout",
288 defaultPerRPCRetryTimeout,
289 "The default timeout per RPC retry")
290
khenaidoo106c61a2021-08-11 18:05:46 -0400291 flag.DurationVar(&(so.MaxBackoffRetryDelay),
292 "max_retry_delay",
293 defaultMaxBackoffRetryDelay,
294 "The maximum number of milliseconds to delay before a connection retry attempt")
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000295
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530296 flag.UintVar(&(so.MaxRetries),
297 "max_grpc_client_retry",
298 defaultMaxRetries,
299 "The maximum number of times olt adaptor will retry in case grpc request timeouts")
300
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530301 flag.BoolVar(&(so.CheckOnuDevExistenceAtOnuDiscovery),
302 "check_onu_exist_on_discovery",
303 defaultCheckOnuDevExistenceAtOnuDiscovery,
304 "Whether to check for flows only or child device before honoring discovery?")
305
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530306 flag.Parse()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400307 containerName := getContainerInfo()
308 if len(containerName) > 0 {
309 so.InstanceID = containerName
310 }
311
312}
313
314func getContainerInfo() string {
315 return os.Getenv("HOSTNAME")
316}