blob: 5d92f705c3d26953eb79eeae53d9fc9ef1fdae92 [file] [log] [blame]
Matteo Scandolo84f7d482019-08-08 19:00:47 -07001package main
2
3import (
4 "context"
Matteo Scandolo84f7d482019-08-08 19:00:47 -07005 "gerrit.opencord.org/bbsim/api/bbsim"
6 "gerrit.opencord.org/bbsim/internal/bbsim/devices"
7 log "github.com/sirupsen/logrus"
8)
9
10var logger = log.WithFields(log.Fields{
11 "module": "GrpcApiServer",
12})
13
14var (
15 version string
16 buildTime string
17 commitHash string
18 gitStatus string
19)
20
21type BBSimServer struct {
22}
23
24func (s BBSimServer) Version(ctx context.Context, req *bbsim.Empty) (*bbsim.VersionNumber, error) {
25 // TODO add a flag to specofy whether the tree was clean at this commit or not
26 return &bbsim.VersionNumber{
27 Version: version,
28 BuildTime: buildTime,
29 CommitHash: commitHash,
30 GitStatus: gitStatus,
31 }, nil
32}
33
34func (s BBSimServer) GetOlt(ctx context.Context, req *bbsim.Empty) (*bbsim.Olt, error) {
35 olt := devices.GetOLT()
36 nnis := []*bbsim.NNIPort{}
37 pons := []*bbsim.PONPort{}
38
39 for _, nni := range olt.Nnis {
40 n := bbsim.NNIPort{
41 ID: int32(nni.ID),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070042 OperState: nni.OperState.Current(),
Matteo Scandolo84f7d482019-08-08 19:00:47 -070043 }
44 nnis = append(nnis, &n)
45 }
46
47 for _, pon := range olt.Pons {
48 p := bbsim.PONPort{
49 ID: int32(pon.ID),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070050 OperState: pon.OperState.Current(),
Matteo Scandolo84f7d482019-08-08 19:00:47 -070051 }
52 pons = append(pons, &p)
53 }
54
55 res := bbsim.Olt{
56 ID: int32(olt.ID),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070057 OperState: olt.OperState.Current(),
58 InternalState: olt.InternalState.Current(),
Matteo Scandolo84f7d482019-08-08 19:00:47 -070059 NNIPorts: nnis,
60 PONPorts: pons,
61 }
62 return &res, nil
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070063}
64
65func (s BBSimServer) GetONUs(ctx context.Context, req *bbsim.Empty) (*bbsim.ONUs, error){
66 olt := devices.GetOLT()
67 onus := bbsim.ONUs{
68 Items: []*bbsim.ONU{},
69 }
70
71 for _, pon := range olt.Pons {
72 for _, o := range pon.Onus {
73 onu := bbsim.ONU{
74 ID: int32(o.ID),
75 SerialNumber: o.SerialNumber.String(),
76 OperState: o.OperState.Current(),
77 InternalState: o.InternalState.Current(),
78 PonPortID: int32(o.PonPortID),
79 }
80 onus.Items = append(onus.Items, &onu)
81 }
82 }
83 return &onus, nil
Matteo Scandolo84f7d482019-08-08 19:00:47 -070084}