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 ( |
| 25 | bbrdevices "github.com/opencord/bbsim/internal/bbr/devices" |
| 26 | "github.com/opencord/bbsim/internal/bbsim/devices" |
| 27 | "github.com/opencord/bbsim/internal/common" |
| 28 | log "github.com/sirupsen/logrus" |
| 29 | "os" |
| 30 | "runtime/pprof" |
| 31 | "time" |
| 32 | ) |
| 33 | |
| 34 | // usage |
| 35 | func main() { |
| 36 | options := common.GetBBROpts() |
| 37 | |
| 38 | common.SetLogLevel(log.StandardLogger(), options.LogLevel, options.LogCaller) |
| 39 | |
Matteo Scandolo | f5c537e | 2019-10-28 16:45:57 -0700 | [diff] [blame] | 40 | if options.LogFile != "" { |
| 41 | file, err := os.OpenFile(options.LogFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) |
| 42 | if err == nil { |
| 43 | log.StandardLogger().Out = file |
| 44 | } else { |
| 45 | log.Fatal("Failed to log to file, using default stderr") |
| 46 | } |
| 47 | } |
| 48 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 49 | if *options.ProfileCpu != "" { |
| 50 | // start profiling |
| 51 | log.Infof("Creating profile file at: %s", *options.ProfileCpu) |
| 52 | f, err := os.Create(*options.ProfileCpu) |
| 53 | if err != nil { |
| 54 | log.Fatal(err) |
| 55 | } |
| 56 | pprof.StartCPUProfile(f) |
| 57 | } |
| 58 | |
| 59 | log.WithFields(log.Fields{ |
| 60 | "OltID": options.OltID, |
| 61 | "NumNniPerOlt": options.NumNniPerOlt, |
| 62 | "NumPonPerOlt": options.NumPonPerOlt, |
| 63 | "NumOnuPerPon": options.NumOnuPerPon, |
Matteo Scandolo | ba342de | 2019-10-22 10:41:33 -0700 | [diff] [blame] | 64 | "BBSimIp": options.BBSimIp, |
| 65 | "BBSimPort": options.BBSimPort, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 66 | }).Info("BroadBand Reflector is on") |
| 67 | |
| 68 | // NOTE this are probably useless in the MockOLT case, check if we can avoid using them in the CreateOlt method |
| 69 | oltDoneChannel := make(chan bool) |
| 70 | apiDoneChannel := make(chan bool) |
| 71 | |
| 72 | // create the OLT device |
| 73 | olt := devices.CreateOLT(options.OltID, options.NumNniPerOlt, options.NumPonPerOlt, options.NumOnuPerPon, options.STag, options.CTagInit, &oltDoneChannel, &apiDoneChannel, true) |
| 74 | oltMock := bbrdevices.OltMock{ |
| 75 | Olt: olt, |
| 76 | TargetOnus: options.NumPonPerOlt * options.NumOnuPerPon, |
| 77 | CompletedOnus: 0, |
| 78 | BBSimIp: options.BBSimIp, |
| 79 | BBSimPort: options.BBSimPort, |
| 80 | BBSimApiPort: options.BBSimApiPort, |
| 81 | } |
| 82 | |
| 83 | // start the enable sequence |
| 84 | startTime := time.Now() |
| 85 | defer func() { |
| 86 | endTime := time.Now() |
| 87 | runTime := endTime.Sub(startTime) |
| 88 | log.WithField("Duration", runTime).Info("BBR done!") |
| 89 | }() |
| 90 | oltMock.Start() |
| 91 | } |