Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 1 | /* |
| 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 |
| 18 | package config |
| 19 | |
| 20 | import ( |
| 21 | "flag" |
| 22 | "fmt" |
| 23 | "os" |
| 24 | "time" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 25 | ) |
| 26 | |
| 27 | // Open ONU default constants |
| 28 | const ( |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 29 | etcdStoreName = "etcd" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 30 | defaultInstanceid = "openonu" |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 31 | defaultKafkaadapteraddress = "127.0.0.1:9092" |
| 32 | defaultKafkaclusteraddress = "127.0.0.1:9092" |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 33 | defaultKvstoretype = etcdStoreName |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 34 | defaultKvstoretimeout = 5 * time.Second |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 35 | defaultKvstoreaddress = "127.0.0.1:2379" |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 36 | defaultLoglevel = "WARN" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 37 | defaultBanner = false |
| 38 | defaultDisplayVersionOnly = false |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 39 | defaultAccIncrEvto = false |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 40 | defaultTopic = "openonu" |
Holger Hildebrandt | a768fe9 | 2020-10-01 13:06:21 +0000 | [diff] [blame] | 41 | defaultCoreTopic = "rwcore" |
| 42 | defaultEventTopic = "voltha.events" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 43 | defaultOnunumber = 1 |
| 44 | defaultProbeHost = "" |
| 45 | defaultProbePort = 8080 |
| 46 | defaultLiveProbeInterval = 60 * time.Second |
| 47 | defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive |
| 48 | //defaultHearbeatFailReportInterval is the time in seconds the adapter will keep checking the hardware for heartbeat. |
| 49 | defaultHearbeatCheckInterval = 30 * time.Second |
| 50 | // defaultHearbeatFailReportInterval is the time adapter will wait before updating the state to the core. |
| 51 | defaultHearbeatFailReportInterval = 180 * time.Second |
| 52 | //defaultKafkaReconnectRetries -1: reconnect endlessly. |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 53 | defaultKafkaReconnectRetries = -1 |
| 54 | defaultCurrentReplica = 1 |
| 55 | defaultTotalReplicas = 1 |
| 56 | defaultMaxTimeoutInterAdapterComm = 30 * time.Second |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 57 | defaultMaxTimeoutReconciling = 10 * time.Second |
Andrea Campanella | 3d7c931 | 2021-01-19 09:20:49 +0100 | [diff] [blame] | 58 | defaultOnuVendorIds = "OPEN,ALCL,BRCM,TWSH,ALPH,ISKT,SFAA,BBSM,SCOM,ARPX,DACM,ERSN,HWTC,CIGG,ADTN,ARCA,AVMG" |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 59 | |
| 60 | // For Tracing |
| 61 | defaultTraceEnabled = false |
| 62 | defaultTraceAgentAddress = "127.0.0.1:6831" |
| 63 | defaultLogCorrelationEnabled = true |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 64 | |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 65 | defaultMetricsEnabled = false |
| 66 | defaultMibAuditInterval = 0 |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 67 | ) |
| 68 | |
| 69 | // AdapterFlags represents the set of configurations used by the read-write adaptercore service |
| 70 | type AdapterFlags struct { |
| 71 | // Command line parameters |
| 72 | InstanceID string |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 73 | KafkaAdapterAddress string |
| 74 | KafkaClusterAddress string // NOTE this is unused across the adapter |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 75 | KVStoreType string |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 76 | KVStoreTimeout time.Duration |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 77 | KVStoreAddress string |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 78 | Topic string |
| 79 | CoreTopic string |
| 80 | EventTopic string |
| 81 | LogLevel string |
| 82 | OnuNumber int |
| 83 | Banner bool |
| 84 | DisplayVersionOnly bool |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 85 | AccIncrEvto bool |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 86 | ProbeHost string |
| 87 | ProbePort int |
| 88 | LiveProbeInterval time.Duration |
| 89 | NotLiveProbeInterval time.Duration |
| 90 | HeartbeatCheckInterval time.Duration |
| 91 | HeartbeatFailReportInterval time.Duration |
| 92 | KafkaReconnectRetries int |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 93 | CurrentReplica int |
| 94 | TotalReplicas int |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 95 | MaxTimeoutInterAdapterComm time.Duration |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 96 | MaxTimeoutReconciling time.Duration |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 97 | TraceEnabled bool |
| 98 | TraceAgentAddress string |
| 99 | LogCorrelationEnabled bool |
Andrea Campanella | 3d7c931 | 2021-01-19 09:20:49 +0100 | [diff] [blame] | 100 | OnuVendorIds string |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 101 | MetricsEnabled bool |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 102 | MibAuditInterval time.Duration |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | // NewAdapterFlags returns a new RWCore config |
| 106 | func NewAdapterFlags() *AdapterFlags { |
| 107 | var adapterFlags = AdapterFlags{ // Default values |
| 108 | InstanceID: defaultInstanceid, |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 109 | KafkaAdapterAddress: defaultKafkaadapteraddress, |
| 110 | KafkaClusterAddress: defaultKafkaclusteraddress, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 111 | KVStoreType: defaultKvstoretype, |
| 112 | KVStoreTimeout: defaultKvstoretimeout, |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 113 | KVStoreAddress: defaultKvstoreaddress, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 114 | Topic: defaultTopic, |
Holger Hildebrandt | a768fe9 | 2020-10-01 13:06:21 +0000 | [diff] [blame] | 115 | CoreTopic: defaultCoreTopic, |
| 116 | EventTopic: defaultEventTopic, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 117 | LogLevel: defaultLoglevel, |
| 118 | OnuNumber: defaultOnunumber, |
| 119 | Banner: defaultBanner, |
| 120 | DisplayVersionOnly: defaultDisplayVersionOnly, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 121 | AccIncrEvto: defaultAccIncrEvto, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 122 | ProbeHost: defaultProbeHost, |
| 123 | ProbePort: defaultProbePort, |
| 124 | LiveProbeInterval: defaultLiveProbeInterval, |
| 125 | NotLiveProbeInterval: defaultNotLiveProbeInterval, |
| 126 | HeartbeatCheckInterval: defaultHearbeatCheckInterval, |
| 127 | HeartbeatFailReportInterval: defaultHearbeatFailReportInterval, |
| 128 | KafkaReconnectRetries: defaultKafkaReconnectRetries, |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 129 | CurrentReplica: defaultCurrentReplica, |
| 130 | TotalReplicas: defaultTotalReplicas, |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 131 | MaxTimeoutInterAdapterComm: defaultMaxTimeoutInterAdapterComm, |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 132 | MaxTimeoutReconciling: defaultMaxTimeoutReconciling, |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 133 | TraceEnabled: defaultTraceEnabled, |
| 134 | TraceAgentAddress: defaultTraceAgentAddress, |
| 135 | LogCorrelationEnabled: defaultLogCorrelationEnabled, |
Andrea Campanella | 3d7c931 | 2021-01-19 09:20:49 +0100 | [diff] [blame] | 136 | OnuVendorIds: defaultOnuVendorIds, |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 137 | MetricsEnabled: defaultMetricsEnabled, |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 138 | MibAuditInterval: defaultMibAuditInterval, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 139 | } |
| 140 | return &adapterFlags |
| 141 | } |
| 142 | |
| 143 | // ParseCommandArguments parses the arguments when running read-write adaptercore service |
| 144 | func (so *AdapterFlags) ParseCommandArguments() { |
| 145 | |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 146 | help := fmt.Sprintf("Kafka - Adapter messaging address") |
| 147 | flag.StringVar(&(so.KafkaAdapterAddress), "kafka_adapter_address", defaultKafkaadapteraddress, help) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 148 | |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 149 | help = fmt.Sprintf("Kafka - Cluster messaging address") |
| 150 | flag.StringVar(&(so.KafkaClusterAddress), "kafka_cluster_address", defaultKafkaclusteraddress, help) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 151 | |
| 152 | help = fmt.Sprintf("Open ONU topic") |
Andrea Campanella | 961734c | 2021-01-18 11:44:47 +0100 | [diff] [blame] | 153 | baseAdapterTopic := flag.String("adapter_topic", defaultTopic, help) |
Holger Hildebrandt | a768fe9 | 2020-10-01 13:06:21 +0000 | [diff] [blame] | 154 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 155 | help = fmt.Sprintf("Core topic") |
Holger Hildebrandt | a768fe9 | 2020-10-01 13:06:21 +0000 | [diff] [blame] | 156 | flag.StringVar(&(so.CoreTopic), "core_topic", defaultCoreTopic, help) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 157 | |
| 158 | help = fmt.Sprintf("Event topic") |
Holger Hildebrandt | a768fe9 | 2020-10-01 13:06:21 +0000 | [diff] [blame] | 159 | flag.StringVar(&(so.EventTopic), "event_topic", defaultEventTopic, help) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 160 | |
| 161 | help = fmt.Sprintf("KV store type") |
| 162 | flag.StringVar(&(so.KVStoreType), "kv_store_type", defaultKvstoretype, help) |
| 163 | |
| 164 | help = fmt.Sprintf("The default timeout when making a kv store request") |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 165 | flag.DurationVar(&(so.KVStoreTimeout), "kv_store_request_timeout", defaultKvstoretimeout, help) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 166 | |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 167 | help = fmt.Sprintf("KV store address") |
| 168 | flag.StringVar(&(so.KVStoreAddress), "kv_store_address", defaultKvstoreaddress, help) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 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 | |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 182 | help = fmt.Sprintf("Acceptance of incremental EVTOCD configuration") |
| 183 | flag.BoolVar(&(so.AccIncrEvto), "accept_incr_evto", defaultAccIncrEvto, help) |
| 184 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 185 | 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 Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 206 | 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 Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 212 | 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 Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 216 | help = fmt.Sprintf("Maximum Number of seconds for the default ONU reconciling timeout") |
| 217 | flag.DurationVar(&(so.MaxTimeoutReconciling), "max_timeout_reconciling", |
| 218 | defaultMaxTimeoutReconciling, help) |
| 219 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 220 | help = fmt.Sprintf("Whether to send logs to tracing agent?") |
| 221 | flag.BoolVar(&(so.TraceEnabled), "trace_enabled", defaultTraceEnabled, help) |
| 222 | |
| 223 | help = fmt.Sprintf("The address of tracing agent to which span info should be sent.") |
| 224 | flag.StringVar(&(so.TraceAgentAddress), "trace_agent_address", defaultTraceAgentAddress, help) |
| 225 | |
| 226 | help = fmt.Sprintf("Whether to enrich log statements with fields denoting operation being executed for achieving correlation?") |
| 227 | flag.BoolVar(&(so.LogCorrelationEnabled), "log_correlation_enabled", defaultLogCorrelationEnabled, help) |
| 228 | |
Andrea Campanella | 3d7c931 | 2021-01-19 09:20:49 +0100 | [diff] [blame] | 229 | help = fmt.Sprintf("List of Allowed ONU Vendor Ids") |
| 230 | flag.StringVar(&(so.OnuVendorIds), "allowed_onu_vendors", defaultOnuVendorIds, help) |
| 231 | |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 232 | help = fmt.Sprintf("Whether to enable metrics collection") |
| 233 | flag.BoolVar(&(so.MetricsEnabled), "metrics_enabled", defaultMetricsEnabled, help) |
| 234 | |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 235 | help = fmt.Sprintf("Mib Audit Interval in seconds - the value zero will disable Mib Audit") |
| 236 | flag.DurationVar(&(so.MibAuditInterval), "mib_audit_interval", defaultMibAuditInterval, help) |
| 237 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 238 | flag.Parse() |
| 239 | containerName := getContainerInfo() |
| 240 | if len(containerName) > 0 { |
| 241 | so.InstanceID = containerName |
| 242 | } |
| 243 | |
Andrea Campanella | 961734c | 2021-01-18 11:44:47 +0100 | [diff] [blame] | 244 | so.Topic = fmt.Sprintf("%s_%d", *baseAdapterTopic, int32(so.CurrentReplica)) |
| 245 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | func getContainerInfo() string { |
| 249 | return os.Getenv("HOSTNAME") |
| 250 | } |