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" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 22 | "os" |
| 23 | "time" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | // Open ONU default constants |
| 27 | const ( |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 28 | EtcdStoreName = "etcd" |
| 29 | OnuVendorIds = "OPEN,ALCL,BRCM,TWSH,ALPH,ISKT,SFAA,BBSM,SCOM,ARPX,DACM,ERSN,HWTC,CIGG,ADTN,ARCA,AVMG" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 30 | ) |
| 31 | |
| 32 | // AdapterFlags represents the set of configurations used by the read-write adaptercore service |
| 33 | type AdapterFlags struct { |
| 34 | // Command line parameters |
| 35 | InstanceID string |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 36 | KafkaClusterAddress string // NOTE this is unused across the adapter |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 37 | KVStoreType string |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 38 | KVStoreTimeout time.Duration |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 39 | KVStoreAddress string |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 40 | EventTopic string |
| 41 | LogLevel string |
| 42 | OnuNumber int |
| 43 | Banner bool |
| 44 | DisplayVersionOnly bool |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 45 | AccIncrEvto bool |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 46 | ProbeHost string |
| 47 | ProbePort int |
| 48 | LiveProbeInterval time.Duration |
| 49 | NotLiveProbeInterval time.Duration |
| 50 | HeartbeatCheckInterval time.Duration |
| 51 | HeartbeatFailReportInterval time.Duration |
| 52 | KafkaReconnectRetries int |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 53 | CurrentReplica int |
| 54 | TotalReplicas int |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 55 | MaxTimeoutInterAdapterComm time.Duration |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 56 | MaxTimeoutReconciling time.Duration |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 57 | TraceEnabled bool |
| 58 | TraceAgentAddress string |
| 59 | LogCorrelationEnabled bool |
Andrea Campanella | 3d7c931 | 2021-01-19 09:20:49 +0100 | [diff] [blame] | 60 | OnuVendorIds string |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 61 | MetricsEnabled bool |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 62 | MibAuditInterval time.Duration |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 63 | OmciTimeout time.Duration |
Himani Chawla | 075f164 | 2021-03-15 19:23:24 +0530 | [diff] [blame] | 64 | AlarmAuditInterval time.Duration |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 65 | DownloadToAdapterTimeout time.Duration |
| 66 | DownloadToOnuTimeout4MB time.Duration |
Matteo Scandolo | 20d180c | 2021-06-10 17:20:21 +0200 | [diff] [blame] | 67 | UniPortMask int |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 68 | MinBackoffRetryDelay time.Duration |
| 69 | MaxBackoffRetryDelay time.Duration |
| 70 | AdapterEndpoint string |
| 71 | GrpcAddress string |
| 72 | CoreEndpoint string |
| 73 | RPCTimeout time.Duration |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | // ParseCommandArguments parses the arguments when running read-write adaptercore service |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 77 | func (so *AdapterFlags) ParseCommandArguments(args []string) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 78 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 79 | fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 80 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 81 | fs.StringVar(&(so.KafkaClusterAddress), |
| 82 | "kafka_cluster_address", |
| 83 | "127.0.0.1:9092", |
| 84 | "Kafka - Cluster messaging address") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 85 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 86 | fs.StringVar(&(so.EventTopic), |
| 87 | "event_topic", |
| 88 | "voltha.events", |
| 89 | "Event topic") |
Holger Hildebrandt | a768fe9 | 2020-10-01 13:06:21 +0000 | [diff] [blame] | 90 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 91 | fs.StringVar(&(so.KVStoreType), |
| 92 | "kv_store_type", |
| 93 | EtcdStoreName, |
| 94 | "KV store type") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 95 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 96 | fs.DurationVar(&(so.KVStoreTimeout), |
| 97 | "kv_store_request_timeout", |
| 98 | 5*time.Second, |
| 99 | "The default timeout when making a kv store request") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 100 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 101 | fs.StringVar(&(so.KVStoreAddress), |
| 102 | "kv_store_address", |
| 103 | "127.0.0.1:2379", |
| 104 | "KV store address") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 105 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 106 | fs.StringVar(&(so.LogLevel), |
| 107 | "log_level", |
| 108 | "WARN", |
| 109 | "Log level") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 110 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 111 | fs.IntVar(&(so.OnuNumber), |
| 112 | "onu_number", |
| 113 | 1, |
| 114 | "Number of ONUs") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 115 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 116 | fs.BoolVar(&(so.Banner), |
| 117 | "banner", |
| 118 | false, |
| 119 | "Show startup banner log lines") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 120 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 121 | fs.BoolVar(&(so.DisplayVersionOnly), |
| 122 | "version", |
| 123 | false, |
| 124 | "Show version information and exit") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 125 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 126 | fs.BoolVar(&(so.AccIncrEvto), |
| 127 | "accept_incr_evto", |
| 128 | false, |
| 129 | "Acceptance of incremental EVTOCD configuration") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 130 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 131 | fs.StringVar(&(so.ProbeHost), |
| 132 | "probe_host", |
| 133 | "", |
| 134 | "The address on which to listen to answer liveness and readiness probe queries over HTTP") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 135 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 136 | fs.IntVar(&(so.ProbePort), |
| 137 | "probe_port", |
| 138 | 8080, |
| 139 | "The port on which to listen to answer liveness and readiness probe queries over HTTP") |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 140 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 141 | fs.DurationVar(&(so.LiveProbeInterval), |
| 142 | "live_probe_interval", |
| 143 | 60*time.Second, |
| 144 | "Number of seconds for the default liveliness check") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 145 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 146 | fs.DurationVar(&(so.NotLiveProbeInterval), |
| 147 | "not_live_probe_interval", |
| 148 | 60*time.Second, |
| 149 | "Number of seconds for liveliness check if probe is not running") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 150 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 151 | fs.DurationVar(&(so.HeartbeatCheckInterval), |
| 152 | "hearbeat_check_interval", |
| 153 | 30*time.Second, |
| 154 | "Number of seconds for heartbeat check interval") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 155 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 156 | fs.DurationVar(&(so.HeartbeatFailReportInterval), |
| 157 | "hearbeat_fail_interval", |
| 158 | 30*time.Second, |
| 159 | "Number of seconds adapter has to wait before reporting core on the hearbeat check failure") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 160 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 161 | fs.IntVar(&(so.KafkaReconnectRetries), |
| 162 | "kafka_reconnect_retries", |
| 163 | -1, |
| 164 | "Number of retries to connect to Kafka") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 165 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 166 | fs.IntVar(&(so.CurrentReplica), |
| 167 | "current_replica", |
| 168 | 1, |
| 169 | "Replica number of this particular instance") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 170 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 171 | fs.IntVar(&(so.TotalReplicas), |
| 172 | "total_replica", |
| 173 | 1, |
| 174 | "Total number of instances for this adapter") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 175 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 176 | fs.DurationVar(&(so.MaxTimeoutInterAdapterComm), |
| 177 | "max_timeout_interadapter_comm", |
| 178 | 30*time.Second, |
| 179 | "Maximum Number of seconds for the default interadapter communication timeout") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 180 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 181 | fs.DurationVar(&(so.MaxTimeoutReconciling), |
| 182 | "max_timeout_reconciling", |
| 183 | 10*time.Second, |
| 184 | "Maximum Number of seconds for the default ONU reconciling timeout") |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 185 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 186 | fs.BoolVar(&(so.TraceEnabled), |
| 187 | "trace_enabled", |
| 188 | false, |
| 189 | "Whether to send logs to tracing agent") |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 190 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 191 | fs.StringVar(&(so.TraceAgentAddress), |
| 192 | "trace_agent_address", |
| 193 | "127.0.0.1:6831", |
| 194 | "The address of tracing agent to which span info should be sent") |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 195 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 196 | fs.BoolVar(&(so.LogCorrelationEnabled), |
| 197 | "log_correlation_enabled", |
| 198 | true, |
| 199 | "Whether to enrich log statements with fields denoting operation being executed for achieving correlation") |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 200 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 201 | fs.StringVar(&(so.OnuVendorIds), |
| 202 | "allowed_onu_vendors", |
| 203 | OnuVendorIds, |
| 204 | "List of Allowed ONU Vendor Ids") |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 205 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 206 | fs.BoolVar(&(so.MetricsEnabled), |
| 207 | "metrics_enabled", |
| 208 | false, |
| 209 | "Whether to enable metrics collection") |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 210 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 211 | fs.DurationVar(&(so.MibAuditInterval), |
| 212 | "mib_audit_interval", |
| 213 | 300*time.Second, |
| 214 | "Mib Audit Interval in seconds - the value zero will disable Mib Audit") |
Andrea Campanella | 3d7c931 | 2021-01-19 09:20:49 +0100 | [diff] [blame] | 215 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 216 | fs.DurationVar(&(so.OmciTimeout), |
| 217 | "omci_timeout", |
| 218 | 3*time.Second, |
| 219 | "OMCI timeout duration - this timeout value is used on the OMCI channel for waiting on response from ONU") |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 220 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 221 | fs.DurationVar(&(so.AlarmAuditInterval), |
| 222 | "alarm_audit_interval", |
| 223 | 300*time.Second, |
| 224 | "Alarm Audit Interval in seconds - the value zero will disable alarm audit") |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 225 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 226 | fs.DurationVar(&(so.DownloadToAdapterTimeout), |
| 227 | "download_to_adapter_timeout", |
| 228 | 10*time.Second, |
| 229 | "File download to adapter timeout in seconds") |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 230 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 231 | fs.DurationVar(&(so.DownloadToOnuTimeout4MB), |
| 232 | "download_to_onu_timeout_4MB", |
| 233 | 60*time.Minute, |
| 234 | "File download to ONU timeout in minutes for a block of 4MB") |
Himani Chawla | 075f164 | 2021-03-15 19:23:24 +0530 | [diff] [blame] | 235 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 236 | //Mask to indicate which possibly active ONU UNI state is really reported to the core |
| 237 | // compare python code - at the moment restrict active state to the first ONU UNI port |
| 238 | // check is limited to max 16 uni ports - cmp above UNI limit!!! |
| 239 | fs.IntVar(&(so.UniPortMask), |
| 240 | "uni_port_mask", |
| 241 | 0x0001, |
| 242 | "The bitmask to identify UNI ports that need to be enabled") |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 243 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 244 | fs.StringVar(&(so.GrpcAddress), |
| 245 | "grpc_address", |
| 246 | ":50060", |
| 247 | "Adapter GRPC Server address") |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 248 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 249 | fs.StringVar(&(so.CoreEndpoint), |
| 250 | "core_endpoint", |
| 251 | ":55555", |
| 252 | "Core endpoint") |
Matteo Scandolo | 20d180c | 2021-06-10 17:20:21 +0200 | [diff] [blame] | 253 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 254 | fs.StringVar(&(so.AdapterEndpoint), |
| 255 | "adapter_endpoint", |
| 256 | "", |
| 257 | "Adapter Endpoint") |
| 258 | |
| 259 | fs.DurationVar(&(so.RPCTimeout), |
| 260 | "rpc_timeout", |
| 261 | 10*time.Second, |
| 262 | "The default timeout when making an RPC request") |
| 263 | |
| 264 | fs.DurationVar(&(so.MinBackoffRetryDelay), |
| 265 | "min_retry_delay", |
| 266 | 500*time.Millisecond, |
| 267 | "The minimum number of milliseconds to delay before a connection retry attempt") |
| 268 | |
| 269 | fs.DurationVar(&(so.MaxBackoffRetryDelay), |
| 270 | "max_retry_delay", |
| 271 | 10*time.Second, |
| 272 | "The maximum number of milliseconds to delay before a connection retry attempt") |
| 273 | |
| 274 | _ = fs.Parse(args) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 275 | containerName := getContainerInfo() |
| 276 | if len(containerName) > 0 { |
| 277 | so.InstanceID = containerName |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 278 | } else { |
| 279 | so.InstanceID = "openonu" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | func getContainerInfo() string { |
| 285 | return os.Getenv("HOSTNAME") |
| 286 | } |