Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | |
| 17 | package common |
| 18 | |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 19 | import ( |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 20 | "errors" |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 21 | "flag" |
| 22 | "fmt" |
| 23 | "io/ioutil" |
| 24 | "net" |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 25 | "strings" |
Shrey Baid | 64cda47 | 2020-04-24 18:58:18 +0530 | [diff] [blame] | 26 | |
| 27 | "github.com/ghodss/yaml" |
| 28 | log "github.com/sirupsen/logrus" |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 29 | ) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 30 | |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 31 | var tagAllocationValues = []string{ |
| 32 | "unknown", |
| 33 | "shared", |
| 34 | "unique", |
| 35 | } |
| 36 | |
| 37 | type TagAllocation int |
| 38 | |
| 39 | func (t TagAllocation) String() string { |
| 40 | return tagAllocationValues[t] |
| 41 | } |
| 42 | |
| 43 | func tagAllocationFromString(s string) (TagAllocation, error) { |
| 44 | for i, v := range tagAllocationValues { |
| 45 | if v == s { |
| 46 | return TagAllocation(i), nil |
| 47 | } |
| 48 | } |
| 49 | log.WithFields(log.Fields{ |
| 50 | "ValidValues": strings.Join(tagAllocationValues[1:], ", "), |
| 51 | }).Errorf("%s-is-not-a-valid-tag-allocation", s) |
| 52 | return TagAllocation(0), errors.New(fmt.Sprintf("%s-is-not-a-valid-tag-allocation", s)) |
| 53 | } |
| 54 | |
| 55 | const ( |
| 56 | _ TagAllocation = iota |
| 57 | TagAllocationShared |
| 58 | TagAllocationUnique |
| 59 | ) |
| 60 | |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 61 | var sadisFormatValues = []string{ |
| 62 | "unknown", |
| 63 | "att", |
| 64 | "dt", |
| 65 | "tt", |
| 66 | } |
| 67 | |
| 68 | type SadisFormat int |
| 69 | |
| 70 | func (s SadisFormat) String() string { |
| 71 | return sadisFormatValues[s] |
| 72 | } |
| 73 | |
| 74 | func sadisFormatFromString(s string) (SadisFormat, error) { |
| 75 | for i, v := range sadisFormatValues { |
| 76 | if v == s { |
| 77 | return SadisFormat(i), nil |
| 78 | } |
| 79 | } |
| 80 | log.WithFields(log.Fields{ |
| 81 | "ValidValues": strings.Join(sadisFormatValues[1:], ", "), |
| 82 | }).Errorf("%s-is-not-a-valid-sadis-format", s) |
| 83 | return SadisFormat(0), errors.New(fmt.Sprintf("%s-is-not-a-valid-sadis-format", s)) |
| 84 | } |
| 85 | |
| 86 | const ( |
| 87 | _ SadisFormat = iota |
| 88 | SadisFormatAtt |
| 89 | SadisFormatDt |
| 90 | SadisFormatTt |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 91 | ) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 92 | |
| 93 | type BBRCliOptions struct { |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 94 | *BBSimYamlConfig |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 95 | BBSimIp string |
| 96 | BBSimPort string |
| 97 | BBSimApiPort string |
Matteo Scandolo | f5c537e | 2019-10-28 16:45:57 -0700 | [diff] [blame] | 98 | LogFile string |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 101 | type BBSimYamlConfig struct { |
| 102 | BBSim BBSimConfig |
| 103 | Olt OltConfig |
| 104 | BBR BBRConfig |
| 105 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 106 | |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 107 | type OltConfig struct { |
| 108 | Model string `yaml:"model"` |
| 109 | Vendor string `yaml:"vendor"` |
| 110 | HardwareVersion string `yaml:"hardware_version"` |
| 111 | FirmwareVersion string `yaml:"firmware_version"` |
| 112 | DeviceId string `yaml:"device_id"` |
| 113 | DeviceSerialNumber string `yaml:"device_serial_number"` |
| 114 | PonPorts uint32 `yaml:"pon_ports"` |
| 115 | NniPorts uint32 `yaml:"nni_ports"` |
| 116 | OnusPonPort uint32 `yaml:"onus_per_port"` |
| 117 | Technology string `yaml:"technology"` |
| 118 | ID int `yaml:"id"` |
| 119 | OltRebootDelay int `yaml:"reboot_delay"` |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 120 | PortStatsInterval int `yaml: "port_stats_interval"` |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 121 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 122 | |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 123 | type BBSimConfig struct { |
Shrey Baid | f8abccc | 2020-06-15 19:41:22 +0530 | [diff] [blame] | 124 | DhcpRetry bool `yaml:"dhcp_retry"` |
| 125 | AuthRetry bool `yaml:"auth_retry"` |
Shrey Baid | e72b3cc | 2020-05-12 00:03:06 +0530 | [diff] [blame] | 126 | EnableIgmp bool `yaml:"enable_igmp"` |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 127 | EnableDhcp bool `yaml:"enable_dhcp"` |
| 128 | EnableAuth bool `yaml:"enable_auth"` |
| 129 | LogLevel string `yaml:"log_level"` |
| 130 | LogCaller bool `yaml:"log_caller"` |
| 131 | Delay int `yaml:"delay"` |
| 132 | CpuProfile *string `yaml:"cpu_profile"` |
| 133 | CTagAllocation TagAllocation `yaml:"c_tag_allocation"` |
| 134 | CTag int `yaml:"c_tag"` |
| 135 | STagAllocation TagAllocation `yaml:"s_tag_allocation"` |
| 136 | STag int `yaml:"s_tag"` |
| 137 | OpenOltAddress string `yaml:"openolt_address"` |
| 138 | ApiAddress string `yaml:"api_address"` |
| 139 | RestApiAddress string `yaml:"rest_api_address"` |
| 140 | LegacyApiAddress string `yaml:"legacy_api_address"` |
| 141 | LegacyRestApiAddress string `yaml:"legacy_rest_api_address"` |
| 142 | SadisRestAddress string `yaml:"sadis_rest_address"` |
| 143 | SadisServer bool `yaml:"sadis_server"` |
| 144 | SadisFormat SadisFormat `yaml:"sadis_format"` |
| 145 | KafkaAddress string `yaml:"kafka_address"` |
| 146 | Events bool `yaml:"enable_events"` |
| 147 | ControlledActivation string `yaml:"controlled_activation"` |
| 148 | EnablePerf bool `yaml:"enable_perf"` |
Shrey Baid | 64cda47 | 2020-04-24 18:58:18 +0530 | [diff] [blame] | 149 | KafkaEventTopic string `yaml:"kafka_event_topic` |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 150 | } |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 151 | |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 152 | type BBRConfig struct { |
| 153 | Log string `yaml:"log"` |
| 154 | LogLevel string `yaml:"log_level"` |
| 155 | LogCaller bool `yaml:"log_caller"` |
| 156 | } |
| 157 | |
| 158 | var Options *BBSimYamlConfig |
| 159 | |
| 160 | func init() { |
| 161 | // load settings from config file first |
| 162 | Options, _ = LoadBBSimConf("configs/bbsim.yaml") |
| 163 | } |
| 164 | |
| 165 | func getDefaultOps() *BBSimYamlConfig { |
| 166 | |
| 167 | c := &BBSimYamlConfig{ |
| 168 | BBSimConfig{ |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 169 | STagAllocation: TagAllocationShared, |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 170 | STag: 900, |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 171 | CTagAllocation: TagAllocationUnique, |
| 172 | CTag: 900, |
Shrey Baid | e72b3cc | 2020-05-12 00:03:06 +0530 | [diff] [blame] | 173 | EnableIgmp: false, |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 174 | EnableDhcp: false, |
| 175 | EnableAuth: false, |
| 176 | LogLevel: "debug", |
| 177 | LogCaller: false, |
| 178 | Delay: 200, |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 179 | OpenOltAddress: ":50060", |
| 180 | ApiAddress: ":50070", |
| 181 | RestApiAddress: ":50071", |
| 182 | LegacyApiAddress: ":50072", |
| 183 | LegacyRestApiAddress: ":50073", |
| 184 | SadisRestAddress: ":50074", |
| 185 | SadisServer: true, |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 186 | SadisFormat: SadisFormatAtt, |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 187 | KafkaAddress: ":9092", |
| 188 | Events: false, |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 189 | ControlledActivation: "default", |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 190 | EnablePerf: false, |
Shrey Baid | 64cda47 | 2020-04-24 18:58:18 +0530 | [diff] [blame] | 191 | KafkaEventTopic: "", |
Shrey Baid | f8abccc | 2020-06-15 19:41:22 +0530 | [diff] [blame] | 192 | DhcpRetry: false, |
| 193 | AuthRetry: false, |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 194 | }, |
| 195 | OltConfig{ |
| 196 | Vendor: "BBSim", |
| 197 | Model: "asfvolt16", |
| 198 | HardwareVersion: "emulated", |
| 199 | FirmwareVersion: "", |
| 200 | DeviceSerialNumber: "BBSM00000001", |
| 201 | PonPorts: 1, |
| 202 | NniPorts: 1, |
| 203 | OnusPonPort: 1, |
| 204 | Technology: "XGS-PON", |
| 205 | ID: 0, |
| 206 | OltRebootDelay: 10, |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 207 | PortStatsInterval: 20, |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 208 | }, |
| 209 | BBRConfig{ |
| 210 | LogLevel: "debug", |
| 211 | LogCaller: false, |
| 212 | }, |
| 213 | } |
| 214 | return c |
| 215 | } |
| 216 | |
| 217 | // LoadBBSimConf loads the BBSim configuration from a YAML file |
| 218 | func LoadBBSimConf(filename string) (*BBSimYamlConfig, error) { |
| 219 | yamlConfig := getDefaultOps() |
| 220 | |
| 221 | yamlFile, err := ioutil.ReadFile(filename) |
| 222 | if err != nil { |
| 223 | fmt.Printf("Cannot load BBSim configuration file: %s. Using defaults.\n", err) |
| 224 | return yamlConfig, nil |
| 225 | } |
| 226 | |
| 227 | err = yaml.Unmarshal(yamlFile, yamlConfig) |
| 228 | if err != nil { |
| 229 | fmt.Printf("Error parsing YAML file: %s\n", err) |
| 230 | } |
| 231 | |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 232 | // TODO convert from string to TagAllocation |
| 233 | |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 234 | return yamlConfig, nil |
| 235 | } |
| 236 | |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 237 | // GetBBSimOpts loads the BBSim configuration file and over-rides options with corresponding CLI flags if set |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 238 | func GetBBSimOpts() *BBSimYamlConfig { |
| 239 | conf := Options |
| 240 | |
| 241 | olt_id := flag.Int("olt_id", conf.Olt.ID, "OLT device ID") |
| 242 | nni := flag.Int("nni", int(conf.Olt.NniPorts), "Number of NNI ports per OLT device to be emulated") |
| 243 | pon := flag.Int("pon", int(conf.Olt.PonPorts), "Number of PON ports per OLT device to be emulated") |
| 244 | onu := flag.Int("onu", int(conf.Olt.OnusPonPort), "Number of ONU devices per PON port to be emulated") |
| 245 | |
rajesh | f921f88 | 2020-03-06 18:24:28 +0530 | [diff] [blame] | 246 | openolt_address := flag.String("openolt_address", conf.BBSim.OpenOltAddress, "IP address:port") |
| 247 | api_address := flag.String("api_address", conf.BBSim.ApiAddress, "IP address:port") |
| 248 | rest_api_address := flag.String("rest_api_address", conf.BBSim.RestApiAddress, "IP address:port") |
| 249 | |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 250 | s_tag_allocation := flag.String("s_tag_allocation", conf.BBSim.STagAllocation.String(), "Use 'unique' for incremental values, 'shared' to use the same value in all the ONUs") |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 251 | s_tag := flag.Int("s_tag", conf.BBSim.STag, "S-Tag initial value") |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 252 | |
| 253 | c_tag_allocation := flag.String("c_tag_allocation", conf.BBSim.CTagAllocation.String(), "Use 'unique' for incremental values, 'shared' to use the same value in all the ONUs") |
| 254 | c_tag := flag.Int("c_tag", conf.BBSim.CTag, "C-Tag starting value, each ONU will get a sequential one (targeting 1024 ONUs per BBSim instance the range is big enough)") |
| 255 | |
| 256 | sadisFormat := flag.String("sadisFormat", conf.BBSim.SadisFormat.String(), fmt.Sprintf("Which format should sadis expose? [%s]", strings.Join(sadisFormatValues[1:], "|"))) |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 257 | |
| 258 | auth := flag.Bool("auth", conf.BBSim.EnableAuth, "Set this flag if you want authentication to start automatically") |
| 259 | dhcp := flag.Bool("dhcp", conf.BBSim.EnableDhcp, "Set this flag if you want DHCP to start automatically") |
Shrey Baid | e72b3cc | 2020-05-12 00:03:06 +0530 | [diff] [blame] | 260 | igmp := flag.Bool("igmp", conf.BBSim.EnableIgmp, "Set this flag if you want IGMP to start automatically") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 261 | profileCpu := flag.String("cpuprofile", "", "write cpu profile to file") |
| 262 | |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 263 | logLevel := flag.String("logLevel", conf.BBSim.LogLevel, "Set the log level (trace, debug, info, warn, error)") |
| 264 | logCaller := flag.Bool("logCaller", conf.BBSim.LogCaller, "Whether to print the caller filename or not") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 265 | |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 266 | delay := flag.Int("delay", conf.BBSim.Delay, "The delay between ONU DISCOVERY batches in milliseconds (1 ONU per each PON PORT at a time") |
Matteo Scandolo | e33447a | 2019-10-31 12:38:23 -0700 | [diff] [blame] | 267 | |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 268 | controlledActivation := flag.String("ca", conf.BBSim.ControlledActivation, "Set the mode for controlled activation of PON ports and ONUs") |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 269 | enablePerf := flag.Bool("enableperf", conf.BBSim.EnablePerf, "Setting this flag will cause BBSim to not store data like traffic schedulers, flows of ONUs etc..") |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 270 | enableEvents := flag.Bool("enableEvents", conf.BBSim.Events, "Enable sending BBSim events on configured kafka server") |
| 271 | kafkaAddress := flag.String("kafkaAddress", conf.BBSim.KafkaAddress, "IP:Port for kafka") |
Shrey Baid | 64cda47 | 2020-04-24 18:58:18 +0530 | [diff] [blame] | 272 | kafkaEventTopic := flag.String("kafkaEventTopic", conf.BBSim.KafkaEventTopic, "Ability to configure the topic on which BBSim publishes events on Kafka") |
Shrey Baid | f8abccc | 2020-06-15 19:41:22 +0530 | [diff] [blame] | 273 | dhcpRetry := flag.Bool("dhcpRetry", conf.BBSim.DhcpRetry, "Set this flag if BBSim should retry DHCP upon failure until success") |
| 274 | authRetry := flag.Bool("authRetry", conf.BBSim.AuthRetry, "Set this flag if BBSim should retry EAPOL (Authentication) upon failure until success") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 275 | flag.Parse() |
| 276 | |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 277 | sTagAlloc, err := tagAllocationFromString(*s_tag_allocation) |
| 278 | if err != nil { |
| 279 | log.Fatal(err) |
| 280 | } |
| 281 | |
| 282 | cTagAlloc, err := tagAllocationFromString(*c_tag_allocation) |
| 283 | if err != nil { |
| 284 | log.Fatal(err) |
| 285 | } |
| 286 | |
| 287 | sf, err := sadisFormatFromString(*sadisFormat) |
| 288 | if err != nil { |
| 289 | log.Fatal(err) |
| 290 | } |
| 291 | |
| 292 | if sf == SadisFormatTt { |
| 293 | log.Fatalf("Sadis format %s is not yet supported", sf.String()) |
| 294 | } |
| 295 | |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 296 | conf.Olt.ID = int(*olt_id) |
| 297 | conf.Olt.NniPorts = uint32(*nni) |
| 298 | conf.Olt.PonPorts = uint32(*pon) |
| 299 | conf.Olt.OnusPonPort = uint32(*onu) |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 300 | conf.BBSim.STagAllocation = sTagAlloc |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 301 | conf.BBSim.STag = int(*s_tag) |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 302 | conf.BBSim.CTagAllocation = cTagAlloc |
| 303 | conf.BBSim.CTag = int(*c_tag) |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 304 | conf.BBSim.CpuProfile = profileCpu |
| 305 | conf.BBSim.LogLevel = *logLevel |
| 306 | conf.BBSim.LogCaller = *logCaller |
| 307 | conf.BBSim.EnableAuth = *auth |
| 308 | conf.BBSim.EnableDhcp = *dhcp |
Shrey Baid | e72b3cc | 2020-05-12 00:03:06 +0530 | [diff] [blame] | 309 | conf.BBSim.EnableIgmp = *igmp |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 310 | conf.BBSim.Delay = *delay |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 311 | conf.BBSim.ControlledActivation = *controlledActivation |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 312 | conf.BBSim.EnablePerf = *enablePerf |
Pragya Arya | 324337e | 2020-02-20 14:35:08 +0530 | [diff] [blame] | 313 | conf.BBSim.Events = *enableEvents |
| 314 | conf.BBSim.KafkaAddress = *kafkaAddress |
rajesh | f921f88 | 2020-03-06 18:24:28 +0530 | [diff] [blame] | 315 | conf.BBSim.OpenOltAddress = *openolt_address |
| 316 | conf.BBSim.ApiAddress = *api_address |
| 317 | conf.BBSim.RestApiAddress = *rest_api_address |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 318 | conf.BBSim.SadisFormat = sf |
Shrey Baid | 64cda47 | 2020-04-24 18:58:18 +0530 | [diff] [blame] | 319 | conf.BBSim.KafkaEventTopic = *kafkaEventTopic |
Shrey Baid | f8abccc | 2020-06-15 19:41:22 +0530 | [diff] [blame] | 320 | conf.BBSim.AuthRetry = *authRetry |
| 321 | conf.BBSim.DhcpRetry = *dhcpRetry |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 322 | |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 323 | // update device id if not set |
| 324 | if conf.Olt.DeviceId == "" { |
| 325 | conf.Olt.DeviceId = net.HardwareAddr{0xA, 0xA, 0xA, 0xA, 0xA, byte(conf.Olt.ID)}.String() |
| 326 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 327 | |
Zdravko Bozakov | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 328 | Options = conf |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 329 | return conf |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | func GetBBROpts() BBRCliOptions { |
| 333 | |
| 334 | bbsimIp := flag.String("bbsimIp", "127.0.0.1", "BBSim IP") |
| 335 | bbsimPort := flag.String("bbsimPort", "50060", "BBSim Port") |
| 336 | bbsimApiPort := flag.String("bbsimApiPort", "50070", "BBSim API Port") |
Matteo Scandolo | f5c537e | 2019-10-28 16:45:57 -0700 | [diff] [blame] | 337 | logFile := flag.String("logfile", "", "Log to a file") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 338 | |
| 339 | options := GetBBSimOpts() |
| 340 | |
| 341 | bbrOptions := BBRCliOptions{ |
| 342 | options, |
| 343 | *bbsimIp, |
| 344 | *bbsimPort, |
| 345 | *bbsimApiPort, |
Matteo Scandolo | f5c537e | 2019-10-28 16:45:57 -0700 | [diff] [blame] | 346 | *logFile, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | return bbrOptions |
| 350 | } |