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" |
divyadesai | 81bb7ba | 2020-03-11 11:45:23 +0000 | [diff] [blame] | 20 | "os" |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 21 | "time" |
| 22 | ) |
| 23 | |
| 24 | type Config struct { |
| 25 | OFControllerEndPoint string |
| 26 | VolthaApiEndPoint string |
| 27 | LogLevel string |
| 28 | Banner bool |
| 29 | Version bool |
| 30 | ProbeEndPoint string |
| 31 | CpuProfile string |
| 32 | MemProfile string |
| 33 | DeviceListRefreshInterval time.Duration |
| 34 | ConnectionRetryDelay time.Duration |
| 35 | ConnectionMaxRetries int |
divyadesai | 81bb7ba | 2020-03-11 11:45:23 +0000 | [diff] [blame] | 36 | KVStoreType string |
| 37 | KVStoreTimeout int // in seconds |
| 38 | KVStoreHost string |
| 39 | KVStorePort int |
| 40 | InstanceID string |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | func parseCommandLineArguments() (*Config, error) { |
| 44 | config := Config{} |
| 45 | |
| 46 | flag.BoolVar(&(config.Banner), |
| 47 | "banner", |
| 48 | true, |
| 49 | "display application banner on startup") |
| 50 | flag.BoolVar(&(config.Version), |
| 51 | "version", |
| 52 | false, |
| 53 | "display application version and exit") |
| 54 | flag.StringVar(&(config.OFControllerEndPoint), |
| 55 | "controller", |
| 56 | "onos-openflow:6653", |
| 57 | "connection to the OF controller specified as host:port") |
| 58 | flag.StringVar(&(config.OFControllerEndPoint), |
| 59 | "O", |
| 60 | "onos-openflow:6653", |
| 61 | "(short) connection to the OF controller specified as host:port") |
| 62 | flag.StringVar(&(config.VolthaApiEndPoint), |
| 63 | "voltha", |
| 64 | "voltha-api-server:50060", |
| 65 | "connection to the VOLTHA API server specified as host:port") |
| 66 | flag.StringVar(&(config.VolthaApiEndPoint), |
| 67 | "A", |
| 68 | "voltha-api-server:50060", |
| 69 | "(short) connection to the VOLTHA API server specified as host:port") |
| 70 | flag.StringVar(&(config.ProbeEndPoint), |
| 71 | "probe", |
| 72 | ":8080", |
| 73 | "address and port on which to listen for k8s live and ready probe requests") |
| 74 | flag.StringVar(&(config.ProbeEndPoint), |
| 75 | "P", |
| 76 | ":8080", |
| 77 | "(short) address and port on which to listen for k8s live and ready probe requests") |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 78 | flag.StringVar(&(config.CpuProfile), |
| 79 | "cpuprofile", |
| 80 | "", |
| 81 | "write cpu profile to 'file' if specified") |
| 82 | flag.StringVar(&(config.MemProfile), |
| 83 | "memprofile", |
| 84 | "", |
| 85 | "write memory profile to 'file' if specified") |
| 86 | flag.DurationVar(&(config.ConnectionRetryDelay), |
| 87 | "cd", |
| 88 | 3*time.Second, |
| 89 | "(short) delay to wait before connection establishment retries") |
| 90 | flag.DurationVar(&(config.ConnectionRetryDelay), |
| 91 | "connnection-delay", |
| 92 | 3*time.Second, |
| 93 | "delay to wait before connection establishment retries") |
| 94 | flag.IntVar(&(config.ConnectionMaxRetries), |
| 95 | "mr", |
| 96 | 0, |
| 97 | "(short) number of retries when attempting to estblish a connection, 0 is unlimted") |
| 98 | flag.IntVar(&(config.ConnectionMaxRetries), |
| 99 | "connnection-retries", |
| 100 | 0, |
| 101 | "number of retries when attempting to estblish a connection, 0 is unlimted") |
| 102 | flag.DurationVar(&(config.DeviceListRefreshInterval), |
| 103 | "dri", |
| 104 | 1*time.Minute, |
| 105 | "(short) interval between attempts to synchronize devices from voltha to ofagent") |
| 106 | flag.DurationVar(&(config.DeviceListRefreshInterval), |
| 107 | "device-refresh-interval", |
| 108 | 1*time.Minute, |
| 109 | "interval between attempts to synchronize devices from voltha to ofagent") |
divyadesai | 81bb7ba | 2020-03-11 11:45:23 +0000 | [diff] [blame] | 110 | flag.StringVar(&(config.KVStoreType), "kv_store_type", "etcd", "KV store type") |
| 111 | |
| 112 | flag.IntVar(&(config.KVStoreTimeout), "kv_store_request_timeout", 5, "The default timeout when making a kv store request") |
| 113 | |
| 114 | flag.StringVar(&(config.KVStoreHost), "kv_store_host", "voltha-etcd-cluster-client.voltha.svc.cluster.local", "KV store host") |
| 115 | |
| 116 | flag.IntVar(&(config.KVStorePort), "kv_store_port", 2379, "KV store port") |
| 117 | |
David Bainbridge | df40049 | 2020-03-17 15:06:59 -0700 | [diff] [blame] | 118 | flag.StringVar(&(config.LogLevel), "log_level", "WARN", "Log level") |
divyadesai | 81bb7ba | 2020-03-11 11:45:23 +0000 | [diff] [blame] | 119 | |
| 120 | containerName := getContainerInfo() |
| 121 | if len(containerName) > 0 { |
| 122 | config.InstanceID = containerName |
| 123 | } else { |
| 124 | config.InstanceID = "openFlowAgent001" |
| 125 | } |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 126 | |
| 127 | return &config, nil |
| 128 | } |
divyadesai | 81bb7ba | 2020-03-11 11:45:23 +0000 | [diff] [blame] | 129 | |
| 130 | func getContainerInfo() string { |
| 131 | return os.Getenv("HOSTNAME") |
| 132 | } |