David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2019 the original author or authors. |
| 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 | package main |
| 17 | |
| 18 | import ( |
| 19 | "flag" |
| 20 | "time" |
| 21 | ) |
| 22 | |
| 23 | type Config struct { |
| 24 | OFControllerEndPoint string |
| 25 | VolthaApiEndPoint string |
| 26 | LogLevel string |
| 27 | Banner bool |
| 28 | Version bool |
| 29 | ProbeEndPoint string |
| 30 | CpuProfile string |
| 31 | MemProfile string |
| 32 | DeviceListRefreshInterval time.Duration |
| 33 | ConnectionRetryDelay time.Duration |
| 34 | ConnectionMaxRetries int |
| 35 | } |
| 36 | |
| 37 | func parseCommandLineArguments() (*Config, error) { |
| 38 | config := Config{} |
| 39 | |
| 40 | flag.BoolVar(&(config.Banner), |
| 41 | "banner", |
| 42 | true, |
| 43 | "display application banner on startup") |
| 44 | flag.BoolVar(&(config.Version), |
| 45 | "version", |
| 46 | false, |
| 47 | "display application version and exit") |
| 48 | flag.StringVar(&(config.OFControllerEndPoint), |
| 49 | "controller", |
| 50 | "onos-openflow:6653", |
| 51 | "connection to the OF controller specified as host:port") |
| 52 | flag.StringVar(&(config.OFControllerEndPoint), |
| 53 | "O", |
| 54 | "onos-openflow:6653", |
| 55 | "(short) connection to the OF controller specified as host:port") |
| 56 | flag.StringVar(&(config.VolthaApiEndPoint), |
| 57 | "voltha", |
| 58 | "voltha-api-server:50060", |
| 59 | "connection to the VOLTHA API server specified as host:port") |
| 60 | flag.StringVar(&(config.VolthaApiEndPoint), |
| 61 | "A", |
| 62 | "voltha-api-server:50060", |
| 63 | "(short) connection to the VOLTHA API server specified as host:port") |
| 64 | flag.StringVar(&(config.ProbeEndPoint), |
| 65 | "probe", |
| 66 | ":8080", |
| 67 | "address and port on which to listen for k8s live and ready probe requests") |
| 68 | flag.StringVar(&(config.ProbeEndPoint), |
| 69 | "P", |
| 70 | ":8080", |
| 71 | "(short) address and port on which to listen for k8s live and ready probe requests") |
| 72 | flag.StringVar(&(config.LogLevel), |
| 73 | "loglevel", |
| 74 | "WARN", |
| 75 | "initial log level setting, overriden by any value set in configuration store") |
| 76 | flag.StringVar(&(config.LogLevel), |
| 77 | "L", |
| 78 | "WARN", |
| 79 | "(short) initial log level setting, overriden by any value set in configuration store") |
| 80 | flag.StringVar(&(config.CpuProfile), |
| 81 | "cpuprofile", |
| 82 | "", |
| 83 | "write cpu profile to 'file' if specified") |
| 84 | flag.StringVar(&(config.MemProfile), |
| 85 | "memprofile", |
| 86 | "", |
| 87 | "write memory profile to 'file' if specified") |
| 88 | flag.DurationVar(&(config.ConnectionRetryDelay), |
| 89 | "cd", |
| 90 | 3*time.Second, |
| 91 | "(short) delay to wait before connection establishment retries") |
| 92 | flag.DurationVar(&(config.ConnectionRetryDelay), |
| 93 | "connnection-delay", |
| 94 | 3*time.Second, |
| 95 | "delay to wait before connection establishment retries") |
| 96 | flag.IntVar(&(config.ConnectionMaxRetries), |
| 97 | "mr", |
| 98 | 0, |
| 99 | "(short) number of retries when attempting to estblish a connection, 0 is unlimted") |
| 100 | flag.IntVar(&(config.ConnectionMaxRetries), |
| 101 | "connnection-retries", |
| 102 | 0, |
| 103 | "number of retries when attempting to estblish a connection, 0 is unlimted") |
| 104 | flag.DurationVar(&(config.DeviceListRefreshInterval), |
| 105 | "dri", |
| 106 | 1*time.Minute, |
| 107 | "(short) interval between attempts to synchronize devices from voltha to ofagent") |
| 108 | flag.DurationVar(&(config.DeviceListRefreshInterval), |
| 109 | "device-refresh-interval", |
| 110 | 1*time.Minute, |
| 111 | "interval between attempts to synchronize devices from voltha to ofagent") |
| 112 | |
| 113 | return &config, nil |
| 114 | } |