blob: 9df725b830525fdcf1b82f9781742154113c4f0c [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"
Zdravko Bozakov2da76342019-10-21 09:47:35 +020021
Matteo Scandolo11006992019-08-28 11:29:46 -070022 "github.com/opencord/bbsim/api/bbsim"
23 "github.com/opencord/bbsim/internal/bbsim/devices"
Matteo Scandolo40e067f2019-10-16 16:59:41 -070024 "github.com/opencord/bbsim/internal/common"
Matteo Scandolo84f7d482019-08-08 19:00:47 -070025 log "github.com/sirupsen/logrus"
26)
27
28var logger = log.WithFields(log.Fields{
29 "module": "GrpcApiServer",
30})
31
32var (
Matteo Scandolo8df63df2019-09-12 10:34:32 -070033 version string
34 buildTime string
35 commitHash string
36 gitStatus string
Matteo Scandolo84f7d482019-08-08 19:00:47 -070037)
38
39type BBSimServer struct {
40}
41
Matteo Scandolo8df63df2019-09-12 10:34:32 -070042func (s BBSimServer) Version(ctx context.Context, req *bbsim.Empty) (*bbsim.VersionNumber, error) {
Zdravko Bozakov2da76342019-10-21 09:47:35 +020043 // TODO add a flag to specify whether the tree was clean at this commit or not
Matteo Scandolo84f7d482019-08-08 19:00:47 -070044 return &bbsim.VersionNumber{
Matteo Scandolo8df63df2019-09-12 10:34:32 -070045 Version: version,
46 BuildTime: buildTime,
Matteo Scandolo84f7d482019-08-08 19:00:47 -070047 CommitHash: commitHash,
Matteo Scandolo8df63df2019-09-12 10:34:32 -070048 GitStatus: gitStatus,
Matteo Scandolo84f7d482019-08-08 19:00:47 -070049 }, nil
50}
51
52func (s BBSimServer) GetOlt(ctx context.Context, req *bbsim.Empty) (*bbsim.Olt, error) {
53 olt := devices.GetOLT()
54 nnis := []*bbsim.NNIPort{}
55 pons := []*bbsim.PONPort{}
56
57 for _, nni := range olt.Nnis {
58 n := bbsim.NNIPort{
Matteo Scandolo8df63df2019-09-12 10:34:32 -070059 ID: int32(nni.ID),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070060 OperState: nni.OperState.Current(),
Matteo Scandolo84f7d482019-08-08 19:00:47 -070061 }
62 nnis = append(nnis, &n)
63 }
64
65 for _, pon := range olt.Pons {
66 p := bbsim.PONPort{
Matteo Scandolo8df63df2019-09-12 10:34:32 -070067 ID: int32(pon.ID),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070068 OperState: pon.OperState.Current(),
Matteo Scandolo84f7d482019-08-08 19:00:47 -070069 }
70 pons = append(pons, &p)
71 }
72
73 res := bbsim.Olt{
Matteo Scandolo8df63df2019-09-12 10:34:32 -070074 ID: int32(olt.ID),
75 SerialNumber: olt.SerialNumber,
76 OperState: olt.OperState.Current(),
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070077 InternalState: olt.InternalState.Current(),
Matteo Scandolo8df63df2019-09-12 10:34:32 -070078 NNIPorts: nnis,
79 PONPorts: pons,
Matteo Scandolo84f7d482019-08-08 19:00:47 -070080 }
81 return &res, nil
Matteo Scandolo9a3518c2019-08-13 14:36:01 -070082}
83
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070084func (s BBSimServer) SetLogLevel(ctx context.Context, req *bbsim.LogLevel) (*bbsim.LogLevel, error) {
85
Matteo Scandolo40e067f2019-10-16 16:59:41 -070086 common.SetLogLevel(log.StandardLogger(), req.Level, req.Caller)
Matteo Scandolo2bf742a2019-10-01 11:33:34 -070087
88 return &bbsim.LogLevel{
89 Level: log.StandardLogger().Level.String(),
90 Caller: log.StandardLogger().ReportCaller,
91 }, nil
92}