Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "context" |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 5 | "gerrit.opencord.org/bbsim/api/bbsim" |
| 6 | "gerrit.opencord.org/bbsim/internal/bbsim/devices" |
| 7 | log "github.com/sirupsen/logrus" |
| 8 | ) |
| 9 | |
| 10 | var logger = log.WithFields(log.Fields{ |
| 11 | "module": "GrpcApiServer", |
| 12 | }) |
| 13 | |
| 14 | var ( |
| 15 | version string |
| 16 | buildTime string |
| 17 | commitHash string |
| 18 | gitStatus string |
| 19 | ) |
| 20 | |
| 21 | type BBSimServer struct { |
| 22 | } |
| 23 | |
| 24 | func (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 | |
| 34 | func (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 Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame^] | 42 | OperState: nni.OperState.Current(), |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 43 | } |
| 44 | nnis = append(nnis, &n) |
| 45 | } |
| 46 | |
| 47 | for _, pon := range olt.Pons { |
| 48 | p := bbsim.PONPort{ |
| 49 | ID: int32(pon.ID), |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame^] | 50 | OperState: pon.OperState.Current(), |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 51 | } |
| 52 | pons = append(pons, &p) |
| 53 | } |
| 54 | |
| 55 | res := bbsim.Olt{ |
| 56 | ID: int32(olt.ID), |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame^] | 57 | OperState: olt.OperState.Current(), |
| 58 | InternalState: olt.InternalState.Current(), |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 59 | NNIPorts: nnis, |
| 60 | PONPorts: pons, |
| 61 | } |
| 62 | return &res, nil |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame^] | 63 | } |
| 64 | |
| 65 | func (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 Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 84 | } |