blob: ba8b710109773616aaa479fbbbcc1249a623702e [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
David K. Bainbridge157bdab2020-01-16 14:38:05 -080041}
42
Jonathan Hart4b110f62020-03-13 17:36:19 -070043type multiFlag []string
44
45func (m *multiFlag) String() string {
46 return "[" + strings.Join(*m, ", ") + "]"
47}
48
49func (m *multiFlag) Set(value string) error {
50 *m = append(*m, value)
51 return nil
52}
53
David K. Bainbridge157bdab2020-01-16 14:38:05 -080054func 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 Hart4b110f62020-03-13 17:36:19 -070065 flag.Var(&config.OFControllerEndPoints,
David K. Bainbridge157bdab2020-01-16 14:38:05 -080066 "controller",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080067 "connection to the OF controller specified as host:port")
Jonathan Hart4b110f62020-03-13 17:36:19 -070068 flag.Var(&config.OFControllerEndPoints,
David K. Bainbridge157bdab2020-01-16 14:38:05 -080069 "O",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080070 "(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. Bainbridge157bdab2020-01-16 14:38:05 -080087 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")
divyadesai81bb7ba2020-03-11 11:45:23 +0000119 flag.StringVar(&(config.KVStoreType), "kv_store_type", "etcd", "KV store type")
120
Neha Sharma87d43d72020-04-08 14:10:40 +0000121 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 +0000122
Neha Sharma318a1292020-05-14 19:53:26 +0000123 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 +0000124
David Bainbridgedf400492020-03-17 15:06:59 -0700125 flag.StringVar(&(config.LogLevel), "log_level", "WARN", "Log level")
divyadesai81bb7ba2020-03-11 11:45:23 +0000126
127 containerName := getContainerInfo()
128 if len(containerName) > 0 {
129 config.InstanceID = containerName
130 } else {
131 config.InstanceID = "openFlowAgent001"
132 }
David K. Bainbridge157bdab2020-01-16 14:38:05 -0800133
134 return &config, nil
135}
divyadesai81bb7ba2020-03-11 11:45:23 +0000136
137func getContainerInfo() string {
138 return os.Getenv("HOSTNAME")
139}