blob: 4f9eb03d2d55f876891a8b160fe9b610f03e4964 [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 (
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
35func main() {
36 options := common.GetBBROpts()
37
38 common.SetLogLevel(log.StandardLogger(), options.LogLevel, options.LogCaller)
39
Matteo Scandolof5c537e2019-10-28 16:45:57 -070040 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 Scandolo40e067f2019-10-16 16:59:41 -070049 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 Scandoloba342de2019-10-22 10:41:33 -070064 "BBSimIp": options.BBSimIp,
65 "BBSimPort": options.BBSimPort,
Matteo Scandolo40e067f2019-10-16 16:59:41 -070066 }).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
Matteo Scandoloc1147092019-10-29 09:38:33 -070073 olt := devices.CreateOLT(
74 options.OltID,
75 options.NumNniPerOlt,
76 options.NumPonPerOlt,
77 options.NumOnuPerPon,
78 options.STag,
79 options.CTagInit,
80 &oltDoneChannel,
81 &apiDoneChannel,
82 true, // this parameter is not important in the BBR Case
83 true, // this parameter is not important in the BBR Case
Matteo Scandolo5e081b52019-11-21 14:34:25 -080084 0, // this parameter does not matter in the BBR case
Matteo Scandoloc1147092019-10-29 09:38:33 -070085 true,
86 )
Matteo Scandolo40e067f2019-10-16 16:59:41 -070087 oltMock := bbrdevices.OltMock{
88 Olt: olt,
89 TargetOnus: options.NumPonPerOlt * options.NumOnuPerPon,
90 CompletedOnus: 0,
91 BBSimIp: options.BBSimIp,
92 BBSimPort: options.BBSimPort,
93 BBSimApiPort: options.BBSimApiPort,
94 }
95
96 // start the enable sequence
97 startTime := time.Now()
98 defer func() {
99 endTime := time.Now()
100 runTime := endTime.Sub(startTime)
101 log.WithField("Duration", runTime).Info("BBR done!")
102 }()
103 oltMock.Start()
104}