blob: fea52a8ff9ac544195232bedd38d2840ccd91cfb [file] [log] [blame]
amit.ghosh258d14c2020-10-02 15:13:38 +02001/*
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
17package dmiserver
18
19import (
Humera Kousera4442952020-11-23 23:51:19 +053020 "context"
amit.ghosh258d14c2020-10-02 15:13:38 +020021 "net"
22
hkouser24361d42020-12-14 19:21:47 +053023 "github.com/opencord/bbsim/api/bbsim"
amit.ghosh258d14c2020-10-02 15:13:38 +020024 "github.com/opencord/bbsim/internal/common"
25 dmi "github.com/opencord/device-management-interface/go/dmi"
26 log "github.com/sirupsen/logrus"
27
28 "google.golang.org/grpc"
29 "google.golang.org/grpc/reflection"
30)
31
32var logger = log.WithFields(log.Fields{
33 "module": "DmiServer",
34})
35
36//DmiAPIServer has the attributes for the Server handling the Device Management Interface
37type DmiAPIServer struct {
38 deviceSerial string
39 deviceName string
40 ipAddress string
41 uuid string
42 ponTransceiverUuids []string
43 ponTransceiverCageUuids []string
Humera Kousera4442952020-11-23 23:51:19 +053044 root *dmi.Component
45 metricChannel chan interface{}
hkouser24361d42020-12-14 19:21:47 +053046 eventChannel chan interface{}
Humera Kousera4442952020-11-23 23:51:19 +053047 kafkaEndpoint string
ssiddiqui6ca40702021-03-08 18:20:21 +053048 loggingEndpoint string
49 loggingProtocol string
Humera Kousera4442952020-11-23 23:51:19 +053050 mPublisherCancelFunc context.CancelFunc
amit.ghosh258d14c2020-10-02 15:13:38 +020051}
52
53var dmiServ DmiAPIServer
54
55//StartDmiAPIServer starts a new grpc server for the Device Manager Interface
56func StartDmiAPIServer() (*grpc.Server, error) {
57 dmiServ = DmiAPIServer{}
58
59 return dmiServ.newDmiAPIServer()
60}
61
62// newDmiAPIServer launches a new grpc server for the Device Manager Interface
63func (dms *DmiAPIServer) newDmiAPIServer() (*grpc.Server, error) {
64 address := common.Config.BBSim.DmiServerAddress
65 lis, err := net.Listen("tcp", address)
66 if err != nil {
67 return nil, err
68 }
69
70 grpcServer := grpc.NewServer()
71
72 dmi.RegisterNativeHWManagementServiceServer(grpcServer, dms)
73 dmi.RegisterNativeSoftwareManagementServiceServer(grpcServer, dms)
74 dmi.RegisterNativeEventsManagementServiceServer(grpcServer, dms)
75 dmi.RegisterNativeMetricsManagementServiceServer(grpcServer, dms)
hkouser24361d42020-12-14 19:21:47 +053076 bbsim.RegisterBBsimDmiServer(grpcServer, dms)
amit.ghosh258d14c2020-10-02 15:13:38 +020077
78 reflection.Register(grpcServer)
79
80 go func() { _ = grpcServer.Serve(lis) }()
81 logger.Debugf("DMI grpc Server listening on %v", address)
amit.ghosh258d14c2020-10-02 15:13:38 +020082
83 return grpcServer, nil
84}