blob: 34cf2ece97bb37961a48769dcce59bab36ca5fd3 [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.
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053050 defaultGrpcTimeoutInterval = 2 * time.Second
51 defaultCurrentReplica = 1
52 defaultTotalReplicas = 1
53 defaultTraceEnabled = false
54 defaultTraceAgentAddress = "127.0.0.1:6831"
55 defaultLogCorrelationEnabled = true
56 defaultOmccEncryption = false
57 defaultEnableONUStats = false
58 defaultEnableGEMStats = false
59 defaultMinBackoffRetryDelay = 500 * time.Millisecond
60 defaultMaxBackoffRetryDelay = 10 * time.Second
61 defaultAdapterEndpoint = "adapter-open-olt"
62 defaultCheckOnuDevExistenceAtOnuDiscovery = false
Girish Gowdru0c588b22019-04-23 23:24:56 -040063)
64
65// AdapterFlags represents the set of configurations used by the read-write adaptercore service
66type AdapterFlags struct {
67 // Command line parameters
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +053068 AdapterName string
69 InstanceID string // NOTE what am I used for? why not cli but only ENV? TODO expose in the chart
70 KafkaClusterAddress string
71 KVStoreType string
72 KVStoreTimeout time.Duration
73 KVStoreAddress string
74 RPCTimeout time.Duration
75 EventTopic string
76 LogLevel string
77 OnuNumber int
78 Banner bool
79 DisplayVersionOnly bool
80 ProbeAddress string
81 LiveProbeInterval time.Duration
82 NotLiveProbeInterval time.Duration
83 HeartbeatCheckInterval time.Duration
84 HeartbeatFailReportInterval time.Duration
85 GrpcTimeoutInterval time.Duration
86 GrpcAddress string
87 CoreEndpoint string
88 CurrentReplica int
89 TotalReplicas int
90 TraceEnabled bool
91 TraceAgentAddress string
92 LogCorrelationEnabled bool
93 OmccEncryption bool
94 EnableONUStats bool
95 EnableGEMStats bool
96 MinBackoffRetryDelay time.Duration
97 MaxBackoffRetryDelay time.Duration
98 AdapterEndpoint string
99 CheckOnuDevExistenceAtOnuDiscovery bool
Girish Gowdru0c588b22019-04-23 23:24:56 -0400100}
101
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700102// NewAdapterFlags returns a new RWCore config
Girish Gowdru0c588b22019-04-23 23:24:56 -0400103func NewAdapterFlags() *AdapterFlags {
104 var adapterFlags = AdapterFlags{ // Default values
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530105 InstanceID: defaultInstanceid,
106 KafkaClusterAddress: defaultKafkaclusteraddress,
107 KVStoreType: defaultKvstoretype,
108 KVStoreTimeout: defaultKvstoretimeout,
109 KVStoreAddress: defaultKvstoreaddress,
110 EventTopic: defaultEventtopic,
111 LogLevel: defaultLoglevel,
112 OnuNumber: defaultOnunumber,
113 Banner: defaultBanner,
114 DisplayVersionOnly: defaultDisplayVersionOnly,
115 ProbeAddress: defaultProbeAddress,
116 LiveProbeInterval: defaultLiveProbeInterval,
117 NotLiveProbeInterval: defaultNotLiveProbeInterval,
118 HeartbeatCheckInterval: defaultHeartbeatCheckInterval,
119 HeartbeatFailReportInterval: defaultHeartbeatFailReportInterval,
120 GrpcAddress: defaultGrpcAddress,
121 CoreEndpoint: defaultCoreEndpoint,
122 GrpcTimeoutInterval: defaultGrpcTimeoutInterval,
123 TraceEnabled: defaultTraceEnabled,
124 TraceAgentAddress: defaultTraceAgentAddress,
125 LogCorrelationEnabled: defaultLogCorrelationEnabled,
126 OmccEncryption: defaultOmccEncryption,
127 EnableONUStats: defaultEnableONUStats,
128 EnableGEMStats: defaultEnableGEMStats,
129 RPCTimeout: defaultRPCTimeout,
130 MinBackoffRetryDelay: defaultMinBackoffRetryDelay,
131 MaxBackoffRetryDelay: defaultMaxBackoffRetryDelay,
132 CheckOnuDevExistenceAtOnuDiscovery: defaultCheckOnuDevExistenceAtOnuDiscovery,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400133 }
134 return &adapterFlags
135}
136
137// ParseCommandArguments parses the arguments when running read-write adaptercore service
138func (so *AdapterFlags) ParseCommandArguments() {
139
khenaidoo106c61a2021-08-11 18:05:46 -0400140 flag.StringVar(&(so.KafkaClusterAddress),
141 "kafka_cluster_address",
142 defaultKafkaclusteraddress,
143 "Kafka - Cluster messaging address")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400144
khenaidoo106c61a2021-08-11 18:05:46 -0400145 flag.StringVar(&(so.EventTopic),
146 "event_topic",
147 defaultEventtopic,
148 "Event topic")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400149
khenaidoo106c61a2021-08-11 18:05:46 -0400150 flag.StringVar(&(so.KVStoreType),
151 "kv_store_type",
152 defaultKvstoretype,
153 "KV store type")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400154
khenaidoo106c61a2021-08-11 18:05:46 -0400155 flag.DurationVar(&(so.KVStoreTimeout),
156 "kv_store_request_timeout",
157 defaultKvstoretimeout,
158 "The default timeout when making a kv store request")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400159
khenaidoo106c61a2021-08-11 18:05:46 -0400160 flag.StringVar(&(so.KVStoreAddress),
161 "kv_store_address",
162 defaultKvstoreaddress,
163 "KV store address")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400164
khenaidoo106c61a2021-08-11 18:05:46 -0400165 flag.StringVar(&(so.LogLevel),
166 "log_level",
167 defaultLoglevel,
168 "Log level")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400169
khenaidoo106c61a2021-08-11 18:05:46 -0400170 flag.IntVar(&(so.OnuNumber),
171 "onu_number",
172 defaultOnunumber,
173 "Number of ONUs")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400174
khenaidoo106c61a2021-08-11 18:05:46 -0400175 flag.BoolVar(&(so.Banner),
176 "banner",
177 defaultBanner,
178 "Show startup banner log lines")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400179
khenaidoo106c61a2021-08-11 18:05:46 -0400180 flag.BoolVar(&(so.DisplayVersionOnly),
181 "version",
182 defaultDisplayVersionOnly,
183 "Show version information and exit")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400184
khenaidoo106c61a2021-08-11 18:05:46 -0400185 flag.StringVar(&(so.ProbeAddress),
186 "probe_address",
187 defaultProbeAddress,
188 "The address on which to listen to answer liveness and readiness probe queries over HTTP.")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400189
khenaidoo106c61a2021-08-11 18:05:46 -0400190 flag.DurationVar(&(so.LiveProbeInterval),
191 "live_probe_interval",
192 defaultLiveProbeInterval,
193 "Number of seconds for the default liveliness check")
Matt Jeanneretf880eb62019-07-16 20:08:03 -0400194
khenaidoo106c61a2021-08-11 18:05:46 -0400195 flag.DurationVar(&(so.NotLiveProbeInterval),
196 "not_live_probe_interval",
197 defaultNotLiveProbeInterval,
198 "Number of seconds for liveliness check if probe is not running")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400199
khenaidoo106c61a2021-08-11 18:05:46 -0400200 flag.DurationVar(&(so.HeartbeatCheckInterval),
201 "heartbeat_check_interval",
202 defaultHeartbeatCheckInterval,
203 "Number of seconds for heartbeat check interval")
Rohan Agrawal828bf4e2019-10-22 10:13:19 +0000204
khenaidoo106c61a2021-08-11 18:05:46 -0400205 flag.DurationVar(&(so.HeartbeatFailReportInterval),
206 "heartbeat_fail_interval",
207 defaultHeartbeatFailReportInterval,
208 "Number of seconds adapter has to wait before reporting core on the heartbeat check failure")
cbabu116b73f2019-12-10 17:56:32 +0530209
khenaidoo106c61a2021-08-11 18:05:46 -0400210 flag.DurationVar(&(so.GrpcTimeoutInterval),
211 "grpc_timeout_interval",
212 defaultGrpcTimeoutInterval,
213 "Number of seconds for GRPC timeout")
cbabu116b73f2019-12-10 17:56:32 +0530214
khenaidoo106c61a2021-08-11 18:05:46 -0400215 flag.IntVar(&(so.CurrentReplica),
216 "current_replica",
217 defaultCurrentReplica,
218 "Replica number of this particular instance")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400219
khenaidoo106c61a2021-08-11 18:05:46 -0400220 flag.IntVar(&(so.TotalReplicas),
221 "total_replica",
222 defaultTotalReplicas,
223 "Total number of instances for this adapter")
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530224
khenaidoo106c61a2021-08-11 18:05:46 -0400225 flag.BoolVar(&(so.TraceEnabled),
226 "trace_enabled",
227 defaultTraceEnabled,
228 "Whether to send logs to tracing agent?")
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530229
khenaidoo106c61a2021-08-11 18:05:46 -0400230 flag.StringVar(&(so.TraceAgentAddress),
231 "trace_agent_address",
232 defaultTraceAgentAddress,
233 "The address of tracing agent to which span info should be sent")
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -0700234
khenaidoo106c61a2021-08-11 18:05:46 -0400235 flag.BoolVar(&(so.LogCorrelationEnabled),
236 "log_correlation_enabled",
237 defaultLogCorrelationEnabled,
238 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -0700239
khenaidoo106c61a2021-08-11 18:05:46 -0400240 flag.BoolVar(&(so.OmccEncryption),
241 "omcc_encryption",
242 defaultOmccEncryption,
243 "OMCI Channel encryption status")
Girish Kumar11e15972020-06-15 14:51:10 +0000244
khenaidoo106c61a2021-08-11 18:05:46 -0400245 flag.BoolVar(&(so.EnableONUStats),
246 "enable_onu_stats",
247 defaultEnableONUStats,
248 "Enable ONU Statistics")
Girish Kumar11e15972020-06-15 14:51:10 +0000249
khenaidoo106c61a2021-08-11 18:05:46 -0400250 flag.BoolVar(&(so.EnableGEMStats),
251 "enable_gem_stats",
252 defaultEnableGEMStats,
253 "Enable GEM Statistics")
Girish Kumar11e15972020-06-15 14:51:10 +0000254
khenaidoo106c61a2021-08-11 18:05:46 -0400255 flag.StringVar(&(so.GrpcAddress),
256 "grpc_address",
257 defaultGrpcAddress,
258 "Adapter GRPC Server address")
kesavand494c2082020-08-31 11:16:12 +0530259
khenaidoo106c61a2021-08-11 18:05:46 -0400260 flag.StringVar(&(so.CoreEndpoint),
261 "core_endpoint",
262 defaultCoreEndpoint,
263 "Core endpoint")
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000264
khenaidoo106c61a2021-08-11 18:05:46 -0400265 flag.StringVar(&(so.AdapterEndpoint),
266 "adapter_endpoint",
267 defaultAdapterEndpoint,
268 "Adapter Endpoint")
269
270 flag.DurationVar(&(so.RPCTimeout),
271 "rpc_timeout",
272 defaultRPCTimeout,
273 "The default timeout when making an RPC request")
274
275 flag.DurationVar(&(so.MinBackoffRetryDelay),
276 "min_retry_delay",
277 defaultMinBackoffRetryDelay,
278 "The minimum number of milliseconds to delay before a connection retry attempt")
279
280 flag.DurationVar(&(so.MaxBackoffRetryDelay),
281 "max_retry_delay",
282 defaultMaxBackoffRetryDelay,
283 "The maximum number of milliseconds to delay before a connection retry attempt")
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000284
Abhilash Laxmeshward0f58cf2022-06-01 12:15:19 +0530285 flag.BoolVar(&(so.CheckOnuDevExistenceAtOnuDiscovery),
286 "check_onu_exist_on_discovery",
287 defaultCheckOnuDevExistenceAtOnuDiscovery,
288 "Whether to check for flows only or child device before honoring discovery?")
289
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530290 flag.Parse()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400291 containerName := getContainerInfo()
292 if len(containerName) > 0 {
293 so.InstanceID = containerName
294 }
295
296}
297
298func getContainerInfo() string {
299 return os.Getenv("HOSTNAME")
300}