blob: 0bd4fde7e3f80c6941ee0f0d70d7d49404ea1211 [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
Akash Kankanala041a2122024-10-16 15:49:22 +053044 // defaultHeartbeatCheckInterval is the time in seconds the adapter will keep checking the hardware for heartbeat.
Girish Gowdra495dde42021-03-17 14:59:56 -070045 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"
Akash Kankanala041a2122024-10-16 15:49:22 +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
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053074 KVStoreAddress string
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053075 EventTopic string
76 LogLevel string
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053077 ProbeAddress string
Akash Kankanala041a2122024-10-16 15:49:22 +053078 GrpcAddress string
79 CoreEndpoint string
80 TraceAgentAddress string
81 AdapterEndpoint string
82 KVStoreTimeout time.Duration
83 RPCTimeout time.Duration
84 PerRPCRetryTimeout time.Duration
85 OnuNumber int
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053086 LiveProbeInterval time.Duration
87 NotLiveProbeInterval time.Duration
88 HeartbeatCheckInterval time.Duration
89 HeartbeatFailReportInterval time.Duration
90 GrpcTimeoutInterval time.Duration
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053091 CurrentReplica int
92 TotalReplicas int
Akash Kankanala041a2122024-10-16 15:49:22 +053093 MinBackoffRetryDelay time.Duration
94 MaxBackoffRetryDelay time.Duration
95 MaxRetries uint
96 Banner bool
97 DisplayVersionOnly bool
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053098 TraceEnabled bool
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053099 LogCorrelationEnabled bool
100 OmccEncryption bool
101 EnableONUStats bool
102 EnableGEMStats bool
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530103 CheckOnuDevExistenceAtOnuDiscovery bool
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() {
khenaidoo106c61a2021-08-11 18:05:46 -0400145 flag.StringVar(&(so.KafkaClusterAddress),
146 "kafka_cluster_address",
147 defaultKafkaclusteraddress,
148 "Kafka - Cluster messaging address")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400149
khenaidoo106c61a2021-08-11 18:05:46 -0400150 flag.StringVar(&(so.EventTopic),
151 "event_topic",
152 defaultEventtopic,
153 "Event topic")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400154
khenaidoo106c61a2021-08-11 18:05:46 -0400155 flag.StringVar(&(so.KVStoreType),
156 "kv_store_type",
157 defaultKvstoretype,
158 "KV store type")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400159
khenaidoo106c61a2021-08-11 18:05:46 -0400160 flag.DurationVar(&(so.KVStoreTimeout),
161 "kv_store_request_timeout",
162 defaultKvstoretimeout,
163 "The default timeout when making a kv store request")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400164
khenaidoo106c61a2021-08-11 18:05:46 -0400165 flag.StringVar(&(so.KVStoreAddress),
166 "kv_store_address",
167 defaultKvstoreaddress,
168 "KV store address")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400169
khenaidoo106c61a2021-08-11 18:05:46 -0400170 flag.StringVar(&(so.LogLevel),
171 "log_level",
172 defaultLoglevel,
173 "Log level")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400174
khenaidoo106c61a2021-08-11 18:05:46 -0400175 flag.IntVar(&(so.OnuNumber),
176 "onu_number",
177 defaultOnunumber,
178 "Number of ONUs")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400179
khenaidoo106c61a2021-08-11 18:05:46 -0400180 flag.BoolVar(&(so.Banner),
181 "banner",
182 defaultBanner,
183 "Show startup banner log lines")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400184
khenaidoo106c61a2021-08-11 18:05:46 -0400185 flag.BoolVar(&(so.DisplayVersionOnly),
186 "version",
187 defaultDisplayVersionOnly,
188 "Show version information and exit")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400189
khenaidoo106c61a2021-08-11 18:05:46 -0400190 flag.StringVar(&(so.ProbeAddress),
191 "probe_address",
192 defaultProbeAddress,
193 "The address on which to listen to answer liveness and readiness probe queries over HTTP.")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400194
khenaidoo106c61a2021-08-11 18:05:46 -0400195 flag.DurationVar(&(so.LiveProbeInterval),
196 "live_probe_interval",
197 defaultLiveProbeInterval,
198 "Number of seconds for the default liveliness check")
Matt Jeanneretf880eb62019-07-16 20:08:03 -0400199
khenaidoo106c61a2021-08-11 18:05:46 -0400200 flag.DurationVar(&(so.NotLiveProbeInterval),
201 "not_live_probe_interval",
202 defaultNotLiveProbeInterval,
203 "Number of seconds for liveliness check if probe is not running")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400204
khenaidoo106c61a2021-08-11 18:05:46 -0400205 flag.DurationVar(&(so.HeartbeatCheckInterval),
206 "heartbeat_check_interval",
207 defaultHeartbeatCheckInterval,
208 "Number of seconds for heartbeat check interval")
Rohan Agrawal828bf4e2019-10-22 10:13:19 +0000209
khenaidoo106c61a2021-08-11 18:05:46 -0400210 flag.DurationVar(&(so.HeartbeatFailReportInterval),
211 "heartbeat_fail_interval",
212 defaultHeartbeatFailReportInterval,
213 "Number of seconds adapter has to wait before reporting core on the heartbeat check failure")
cbabu116b73f2019-12-10 17:56:32 +0530214
khenaidoo106c61a2021-08-11 18:05:46 -0400215 flag.DurationVar(&(so.GrpcTimeoutInterval),
216 "grpc_timeout_interval",
217 defaultGrpcTimeoutInterval,
218 "Number of seconds for GRPC timeout")
cbabu116b73f2019-12-10 17:56:32 +0530219
khenaidoo106c61a2021-08-11 18:05:46 -0400220 flag.IntVar(&(so.CurrentReplica),
221 "current_replica",
222 defaultCurrentReplica,
223 "Replica number of this particular instance")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400224
khenaidoo106c61a2021-08-11 18:05:46 -0400225 flag.IntVar(&(so.TotalReplicas),
226 "total_replica",
227 defaultTotalReplicas,
228 "Total number of instances for this adapter")
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530229
khenaidoo106c61a2021-08-11 18:05:46 -0400230 flag.BoolVar(&(so.TraceEnabled),
231 "trace_enabled",
232 defaultTraceEnabled,
233 "Whether to send logs to tracing agent?")
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530234
khenaidoo106c61a2021-08-11 18:05:46 -0400235 flag.StringVar(&(so.TraceAgentAddress),
236 "trace_agent_address",
237 defaultTraceAgentAddress,
238 "The address of tracing agent to which span info should be sent")
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -0700239
khenaidoo106c61a2021-08-11 18:05:46 -0400240 flag.BoolVar(&(so.LogCorrelationEnabled),
241 "log_correlation_enabled",
242 defaultLogCorrelationEnabled,
243 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -0700244
khenaidoo106c61a2021-08-11 18:05:46 -0400245 flag.BoolVar(&(so.OmccEncryption),
246 "omcc_encryption",
247 defaultOmccEncryption,
248 "OMCI Channel encryption status")
Girish Kumar11e15972020-06-15 14:51:10 +0000249
khenaidoo106c61a2021-08-11 18:05:46 -0400250 flag.BoolVar(&(so.EnableONUStats),
251 "enable_onu_stats",
252 defaultEnableONUStats,
253 "Enable ONU Statistics")
Girish Kumar11e15972020-06-15 14:51:10 +0000254
khenaidoo106c61a2021-08-11 18:05:46 -0400255 flag.BoolVar(&(so.EnableGEMStats),
256 "enable_gem_stats",
257 defaultEnableGEMStats,
258 "Enable GEM Statistics")
Girish Kumar11e15972020-06-15 14:51:10 +0000259
khenaidoo106c61a2021-08-11 18:05:46 -0400260 flag.StringVar(&(so.GrpcAddress),
261 "grpc_address",
262 defaultGrpcAddress,
263 "Adapter GRPC Server address")
kesavand494c2082020-08-31 11:16:12 +0530264
khenaidoo106c61a2021-08-11 18:05:46 -0400265 flag.StringVar(&(so.CoreEndpoint),
266 "core_endpoint",
267 defaultCoreEndpoint,
268 "Core endpoint")
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000269
khenaidoo106c61a2021-08-11 18:05:46 -0400270 flag.StringVar(&(so.AdapterEndpoint),
271 "adapter_endpoint",
272 defaultAdapterEndpoint,
273 "Adapter Endpoint")
274
275 flag.DurationVar(&(so.RPCTimeout),
276 "rpc_timeout",
277 defaultRPCTimeout,
278 "The default timeout when making an RPC request")
279
280 flag.DurationVar(&(so.MinBackoffRetryDelay),
281 "min_retry_delay",
282 defaultMinBackoffRetryDelay,
283 "The minimum number of milliseconds to delay before a connection retry attempt")
284
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530285 flag.DurationVar(&(so.PerRPCRetryTimeout),
286 "per_rpc_retry_timeout",
287 defaultPerRPCRetryTimeout,
288 "The default timeout per RPC retry")
289
khenaidoo106c61a2021-08-11 18:05:46 -0400290 flag.DurationVar(&(so.MaxBackoffRetryDelay),
291 "max_retry_delay",
292 defaultMaxBackoffRetryDelay,
293 "The maximum number of milliseconds to delay before a connection retry attempt")
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000294
nikesh.krishnan6dd882b2023-03-14 10:02:41 +0530295 flag.UintVar(&(so.MaxRetries),
296 "max_grpc_client_retry",
297 defaultMaxRetries,
298 "The maximum number of times olt adaptor will retry in case grpc request timeouts")
299
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530300 flag.BoolVar(&(so.CheckOnuDevExistenceAtOnuDiscovery),
301 "check_onu_exist_on_discovery",
302 defaultCheckOnuDevExistenceAtOnuDiscovery,
303 "Whether to check for flows only or child device before honoring discovery?")
304
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530305 flag.Parse()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400306 containerName := getContainerInfo()
307 if len(containerName) > 0 {
308 so.InstanceID = containerName
309 }
Girish Gowdru0c588b22019-04-23 23:24:56 -0400310}
311
312func getContainerInfo() string {
313 return os.Getenv("HOSTNAME")
314}