blob: 68d1b29535ad0ecfb54da596231f1dbb10b87ce0 [file] [log] [blame]
Takahiro Suzukid7bf8202020-12-17 20:21:59 +09001/*
2* Copyright 2020-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 "os"
23 "time"
24)
25
26// Open OLT default constants
27const (
28 EtcdStoreName = "etcd"
29 defaultInstanceid = "openOlt001"
30 defaultKafkaadapteraddress = "127.0.0.1:9092"
31 defaultKafkaclusteraddress = "127.0.0.1:9094"
32 defaultKvstoretype = EtcdStoreName
33 defaultKvstoretimeout = 5 * time.Second
34 defaultKvstoreaddress = "127.0.0.1:2379" // Port: Consul = 8500; Etcd = 2379
35 defaultLoglevel = "WARN"
36 defaultBanner = false
37 defaultDisplayVersionOnly = false
38 defaultTopic = "openolt"
39 defaultCoretopic = "rwcore"
40 defaultEventtopic = "voltha.events"
41 defaultOnunumber = 1
42 defaultProbeAddress = ":8080"
43 defaultLiveProbeInterval = 60 * time.Second
44 defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
45 defaultHearbeatCheckInterval = 15 * time.Second
46 defaultHearbeatFailReportInterval = 0 * time.Second
47 defaultGrpcTimeoutInterval = 2 * time.Second
48 defaultCurrentReplica = 1
49 defaultTotalReplicas = 1
50 defaultTraceEnabled = false
51 defaultTraceAgentAddress = "127.0.0.1:6831"
52 defaultLogCorrelationEnabled = true
53 defaultInterfaceName = "eth0"
54 defaultSrcMac = ""
55)
56
57// AdapterFlags represents the set of configurations used by the read-write adaptercore service
58type AdapterFlags struct {
59 InstanceID string
60 KafkaAdapterAddress string
61 KafkaClusterAddress string
62 KVStoreType string
63 KVStoreTimeout time.Duration
64 KVStoreAddress string
65 Topic string
66 CoreTopic string
67 EventTopic string
68 LogLevel string
69 OnuNumber int
70 Banner bool
71 DisplayVersionOnly bool
72 ProbeAddress string
73 LiveProbeInterval time.Duration
74 NotLiveProbeInterval time.Duration
75 HeartbeatCheckInterval time.Duration
76 HeartbeatFailReportInterval time.Duration
77 GrpcTimeoutInterval time.Duration
78 CurrentReplica int
79 TotalReplicas int
80 TraceEnabled bool
81 TraceAgentAddress string
82 LogCorrelationEnabled bool
83 InterfaceName string
84 SrcMac string
85}
86
87// NewAdapterFlags returns a new RWCore config
88func NewAdapterFlags() *AdapterFlags {
89 var adapterFlags = AdapterFlags{ // Default values
90 InstanceID: defaultInstanceid,
91 KafkaAdapterAddress: defaultKafkaadapteraddress,
92 KafkaClusterAddress: defaultKafkaclusteraddress,
93 KVStoreType: defaultKvstoretype,
94 KVStoreTimeout: defaultKvstoretimeout,
95 KVStoreAddress: defaultKvstoreaddress,
96 Topic: defaultTopic,
97 CoreTopic: defaultCoretopic,
98 EventTopic: defaultEventtopic,
99 LogLevel: defaultLoglevel,
100 OnuNumber: defaultOnunumber,
101 Banner: defaultBanner,
102 DisplayVersionOnly: defaultDisplayVersionOnly,
103 ProbeAddress: defaultProbeAddress,
104 LiveProbeInterval: defaultLiveProbeInterval,
105 NotLiveProbeInterval: defaultNotLiveProbeInterval,
106 HeartbeatCheckInterval: defaultHearbeatCheckInterval,
107 HeartbeatFailReportInterval: defaultHearbeatFailReportInterval,
108 GrpcTimeoutInterval: defaultGrpcTimeoutInterval,
109 TraceEnabled: defaultTraceEnabled,
110 TraceAgentAddress: defaultTraceAgentAddress,
111 LogCorrelationEnabled: defaultLogCorrelationEnabled,
112 InterfaceName: defaultInterfaceName,
113 SrcMac: defaultSrcMac,
114 }
115 return &adapterFlags
116}
117
118// ParseCommandArguments parses the arguments when running read-write adaptercore service
119func (so *AdapterFlags) ParseCommandArguments() {
120
121 help := "Kafka - Adapter messaging address"
122 flag.StringVar(&(so.KafkaAdapterAddress), "kafka_adapter_address", defaultKafkaadapteraddress, help)
123
124 help = "Kafka - Cluster messaging address"
125 flag.StringVar(&(so.KafkaClusterAddress), "kafka_cluster_address", defaultKafkaclusteraddress, help)
126
127 help = "Open OLT topic"
128 flag.StringVar(&(so.Topic), "adapter_topic", defaultTopic, help)
129
130 help = "Core topic"
131 flag.StringVar(&(so.CoreTopic), "core_topic", defaultCoretopic, help)
132
133 help = "Event topic"
134 flag.StringVar(&(so.EventTopic), "event_topic", defaultEventtopic, help)
135
136 help = "KV store type"
137 flag.StringVar(&(so.KVStoreType), "kv_store_type", defaultKvstoretype, help)
138
139 help = "The default timeout when making a kv store request"
140 flag.DurationVar(&(so.KVStoreTimeout), "kv_store_request_timeout", defaultKvstoretimeout, help)
141
142 help = "KV store address"
143 flag.StringVar(&(so.KVStoreAddress), "kv_store_address", defaultKvstoreaddress, help)
144
145 help = "Log level"
146 flag.StringVar(&(so.LogLevel), "log_level", defaultLoglevel, help)
147
148 help = "Number of ONUs"
149 flag.IntVar(&(so.OnuNumber), "onu_number", defaultOnunumber, help)
150
151 help = "Show startup banner log lines"
152 flag.BoolVar(&(so.Banner), "banner", defaultBanner, help)
153
154 help = "Show version information and exit"
155 flag.BoolVar(&(so.DisplayVersionOnly), "version", defaultDisplayVersionOnly, help)
156
157 help = "The address on which to listen to answer liveness and readiness probe queries over HTTP."
158 flag.StringVar(&(so.ProbeAddress), "probe_address", defaultProbeAddress, help)
159
160 help = "Number of seconds for the default liveliness check"
161 flag.DurationVar(&(so.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, help)
162
163 help = "Number of seconds for liveliness check if probe is not running"
164 flag.DurationVar(&(so.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, help)
165
166 help = "Number of seconds for heartbeat check interval."
167 flag.DurationVar(&(so.HeartbeatCheckInterval), "hearbeat_check_interval", defaultHearbeatCheckInterval, help)
168
169 help = "Number of seconds adapter has to wait before reporting core on the hearbeat check failure."
170 flag.DurationVar(&(so.HeartbeatFailReportInterval), "hearbeat_fail_interval", defaultHearbeatFailReportInterval, help)
171
172 help = "Number of seconds for GRPC timeout."
173 flag.DurationVar(&(so.GrpcTimeoutInterval), "grpc_timeout_interval", defaultGrpcTimeoutInterval, help)
174
175 help = "Replica number of this particular instance (default: %s)"
176 flag.IntVar(&(so.CurrentReplica), "current_replica", defaultCurrentReplica, help)
177
178 help = "Total number of instances for this adapter"
179 flag.IntVar(&(so.TotalReplicas), "total_replica", defaultTotalReplicas, help)
180
181 help = "Whether to send logs to tracing agent?"
182 flag.BoolVar(&(so.TraceEnabled), "trace_enabled", defaultTraceEnabled, help)
183
184 help = "The address of tracing agent to which span info should be sent."
185 flag.StringVar(&(so.TraceAgentAddress), "trace_agent_address", defaultTraceAgentAddress, help)
186
187 help = "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?"
188 flag.BoolVar(&(so.LogCorrelationEnabled), "log_correlation_enabled", defaultLogCorrelationEnabled, help)
189
190 help = "Interface name."
191 flag.StringVar(&(so.InterfaceName), "interface_name", defaultInterfaceName, help)
192
193 help = "Source mac address."
194 flag.StringVar(&(so.SrcMac), "src_mac", defaultSrcMac, help)
195
196 flag.Parse()
197 containerName := getContainerInfo()
198 if len(containerName) > 0 {
199 so.InstanceID = containerName
200 }
201
202}
203
204func getContainerInfo() string {
205 return os.Getenv("HOSTNAME")
206}