blob: 1cd33bc6c19a1a7d89abefafb05f789b8cfdc9b9 [file] [log] [blame]
Matteo Scandolo40e067f2019-10-16 16:59:41 -07001/*
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.
22package main
23
24import (
Zdravko Bozakov681364d2019-11-10 14:28:46 +010025 "os"
26 "runtime/pprof"
27 "time"
28
Matteo Scandolo40e067f2019-10-16 16:59:41 -070029 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 Scandolo40e067f2019-10-16 16:59:41 -070033)
34
35// usage
36func main() {
Matteo Scandolo4a036262020-08-17 15:56:13 -070037 config := common.GetBBROpts()
Matteo Scandolo40e067f2019-10-16 16:59:41 -070038
Matteo Scandolo4a036262020-08-17 15:56:13 -070039 common.SetLogLevel(log.StandardLogger(), config.BBR.LogLevel, config.BBR.LogCaller)
Matteo Scandolo40e067f2019-10-16 16:59:41 -070040
Matteo Scandolo4a036262020-08-17 15:56:13 -070041 if config.LogFile != "" {
42 file, err := os.OpenFile(config.LogFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
Matteo Scandolof5c537e2019-10-28 16:45:57 -070043 if err == nil {
44 log.StandardLogger().Out = file
45 } else {
46 log.Fatal("Failed to log to file, using default stderr")
47 }
48 }
49
Matteo Scandolo4a036262020-08-17 15:56:13 -070050 if *config.BBSim.CpuProfile != "" {
Matteo Scandolo40e067f2019-10-16 16:59:41 -070051 // start profiling
Matteo Scandolo4a036262020-08-17 15:56:13 -070052 log.Infof("Creating profile file at: %s", *config.BBSim.CpuProfile)
53 f, err := os.Create(*config.BBSim.CpuProfile)
Matteo Scandolo40e067f2019-10-16 16:59:41 -070054 if err != nil {
55 log.Fatal(err)
56 }
Shrey Baid688b4242020-07-10 20:40:10 +053057 _ = pprof.StartCPUProfile(f)
Matteo Scandolo40e067f2019-10-16 16:59:41 -070058 }
59
60 log.WithFields(log.Fields{
Matteo Scandolo4a036262020-08-17 15:56:13 -070061 "OltID": config.Olt.ID,
62 "NumNniPerOlt": config.Olt.NniPorts,
63 "NumPonPerOlt": config.Olt.PonPorts,
64 "NumOnuPerPon": config.Olt.OnusPonPort,
65 "BBSimIp": config.BBSimIp,
66 "BBSimPort": config.BBSimPort,
67 "LogLevel": config.BBR.LogLevel,
68 "TotalOnus": config.Olt.PonPorts * config.Olt.OnusPonPort,
Matteo Scandolo40e067f2019-10-16 16:59:41 -070069 }).Info("BroadBand Reflector is on")
70
Matteo Scandolo40e067f2019-10-16 16:59:41 -070071 // create the OLT device
Matteo Scandoloc1147092019-10-29 09:38:33 -070072 olt := devices.CreateOLT(
Matteo Scandolo4a036262020-08-17 15:56:13 -070073 *config.GlobalConfig,
74 common.Services,
Matteo Scandoloc1147092019-10-29 09:38:33 -070075 true,
76 )
Matteo Scandolo583f17d2020-02-13 10:35:17 -080077
Matteo Scandolo4a036262020-08-17 15:56:13 -070078 onuIdMap := make(map[uint32]uint32, config.Olt.PonPorts)
Matteo Scandolo583f17d2020-02-13 10:35:17 -080079
Matteo Scandolo40e067f2019-10-16 16:59:41 -070080 oltMock := bbrdevices.OltMock{
81 Olt: olt,
Matteo Scandolo4a036262020-08-17 15:56:13 -070082 TargetOnus: int(config.Olt.PonPorts * config.Olt.OnusPonPort),
Matteo Scandolo40e067f2019-10-16 16:59:41 -070083 CompletedOnus: 0,
Matteo Scandolo4a036262020-08-17 15:56:13 -070084 BBSimIp: config.BBSimIp,
85 BBSimPort: config.BBSimPort,
86 BBSimApiPort: config.BBSimApiPort,
Matteo Scandolo583f17d2020-02-13 10:35:17 -080087 LastUsedOnuId: onuIdMap,
Matteo Scandolo40e067f2019-10-16 16:59:41 -070088 }
89
90 // start the enable sequence
91 startTime := time.Now()
92 defer func() {
93 endTime := time.Now()
94 runTime := endTime.Sub(startTime)
95 log.WithField("Duration", runTime).Info("BBR done!")
96 }()
97 oltMock.Start()
98}