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 | |
| 40 | if *options.ProfileCpu != "" { |
| 41 | // start profiling |
| 42 | log.Infof("Creating profile file at: %s", *options.ProfileCpu) |
| 43 | f, err := os.Create(*options.ProfileCpu) |
| 44 | if err != nil { |
| 45 | log.Fatal(err) |
| 46 | } |
| 47 | pprof.StartCPUProfile(f) |
| 48 | } |
| 49 | |
| 50 | log.WithFields(log.Fields{ |
| 51 | "OltID": options.OltID, |
| 52 | "NumNniPerOlt": options.NumNniPerOlt, |
| 53 | "NumPonPerOlt": options.NumPonPerOlt, |
| 54 | "NumOnuPerPon": options.NumOnuPerPon, |
Matteo Scandolo | ba342de | 2019-10-22 10:41:33 -0700 | [diff] [blame] | 55 | "BBSimIp": options.BBSimIp, |
| 56 | "BBSimPort": options.BBSimPort, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 57 | }).Info("BroadBand Reflector is on") |
| 58 | |
| 59 | // NOTE this are probably useless in the MockOLT case, check if we can avoid using them in the CreateOlt method |
| 60 | oltDoneChannel := make(chan bool) |
| 61 | apiDoneChannel := make(chan bool) |
| 62 | |
| 63 | // create the OLT device |
| 64 | olt := devices.CreateOLT(options.OltID, options.NumNniPerOlt, options.NumPonPerOlt, options.NumOnuPerPon, options.STag, options.CTagInit, &oltDoneChannel, &apiDoneChannel, true) |
| 65 | oltMock := bbrdevices.OltMock{ |
| 66 | Olt: olt, |
| 67 | TargetOnus: options.NumPonPerOlt * options.NumOnuPerPon, |
| 68 | CompletedOnus: 0, |
| 69 | BBSimIp: options.BBSimIp, |
| 70 | BBSimPort: options.BBSimPort, |
| 71 | BBSimApiPort: options.BBSimApiPort, |
| 72 | } |
| 73 | |
| 74 | // start the enable sequence |
| 75 | startTime := time.Now() |
| 76 | defer func() { |
| 77 | endTime := time.Now() |
| 78 | runTime := endTime.Sub(startTime) |
| 79 | log.WithField("Duration", runTime).Info("BBR done!") |
| 80 | }() |
| 81 | oltMock.Start() |
| 82 | } |