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 | // 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() { |
| 37 | options := common.GetBBROpts() |
| 38 | |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 39 | common.SetLogLevel(log.StandardLogger(), options.BBR.LogLevel, options.BBR.LogCaller) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 40 | |
Matteo Scandolo | f5c537e | 2019-10-28 16:45:57 -0700 | [diff] [blame] | 41 | if options.LogFile != "" { |
| 42 | file, err := os.OpenFile(options.LogFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) |
| 43 | if err == nil { |
| 44 | log.StandardLogger().Out = file |
| 45 | } else { |
| 46 | log.Fatal("Failed to log to file, using default stderr") |
| 47 | } |
| 48 | } |
| 49 | |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 50 | if *options.BBSim.CpuProfile != "" { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 51 | // start profiling |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 52 | log.Infof("Creating profile file at: %s", *options.BBSim.CpuProfile) |
| 53 | f, err := os.Create(*options.BBSim.CpuProfile) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 54 | if err != nil { |
| 55 | log.Fatal(err) |
| 56 | } |
| 57 | pprof.StartCPUProfile(f) |
| 58 | } |
| 59 | |
| 60 | log.WithFields(log.Fields{ |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 61 | "OltID": options.Olt.ID, |
| 62 | "NumNniPerOlt": options.Olt.NniPorts, |
| 63 | "NumPonPerOlt": options.Olt.PonPorts, |
| 64 | "NumOnuPerPon": options.Olt.OnusPonPort, |
Matteo Scandolo | ba342de | 2019-10-22 10:41:33 -0700 | [diff] [blame] | 65 | "BBSimIp": options.BBSimIp, |
| 66 | "BBSimPort": options.BBSimPort, |
Matteo Scandolo | 583f17d | 2020-02-13 10:35:17 -0800 | [diff] [blame] | 67 | "LogLevel": options.BBR.LogLevel, |
| 68 | "TotalOnus": options.Olt.PonPorts * options.Olt.OnusPonPort, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 69 | }).Info("BroadBand Reflector is on") |
| 70 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 71 | // create the OLT device |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 72 | olt := devices.CreateOLT( |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 73 | options.Olt.ID, |
| 74 | int(options.Olt.NniPorts), |
| 75 | int(options.Olt.PonPorts), |
| 76 | int(options.Olt.OnusPonPort), |
| 77 | options.BBSim.STag, |
| 78 | options.BBSim.CTagInit, |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 79 | true, // this parameter is not important in the BBR Case |
| 80 | true, // this parameter is not important in the BBR Case |
Matteo Scandolo | 5e081b5 | 2019-11-21 14:34:25 -0800 | [diff] [blame] | 81 | 0, // this parameter does not matter in the BBR case |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 82 | options.BBSim.ControlledActivation, |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 83 | true, |
| 84 | ) |
Matteo Scandolo | 583f17d | 2020-02-13 10:35:17 -0800 | [diff] [blame] | 85 | |
| 86 | onuIdMap := make(map[uint32]uint32, options.Olt.PonPorts) |
| 87 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 88 | oltMock := bbrdevices.OltMock{ |
| 89 | Olt: olt, |
Zdravko Bozakov | 3ddb245 | 2019-11-29 14:33:41 +0100 | [diff] [blame] | 90 | TargetOnus: int(options.Olt.PonPorts * options.Olt.OnusPonPort), |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 91 | CompletedOnus: 0, |
| 92 | BBSimIp: options.BBSimIp, |
| 93 | BBSimPort: options.BBSimPort, |
| 94 | BBSimApiPort: options.BBSimApiPort, |
Matteo Scandolo | 583f17d | 2020-02-13 10:35:17 -0800 | [diff] [blame] | 95 | LastUsedOnuId: onuIdMap, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | // start the enable sequence |
| 99 | startTime := time.Now() |
| 100 | defer func() { |
| 101 | endTime := time.Now() |
| 102 | runTime := endTime.Sub(startTime) |
| 103 | log.WithField("Duration", runTime).Info("BBR done!") |
| 104 | }() |
| 105 | oltMock.Start() |
| 106 | } |