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