blob: 9ceca406b15527ebcec2f029afafa7fc3f12fa85 [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001/*
2* Copyright 2018-present Open Networking Foundation
3
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
7
8* http://www.apache.org/licenses/LICENSE-2.0
9
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.
15 */
16
17//Package config provides the Log, kvstore, Kafka configuration
18package config
19
20import (
21 "flag"
22 "fmt"
23 "os"
24 "time"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000025)
26
27// Open ONU default constants
28const (
Himani Chawla6d2ae152020-09-02 13:11:20 +053029 etcdStoreName = "etcd"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000030 defaultInstanceid = "openonu"
31 defaultKafkaadapterhost = "192.168.0.20"
32 defaultKafkaadapterport = 9092
33 defaultKafkaclusterhost = "10.100.198.220"
34 defaultKafkaclusterport = 9092
Himani Chawla6d2ae152020-09-02 13:11:20 +053035 defaultKvstoretype = etcdStoreName
mpagenkoaf801632020-07-03 10:00:42 +000036 defaultKvstoretimeout = 5 * time.Second
Holger Hildebrandtfa074992020-03-27 15:42:06 +000037 defaultKvstorehost = "localhost"
38 defaultKvstoreport = 2379 // Consul = 8500; Etcd = 2379
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000039 defaultLoglevel = "WARN"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000040 defaultBanner = false
41 defaultDisplayVersionOnly = false
mpagenkodff5dda2020-08-28 11:52:01 +000042 defaultAccIncrEvto = false
Holger Hildebrandtfa074992020-03-27 15:42:06 +000043 defaultTopic = "openonu"
Holger Hildebrandta768fe92020-10-01 13:06:21 +000044 defaultCoreTopic = "rwcore"
45 defaultEventTopic = "voltha.events"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000046 defaultOnunumber = 1
47 defaultProbeHost = ""
48 defaultProbePort = 8080
49 defaultLiveProbeInterval = 60 * time.Second
50 defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
51 //defaultHearbeatFailReportInterval is the time in seconds the adapter will keep checking the hardware for heartbeat.
52 defaultHearbeatCheckInterval = 30 * time.Second
53 // defaultHearbeatFailReportInterval is the time adapter will wait before updating the state to the core.
54 defaultHearbeatFailReportInterval = 180 * time.Second
55 //defaultKafkaReconnectRetries -1: reconnect endlessly.
Himani Chawlad96df182020-09-28 11:12:02 +053056 defaultKafkaReconnectRetries = -1
57 defaultCurrentReplica = 1
58 defaultTotalReplicas = 1
59 defaultMaxTimeoutInterAdapterComm = 30 * time.Second
Andrea Campanella3d7c9312021-01-19 09:20:49 +010060 defaultOnuVendorIds = "OPEN,ALCL,BRCM,TWSH,ALPH,ISKT,SFAA,BBSM,SCOM,ARPX,DACM,ERSN,HWTC,CIGG,ADTN,ARCA,AVMG"
dbainbri4d3a0dc2020-12-02 00:33:42 +000061
62 // For Tracing
63 defaultTraceEnabled = false
64 defaultTraceAgentAddress = "127.0.0.1:6831"
65 defaultLogCorrelationEnabled = true
Girish Gowdraaf0ad632021-01-27 13:00:01 -080066
67 defaultMetricsEnabled = false
Holger Hildebrandtfa074992020-03-27 15:42:06 +000068)
69
70// AdapterFlags represents the set of configurations used by the read-write adaptercore service
71type AdapterFlags struct {
72 // Command line parameters
73 InstanceID string
74 KafkaAdapterHost string
75 KafkaAdapterPort int
76 KafkaClusterHost string
77 KafkaClusterPort int
78 KVStoreType string
mpagenkoaf801632020-07-03 10:00:42 +000079 KVStoreTimeout time.Duration
Holger Hildebrandtfa074992020-03-27 15:42:06 +000080 KVStoreHost string
81 KVStorePort int
82 Topic string
83 CoreTopic string
84 EventTopic string
85 LogLevel string
86 OnuNumber int
87 Banner bool
88 DisplayVersionOnly bool
mpagenkodff5dda2020-08-28 11:52:01 +000089 AccIncrEvto bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +000090 ProbeHost string
91 ProbePort int
92 LiveProbeInterval time.Duration
93 NotLiveProbeInterval time.Duration
94 HeartbeatCheckInterval time.Duration
95 HeartbeatFailReportInterval time.Duration
96 KafkaReconnectRetries int
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000097 CurrentReplica int
98 TotalReplicas int
Himani Chawlad96df182020-09-28 11:12:02 +053099 MaxTimeoutInterAdapterComm time.Duration
dbainbri4d3a0dc2020-12-02 00:33:42 +0000100 TraceEnabled bool
101 TraceAgentAddress string
102 LogCorrelationEnabled bool
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100103 OnuVendorIds string
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800104 MetricsEnabled bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000105}
106
107// NewAdapterFlags returns a new RWCore config
108func NewAdapterFlags() *AdapterFlags {
109 var adapterFlags = AdapterFlags{ // Default values
110 InstanceID: defaultInstanceid,
111 KafkaAdapterHost: defaultKafkaadapterhost,
112 KafkaAdapterPort: defaultKafkaadapterport,
113 KafkaClusterHost: defaultKafkaclusterhost,
114 KafkaClusterPort: defaultKafkaclusterport,
115 KVStoreType: defaultKvstoretype,
116 KVStoreTimeout: defaultKvstoretimeout,
117 KVStoreHost: defaultKvstorehost,
118 KVStorePort: defaultKvstoreport,
119 Topic: defaultTopic,
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000120 CoreTopic: defaultCoreTopic,
121 EventTopic: defaultEventTopic,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000122 LogLevel: defaultLoglevel,
123 OnuNumber: defaultOnunumber,
124 Banner: defaultBanner,
125 DisplayVersionOnly: defaultDisplayVersionOnly,
mpagenkodff5dda2020-08-28 11:52:01 +0000126 AccIncrEvto: defaultAccIncrEvto,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000127 ProbeHost: defaultProbeHost,
128 ProbePort: defaultProbePort,
129 LiveProbeInterval: defaultLiveProbeInterval,
130 NotLiveProbeInterval: defaultNotLiveProbeInterval,
131 HeartbeatCheckInterval: defaultHearbeatCheckInterval,
132 HeartbeatFailReportInterval: defaultHearbeatFailReportInterval,
133 KafkaReconnectRetries: defaultKafkaReconnectRetries,
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000134 CurrentReplica: defaultCurrentReplica,
135 TotalReplicas: defaultTotalReplicas,
Himani Chawlad96df182020-09-28 11:12:02 +0530136 MaxTimeoutInterAdapterComm: defaultMaxTimeoutInterAdapterComm,
dbainbri4d3a0dc2020-12-02 00:33:42 +0000137 TraceEnabled: defaultTraceEnabled,
138 TraceAgentAddress: defaultTraceAgentAddress,
139 LogCorrelationEnabled: defaultLogCorrelationEnabled,
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100140 OnuVendorIds: defaultOnuVendorIds,
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800141 MetricsEnabled: defaultMetricsEnabled,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000142 }
143 return &adapterFlags
144}
145
146// ParseCommandArguments parses the arguments when running read-write adaptercore service
147func (so *AdapterFlags) ParseCommandArguments() {
148
149 help := fmt.Sprintf("Kafka - Adapter messaging host")
150 flag.StringVar(&(so.KafkaAdapterHost), "kafka_adapter_host", defaultKafkaadapterhost, help)
151
152 help = fmt.Sprintf("Kafka - Adapter messaging port")
153 flag.IntVar(&(so.KafkaAdapterPort), "kafka_adapter_port", defaultKafkaadapterport, help)
154
155 help = fmt.Sprintf("Kafka - Cluster messaging host")
156 flag.StringVar(&(so.KafkaClusterHost), "kafka_cluster_host", defaultKafkaclusterhost, help)
157
158 help = fmt.Sprintf("Kafka - Cluster messaging port")
159 flag.IntVar(&(so.KafkaClusterPort), "kafka_cluster_port", defaultKafkaclusterport, help)
160
161 help = fmt.Sprintf("Open ONU topic")
Andrea Campanella961734c2021-01-18 11:44:47 +0100162 baseAdapterTopic := flag.String("adapter_topic", defaultTopic, help)
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000163
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000164 help = fmt.Sprintf("Core topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000165 flag.StringVar(&(so.CoreTopic), "core_topic", defaultCoreTopic, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000166
167 help = fmt.Sprintf("Event topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000168 flag.StringVar(&(so.EventTopic), "event_topic", defaultEventTopic, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000169
170 help = fmt.Sprintf("KV store type")
171 flag.StringVar(&(so.KVStoreType), "kv_store_type", defaultKvstoretype, help)
172
173 help = fmt.Sprintf("The default timeout when making a kv store request")
mpagenkoaf801632020-07-03 10:00:42 +0000174 flag.DurationVar(&(so.KVStoreTimeout), "kv_store_request_timeout", defaultKvstoretimeout, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000175
176 help = fmt.Sprintf("KV store host")
177 flag.StringVar(&(so.KVStoreHost), "kv_store_host", defaultKvstorehost, help)
178
179 help = fmt.Sprintf("KV store port")
180 flag.IntVar(&(so.KVStorePort), "kv_store_port", defaultKvstoreport, help)
181
182 help = fmt.Sprintf("Log level")
183 flag.StringVar(&(so.LogLevel), "log_level", defaultLoglevel, help)
184
185 help = fmt.Sprintf("Number of ONUs")
186 flag.IntVar(&(so.OnuNumber), "onu_number", defaultOnunumber, help)
187
188 help = fmt.Sprintf("Show startup banner log lines")
189 flag.BoolVar(&(so.Banner), "banner", defaultBanner, help)
190
191 help = fmt.Sprintf("Show version information and exit")
192 flag.BoolVar(&(so.DisplayVersionOnly), "version", defaultDisplayVersionOnly, help)
193
mpagenkodff5dda2020-08-28 11:52:01 +0000194 help = fmt.Sprintf("Acceptance of incremental EVTOCD configuration")
195 flag.BoolVar(&(so.AccIncrEvto), "accept_incr_evto", defaultAccIncrEvto, help)
196
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000197 help = fmt.Sprintf("The address on which to listen to answer liveness and readiness probe queries over HTTP.")
198 flag.StringVar(&(so.ProbeHost), "probe_host", defaultProbeHost, help)
199
200 help = fmt.Sprintf("The port on which to listen to answer liveness and readiness probe queries over HTTP.")
201 flag.IntVar(&(so.ProbePort), "probe_port", defaultProbePort, help)
202
203 help = fmt.Sprintf("Number of seconds for the default liveliness check")
204 flag.DurationVar(&(so.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, help)
205
206 help = fmt.Sprintf("Number of seconds for liveliness check if probe is not running")
207 flag.DurationVar(&(so.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, help)
208
209 help = fmt.Sprintf("Number of seconds for heartbeat check interval.")
210 flag.DurationVar(&(so.HeartbeatCheckInterval), "hearbeat_check_interval", defaultHearbeatCheckInterval, help)
211
212 help = fmt.Sprintf("Number of seconds adapter has to wait before reporting core on the hearbeat check failure.")
213 flag.DurationVar(&(so.HeartbeatFailReportInterval), "hearbeat_fail_interval", defaultHearbeatFailReportInterval, help)
214
215 help = fmt.Sprintf("Number of retries to connect to Kafka.")
216 flag.IntVar(&(so.KafkaReconnectRetries), "kafka_reconnect_retries", defaultKafkaReconnectRetries, help)
217
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000218 help = "Replica number of this particular instance (default: %s)"
219 flag.IntVar(&(so.CurrentReplica), "current_replica", defaultCurrentReplica, help)
220
221 help = "Total number of instances for this adapter"
222 flag.IntVar(&(so.TotalReplicas), "total_replica", defaultTotalReplicas, help)
223
Himani Chawlad96df182020-09-28 11:12:02 +0530224 help = fmt.Sprintf("Maximum Number of seconds for the default interadapter communication timeout")
225 flag.DurationVar(&(so.MaxTimeoutInterAdapterComm), "max_timeout_interadapter_comm",
226 defaultMaxTimeoutInterAdapterComm, help)
227
dbainbri4d3a0dc2020-12-02 00:33:42 +0000228 help = fmt.Sprintf("Whether to send logs to tracing agent?")
229 flag.BoolVar(&(so.TraceEnabled), "trace_enabled", defaultTraceEnabled, help)
230
231 help = fmt.Sprintf("The address of tracing agent to which span info should be sent.")
232 flag.StringVar(&(so.TraceAgentAddress), "trace_agent_address", defaultTraceAgentAddress, help)
233
234 help = fmt.Sprintf("Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
235 flag.BoolVar(&(so.LogCorrelationEnabled), "log_correlation_enabled", defaultLogCorrelationEnabled, help)
236
Andrea Campanella3d7c9312021-01-19 09:20:49 +0100237 help = fmt.Sprintf("List of Allowed ONU Vendor Ids")
238 flag.StringVar(&(so.OnuVendorIds), "allowed_onu_vendors", defaultOnuVendorIds, help)
239
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800240 help = fmt.Sprintf("Whether to enable metrics collection")
241 flag.BoolVar(&(so.MetricsEnabled), "metrics_enabled", defaultMetricsEnabled, help)
242
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000243 flag.Parse()
244 containerName := getContainerInfo()
245 if len(containerName) > 0 {
246 so.InstanceID = containerName
247 }
248
Andrea Campanella961734c2021-01-18 11:44:47 +0100249 so.Topic = fmt.Sprintf("%s_%d", *baseAdapterTopic, int32(so.CurrentReplica))
250
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000251}
252
253func getContainerInfo() string {
254 return os.Getenv("HOSTNAME")
255}