blob: deb7f40f868007fbfd6dff02651901ff81200505 [file] [log] [blame]
Matteo Scandolo11006992019-08-28 11:29:46 -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
Matteo Scandolo4747d292019-08-05 11:50:18 -070017package main
18
19import (
20 "flag"
Matteo Scandolo11006992019-08-28 11:29:46 -070021 "github.com/opencord/bbsim/api/bbsim"
22 "github.com/opencord/bbsim/internal/bbsim/devices"
Matteo Scandolo4747d292019-08-05 11:50:18 -070023 log "github.com/sirupsen/logrus"
Matteo Scandolo84f7d482019-08-08 19:00:47 -070024 "google.golang.org/grpc"
25 "google.golang.org/grpc/reflection"
26 "net"
Matteo Scandolo4747d292019-08-05 11:50:18 -070027 "sync"
28)
29
30func getOpts() *CliOptions {
31
32 olt_id := flag.Int("olt_id", 0, "Number of OLT devices to be emulated (default is 1)")
33 nni := flag.Int("nni", 1, "Number of NNI ports per OLT device to be emulated (default is 1)")
34 pon := flag.Int("pon", 1, "Number of PON ports per OLT device to be emulated (default is 1)")
35 onu := flag.Int("onu", 1, "Number of ONU devices per PON port to be emulated (default is 1)")
36 flag.Parse()
37
38 o := new(CliOptions)
39
40 o.OltID = int(*olt_id)
41 o.NumNniPerOlt = int(*nni)
42 o.NumPonPerOlt = int(*pon)
43 o.NumOnuPerPon = int(*onu)
44
45 return o
46}
47
Matteo Scandolo84f7d482019-08-08 19:00:47 -070048func startApiServer() {
49 // TODO make configurable
50 address := "0.0.0.0:50070"
51 log.Debugf("APIServer Listening on: %v", address)
52 lis, err := net.Listen("tcp", address)
53 if err != nil {
54 log.Fatalf("APIServer failed to listen: %v", err)
55 }
56 grpcServer := grpc.NewServer()
57 bbsim.RegisterBBSimServer(grpcServer, BBSimServer{})
58
59 reflection.Register(grpcServer)
60
61 go grpcServer.Serve(lis)
62}
63
Matteo Scandolo4747d292019-08-05 11:50:18 -070064func init() {
Matteo Scandoloc559ef12019-08-20 13:24:21 -070065 //log.SetLevel(log.DebugLevel)
66 log.SetLevel(log.TraceLevel)
Matteo Scandolo4747d292019-08-05 11:50:18 -070067 //log.SetReportCaller(true)
68}
69
70func main() {
71
72 options := getOpts()
73
74 log.WithFields(log.Fields{
75 "OltID": options.OltID,
76 "NumNniPerOlt": options.NumNniPerOlt,
77 "NumPonPerOlt": options.NumPonPerOlt,
78 "NumOnuPerPon": options.NumOnuPerPon,
79 }).Info("BroadBand Simulator is on")
80
81 wg := sync.WaitGroup{}
Matteo Scandolo84f7d482019-08-08 19:00:47 -070082 wg.Add(2)
Matteo Scandolo4747d292019-08-05 11:50:18 -070083
84
85 go devices.CreateOLT(options.OltID, options.NumNniPerOlt, options.NumPonPerOlt, options.NumOnuPerPon)
86 log.Debugf("Created OLT with id: %d", options.OltID)
Matteo Scandolo84f7d482019-08-08 19:00:47 -070087 go startApiServer()
88 log.Debugf("Started APIService")
Matteo Scandolo4747d292019-08-05 11:50:18 -070089
90 wg.Wait()
91
92 defer func() {
93 log.Info("BroadBand Simulator is off")
94 }()
95}