blob: a9290779e7d0cb78e60d016a25f9d8885493bf4d [file] [log] [blame]
David K. Bainbridge157bdab2020-01-16 14:38:05 -08001/*
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*/
16package main
17
18import (
19 "flag"
divyadesai81bb7ba2020-03-11 11:45:23 +000020 "os"
Jonathan Hart4b110f62020-03-13 17:36:19 -070021 "strings"
David K. Bainbridge157bdab2020-01-16 14:38:05 -080022 "time"
23)
24
25type Config struct {
Jonathan Hart4b110f62020-03-13 17:36:19 -070026 OFControllerEndPoints multiFlag
David K. Bainbridge157bdab2020-01-16 14:38:05 -080027 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
divyadesai81bb7ba2020-03-11 11:45:23 +000037 KVStoreType string
Neha Sharma87d43d72020-04-08 14:10:40 +000038 KVStoreTimeout time.Duration
Neha Sharma318a1292020-05-14 19:53:26 +000039 KVStoreAddress string
divyadesai81bb7ba2020-03-11 11:45:23 +000040 InstanceID string
Girish Kumaradc3ba12020-06-15 14:22:55 +000041 TraceEnabled bool
42 TraceAgentAddress string
43 LogCorrelationEnabled bool
David K. Bainbridge157bdab2020-01-16 14:38:05 -080044}
45
Jonathan Hart4b110f62020-03-13 17:36:19 -070046type multiFlag []string
47
48func (m *multiFlag) String() string {
49 return "[" + strings.Join(*m, ", ") + "]"
50}
51
52func (m *multiFlag) Set(value string) error {
53 *m = append(*m, value)
54 return nil
55}
56
David K. Bainbridge157bdab2020-01-16 14:38:05 -080057func 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 Hart4b110f62020-03-13 17:36:19 -070068 flag.Var(&config.OFControllerEndPoints,
David K. Bainbridge157bdab2020-01-16 14:38:05 -080069 "controller",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080070 "connection to the OF controller specified as host:port")
Jonathan Hart4b110f62020-03-13 17:36:19 -070071 flag.Var(&config.OFControllerEndPoints,
David K. Bainbridge157bdab2020-01-16 14:38:05 -080072 "O",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080073 "(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. Bainbridge157bdab2020-01-16 14:38:05 -080090 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")
divyadesai81bb7ba2020-03-11 11:45:23 +0000122 flag.StringVar(&(config.KVStoreType), "kv_store_type", "etcd", "KV store type")
123
Neha Sharma87d43d72020-04-08 14:10:40 +0000124 flag.DurationVar(&(config.KVStoreTimeout), "kv_store_request_timeout", 5*time.Second, "The default timeout when making a kv store request")
divyadesai81bb7ba2020-03-11 11:45:23 +0000125
Neha Sharma318a1292020-05-14 19:53:26 +0000126 flag.StringVar(&(config.KVStoreAddress), "kv_store_address", "voltha-etcd-cluster-client.voltha.svc.cluster.local:2379", "KV store address")
divyadesai81bb7ba2020-03-11 11:45:23 +0000127
David Bainbridgedf400492020-03-17 15:06:59 -0700128 flag.StringVar(&(config.LogLevel), "log_level", "WARN", "Log level")
divyadesai81bb7ba2020-03-11 11:45:23 +0000129
Girish Kumaradc3ba12020-06-15 14:22:55 +0000130 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
divyadesai81bb7ba2020-03-11 11:45:23 +0000143 containerName := getContainerInfo()
144 if len(containerName) > 0 {
145 config.InstanceID = containerName
146 } else {
147 config.InstanceID = "openFlowAgent001"
148 }
David K. Bainbridge157bdab2020-01-16 14:38:05 -0800149
150 return &config, nil
151}
divyadesai81bb7ba2020-03-11 11:45:23 +0000152
153func getContainerInfo() string {
154 return os.Getenv("HOSTNAME")
155}