blob: 47d2df042a9961301cc708a86cca8a0dad608d18 [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"
22 "fmt"
Girish Gowdru0c588b22019-04-23 23:24:56 -040023 "os"
cbabu116b73f2019-12-10 17:56:32 +053024 "time"
Girish Gowdru0c588b22019-04-23 23:24:56 -040025)
26
27// Open OLT default constants
28const (
cbabu116b73f2019-12-10 17:56:32 +053029 EtcdStoreName = "etcd"
30 defaultInstanceid = "openOlt001"
Neha Sharma3f221ae2020-04-29 19:02:12 +000031 defaultKafkaadapteraddress = "127.0.0.1:9092"
32 defaultKafkaclusteraddress = "127.0.0.1:9094"
cbabu116b73f2019-12-10 17:56:32 +053033 defaultKvstoretype = EtcdStoreName
Neha Sharma3f221ae2020-04-29 19:02:12 +000034 defaultKvstoretimeout = 5 * time.Second
35 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
39 defaultTopic = "openolt"
40 defaultCoretopic = "rwcore"
41 defaultEventtopic = "voltha.events"
42 defaultOnunumber = 1
Neha Sharma3f221ae2020-04-29 19:02:12 +000043 defaultProbeAddress = ":8080"
cbabu116b73f2019-12-10 17:56:32 +053044 defaultLiveProbeInterval = 60 * time.Second
45 defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
Girish Gowdra495dde42021-03-17 14:59:56 -070046 //defaultHeartbeatCheckInterval is the time in seconds the adapter will keep checking the hardware for heartbeat.
47 defaultHeartbeatCheckInterval = 15 * time.Second
48 // defaultHeartbeatFailReportInterval is the time adapter will wait before updating the state to the core.
49 defaultHeartbeatFailReportInterval = 0 * time.Second
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053050 //defaultGrpcTimeoutInterval is the time in seconds a grpc call will wait before returning error.
Girish Kumar11e15972020-06-15 14:51:10 +000051 defaultGrpcTimeoutInterval = 2 * time.Second
52 defaultCurrentReplica = 1
53 defaultTotalReplicas = 1
54 defaultTraceEnabled = false
55 defaultTraceAgentAddress = "127.0.0.1:6831"
56 defaultLogCorrelationEnabled = true
kesavand494c2082020-08-31 11:16:12 +053057 defaultOmccEncryption = false
Gamze Abakafcbd6e72020-12-17 13:25:16 +000058 defaultEnableONUStats = false
59 defaultEnableGEMStats = false
Matteo Scandolo66fbaf52021-03-24 14:13:38 -070060 defaultReconnectTimeout = 1 * time.Minute
Girish Gowdru0c588b22019-04-23 23:24:56 -040061)
62
63// AdapterFlags represents the set of configurations used by the read-write adaptercore service
64type AdapterFlags struct {
65 // Command line parameters
Matteo Scandolodfa7a972020-11-06 13:03:40 -080066 AdapterName string
67 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 +000068 KafkaAdapterAddress string
69 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
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053073 Topic string
74 CoreTopic string
75 EventTopic string
Rohan Agrawal2488f192020-01-31 09:26:55 +000076 LogLevel string
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053077 OnuNumber int
78 Banner bool
79 DisplayVersionOnly bool
Neha Sharma3f221ae2020-04-29 19:02:12 +000080 ProbeAddress string
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +053081 LiveProbeInterval time.Duration
82 NotLiveProbeInterval time.Duration
83 HeartbeatCheckInterval time.Duration
84 HeartbeatFailReportInterval time.Duration
85 GrpcTimeoutInterval time.Duration
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -070086 CurrentReplica int
87 TotalReplicas int
Girish Kumar11e15972020-06-15 14:51:10 +000088 TraceEnabled bool
89 TraceAgentAddress string
90 LogCorrelationEnabled bool
kesavand494c2082020-08-31 11:16:12 +053091 OmccEncryption bool
Gamze Abakafcbd6e72020-12-17 13:25:16 +000092 EnableONUStats bool
93 EnableGEMStats bool
Matteo Scandolo66fbaf52021-03-24 14:13:38 -070094 ReconnectTimeout time.Duration
Girish Gowdru0c588b22019-04-23 23:24:56 -040095}
96
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070097// NewAdapterFlags returns a new RWCore config
Girish Gowdru0c588b22019-04-23 23:24:56 -040098func NewAdapterFlags() *AdapterFlags {
99 var adapterFlags = AdapterFlags{ // Default values
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530100 InstanceID: defaultInstanceid,
Neha Sharma3f221ae2020-04-29 19:02:12 +0000101 KafkaAdapterAddress: defaultKafkaadapteraddress,
102 KafkaClusterAddress: defaultKafkaclusteraddress,
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530103 KVStoreType: defaultKvstoretype,
104 KVStoreTimeout: defaultKvstoretimeout,
Neha Sharma3f221ae2020-04-29 19:02:12 +0000105 KVStoreAddress: defaultKvstoreaddress,
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530106 Topic: defaultTopic,
107 CoreTopic: defaultCoretopic,
108 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,
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530118 GrpcTimeoutInterval: defaultGrpcTimeoutInterval,
Girish Kumar11e15972020-06-15 14:51:10 +0000119 TraceEnabled: defaultTraceEnabled,
120 TraceAgentAddress: defaultTraceAgentAddress,
121 LogCorrelationEnabled: defaultLogCorrelationEnabled,
kesavand494c2082020-08-31 11:16:12 +0530122 OmccEncryption: defaultOmccEncryption,
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000123 EnableONUStats: defaultEnableONUStats,
124 EnableGEMStats: defaultEnableGEMStats,
Matteo Scandolo66fbaf52021-03-24 14:13:38 -0700125 ReconnectTimeout: defaultReconnectTimeout,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400126 }
127 return &adapterFlags
128}
129
130// ParseCommandArguments parses the arguments when running read-write adaptercore service
131func (so *AdapterFlags) ParseCommandArguments() {
132
Neha Sharma3f221ae2020-04-29 19:02:12 +0000133 help := fmt.Sprintf("Kafka - Adapter messaging address")
134 flag.StringVar(&(so.KafkaAdapterAddress), "kafka_adapter_address", defaultKafkaadapteraddress, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400135
Neha Sharma3f221ae2020-04-29 19:02:12 +0000136 help = fmt.Sprintf("Kafka - Cluster messaging address")
137 flag.StringVar(&(so.KafkaClusterAddress), "kafka_cluster_address", defaultKafkaclusteraddress, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400138
139 help = fmt.Sprintf("Open OLT topic")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700140 flag.StringVar(&(so.Topic), "adapter_topic", defaultTopic, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400141
142 help = fmt.Sprintf("Core topic")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700143 flag.StringVar(&(so.CoreTopic), "core_topic", defaultCoretopic, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400144
Devmalya Paulfb990a52019-07-09 10:01:49 -0400145 help = fmt.Sprintf("Event topic")
146 flag.StringVar(&(so.EventTopic), "event_topic", defaultEventtopic, help)
147
Girish Gowdru0c588b22019-04-23 23:24:56 -0400148 help = fmt.Sprintf("KV store type")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700149 flag.StringVar(&(so.KVStoreType), "kv_store_type", defaultKvstoretype, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400150
151 help = fmt.Sprintf("The default timeout when making a kv store request")
Neha Sharmacc656962020-04-14 14:26:11 +0000152 flag.DurationVar(&(so.KVStoreTimeout), "kv_store_request_timeout", defaultKvstoretimeout, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400153
Neha Sharma3f221ae2020-04-29 19:02:12 +0000154 help = fmt.Sprintf("KV store address")
155 flag.StringVar(&(so.KVStoreAddress), "kv_store_address", defaultKvstoreaddress, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400156
157 help = fmt.Sprintf("Log level")
Rohan Agrawal2488f192020-01-31 09:26:55 +0000158 flag.StringVar(&(so.LogLevel), "log_level", defaultLoglevel, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400159
160 help = fmt.Sprintf("Number of ONUs")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700161 flag.IntVar(&(so.OnuNumber), "onu_number", defaultOnunumber, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400162
163 help = fmt.Sprintf("Show startup banner log lines")
Matt Jeanneretf880eb62019-07-16 20:08:03 -0400164 flag.BoolVar(&(so.Banner), "banner", defaultBanner, help)
165
166 help = fmt.Sprintf("Show version information and exit")
167 flag.BoolVar(&(so.DisplayVersionOnly), "version", defaultDisplayVersionOnly, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400168
Rohan Agrawal828bf4e2019-10-22 10:13:19 +0000169 help = fmt.Sprintf("The address on which to listen to answer liveness and readiness probe queries over HTTP.")
Neha Sharma3f221ae2020-04-29 19:02:12 +0000170 flag.StringVar(&(so.ProbeAddress), "probe_address", defaultProbeAddress, help)
Rohan Agrawal828bf4e2019-10-22 10:13:19 +0000171
cbabu116b73f2019-12-10 17:56:32 +0530172 help = fmt.Sprintf("Number of seconds for the default liveliness check")
173 flag.DurationVar(&(so.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, help)
174
175 help = fmt.Sprintf("Number of seconds for liveliness check if probe is not running")
176 flag.DurationVar(&(so.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, help)
177
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530178 help = fmt.Sprintf("Number of seconds for heartbeat check interval.")
Girish Gowdra495dde42021-03-17 14:59:56 -0700179 flag.DurationVar(&(so.HeartbeatCheckInterval), "heartbeat_check_interval", defaultHeartbeatCheckInterval, help)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400180
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530181 help = fmt.Sprintf("Number of seconds adapter has to wait before reporting core on the hearbeat check failure.")
Girish Gowdra495dde42021-03-17 14:59:56 -0700182 flag.DurationVar(&(so.HeartbeatFailReportInterval), "heartbeat_fail_interval", defaultHeartbeatFailReportInterval, help)
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530183
184 help = fmt.Sprintf("Number of seconds for GRPC timeout.")
185 flag.DurationVar(&(so.GrpcTimeoutInterval), "grpc_timeout_interval", defaultGrpcTimeoutInterval, help)
186
Matteo Scandolo3ad5d2b2020-04-02 17:02:04 -0700187 help = "Replica number of this particular instance (default: %s)"
188 flag.IntVar(&(so.CurrentReplica), "current_replica", defaultCurrentReplica, help)
189
190 help = "Total number of instances for this adapter"
191 flag.IntVar(&(so.TotalReplicas), "total_replica", defaultTotalReplicas, help)
192
Girish Kumar11e15972020-06-15 14:51:10 +0000193 help = fmt.Sprintf("Whether to send logs to tracing agent?")
194 flag.BoolVar(&(so.TraceEnabled), "trace_enabled", defaultTraceEnabled, help)
195
196 help = fmt.Sprintf("The address of tracing agent to which span info should be sent.")
197 flag.StringVar(&(so.TraceAgentAddress), "trace_agent_address", defaultTraceAgentAddress, help)
198
199 help = fmt.Sprintf("Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
200 flag.BoolVar(&(so.LogCorrelationEnabled), "log_correlation_enabled", defaultLogCorrelationEnabled, help)
201
kesavand494c2082020-08-31 11:16:12 +0530202 help = fmt.Sprintf("OMCI Channel encryption status")
203 flag.BoolVar(&(so.OmccEncryption), "omcc_encryption", defaultOmccEncryption, help)
204
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000205 help = fmt.Sprintf("Enable ONU Statistics")
206 flag.BoolVar(&(so.EnableONUStats), "enable_onu_stats", defaultEnableONUStats, help)
207
208 help = fmt.Sprintf("Enable GEM Statistics")
209 flag.BoolVar(&(so.EnableGEMStats), "enable_gem_stats", defaultEnableGEMStats, help)
210
Matteo Scandolo66fbaf52021-03-24 14:13:38 -0700211 help = fmt.Sprintf("Number of seconds for reconnection retries to a device")
212 flag.DurationVar(&(so.ReconnectTimeout), "reconnection_timeout", defaultReconnectTimeout, help)
213
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530214 flag.Parse()
Girish Gowdru0c588b22019-04-23 23:24:56 -0400215 containerName := getContainerInfo()
216 if len(containerName) > 0 {
217 so.InstanceID = containerName
218 }
219
220}
221
222func getContainerInfo() string {
223 return os.Getenv("HOSTNAME")
224}