blob: 589d557f8a8be37371ff8732ff6aa792926cc277 [file] [log] [blame]
Matteo Scandolo4747d292019-08-05 11:50:18 -07001package main
2
3import (
4 "flag"
Matteo Scandolo84f7d482019-08-08 19:00:47 -07005 "gerrit.opencord.org/bbsim/api/bbsim"
Matteo Scandolo4747d292019-08-05 11:50:18 -07006 "gerrit.opencord.org/bbsim/internal/bbsim/devices"
7 log "github.com/sirupsen/logrus"
Matteo Scandolo84f7d482019-08-08 19:00:47 -07008 "google.golang.org/grpc"
9 "google.golang.org/grpc/reflection"
10 "net"
Matteo Scandolo4747d292019-08-05 11:50:18 -070011 "sync"
12)
13
14func getOpts() *CliOptions {
15
16 olt_id := flag.Int("olt_id", 0, "Number of OLT devices to be emulated (default is 1)")
17 nni := flag.Int("nni", 1, "Number of NNI ports per OLT device to be emulated (default is 1)")
18 pon := flag.Int("pon", 1, "Number of PON ports per OLT device to be emulated (default is 1)")
19 onu := flag.Int("onu", 1, "Number of ONU devices per PON port to be emulated (default is 1)")
20 flag.Parse()
21
22 o := new(CliOptions)
23
24 o.OltID = int(*olt_id)
25 o.NumNniPerOlt = int(*nni)
26 o.NumPonPerOlt = int(*pon)
27 o.NumOnuPerPon = int(*onu)
28
29 return o
30}
31
Matteo Scandolo84f7d482019-08-08 19:00:47 -070032func startApiServer() {
33 // TODO make configurable
34 address := "0.0.0.0:50070"
35 log.Debugf("APIServer Listening on: %v", address)
36 lis, err := net.Listen("tcp", address)
37 if err != nil {
38 log.Fatalf("APIServer failed to listen: %v", err)
39 }
40 grpcServer := grpc.NewServer()
41 bbsim.RegisterBBSimServer(grpcServer, BBSimServer{})
42
43 reflection.Register(grpcServer)
44
45 go grpcServer.Serve(lis)
46}
47
Matteo Scandolo4747d292019-08-05 11:50:18 -070048func init() {
49 log.SetLevel(log.DebugLevel)
50 //log.SetReportCaller(true)
51}
52
53func main() {
54
55 options := getOpts()
56
57 log.WithFields(log.Fields{
58 "OltID": options.OltID,
59 "NumNniPerOlt": options.NumNniPerOlt,
60 "NumPonPerOlt": options.NumPonPerOlt,
61 "NumOnuPerPon": options.NumOnuPerPon,
62 }).Info("BroadBand Simulator is on")
63
64 wg := sync.WaitGroup{}
Matteo Scandolo84f7d482019-08-08 19:00:47 -070065 wg.Add(2)
Matteo Scandolo4747d292019-08-05 11:50:18 -070066
67
68 go devices.CreateOLT(options.OltID, options.NumNniPerOlt, options.NumPonPerOlt, options.NumOnuPerPon)
69 log.Debugf("Created OLT with id: %d", options.OltID)
Matteo Scandolo84f7d482019-08-08 19:00:47 -070070 go startApiServer()
71 log.Debugf("Started APIService")
Matteo Scandolo4747d292019-08-05 11:50:18 -070072
73 wg.Wait()
74
75 defer func() {
76 log.Info("BroadBand Simulator is off")
77 }()
78}