blob: 5bec5262202fd25453a7f0bde957fbcc0143159b [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 defaultOltTopic = "openolt"
45 defaultCoreTopic = "rwcore"
46 defaultEventTopic = "voltha.events"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000047 defaultOnunumber = 1
48 defaultProbeHost = ""
49 defaultProbePort = 8080
50 defaultLiveProbeInterval = 60 * time.Second
51 defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
52 //defaultHearbeatFailReportInterval is the time in seconds the adapter will keep checking the hardware for heartbeat.
53 defaultHearbeatCheckInterval = 30 * time.Second
54 // defaultHearbeatFailReportInterval is the time adapter will wait before updating the state to the core.
55 defaultHearbeatFailReportInterval = 180 * time.Second
56 //defaultKafkaReconnectRetries -1: reconnect endlessly.
Himani Chawlad96df182020-09-28 11:12:02 +053057 defaultKafkaReconnectRetries = -1
58 defaultCurrentReplica = 1
59 defaultTotalReplicas = 1
60 defaultMaxTimeoutInterAdapterComm = 30 * time.Second
Holger Hildebrandtfa074992020-03-27 15:42:06 +000061)
62
63// AdapterFlags represents the set of configurations used by the read-write adaptercore service
64type AdapterFlags struct {
65 // Command line parameters
66 InstanceID string
67 KafkaAdapterHost string
68 KafkaAdapterPort int
69 KafkaClusterHost string
70 KafkaClusterPort int
71 KVStoreType string
mpagenkoaf801632020-07-03 10:00:42 +000072 KVStoreTimeout time.Duration
Holger Hildebrandtfa074992020-03-27 15:42:06 +000073 KVStoreHost string
74 KVStorePort int
75 Topic string
Holger Hildebrandta768fe92020-10-01 13:06:21 +000076 OltTopic string
Holger Hildebrandtfa074992020-03-27 15:42:06 +000077 CoreTopic string
78 EventTopic string
79 LogLevel string
80 OnuNumber int
81 Banner bool
82 DisplayVersionOnly bool
mpagenkodff5dda2020-08-28 11:52:01 +000083 AccIncrEvto bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +000084 ProbeHost string
85 ProbePort int
86 LiveProbeInterval time.Duration
87 NotLiveProbeInterval time.Duration
88 HeartbeatCheckInterval time.Duration
89 HeartbeatFailReportInterval time.Duration
90 KafkaReconnectRetries int
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000091 CurrentReplica int
92 TotalReplicas int
Himani Chawlad96df182020-09-28 11:12:02 +053093 MaxTimeoutInterAdapterComm time.Duration
Holger Hildebrandtfa074992020-03-27 15:42:06 +000094}
95
96// NewAdapterFlags returns a new RWCore config
97func NewAdapterFlags() *AdapterFlags {
98 var adapterFlags = AdapterFlags{ // Default values
99 InstanceID: defaultInstanceid,
100 KafkaAdapterHost: defaultKafkaadapterhost,
101 KafkaAdapterPort: defaultKafkaadapterport,
102 KafkaClusterHost: defaultKafkaclusterhost,
103 KafkaClusterPort: defaultKafkaclusterport,
104 KVStoreType: defaultKvstoretype,
105 KVStoreTimeout: defaultKvstoretimeout,
106 KVStoreHost: defaultKvstorehost,
107 KVStorePort: defaultKvstoreport,
108 Topic: defaultTopic,
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000109 OltTopic: defaultOltTopic,
110 CoreTopic: defaultCoreTopic,
111 EventTopic: defaultEventTopic,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000112 LogLevel: defaultLoglevel,
113 OnuNumber: defaultOnunumber,
114 Banner: defaultBanner,
115 DisplayVersionOnly: defaultDisplayVersionOnly,
mpagenkodff5dda2020-08-28 11:52:01 +0000116 AccIncrEvto: defaultAccIncrEvto,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000117 ProbeHost: defaultProbeHost,
118 ProbePort: defaultProbePort,
119 LiveProbeInterval: defaultLiveProbeInterval,
120 NotLiveProbeInterval: defaultNotLiveProbeInterval,
121 HeartbeatCheckInterval: defaultHearbeatCheckInterval,
122 HeartbeatFailReportInterval: defaultHearbeatFailReportInterval,
123 KafkaReconnectRetries: defaultKafkaReconnectRetries,
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000124 CurrentReplica: defaultCurrentReplica,
125 TotalReplicas: defaultTotalReplicas,
Himani Chawlad96df182020-09-28 11:12:02 +0530126 MaxTimeoutInterAdapterComm: defaultMaxTimeoutInterAdapterComm,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000127 }
128 return &adapterFlags
129}
130
131// ParseCommandArguments parses the arguments when running read-write adaptercore service
132func (so *AdapterFlags) ParseCommandArguments() {
133
134 help := fmt.Sprintf("Kafka - Adapter messaging host")
135 flag.StringVar(&(so.KafkaAdapterHost), "kafka_adapter_host", defaultKafkaadapterhost, help)
136
137 help = fmt.Sprintf("Kafka - Adapter messaging port")
138 flag.IntVar(&(so.KafkaAdapterPort), "kafka_adapter_port", defaultKafkaadapterport, help)
139
140 help = fmt.Sprintf("Kafka - Cluster messaging host")
141 flag.StringVar(&(so.KafkaClusterHost), "kafka_cluster_host", defaultKafkaclusterhost, help)
142
143 help = fmt.Sprintf("Kafka - Cluster messaging port")
144 flag.IntVar(&(so.KafkaClusterPort), "kafka_cluster_port", defaultKafkaclusterport, help)
145
146 help = fmt.Sprintf("Open ONU topic")
147 flag.StringVar(&(so.Topic), "adapter_topic", defaultTopic, help)
148
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000149 help = fmt.Sprintf("Open OLT topic")
150 flag.StringVar(&(so.OltTopic), "olt_adapter_topic", defaultOltTopic, help)
151
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000152 help = fmt.Sprintf("Core topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000153 flag.StringVar(&(so.CoreTopic), "core_topic", defaultCoreTopic, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000154
155 help = fmt.Sprintf("Event topic")
Holger Hildebrandta768fe92020-10-01 13:06:21 +0000156 flag.StringVar(&(so.EventTopic), "event_topic", defaultEventTopic, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000157
158 help = fmt.Sprintf("KV store type")
159 flag.StringVar(&(so.KVStoreType), "kv_store_type", defaultKvstoretype, help)
160
161 help = fmt.Sprintf("The default timeout when making a kv store request")
mpagenkoaf801632020-07-03 10:00:42 +0000162 flag.DurationVar(&(so.KVStoreTimeout), "kv_store_request_timeout", defaultKvstoretimeout, help)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000163
164 help = fmt.Sprintf("KV store host")
165 flag.StringVar(&(so.KVStoreHost), "kv_store_host", defaultKvstorehost, help)
166
167 help = fmt.Sprintf("KV store port")
168 flag.IntVar(&(so.KVStorePort), "kv_store_port", defaultKvstoreport, help)
169
170 help = fmt.Sprintf("Log level")
171 flag.StringVar(&(so.LogLevel), "log_level", defaultLoglevel, help)
172
173 help = fmt.Sprintf("Number of ONUs")
174 flag.IntVar(&(so.OnuNumber), "onu_number", defaultOnunumber, help)
175
176 help = fmt.Sprintf("Show startup banner log lines")
177 flag.BoolVar(&(so.Banner), "banner", defaultBanner, help)
178
179 help = fmt.Sprintf("Show version information and exit")
180 flag.BoolVar(&(so.DisplayVersionOnly), "version", defaultDisplayVersionOnly, help)
181
mpagenkodff5dda2020-08-28 11:52:01 +0000182 help = fmt.Sprintf("Acceptance of incremental EVTOCD configuration")
183 flag.BoolVar(&(so.AccIncrEvto), "accept_incr_evto", defaultAccIncrEvto, help)
184
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000185 help = fmt.Sprintf("The address on which to listen to answer liveness and readiness probe queries over HTTP.")
186 flag.StringVar(&(so.ProbeHost), "probe_host", defaultProbeHost, help)
187
188 help = fmt.Sprintf("The port on which to listen to answer liveness and readiness probe queries over HTTP.")
189 flag.IntVar(&(so.ProbePort), "probe_port", defaultProbePort, help)
190
191 help = fmt.Sprintf("Number of seconds for the default liveliness check")
192 flag.DurationVar(&(so.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, help)
193
194 help = fmt.Sprintf("Number of seconds for liveliness check if probe is not running")
195 flag.DurationVar(&(so.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, help)
196
197 help = fmt.Sprintf("Number of seconds for heartbeat check interval.")
198 flag.DurationVar(&(so.HeartbeatCheckInterval), "hearbeat_check_interval", defaultHearbeatCheckInterval, help)
199
200 help = fmt.Sprintf("Number of seconds adapter has to wait before reporting core on the hearbeat check failure.")
201 flag.DurationVar(&(so.HeartbeatFailReportInterval), "hearbeat_fail_interval", defaultHearbeatFailReportInterval, help)
202
203 help = fmt.Sprintf("Number of retries to connect to Kafka.")
204 flag.IntVar(&(so.KafkaReconnectRetries), "kafka_reconnect_retries", defaultKafkaReconnectRetries, help)
205
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000206 help = "Replica number of this particular instance (default: %s)"
207 flag.IntVar(&(so.CurrentReplica), "current_replica", defaultCurrentReplica, help)
208
209 help = "Total number of instances for this adapter"
210 flag.IntVar(&(so.TotalReplicas), "total_replica", defaultTotalReplicas, help)
211
Himani Chawlad96df182020-09-28 11:12:02 +0530212 help = fmt.Sprintf("Maximum Number of seconds for the default interadapter communication timeout")
213 flag.DurationVar(&(so.MaxTimeoutInterAdapterComm), "max_timeout_interadapter_comm",
214 defaultMaxTimeoutInterAdapterComm, help)
215
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000216 flag.Parse()
217 containerName := getContainerInfo()
218 if len(containerName) > 0 {
219 so.InstanceID = containerName
220 }
221
222}
223
224func getContainerInfo() string {
225 return os.Getenv("HOSTNAME")
226}