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