David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 1 | /* |
Joey Armstrong | 03b2087 | 2024-01-12 13:03:07 -0500 | [diff] [blame] | 2 | Copyright 2019 the original author or authors. |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 3 | |
Joey Armstrong | 03b2087 | 2024-01-12 13:03:07 -0500 | [diff] [blame] | 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 |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 7 | |
Joey Armstrong | 03b2087 | 2024-01-12 13:03:07 -0500 | [diff] [blame] | 8 | http://www.apache.org/licenses/LICENSE-2.0 |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 9 | |
Joey Armstrong | 03b2087 | 2024-01-12 13:03:07 -0500 | [diff] [blame] | 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. |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 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 |
Girish Kumar | adc3ba1 | 2020-06-15 14:22:55 +0000 | [diff] [blame] | 41 | TraceEnabled bool |
| 42 | TraceAgentAddress string |
| 43 | LogCorrelationEnabled bool |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 44 | } |
| 45 | |
Jonathan Hart | 4b110f6 | 2020-03-13 17:36:19 -0700 | [diff] [blame] | 46 | type multiFlag []string |
| 47 | |
| 48 | func (m *multiFlag) String() string { |
| 49 | return "[" + strings.Join(*m, ", ") + "]" |
| 50 | } |
| 51 | |
| 52 | func (m *multiFlag) Set(value string) error { |
| 53 | *m = append(*m, value) |
| 54 | return nil |
| 55 | } |
| 56 | |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 57 | func parseCommandLineArguments() (*Config, error) { |
| 58 | config := Config{} |
| 59 | |
| 60 | flag.BoolVar(&(config.Banner), |
| 61 | "banner", |
| 62 | true, |
| 63 | "display application banner on startup") |
| 64 | flag.BoolVar(&(config.Version), |
| 65 | "version", |
| 66 | false, |
| 67 | "display application version and exit") |
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 | "controller", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 70 | "connection to the OF controller specified as host:port") |
Jonathan Hart | 4b110f6 | 2020-03-13 17:36:19 -0700 | [diff] [blame] | 71 | flag.Var(&config.OFControllerEndPoints, |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 72 | "O", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 73 | "(short) connection to the OF controller specified as host:port") |
| 74 | flag.StringVar(&(config.VolthaApiEndPoint), |
| 75 | "voltha", |
| 76 | "voltha-api-server:50060", |
| 77 | "connection to the VOLTHA API server specified as host:port") |
| 78 | flag.StringVar(&(config.VolthaApiEndPoint), |
| 79 | "A", |
| 80 | "voltha-api-server:50060", |
| 81 | "(short) connection to the VOLTHA API server specified as host:port") |
| 82 | flag.StringVar(&(config.ProbeEndPoint), |
| 83 | "probe", |
| 84 | ":8080", |
| 85 | "address and port on which to listen for k8s live and ready probe requests") |
| 86 | flag.StringVar(&(config.ProbeEndPoint), |
| 87 | "P", |
| 88 | ":8080", |
| 89 | "(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] | 90 | flag.StringVar(&(config.CpuProfile), |
| 91 | "cpuprofile", |
| 92 | "", |
| 93 | "write cpu profile to 'file' if specified") |
| 94 | flag.StringVar(&(config.MemProfile), |
| 95 | "memprofile", |
| 96 | "", |
| 97 | "write memory profile to 'file' if specified") |
| 98 | flag.DurationVar(&(config.ConnectionRetryDelay), |
| 99 | "cd", |
| 100 | 3*time.Second, |
| 101 | "(short) delay to wait before connection establishment retries") |
| 102 | flag.DurationVar(&(config.ConnectionRetryDelay), |
| 103 | "connnection-delay", |
| 104 | 3*time.Second, |
| 105 | "delay to wait before connection establishment retries") |
| 106 | flag.IntVar(&(config.ConnectionMaxRetries), |
| 107 | "mr", |
| 108 | 0, |
| 109 | "(short) number of retries when attempting to estblish a connection, 0 is unlimted") |
| 110 | flag.IntVar(&(config.ConnectionMaxRetries), |
| 111 | "connnection-retries", |
| 112 | 0, |
| 113 | "number of retries when attempting to estblish a connection, 0 is unlimted") |
| 114 | flag.DurationVar(&(config.DeviceListRefreshInterval), |
| 115 | "dri", |
| 116 | 1*time.Minute, |
| 117 | "(short) interval between attempts to synchronize devices from voltha to ofagent") |
| 118 | flag.DurationVar(&(config.DeviceListRefreshInterval), |
| 119 | "device-refresh-interval", |
| 120 | 1*time.Minute, |
| 121 | "interval between attempts to synchronize devices from voltha to ofagent") |
divyadesai | 81bb7ba | 2020-03-11 11:45:23 +0000 | [diff] [blame] | 122 | flag.StringVar(&(config.KVStoreType), "kv_store_type", "etcd", "KV store type") |
| 123 | |
Neha Sharma | 87d43d7 | 2020-04-08 14:10:40 +0000 | [diff] [blame] | 124 | 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] | 125 | |
Neha Sharma | 318a129 | 2020-05-14 19:53:26 +0000 | [diff] [blame] | 126 | 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] | 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 | |
Girish Kumar | adc3ba1 | 2020-06-15 14:22:55 +0000 | [diff] [blame] | 130 | flag.BoolVar(&(config.TraceEnabled), |
| 131 | "trace_enabled", |
| 132 | false, |
| 133 | "Whether to send logs to tracing agent?") |
| 134 | flag.StringVar(&(config.TraceAgentAddress), |
| 135 | "trace_agent_address", |
| 136 | "127.0.0.1:6831", |
| 137 | "The address of tracing agent to which span info should be sent.") |
| 138 | flag.BoolVar(&(config.LogCorrelationEnabled), |
| 139 | "log_correlation_enabled", |
| 140 | true, |
| 141 | "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?") |
| 142 | |
divyadesai | 81bb7ba | 2020-03-11 11:45:23 +0000 | [diff] [blame] | 143 | containerName := getContainerInfo() |
| 144 | if len(containerName) > 0 { |
| 145 | config.InstanceID = containerName |
| 146 | } else { |
| 147 | config.InstanceID = "openFlowAgent001" |
| 148 | } |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 149 | |
| 150 | return &config, nil |
| 151 | } |
divyadesai | 81bb7ba | 2020-03-11 11:45:23 +0000 | [diff] [blame] | 152 | |
| 153 | func getContainerInfo() string { |
| 154 | return os.Getenv("HOSTNAME") |
| 155 | } |