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