blob: 63f5f4a6aa4694d34f6a556b0c45bdbce665516c [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 Scandolo82c16d02019-09-24 09:34:32 -070017package api
Matteo Scandolo84f7d482019-08-08 19:00:47 -070018
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 Scandolo2bf742a2019-10-01 11:33:34 -070023 bbsimLogger "github.com/opencord/bbsim/internal/bbsim/logger"
Matteo Scandolo84f7d482019-08-08 19:00:47 -070024 log "github.com/sirupsen/logrus"
25)
26
27var logger = log.WithFields(log.Fields{
28 "module": "GrpcApiServer",
29})
30
31var (
Matteo Scandolo8df63df2019-09-12 10:34:32 -070032 version string
33 buildTime string
34 commitHash string
35 gitStatus string
Matteo Scandolo84f7d482019-08-08 19:00:47 -070036)
37
38type BBSimServer struct {
39}
40
Matteo Scandolo8df63df2019-09-12 10:34:32 -070041func (s BBSimServer) Version(ctx context.Context, req *bbsim.Empty) (*bbsim.VersionNumber, error) {
Matteo Scandolo84f7d482019-08-08 19:00:47 -070042 // TODO add a flag to specofy whether the tree was clean at this commit or not
43 return &bbsim.VersionNumber{
Matteo Scandolo8df63df2019-09-12 10:34:32 -070044 Version: version,
45 BuildTime: buildTime,
Matteo Scandolo84f7d482019-08-08 19:00:47 -070046 CommitHash: commitHash,
Matteo Scandolo8df63df2019-09-12 10:34:32 -070047 GitStatus: gitStatus,
Matteo Scandolo84f7d482019-08-08 19:00:47 -070048 }, nil
49}
50
51func (s BBSimServer) GetOlt(ctx context.Context, req *bbsim.Empty) (*bbsim.Olt, error) {
52 olt := devices.GetOLT()
53 nnis := []*bbsim.NNIPort{}
54 pons := []*bbsim.PONPort{}
55
56 for _, nni := range olt.Nnis {
57 n := bbsim.NNIPort{
Matteo Scandolo8df63df2019-09-12 10:34:32 -070058 ID: int32(nni.ID),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070059 OperState: nni.OperState.Current(),
Matteo Scandolo84f7d482019-08-08 19:00:47 -070060 }
61 nnis = append(nnis, &n)
62 }
63
64 for _, pon := range olt.Pons {
65 p := bbsim.PONPort{
Matteo Scandolo8df63df2019-09-12 10:34:32 -070066 ID: int32(pon.ID),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070067 OperState: pon.OperState.Current(),
Matteo Scandolo84f7d482019-08-08 19:00:47 -070068 }
69 pons = append(pons, &p)
70 }
71
72 res := bbsim.Olt{
Matteo Scandolo8df63df2019-09-12 10:34:32 -070073 ID: int32(olt.ID),
74 SerialNumber: olt.SerialNumber,
75 OperState: olt.OperState.Current(),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070076 InternalState: olt.InternalState.Current(),
Matteo Scandolo8df63df2019-09-12 10:34:32 -070077 NNIPorts: nnis,
78 PONPorts: pons,
Matteo Scandolo84f7d482019-08-08 19:00:47 -070079 }
80 return &res, nil
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070081}
82
Matteo Scandolo8df63df2019-09-12 10:34:32 -070083func (s BBSimServer) GetONUs(ctx context.Context, req *bbsim.Empty) (*bbsim.ONUs, error) {
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070084 olt := devices.GetOLT()
85 onus := bbsim.ONUs{
86 Items: []*bbsim.ONU{},
87 }
88
89 for _, pon := range olt.Pons {
90 for _, o := range pon.Onus {
91 onu := bbsim.ONU{
Matteo Scandolo8df63df2019-09-12 10:34:32 -070092 ID: int32(o.ID),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070093 SerialNumber: o.Sn(),
Matteo Scandolo8df63df2019-09-12 10:34:32 -070094 OperState: o.OperState.Current(),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070095 InternalState: o.InternalState.Current(),
Matteo Scandolo8df63df2019-09-12 10:34:32 -070096 PonPortID: int32(o.PonPortID),
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070097 STag: int32(o.STag),
98 CTag: int32(o.CTag),
99 HwAddress: o.HwAddress.String(),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -0700100 }
101 onus.Items = append(onus.Items, &onu)
102 }
103 }
104 return &onus, nil
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700105}
Matteo Scandolo2bf742a2019-10-01 11:33:34 -0700106
107func (s BBSimServer) SetLogLevel(ctx context.Context, req *bbsim.LogLevel) (*bbsim.LogLevel, error) {
108
109 bbsimLogger.SetLogLevel(log.StandardLogger(), req.Level, req.Caller)
110
111 return &bbsim.LogLevel{
112 Level: log.StandardLogger().Level.String(),
113 Caller: log.StandardLogger().ReportCaller,
114 }, nil
115}