Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 1 | /* |
Joey Armstrong | 3881b73 | 2022-12-27 07:55:37 -0500 | [diff] [blame] | 2 | * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 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 | // BBR (BBSim Reflector) is a tool designed to scale test BBSim |
| 18 | // It shared most of the code with BBSim itself and replies to messages |
| 19 | // pretending to be VOLTHA. |
| 20 | // The idea behind it is that, given that the BBSim and BBR are based on the same |
| 21 | // codebase, BBR is acting as a wall for BBSim. And you can't beat the wall. |
| 22 | package main |
| 23 | |
| 24 | import ( |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 25 | "os" |
| 26 | "runtime/pprof" |
| 27 | "time" |
| 28 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 29 | bbrdevices "github.com/opencord/bbsim/internal/bbr/devices" |
| 30 | "github.com/opencord/bbsim/internal/bbsim/devices" |
| 31 | "github.com/opencord/bbsim/internal/common" |
| 32 | log "github.com/sirupsen/logrus" |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 33 | ) |
| 34 | |
| 35 | // usage |
| 36 | func main() { |
Matteo Scandolo | c11074d | 2020-09-14 14:59:24 -0700 | [diff] [blame] | 37 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 38 | config := common.GetBBROpts() |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 39 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 40 | common.SetLogLevel(log.StandardLogger(), config.BBR.LogLevel, config.BBR.LogCaller) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 41 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 42 | if config.LogFile != "" { |
| 43 | file, err := os.OpenFile(config.LogFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) |
Matteo Scandolo | f5c537e | 2019-10-28 16:45:57 -0700 | [diff] [blame] | 44 | if err == nil { |
| 45 | log.StandardLogger().Out = file |
| 46 | } else { |
| 47 | log.Fatal("Failed to log to file, using default stderr") |
| 48 | } |
| 49 | } |
| 50 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 51 | if *config.BBSim.CpuProfile != "" { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 52 | // start profiling |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 53 | log.Infof("Creating profile file at: %s", *config.BBSim.CpuProfile) |
| 54 | f, err := os.Create(*config.BBSim.CpuProfile) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 55 | if err != nil { |
| 56 | log.Fatal(err) |
| 57 | } |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 58 | _ = pprof.StartCPUProfile(f) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | log.WithFields(log.Fields{ |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 62 | "OltID": config.Olt.ID, |
| 63 | "NumNniPerOlt": config.Olt.NniPorts, |
| 64 | "NumPonPerOlt": config.Olt.PonPorts, |
| 65 | "NumOnuPerPon": config.Olt.OnusPonPort, |
| 66 | "BBSimIp": config.BBSimIp, |
| 67 | "BBSimPort": config.BBSimPort, |
| 68 | "LogLevel": config.BBR.LogLevel, |
| 69 | "TotalOnus": config.Olt.PonPorts * config.Olt.OnusPonPort, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 70 | }).Info("BroadBand Reflector is on") |
| 71 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 72 | // create the OLT device |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 73 | olt := devices.CreateOLT( |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 74 | *config.GlobalConfig, |
| 75 | common.Services, |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 76 | true, |
| 77 | ) |
Matteo Scandolo | 583f17d | 2020-02-13 10:35:17 -0800 | [diff] [blame] | 78 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 79 | onuIdMap := make(map[uint32]uint32, config.Olt.PonPorts) |
Matteo Scandolo | 583f17d | 2020-02-13 10:35:17 -0800 | [diff] [blame] | 80 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 81 | oltMock := bbrdevices.OltMock{ |
| 82 | Olt: olt, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 83 | TargetOnus: int(config.Olt.PonPorts * config.Olt.OnusPonPort), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 84 | CompletedOnus: 0, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 85 | BBSimIp: config.BBSimIp, |
| 86 | BBSimPort: config.BBSimPort, |
| 87 | BBSimApiPort: config.BBSimApiPort, |
Matteo Scandolo | 583f17d | 2020-02-13 10:35:17 -0800 | [diff] [blame] | 88 | LastUsedOnuId: onuIdMap, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | // start the enable sequence |
| 92 | startTime := time.Now() |
| 93 | defer func() { |
| 94 | endTime := time.Now() |
| 95 | runTime := endTime.Sub(startTime) |
| 96 | log.WithField("Duration", runTime).Info("BBR done!") |
| 97 | }() |
| 98 | oltMock.Start() |
| 99 | } |
Joey Armstrong | a7ef8d2 | 2023-12-11 18:11:53 -0500 | [diff] [blame^] | 100 | |
| 101 | // [EOF] |