Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1 | /* |
Joey Armstrong | a6af152 | 2023-01-17 16:06:16 -0500 | [diff] [blame] | 2 | * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 3 | |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 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 |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 7 | |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 9 | |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 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. |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 15 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 16 | |
| 17 | //Package config provides the Log, kvstore, Kafka configuration |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 18 | package config |
| 19 | |
| 20 | import ( |
| 21 | "flag" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 22 | "os" |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 23 | "time" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | // Open OLT default constants |
| 27 | const ( |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 28 | EtcdStoreName = "etcd" |
| 29 | defaultInstanceid = "openOlt001" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 30 | defaultKafkaclusteraddress = "127.0.0.1:9092" |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 31 | defaultKvstoretype = EtcdStoreName |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 32 | defaultKvstoretimeout = 5 * time.Second |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 33 | defaultRPCTimeout = 10 * time.Second |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 34 | defaultKvstoreaddress = "127.0.0.1:2379" // Port: Consul = 8500; Etcd = 2379 |
David Bainbridge | 2b3d488 | 2020-03-17 15:06:39 -0700 | [diff] [blame] | 35 | defaultLoglevel = "WARN" |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 36 | defaultBanner = false |
| 37 | defaultDisplayVersionOnly = false |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 38 | defaultEventtopic = "voltha.events" |
| 39 | defaultOnunumber = 1 |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 40 | defaultProbeAddress = ":8080" |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 41 | defaultLiveProbeInterval = 60 * time.Second |
| 42 | defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive |
Girish Gowdra | 495dde4 | 2021-03-17 14:59:56 -0700 | [diff] [blame] | 43 | //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 |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 47 | defaultGrpcAddress = ":50060" |
| 48 | defaultCoreEndpoint = ":55555" |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 49 | //defaultGrpcTimeoutInterval is the time in seconds a grpc call will wait before returning error. |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 50 | 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 Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 63 | ) |
| 64 | |
| 65 | // AdapterFlags represents the set of configurations used by the read-write adaptercore service |
| 66 | type AdapterFlags struct { |
| 67 | // Command line parameters |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 68 | 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 Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 100 | } |
| 101 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 102 | // NewAdapterFlags returns a new RWCore config |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 103 | func NewAdapterFlags() *AdapterFlags { |
| 104 | var adapterFlags = AdapterFlags{ // Default values |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 105 | 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 Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 133 | } |
| 134 | return &adapterFlags |
| 135 | } |
| 136 | |
| 137 | // ParseCommandArguments parses the arguments when running read-write adaptercore service |
| 138 | func (so *AdapterFlags) ParseCommandArguments() { |
| 139 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 140 | flag.StringVar(&(so.KafkaClusterAddress), |
| 141 | "kafka_cluster_address", |
| 142 | defaultKafkaclusteraddress, |
| 143 | "Kafka - Cluster messaging address") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 144 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 145 | flag.StringVar(&(so.EventTopic), |
| 146 | "event_topic", |
| 147 | defaultEventtopic, |
| 148 | "Event topic") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 149 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 150 | flag.StringVar(&(so.KVStoreType), |
| 151 | "kv_store_type", |
| 152 | defaultKvstoretype, |
| 153 | "KV store type") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 154 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 155 | flag.DurationVar(&(so.KVStoreTimeout), |
| 156 | "kv_store_request_timeout", |
| 157 | defaultKvstoretimeout, |
| 158 | "The default timeout when making a kv store request") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 159 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 160 | flag.StringVar(&(so.KVStoreAddress), |
| 161 | "kv_store_address", |
| 162 | defaultKvstoreaddress, |
| 163 | "KV store address") |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 164 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 165 | flag.StringVar(&(so.LogLevel), |
| 166 | "log_level", |
| 167 | defaultLoglevel, |
| 168 | "Log level") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 169 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 170 | flag.IntVar(&(so.OnuNumber), |
| 171 | "onu_number", |
| 172 | defaultOnunumber, |
| 173 | "Number of ONUs") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 174 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 175 | flag.BoolVar(&(so.Banner), |
| 176 | "banner", |
| 177 | defaultBanner, |
| 178 | "Show startup banner log lines") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 179 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 180 | flag.BoolVar(&(so.DisplayVersionOnly), |
| 181 | "version", |
| 182 | defaultDisplayVersionOnly, |
| 183 | "Show version information and exit") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 184 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 185 | 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 Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 189 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 190 | flag.DurationVar(&(so.LiveProbeInterval), |
| 191 | "live_probe_interval", |
| 192 | defaultLiveProbeInterval, |
| 193 | "Number of seconds for the default liveliness check") |
Matt Jeanneret | f880eb6 | 2019-07-16 20:08:03 -0400 | [diff] [blame] | 194 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 195 | flag.DurationVar(&(so.NotLiveProbeInterval), |
| 196 | "not_live_probe_interval", |
| 197 | defaultNotLiveProbeInterval, |
| 198 | "Number of seconds for liveliness check if probe is not running") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 199 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 200 | flag.DurationVar(&(so.HeartbeatCheckInterval), |
| 201 | "heartbeat_check_interval", |
| 202 | defaultHeartbeatCheckInterval, |
| 203 | "Number of seconds for heartbeat check interval") |
Rohan Agrawal | 828bf4e | 2019-10-22 10:13:19 +0000 | [diff] [blame] | 204 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 205 | 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") |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 209 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 210 | flag.DurationVar(&(so.GrpcTimeoutInterval), |
| 211 | "grpc_timeout_interval", |
| 212 | defaultGrpcTimeoutInterval, |
| 213 | "Number of seconds for GRPC timeout") |
cbabu | 116b73f | 2019-12-10 17:56:32 +0530 | [diff] [blame] | 214 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 215 | flag.IntVar(&(so.CurrentReplica), |
| 216 | "current_replica", |
| 217 | defaultCurrentReplica, |
| 218 | "Replica number of this particular instance") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 219 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 220 | flag.IntVar(&(so.TotalReplicas), |
| 221 | "total_replica", |
| 222 | defaultTotalReplicas, |
| 223 | "Total number of instances for this adapter") |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 224 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 225 | flag.BoolVar(&(so.TraceEnabled), |
| 226 | "trace_enabled", |
| 227 | defaultTraceEnabled, |
| 228 | "Whether to send logs to tracing agent?") |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 229 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 230 | flag.StringVar(&(so.TraceAgentAddress), |
| 231 | "trace_agent_address", |
| 232 | defaultTraceAgentAddress, |
| 233 | "The address of tracing agent to which span info should be sent") |
Matteo Scandolo | 3ad5d2b | 2020-04-02 17:02:04 -0700 | [diff] [blame] | 234 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 235 | 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 Scandolo | 3ad5d2b | 2020-04-02 17:02:04 -0700 | [diff] [blame] | 239 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 240 | flag.BoolVar(&(so.OmccEncryption), |
| 241 | "omcc_encryption", |
| 242 | defaultOmccEncryption, |
| 243 | "OMCI Channel encryption status") |
Girish Kumar | 11e1597 | 2020-06-15 14:51:10 +0000 | [diff] [blame] | 244 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 245 | flag.BoolVar(&(so.EnableONUStats), |
| 246 | "enable_onu_stats", |
| 247 | defaultEnableONUStats, |
| 248 | "Enable ONU Statistics") |
Girish Kumar | 11e1597 | 2020-06-15 14:51:10 +0000 | [diff] [blame] | 249 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 250 | flag.BoolVar(&(so.EnableGEMStats), |
| 251 | "enable_gem_stats", |
| 252 | defaultEnableGEMStats, |
| 253 | "Enable GEM Statistics") |
Girish Kumar | 11e1597 | 2020-06-15 14:51:10 +0000 | [diff] [blame] | 254 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 255 | flag.StringVar(&(so.GrpcAddress), |
| 256 | "grpc_address", |
| 257 | defaultGrpcAddress, |
| 258 | "Adapter GRPC Server address") |
kesavand | 494c208 | 2020-08-31 11:16:12 +0530 | [diff] [blame] | 259 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 260 | flag.StringVar(&(so.CoreEndpoint), |
| 261 | "core_endpoint", |
| 262 | defaultCoreEndpoint, |
| 263 | "Core endpoint") |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 264 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 265 | 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 Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 284 | |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 285 | 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 Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 290 | flag.Parse() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 291 | containerName := getContainerInfo() |
| 292 | if len(containerName) > 0 { |
| 293 | so.InstanceID = containerName |
| 294 | } |
| 295 | |
| 296 | } |
| 297 | |
| 298 | func getContainerInfo() string { |
| 299 | return os.Getenv("HOSTNAME") |
| 300 | } |