blob: 3c3ab3e6890a8568134f213c82efc0a219f22344 [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 Scandolo84f7d482019-08-08 19:00:47 -070017package main
18
19import (
20 "context"
Matteo Scandolo11006992019-08-28 11:29:46 -070021 "github.com/opencord/bbsim/api/bbsim"
22 "github.com/opencord/bbsim/internal/bbsim/devices"
Matteo Scandolo84f7d482019-08-08 19:00:47 -070023 log "github.com/sirupsen/logrus"
24)
25
26var logger = log.WithFields(log.Fields{
27 "module": "GrpcApiServer",
28})
29
30var (
31 version string
32 buildTime string
33 commitHash string
34 gitStatus string
35)
36
37type BBSimServer struct {
38}
39
40func (s BBSimServer) Version(ctx context.Context, req *bbsim.Empty) (*bbsim.VersionNumber, error) {
41 // TODO add a flag to specofy whether the tree was clean at this commit or not
42 return &bbsim.VersionNumber{
43 Version: version,
44 BuildTime: buildTime,
45 CommitHash: commitHash,
46 GitStatus: gitStatus,
47 }, nil
48}
49
50func (s BBSimServer) GetOlt(ctx context.Context, req *bbsim.Empty) (*bbsim.Olt, error) {
51 olt := devices.GetOLT()
52 nnis := []*bbsim.NNIPort{}
53 pons := []*bbsim.PONPort{}
54
55 for _, nni := range olt.Nnis {
56 n := bbsim.NNIPort{
57 ID: int32(nni.ID),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070058 OperState: nni.OperState.Current(),
Matteo Scandolo84f7d482019-08-08 19:00:47 -070059 }
60 nnis = append(nnis, &n)
61 }
62
63 for _, pon := range olt.Pons {
64 p := bbsim.PONPort{
65 ID: int32(pon.ID),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070066 OperState: pon.OperState.Current(),
Matteo Scandolo84f7d482019-08-08 19:00:47 -070067 }
68 pons = append(pons, &p)
69 }
70
71 res := bbsim.Olt{
72 ID: int32(olt.ID),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070073 OperState: olt.OperState.Current(),
74 InternalState: olt.InternalState.Current(),
Matteo Scandolo84f7d482019-08-08 19:00:47 -070075 NNIPorts: nnis,
76 PONPorts: pons,
77 }
78 return &res, nil
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070079}
80
81func (s BBSimServer) GetONUs(ctx context.Context, req *bbsim.Empty) (*bbsim.ONUs, error){
82 olt := devices.GetOLT()
83 onus := bbsim.ONUs{
84 Items: []*bbsim.ONU{},
85 }
86
87 for _, pon := range olt.Pons {
88 for _, o := range pon.Onus {
89 onu := bbsim.ONU{
90 ID: int32(o.ID),
91 SerialNumber: o.SerialNumber.String(),
92 OperState: o.OperState.Current(),
93 InternalState: o.InternalState.Current(),
94 PonPortID: int32(o.PonPortID),
95 }
96 onus.Items = append(onus.Items, &onu)
97 }
98 }
99 return &onus, nil
Matteo Scandolo84f7d482019-08-08 19:00:47 -0700100}