Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022-present Open Networking Foundation |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | package main |
| 17 | |
| 18 | import ( |
| 19 | "strconv" |
| 20 | "strings" |
| 21 | |
| 22 | "voltha-go-controller/internal/pkg/util/envutils" |
| 23 | ) |
| 24 | |
| 25 | // RW Core service default constants |
| 26 | const ( |
| 27 | defaultLogLevel = "DEBUG" |
| 28 | defaultVolthaHost = "127.0.0.1" |
| 29 | defaultVolthaPort = 50057 |
| 30 | defaultProbeHost = "" |
| 31 | defaultProbePort = 8090 |
| 32 | defaultBanner = true |
| 33 | defaultDisplayVersion = false |
| 34 | defaultCPUProfile = "" |
| 35 | defaultMemProfile = "" |
| 36 | defaultDeviceListRefreshInterval = 10 |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 37 | defaultDeviceSyncDuration = 5 |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame^] | 38 | defaultMaxFlowRetryDuration = 60 |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 39 | /* |
| 40 | FIXME(At RWCORE) Problem: VGC comes up fast by that time RWCORE may not be up and will retry after 10 sec |
| 41 | but rwcore could come up before the 10 second expiry and post indications to VGC which can't be consumed by |
| 42 | VGC. Proper workaround is heml to sping VGC only when RWCORE reports via prope when the grpc server is up |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 43 | OR maintain a event/indiction queue similar to that in openolt-agent(which too is a GRPC SERVER) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 44 | WorkAround: Reduce retry interval to 1 second from existing 10 seconds to that chances of indications getting missed is rare |
| 45 | */ |
| 46 | defaultConnectionRetryDelay = 1 |
| 47 | defaultConnectionMaxRetries = 120 |
Akash Soni | dedc8ee | 2023-03-03 11:51:49 +0530 | [diff] [blame] | 48 | defaultKVStoreType = "etcd" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 49 | defaultKVStoreHost = "127.0.0.1" |
Akash Soni | dedc8ee | 2023-03-03 11:51:49 +0530 | [diff] [blame] | 50 | defaultKVStorePort = 2379 |
| 51 | defaultKVStoreTimeout = 5000000000 |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 52 | defaultKafkaAdapterHost = "127.0.0.1" |
| 53 | defaultKafkaAdapterPort = 9092 |
| 54 | defaultInstanceID = "VGC-01" |
| 55 | defaultVendorID = "" |
| 56 | ) |
| 57 | |
| 58 | func newVGCFlags() *VGCFlags { |
| 59 | var vgcConfig = VGCFlags{ |
| 60 | LogLevel: defaultLogLevel, |
| 61 | VolthaHost: defaultVolthaHost, |
| 62 | VolthaPort: defaultVolthaPort, |
| 63 | KVStoreType: defaultKVStoreType, |
| 64 | KVStoreHost: defaultKVStoreHost, |
| 65 | KVStorePort: defaultKVStorePort, |
| 66 | KVStoreTimeout: defaultKVStoreTimeout, |
| 67 | KafkaAdapterHost: defaultKafkaAdapterHost, |
| 68 | KafkaAdapterPort: defaultKafkaAdapterPort, |
| 69 | ProbeHost: defaultProbeHost, |
| 70 | ProbePort: defaultProbePort, |
| 71 | Banner: defaultBanner, |
| 72 | DisplayVersion: defaultDisplayVersion, |
| 73 | CPUProfile: defaultCPUProfile, |
| 74 | MemProfile: defaultMemProfile, |
| 75 | DeviceListRefreshInterval: defaultDeviceListRefreshInterval, |
| 76 | ConnectionRetryDelay: defaultConnectionRetryDelay, |
| 77 | ConnectionMaxRetries: defaultConnectionMaxRetries, |
| 78 | InstanceID: defaultInstanceID, |
| 79 | VendorID: defaultVendorID, |
| 80 | DeviceSyncDuration: defaultDeviceSyncDuration, |
| 81 | } |
| 82 | |
| 83 | return &vgcConfig |
| 84 | } |
| 85 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 86 | // VGCFlags represents the set of configurations used by the VGC service |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 87 | type VGCFlags struct { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 88 | LogLevel string |
| 89 | VolthaHost string |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 90 | InstanceID string |
| 91 | KVStoreEndPoint string |
| 92 | MsgBusEndPoint string |
| 93 | ProbeEndPoint string |
| 94 | VolthaAPIEndPoint string |
| 95 | VendorID string |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 96 | KVStoreType string |
| 97 | KVStoreHost string |
| 98 | KafkaAdapterHost string |
| 99 | ProbeHost string |
| 100 | CPUProfile string |
| 101 | MemProfile string |
| 102 | OFControllerEndPoints multiFlag |
| 103 | KafkaAdapterPort int |
| 104 | KVStoreTimeout int // in seconds |
| 105 | KVStorePort int |
| 106 | VolthaPort int |
| 107 | ProbePort int |
| 108 | DeviceListRefreshInterval int // in seconds |
| 109 | ConnectionRetryDelay int // in seconds |
| 110 | ConnectionMaxRetries int |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame^] | 111 | DeviceSyncDuration int // Time interval between each cycle of audit task |
| 112 | MaxFlowRetryDuration int // Maximum duration for which flows will be retried upon failures |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 113 | Banner bool |
| 114 | DisplayVersion bool |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | // parseEnvironmentVariables parses the arguments when running read-write VGC service |
| 118 | func (cf *VGCFlags) parseEnvironmentVariables() { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 119 | cf.LogLevel = envutils.ParseStringEnvVariable(envutils.LogLevel, defaultLogLevel) |
| 120 | cf.VolthaHost = envutils.ParseStringEnvVariable(envutils.VolthaHost, defaultVolthaHost) |
| 121 | cf.VolthaPort = int(envutils.ParseIntEnvVariable(envutils.VolthaPort, defaultVolthaPort)) |
| 122 | cf.KVStoreType = envutils.ParseStringEnvVariable(envutils.KvStoreType, defaultKVStoreType) |
| 123 | cf.KVStoreTimeout = int(envutils.ParseIntEnvVariable(envutils.KvStoreTimeout, defaultKVStoreTimeout)) |
| 124 | cf.KVStoreHost = envutils.ParseStringEnvVariable(envutils.KvStoreHost, defaultKVStoreHost) |
| 125 | cf.KVStorePort = int(envutils.ParseIntEnvVariable(envutils.KvStorePort, defaultKVStorePort)) |
| 126 | cf.KafkaAdapterHost = envutils.ParseStringEnvVariable(envutils.KafkaAdapterHost, defaultKafkaAdapterHost) |
| 127 | cf.KafkaAdapterPort = int(envutils.ParseIntEnvVariable(envutils.KafkaAdapterPort, defaultKafkaAdapterPort)) |
| 128 | cf.ProbeHost = envutils.ParseStringEnvVariable(envutils.ProbeHost, defaultProbeHost) |
| 129 | cf.ProbePort = int(envutils.ParseIntEnvVariable(envutils.ProbePort, defaultProbePort)) |
| 130 | cf.Banner = envutils.ParseBoolEnvVariable(envutils.Banner, defaultBanner) |
| 131 | cf.DisplayVersion = envutils.ParseBoolEnvVariable(envutils.DisplayVersionOnly, defaultDisplayVersion) |
| 132 | cf.CPUProfile = envutils.ParseStringEnvVariable(envutils.CPUProfile, defaultCPUProfile) |
| 133 | cf.MemProfile = envutils.ParseStringEnvVariable(envutils.MemProfile, defaultMemProfile) |
| 134 | cf.DeviceListRefreshInterval = int(envutils.ParseIntEnvVariable(envutils.DeviceListRefreshInterval, defaultDeviceListRefreshInterval)) |
| 135 | cf.ConnectionRetryDelay = int(envutils.ParseIntEnvVariable(envutils.ConnectionRetryInterval, defaultConnectionRetryDelay)) |
| 136 | cf.ConnectionMaxRetries = int(envutils.ParseIntEnvVariable(envutils.MaxConnectionRetries, defaultConnectionMaxRetries)) |
| 137 | cf.InstanceID = envutils.ParseStringEnvVariable(envutils.HostName, defaultInstanceID) |
| 138 | cf.VendorID = envutils.ParseStringEnvVariable(envutils.VendorID, defaultVendorID) |
| 139 | |
| 140 | cf.KVStoreEndPoint = cf.KVStoreHost + ":" + strconv.Itoa(cf.KVStorePort) |
| 141 | cf.MsgBusEndPoint = cf.KafkaAdapterHost + ":" + strconv.Itoa(cf.KafkaAdapterPort) |
| 142 | cf.ProbeEndPoint = cf.ProbeHost + ":" + strconv.Itoa(cf.ProbePort) |
| 143 | cf.VolthaAPIEndPoint = cf.VolthaHost + ":" + strconv.Itoa(cf.VolthaPort) |
| 144 | |
| 145 | cf.DeviceSyncDuration = int(envutils.ParseIntEnvVariable(envutils.DeviceSyncDuration, defaultDeviceSyncDuration)) |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame^] | 146 | cf.MaxFlowRetryDuration = int(envutils.ParseIntEnvVariable(envutils.MaxFlowRetryDuration, defaultMaxFlowRetryDuration)) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | type multiFlag []string |
| 150 | |
| 151 | func (m *multiFlag) String() string { |
| 152 | return "[" + strings.Join(*m, ", ") + "]" |
| 153 | } |
| 154 | |
| 155 | func (m *multiFlag) Set(value string) error { |
| 156 | *m = append(*m, value) |
| 157 | return nil |
| 158 | } |
| 159 | |
| 160 | /* |
| 161 | func parseCommandLineArguments() (*VGCFlags, error) { |
| 162 | config := VGCFlags{} |
| 163 | |
| 164 | flag.BoolVar(&(config.Banner), |
| 165 | "banner", |
| 166 | true, |
| 167 | "display application banner on startup") |
| 168 | flag.BoolVar(&(config.DisplayVersion), |
| 169 | "version", |
| 170 | false, |
| 171 | "display application version and exit") |
| 172 | flag.StringVar(&(config.VolthaAPIEndPoint), |
| 173 | "voltha", |
| 174 | "127.0.0.1:50057", |
| 175 | "connection to the VOLTHA API server specified as host:port") |
| 176 | flag.StringVar(&(config.VolthaAPIEndPoint), |
| 177 | "A", |
| 178 | "127.0.0.1:50057", |
| 179 | "(short) connection to the VOLTHA API server specified as host:port") |
| 180 | flag.StringVar(&(config.ProbeEndPoint), |
| 181 | "probe", |
| 182 | ":50080", |
| 183 | "address and port on which to listen for k8s live and ready probe requests") |
| 184 | flag.StringVar(&(config.ProbeEndPoint), |
| 185 | "P", |
| 186 | ":50080", |
| 187 | "(short) address and port on which to listen for k8s live and ready probe requests") |
| 188 | flag.StringVar(&(config.CPUProfile), |
| 189 | "cpuprofile", |
| 190 | "", |
| 191 | "write cpu profile to 'file' if specified") |
| 192 | flag.StringVar(&(config.MemProfile), |
| 193 | "memprofile", |
| 194 | "", |
| 195 | "write memory profile to 'file' if specified") |
| 196 | flag.IntVar(&(config.ConnectionRetryDelay), |
| 197 | "cd", |
| 198 | 3, |
| 199 | "(short) delay to wait before connection establishment retries") |
| 200 | flag.IntVar(&(config.ConnectionRetryDelay), |
| 201 | "connnection-delay", |
| 202 | 3, |
| 203 | "delay to wait before connection establishment retries") |
| 204 | flag.IntVar(&(config.ConnectionMaxRetries), |
| 205 | "mr", |
| 206 | 0, |
| 207 | "(short) number of retries when attempting to estblish a connection, 0 is unlimted") |
| 208 | flag.IntVar(&(config.ConnectionMaxRetries), |
| 209 | "connnection-retries", |
| 210 | 0, |
| 211 | "number of retries when attempting to estblish a connection, 0 is unlimted") |
| 212 | flag.IntVar(&(config.DeviceListRefreshInterval), |
| 213 | "dri", |
| 214 | 10, |
| 215 | "(short) interval between attempts to synchronize devices from voltha to vpagent") |
| 216 | flag.IntVar(&(config.DeviceListRefreshInterval), |
| 217 | "device-refresh-interval", |
| 218 | 10, |
| 219 | "interval between attempts to synchronize devices from voltha to vpagent") |
| 220 | flag.StringVar(&(config.KVStoreType), "kv_store_type", "etcd", "KV store type") |
| 221 | |
| 222 | flag.IntVar(&(config.KVStoreTimeout), "kv_store_request_timeout", 5, "The default timeout when making a kv store request") |
| 223 | |
| 224 | flag.StringVar(&(config.KVStoreHost), "kv_store_host", "127.0.0.1", "KV store host") |
| 225 | |
| 226 | flag.IntVar(&(config.KVStorePort), "kv_store_port", 2379, "KV store port") |
| 227 | |
| 228 | flag.StringVar(&(config.MsgBusEndPoint), "msgbus_addr", "127.0.0.1:9092", "msgbus address") |
| 229 | |
| 230 | flag.StringVar(&(config.LogLevel), "log_level", "DEBUG", "Log level") |
| 231 | |
| 232 | containerName := getContainerInfo() |
| 233 | if len(containerName) > 0 { |
| 234 | config.InstanceID = containerName |
| 235 | } else { |
| 236 | config.InstanceID = "VGC-01" |
| 237 | } |
| 238 | |
| 239 | return &config, nil |
| 240 | } |
| 241 | |
| 242 | func getContainerInfo() string { |
| 243 | return os.Getenv("HOSTNAME") |
| 244 | }*/ |