blob: 9db89eaed52fc34a3c79ffe683a687d6bed996a4 [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
38 KVStoreTimeout int // in seconds
39 KVStoreHost string
40 KVStorePort int
41 InstanceID string
David K. Bainbridge157bdab2020-01-16 14:38:05 -080042}
43
Jonathan Hart4b110f62020-03-13 17:36:19 -070044type multiFlag []string
45
46func (m *multiFlag) String() string {
47 return "[" + strings.Join(*m, ", ") + "]"
48}
49
50func (m *multiFlag) Set(value string) error {
51 *m = append(*m, value)
52 return nil
53}
54
David K. Bainbridge157bdab2020-01-16 14:38:05 -080055func 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 Hart4b110f62020-03-13 17:36:19 -070066 flag.Var(&config.OFControllerEndPoints,
David K. Bainbridge157bdab2020-01-16 14:38:05 -080067 "controller",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080068 "connection to the OF controller specified as host:port")
Jonathan Hart4b110f62020-03-13 17:36:19 -070069 flag.Var(&config.OFControllerEndPoints,
David K. Bainbridge157bdab2020-01-16 14:38:05 -080070 "O",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080071 "(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. Bainbridge157bdab2020-01-16 14:38:05 -080088 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")
divyadesai81bb7ba2020-03-11 11:45:23 +0000120 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 Bainbridgedf400492020-03-17 15:06:59 -0700128 flag.StringVar(&(config.LogLevel), "log_level", "WARN", "Log level")
divyadesai81bb7ba2020-03-11 11:45:23 +0000129
130 containerName := getContainerInfo()
131 if len(containerName) > 0 {
132 config.InstanceID = containerName
133 } else {
134 config.InstanceID = "openFlowAgent001"
135 }
David K. Bainbridge157bdab2020-01-16 14:38:05 -0800136
137 return &config, nil
138}
divyadesai81bb7ba2020-03-11 11:45:23 +0000139
140func getContainerInfo() string {
141 return os.Getenv("HOSTNAME")
142}