Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame^] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "fmt" |
| 6 | "gerrit.opencord.org/bbsim/api/bbsim" |
| 7 | "gerrit.opencord.org/bbsim/internal/bbsim/devices" |
| 8 | log "github.com/sirupsen/logrus" |
| 9 | ) |
| 10 | |
| 11 | var logger = log.WithFields(log.Fields{ |
| 12 | "module": "GrpcApiServer", |
| 13 | }) |
| 14 | |
| 15 | var ( |
| 16 | version string |
| 17 | buildTime string |
| 18 | commitHash string |
| 19 | gitStatus string |
| 20 | ) |
| 21 | |
| 22 | type BBSimServer struct { |
| 23 | } |
| 24 | |
| 25 | func (s BBSimServer) Version(ctx context.Context, req *bbsim.Empty) (*bbsim.VersionNumber, error) { |
| 26 | // TODO add a flag to specofy whether the tree was clean at this commit or not |
| 27 | return &bbsim.VersionNumber{ |
| 28 | Version: version, |
| 29 | BuildTime: buildTime, |
| 30 | CommitHash: commitHash, |
| 31 | GitStatus: gitStatus, |
| 32 | }, nil |
| 33 | } |
| 34 | |
| 35 | func (s BBSimServer) GetOlt(ctx context.Context, req *bbsim.Empty) (*bbsim.Olt, error) { |
| 36 | olt := devices.GetOLT() |
| 37 | nnis := []*bbsim.NNIPort{} |
| 38 | pons := []*bbsim.PONPort{} |
| 39 | |
| 40 | for _, nni := range olt.Nnis { |
| 41 | n := bbsim.NNIPort{ |
| 42 | ID: int32(nni.ID), |
| 43 | OperState: fmt.Sprintf("%s", nni.OperState), |
| 44 | } |
| 45 | nnis = append(nnis, &n) |
| 46 | } |
| 47 | |
| 48 | for _, pon := range olt.Pons { |
| 49 | p := bbsim.PONPort{ |
| 50 | ID: int32(pon.ID), |
| 51 | OperState: fmt.Sprintf("%s", pon.OperState), |
| 52 | } |
| 53 | pons = append(pons, &p) |
| 54 | } |
| 55 | |
| 56 | res := bbsim.Olt{ |
| 57 | ID: int32(olt.ID), |
| 58 | OperState: fmt.Sprintf("%s", olt.OperState), |
| 59 | NNIPorts: nnis, |
| 60 | PONPorts: pons, |
| 61 | } |
| 62 | return &res, nil |
| 63 | } |