blob: 4c83789b48d11152336c9ab4e1ad7d450edbc786 [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() {
37 options := common.GetBBROpts()
38
Zdravko Bozakov3ddb2452019-11-29 14:33:41 +010039 common.SetLogLevel(log.StandardLogger(), options.BBR.LogLevel, options.BBR.LogCaller)
Matteo Scandolo40e067f2019-10-16 16:59:41 -070040
Matteo Scandolof5c537e2019-10-28 16:45:57 -070041 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 Bozakov3ddb2452019-11-29 14:33:41 +010050 if *options.BBSim.CpuProfile != "" {
Matteo Scandolo40e067f2019-10-16 16:59:41 -070051 // start profiling
Zdravko Bozakov3ddb2452019-11-29 14:33:41 +010052 log.Infof("Creating profile file at: %s", *options.BBSim.CpuProfile)
53 f, err := os.Create(*options.BBSim.CpuProfile)
Matteo Scandolo40e067f2019-10-16 16:59:41 -070054 if err != nil {
55 log.Fatal(err)
56 }
57 pprof.StartCPUProfile(f)
58 }
59
60 log.WithFields(log.Fields{
Zdravko Bozakov3ddb2452019-11-29 14:33:41 +010061 "OltID": options.Olt.ID,
62 "NumNniPerOlt": options.Olt.NniPorts,
63 "NumPonPerOlt": options.Olt.PonPorts,
64 "NumOnuPerPon": options.Olt.OnusPonPort,
Matteo Scandoloba342de2019-10-22 10:41:33 -070065 "BBSimIp": options.BBSimIp,
66 "BBSimPort": options.BBSimPort,
Matteo Scandolo40e067f2019-10-16 16:59:41 -070067 }).Info("BroadBand Reflector is on")
68
Matteo Scandolo40e067f2019-10-16 16:59:41 -070069 // create the OLT device
Matteo Scandoloc1147092019-10-29 09:38:33 -070070 olt := devices.CreateOLT(
Zdravko Bozakov3ddb2452019-11-29 14:33:41 +010071 options.Olt.ID,
72 int(options.Olt.NniPorts),
73 int(options.Olt.PonPorts),
74 int(options.Olt.OnusPonPort),
75 options.BBSim.STag,
76 options.BBSim.CTagInit,
Matteo Scandoloc1147092019-10-29 09:38:33 -070077 true, // this parameter is not important in the BBR Case
78 true, // this parameter is not important in the BBR Case
Matteo Scandolo5e081b52019-11-21 14:34:25 -080079 0, // this parameter does not matter in the BBR case
Pragya Arya2225f202020-01-29 18:05:01 +053080 options.BBSim.ControlledActivation,
Matteo Scandoloc1147092019-10-29 09:38:33 -070081 true,
82 )
Matteo Scandolo40e067f2019-10-16 16:59:41 -070083 oltMock := bbrdevices.OltMock{
84 Olt: olt,
Zdravko Bozakov3ddb2452019-11-29 14:33:41 +010085 TargetOnus: int(options.Olt.PonPorts * options.Olt.OnusPonPort),
Matteo Scandolo40e067f2019-10-16 16:59:41 -070086 CompletedOnus: 0,
87 BBSimIp: options.BBSimIp,
88 BBSimPort: options.BBSimPort,
89 BBSimApiPort: options.BBSimApiPort,
90 }
91
92 // start the enable sequence
93 startTime := time.Now()
94 defer func() {
95 endTime := time.Now()
96 runTime := endTime.Sub(startTime)
97 log.WithField("Duration", runTime).Info("BBR done!")
98 }()
99 oltMock.Start()
100}