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 ( |
| 20 | "flag" |
| 21 | "fmt" |
| 22 | "io/ioutil" |
| 23 | "net" |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 24 | "strings" |
Shrey Baid | 64cda47 | 2020-04-24 18:58:18 +0530 | [diff] [blame] | 25 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 26 | "github.com/imdario/mergo" |
Shrey Baid | 64cda47 | 2020-04-24 18:58:18 +0530 | [diff] [blame] | 27 | log "github.com/sirupsen/logrus" |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 28 | "gopkg.in/yaml.v2" |
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 | |
Matteo Scandolo | 9496714 | 2021-05-28 11:37:06 -0700 | [diff] [blame] | 37 | const ( |
| 38 | BP_FORMAT_MEF = "mef" |
| 39 | BP_FORMAT_IETF = "ietf" |
| 40 | ) |
| 41 | |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 42 | type TagAllocation int |
| 43 | |
| 44 | func (t TagAllocation) String() string { |
| 45 | return tagAllocationValues[t] |
| 46 | } |
| 47 | |
| 48 | func tagAllocationFromString(s string) (TagAllocation, error) { |
| 49 | for i, v := range tagAllocationValues { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 50 | if v == strings.TrimSpace(s) { |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 51 | return TagAllocation(i), nil |
| 52 | } |
| 53 | } |
| 54 | log.WithFields(log.Fields{ |
| 55 | "ValidValues": strings.Join(tagAllocationValues[1:], ", "), |
| 56 | }).Errorf("%s-is-not-a-valid-tag-allocation", s) |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 57 | return TagAllocation(0), fmt.Errorf("%s-is-not-a-valid-tag-allocation", s) |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | const ( |
| 61 | _ TagAllocation = iota |
| 62 | TagAllocationShared |
| 63 | TagAllocationUnique |
| 64 | ) |
| 65 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 66 | type BBRCliOptions struct { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 67 | *GlobalConfig |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 68 | BBSimIp string |
| 69 | BBSimPort string |
| 70 | BBSimApiPort string |
Matteo Scandolo | f5c537e | 2019-10-28 16:45:57 -0700 | [diff] [blame] | 71 | LogFile string |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 74 | type GlobalConfig struct { |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 75 | BBSim BBSimConfig |
| 76 | Olt OltConfig |
| 77 | BBR BBRConfig |
| 78 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 79 | |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 80 | type OltConfig struct { |
| 81 | Model string `yaml:"model"` |
| 82 | Vendor string `yaml:"vendor"` |
| 83 | HardwareVersion string `yaml:"hardware_version"` |
| 84 | FirmwareVersion string `yaml:"firmware_version"` |
| 85 | DeviceId string `yaml:"device_id"` |
| 86 | DeviceSerialNumber string `yaml:"device_serial_number"` |
| 87 | PonPorts uint32 `yaml:"pon_ports"` |
| 88 | NniPorts uint32 `yaml:"nni_ports"` |
| 89 | OnusPonPort uint32 `yaml:"onus_per_port"` |
| 90 | Technology string `yaml:"technology"` |
| 91 | ID int `yaml:"id"` |
| 92 | OltRebootDelay int `yaml:"reboot_delay"` |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 93 | PortStatsInterval int `yaml:"port_stats_interval"` |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 94 | OmciResponseRate uint8 `yaml:"omci_response_rate"` |
Mahir Gunyel | a1753ae | 2021-06-23 00:24:56 -0700 | [diff] [blame] | 95 | UniPorts uint32 `yaml:"uni_ports"` |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 96 | PotsPorts uint32 `yaml:"pots_ports"` |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 97 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 98 | |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 99 | type BBSimConfig struct { |
Matteo Scandolo | 9496714 | 2021-05-28 11:37:06 -0700 | [diff] [blame] | 100 | ConfigFile string |
| 101 | ServiceConfigFile string |
| 102 | DhcpRetry bool `yaml:"dhcp_retry"` |
| 103 | AuthRetry bool `yaml:"auth_retry"` |
| 104 | LogLevel string `yaml:"log_level"` |
| 105 | LogCaller bool `yaml:"log_caller"` |
| 106 | Delay int `yaml:"delay"` |
| 107 | CpuProfile *string `yaml:"cpu_profile"` |
| 108 | OpenOltAddress string `yaml:"openolt_address"` |
| 109 | ApiAddress string `yaml:"api_address"` |
| 110 | RestApiAddress string `yaml:"rest_api_address"` |
| 111 | LegacyApiAddress string `yaml:"legacy_api_address"` |
| 112 | LegacyRestApiAddress string `yaml:"legacy_rest_api_address"` |
| 113 | SadisRestAddress string `yaml:"sadis_rest_address"` |
| 114 | SadisServer bool `yaml:"sadis_server"` |
| 115 | KafkaAddress string `yaml:"kafka_address"` |
| 116 | Events bool `yaml:"enable_events"` |
| 117 | ControlledActivation string `yaml:"controlled_activation"` |
| 118 | EnablePerf bool `yaml:"enable_perf"` |
| 119 | KafkaEventTopic string `yaml:"kafka_event_topic"` |
| 120 | DmiServerAddress string `yaml:"dmi_server_address"` |
| 121 | BandwidthProfileFormat string `yaml:"bp_format"` |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 122 | } |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 123 | |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 124 | type BBRConfig struct { |
| 125 | Log string `yaml:"log"` |
| 126 | LogLevel string `yaml:"log_level"` |
| 127 | LogCaller bool `yaml:"log_caller"` |
| 128 | } |
| 129 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 130 | type ServiceYaml struct { |
| 131 | Name string |
| 132 | CTag int `yaml:"c_tag"` |
| 133 | STag int `yaml:"s_tag"` |
| 134 | NeedsEapol bool `yaml:"needs_eapol"` |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 135 | NeedsDhcp bool `yaml:"needs_dhcp"` |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 136 | NeedsIgmp bool `yaml:"needs_igmp"` |
| 137 | CTagAllocation string `yaml:"c_tag_allocation"` |
| 138 | STagAllocation string `yaml:"s_tag_allocation"` |
| 139 | TechnologyProfileID int `yaml:"tp_id"` |
| 140 | UniTagMatch int `yaml:"uni_tag_match"` |
| 141 | ConfigureMacAddress bool `yaml:"configure_mac_address"` |
Matteo Scandolo | 8d28137 | 2020-09-03 16:23:37 -0700 | [diff] [blame] | 142 | UsPonCTagPriority uint8 `yaml:"us_pon_c_tag_priority"` |
| 143 | UsPonSTagPriority uint8 `yaml:"us_pon_s_tag_priority"` |
| 144 | DsPonCTagPriority uint8 `yaml:"ds_pon_c_tag_priority"` |
| 145 | DsPonSTagPriority uint8 `yaml:"ds_pon_s_tag_priority"` |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 146 | } |
| 147 | type YamlServiceConfig struct { |
| 148 | Workflow string |
| 149 | Services []ServiceYaml `yaml:"services,flow"` |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 150 | } |
| 151 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 152 | func (cfg *YamlServiceConfig) String() string { |
| 153 | str := fmt.Sprintf("[workflow: %s, Services: ", cfg.Workflow) |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 154 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 155 | for _, s := range cfg.Services { |
| 156 | str = fmt.Sprintf("%s[", str) |
| 157 | str = fmt.Sprintf("%sname=%s, c_tag=%d, s_tag=%d, ", |
| 158 | str, s.Name, s.CTag, s.STag) |
| 159 | str = fmt.Sprintf("%sc_tag_allocation=%s, s_tag_allocation=%s, ", |
| 160 | str, s.CTagAllocation, s.STagAllocation) |
| 161 | str = fmt.Sprintf("%sneeds_eapol=%t, needs_dhcp=%t, needs_igmp=%t", |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 162 | str, s.NeedsEapol, s.NeedsDhcp, s.NeedsIgmp) |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 163 | str = fmt.Sprintf("%stp_id=%d, uni_tag_match=%d", |
| 164 | str, s.TechnologyProfileID, s.UniTagMatch) |
| 165 | str = fmt.Sprintf("%s]", str) |
| 166 | } |
| 167 | str = fmt.Sprintf("%s]", str) |
| 168 | return str |
| 169 | } |
| 170 | |
| 171 | var ( |
| 172 | Config *GlobalConfig |
| 173 | Services []ServiceYaml |
| 174 | ) |
| 175 | |
| 176 | // Load the BBSim configuration. This is a combination of CLI parameters and YAML files |
| 177 | // We proceed in this order: |
| 178 | // - Read CLI parameters |
| 179 | // - Using those we read the yaml files (config and services) |
| 180 | // - we merge the configuration (CLI has priority over yaml files) |
| 181 | func LoadConfig() { |
| 182 | |
| 183 | Config = getDefaultOps() |
| 184 | |
| 185 | cliConf := readCliParams() |
| 186 | |
| 187 | yamlConf, err := loadBBSimConf(cliConf.BBSim.ConfigFile) |
| 188 | |
| 189 | if err != nil { |
| 190 | log.WithFields(log.Fields{ |
| 191 | "file": cliConf.BBSim.ConfigFile, |
| 192 | "err": err, |
| 193 | }).Fatal("Can't read config file") |
| 194 | } |
| 195 | |
| 196 | // merging Yaml and Default Values |
| 197 | if err := mergo.Merge(Config, yamlConf, mergo.WithOverride); err != nil { |
| 198 | log.WithFields(log.Fields{ |
| 199 | "err": err, |
| 200 | }).Fatal("Can't merge YAML and Config") |
| 201 | } |
| 202 | |
| 203 | // merging CLI values on top of the yaml ones |
| 204 | if err := mergo.Merge(Config, cliConf, mergo.WithOverride); err != nil { |
| 205 | log.WithFields(log.Fields{ |
| 206 | "err": err, |
| 207 | }).Fatal("Can't merge CLI and Config") |
| 208 | } |
| 209 | |
| 210 | services, err := loadBBSimServices(Config.BBSim.ServiceConfigFile) |
| 211 | |
| 212 | if err != nil { |
| 213 | log.WithFields(log.Fields{ |
| 214 | "file": Config.BBSim.ServiceConfigFile, |
| 215 | "err": err, |
| 216 | }).Fatal("Can't read services file") |
| 217 | } |
| 218 | |
| 219 | Services = services |
| 220 | |
| 221 | } |
| 222 | |
| 223 | func readCliParams() *GlobalConfig { |
| 224 | |
Matteo Scandolo | c11074d | 2020-09-14 14:59:24 -0700 | [diff] [blame] | 225 | conf := getDefaultOps() |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 226 | |
| 227 | configFile := flag.String("config", conf.BBSim.ConfigFile, "Configuration file path") |
| 228 | servicesFile := flag.String("services", conf.BBSim.ServiceConfigFile, "Service Configuration file path") |
Matteo Scandolo | 9496714 | 2021-05-28 11:37:06 -0700 | [diff] [blame] | 229 | sadisBpFormat := flag.String("bp_format", conf.BBSim.BandwidthProfileFormat, "Bandwidth profile format, 'mef' or 'ietf'") |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 230 | |
| 231 | olt_id := flag.Int("olt_id", conf.Olt.ID, "OLT device ID") |
| 232 | nni := flag.Int("nni", int(conf.Olt.NniPorts), "Number of NNI ports per OLT device to be emulated") |
| 233 | pon := flag.Int("pon", int(conf.Olt.PonPorts), "Number of PON ports per OLT device to be emulated") |
| 234 | onu := flag.Int("onu", int(conf.Olt.OnusPonPort), "Number of ONU devices per PON port to be emulated") |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 235 | uni := flag.Int("uni", int(conf.Olt.UniPorts), "Number of Ethernet UNI Ports per ONU device to be emulated") |
| 236 | pots := flag.Int("pots", int(conf.Olt.PotsPorts), "Number of POTS UNI Ports per ONU device to be emulated") |
Mahir Gunyel | a1753ae | 2021-06-23 00:24:56 -0700 | [diff] [blame] | 237 | |
Matteo Scandolo | 9356670 | 2020-09-30 15:19:27 -0700 | [diff] [blame] | 238 | oltRebootDelay := flag.Int("oltRebootDelay", conf.Olt.OltRebootDelay, "Time that BBSim should before restarting after a reboot") |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 239 | omci_response_rate := flag.Int("omci_response_rate", int(conf.Olt.OmciResponseRate), "Amount of OMCI messages to respond to") |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 240 | |
| 241 | openolt_address := flag.String("openolt_address", conf.BBSim.OpenOltAddress, "IP address:port") |
| 242 | api_address := flag.String("api_address", conf.BBSim.ApiAddress, "IP address:port") |
| 243 | rest_api_address := flag.String("rest_api_address", conf.BBSim.RestApiAddress, "IP address:port") |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 244 | dmi_server_address := flag.String("dmi_server_address", conf.BBSim.DmiServerAddress, "IP address:port") |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 245 | |
| 246 | profileCpu := flag.String("cpuprofile", "", "write cpu profile to file") |
| 247 | |
| 248 | logLevel := flag.String("logLevel", conf.BBSim.LogLevel, "Set the log level (trace, debug, info, warn, error)") |
| 249 | logCaller := flag.Bool("logCaller", conf.BBSim.LogCaller, "Whether to print the caller filename or not") |
| 250 | |
| 251 | delay := flag.Int("delay", conf.BBSim.Delay, "The delay between ONU DISCOVERY batches in milliseconds (1 ONU per each PON PORT at a time") |
| 252 | |
| 253 | controlledActivation := flag.String("ca", conf.BBSim.ControlledActivation, "Set the mode for controlled activation of PON ports and ONUs") |
| 254 | enablePerf := flag.Bool("enableperf", conf.BBSim.EnablePerf, "Setting this flag will cause BBSim to not store data like traffic schedulers, flows of ONUs etc..") |
| 255 | enableEvents := flag.Bool("enableEvents", conf.BBSim.Events, "Enable sending BBSim events on configured kafka server") |
| 256 | kafkaAddress := flag.String("kafkaAddress", conf.BBSim.KafkaAddress, "IP:Port for kafka") |
| 257 | kafkaEventTopic := flag.String("kafkaEventTopic", conf.BBSim.KafkaEventTopic, "Ability to configure the topic on which BBSim publishes events on Kafka") |
| 258 | dhcpRetry := flag.Bool("dhcpRetry", conf.BBSim.DhcpRetry, "Set this flag if BBSim should retry DHCP upon failure until success") |
| 259 | authRetry := flag.Bool("authRetry", conf.BBSim.AuthRetry, "Set this flag if BBSim should retry EAPOL (Authentication) upon failure until success") |
Matteo Scandolo | 9356670 | 2020-09-30 15:19:27 -0700 | [diff] [blame] | 260 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 261 | flag.Parse() |
| 262 | |
| 263 | conf.Olt.ID = int(*olt_id) |
| 264 | conf.Olt.NniPorts = uint32(*nni) |
| 265 | conf.Olt.PonPorts = uint32(*pon) |
Mahir Gunyel | a1753ae | 2021-06-23 00:24:56 -0700 | [diff] [blame] | 266 | conf.Olt.UniPorts = uint32(*uni) |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 267 | conf.Olt.PotsPorts = uint32(*pots) |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 268 | conf.Olt.OnusPonPort = uint32(*onu) |
Matteo Scandolo | 9356670 | 2020-09-30 15:19:27 -0700 | [diff] [blame] | 269 | conf.Olt.OltRebootDelay = *oltRebootDelay |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 270 | conf.Olt.OmciResponseRate = uint8(*omci_response_rate) |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 271 | conf.BBSim.ConfigFile = *configFile |
| 272 | conf.BBSim.ServiceConfigFile = *servicesFile |
| 273 | conf.BBSim.CpuProfile = profileCpu |
| 274 | conf.BBSim.LogLevel = *logLevel |
| 275 | conf.BBSim.LogCaller = *logCaller |
| 276 | conf.BBSim.Delay = *delay |
| 277 | conf.BBSim.ControlledActivation = *controlledActivation |
| 278 | conf.BBSim.EnablePerf = *enablePerf |
| 279 | conf.BBSim.Events = *enableEvents |
| 280 | conf.BBSim.KafkaAddress = *kafkaAddress |
| 281 | conf.BBSim.OpenOltAddress = *openolt_address |
| 282 | conf.BBSim.ApiAddress = *api_address |
| 283 | conf.BBSim.RestApiAddress = *rest_api_address |
| 284 | conf.BBSim.KafkaEventTopic = *kafkaEventTopic |
| 285 | conf.BBSim.AuthRetry = *authRetry |
| 286 | conf.BBSim.DhcpRetry = *dhcpRetry |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 287 | conf.BBSim.DmiServerAddress = *dmi_server_address |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 288 | |
| 289 | // update device id if not set |
| 290 | if conf.Olt.DeviceId == "" { |
| 291 | conf.Olt.DeviceId = net.HardwareAddr{0xA, 0xA, 0xA, 0xA, 0xA, byte(conf.Olt.ID)}.String() |
| 292 | } |
| 293 | |
Matteo Scandolo | 9496714 | 2021-05-28 11:37:06 -0700 | [diff] [blame] | 294 | // check that the BP format is valid |
| 295 | if (*sadisBpFormat != BP_FORMAT_MEF) && (*sadisBpFormat != BP_FORMAT_IETF) { |
| 296 | log.Fatalf("Invalid parameter 'bp_format', supported values are %s and %s, you provided %s", BP_FORMAT_MEF, BP_FORMAT_IETF, *sadisBpFormat) |
| 297 | } |
| 298 | conf.BBSim.BandwidthProfileFormat = *sadisBpFormat |
| 299 | |
Matteo Scandolo | c11074d | 2020-09-14 14:59:24 -0700 | [diff] [blame] | 300 | return conf |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | func getDefaultOps() *GlobalConfig { |
| 304 | |
| 305 | c := &GlobalConfig{ |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 306 | BBSimConfig{ |
Matteo Scandolo | 9496714 | 2021-05-28 11:37:06 -0700 | [diff] [blame] | 307 | ConfigFile: "configs/bbsim.yaml", |
| 308 | ServiceConfigFile: "configs/att-services.yaml", |
| 309 | LogLevel: "debug", |
| 310 | LogCaller: false, |
| 311 | Delay: 200, |
| 312 | OpenOltAddress: ":50060", |
| 313 | ApiAddress: ":50070", |
| 314 | RestApiAddress: ":50071", |
| 315 | LegacyApiAddress: ":50072", |
| 316 | LegacyRestApiAddress: ":50073", |
| 317 | SadisRestAddress: ":50074", |
| 318 | SadisServer: true, |
| 319 | KafkaAddress: ":9092", |
| 320 | Events: false, |
| 321 | ControlledActivation: "default", |
| 322 | EnablePerf: false, |
| 323 | KafkaEventTopic: "", |
| 324 | DhcpRetry: false, |
| 325 | AuthRetry: false, |
| 326 | DmiServerAddress: ":50075", |
| 327 | BandwidthProfileFormat: BP_FORMAT_MEF, |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 328 | }, |
| 329 | OltConfig{ |
| 330 | Vendor: "BBSim", |
| 331 | Model: "asfvolt16", |
| 332 | HardwareVersion: "emulated", |
| 333 | FirmwareVersion: "", |
| 334 | DeviceSerialNumber: "BBSM00000001", |
| 335 | PonPorts: 1, |
| 336 | NniPorts: 1, |
| 337 | OnusPonPort: 1, |
| 338 | Technology: "XGS-PON", |
| 339 | ID: 0, |
Matteo Scandolo | 9356670 | 2020-09-30 15:19:27 -0700 | [diff] [blame] | 340 | OltRebootDelay: 60, |
Pragya Arya | 996a089 | 2020-03-09 21:47:52 +0530 | [diff] [blame] | 341 | PortStatsInterval: 20, |
Holger Hildebrandt | c10bab1 | 2021-04-27 09:23:48 +0000 | [diff] [blame] | 342 | OmciResponseRate: 10, |
Mahir Gunyel | a1753ae | 2021-06-23 00:24:56 -0700 | [diff] [blame] | 343 | UniPorts: 4, |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 344 | PotsPorts: 0, |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 345 | }, |
| 346 | BBRConfig{ |
| 347 | LogLevel: "debug", |
| 348 | LogCaller: false, |
| 349 | }, |
| 350 | } |
| 351 | return c |
| 352 | } |
| 353 | |
| 354 | // LoadBBSimConf loads the BBSim configuration from a YAML file |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 355 | func loadBBSimConf(filename string) (*GlobalConfig, error) { |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 356 | yamlConfig := getDefaultOps() |
| 357 | |
| 358 | yamlFile, err := ioutil.ReadFile(filename) |
| 359 | if err != nil { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 360 | log.WithFields(log.Fields{ |
| 361 | "err": err, |
| 362 | "filename": filename, |
| 363 | }).Error("Cannot load BBSim configuration file. Using defaults.") |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 364 | return yamlConfig, nil |
| 365 | } |
| 366 | |
| 367 | err = yaml.Unmarshal(yamlFile, yamlConfig) |
| 368 | if err != nil { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 369 | return nil, err |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | return yamlConfig, nil |
| 373 | } |
| 374 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 375 | // LoadBBSimServices parses a file describing the services that need to be created for each UNI |
| 376 | func loadBBSimServices(filename string) ([]ServiceYaml, error) { |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 377 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 378 | yamlServiceCfg := YamlServiceConfig{} |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 379 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 380 | yamlFile, err := ioutil.ReadFile(filename) |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 381 | if err != nil { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 382 | return nil, err |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 385 | err = yaml.Unmarshal([]byte(yamlFile), &yamlServiceCfg) |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 386 | if err != nil { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 387 | return nil, err |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 390 | for _, service := range yamlServiceCfg.Services { |
| 391 | |
| 392 | if service.CTagAllocation == "" || service.STagAllocation == "" { |
| 393 | log.Fatal("c_tag_allocation and s_tag_allocation are mandatory fields") |
| 394 | } |
| 395 | |
| 396 | if _, err := tagAllocationFromString(string(service.CTagAllocation)); err != nil { |
| 397 | log.WithFields(log.Fields{ |
| 398 | "err": err, |
| 399 | }).Fatal("c_tag_allocation is not valid") |
| 400 | } |
Matteo Scandolo | f65e687 | 2020-04-15 15:18:43 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 403 | log.WithFields(log.Fields{ |
| 404 | "services": yamlServiceCfg.String(), |
| 405 | }).Debug("BBSim services description correctly loaded") |
| 406 | return yamlServiceCfg.Services, nil |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 409 | // This is only used by BBR |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 410 | func GetBBROpts() BBRCliOptions { |
| 411 | |
| 412 | bbsimIp := flag.String("bbsimIp", "127.0.0.1", "BBSim IP") |
| 413 | bbsimPort := flag.String("bbsimPort", "50060", "BBSim Port") |
| 414 | bbsimApiPort := flag.String("bbsimApiPort", "50070", "BBSim API Port") |
Matteo Scandolo | f5c537e | 2019-10-28 16:45:57 -0700 | [diff] [blame] | 415 | logFile := flag.String("logfile", "", "Log to a file") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 416 | |
Matteo Scandolo | c11074d | 2020-09-14 14:59:24 -0700 | [diff] [blame] | 417 | LoadConfig() |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 418 | |
| 419 | bbrOptions := BBRCliOptions{ |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 420 | Config, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 421 | *bbsimIp, |
| 422 | *bbsimPort, |
| 423 | *bbsimApiPort, |
Matteo Scandolo | f5c537e | 2019-10-28 16:45:57 -0700 | [diff] [blame] | 424 | *logFile, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | return bbrOptions |
| 428 | } |