blob: f64f801533e39292aa6781645411a695d67d9187 [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
23 "github.com/opencord/bbsim/internal/common"
24 dmi "github.com/opencord/device-management-interface/go/dmi"
25 log "github.com/sirupsen/logrus"
26
27 "google.golang.org/grpc"
28 "google.golang.org/grpc/reflection"
29)
30
31var logger = log.WithFields(log.Fields{
32 "module": "DmiServer",
33})
34
35//DmiAPIServer has the attributes for the Server handling the Device Management Interface
36type DmiAPIServer struct {
37 deviceSerial string
38 deviceName string
39 ipAddress string
40 uuid string
41 ponTransceiverUuids []string
42 ponTransceiverCageUuids []string
Humera Kousera4442952020-11-23 23:51:19 +053043 root *dmi.Component
44 metricChannel chan interface{}
45 kafkaEndpoint string
46 mPublisherCancelFunc context.CancelFunc
amit.ghosh258d14c2020-10-02 15:13:38 +020047}
48
49var dmiServ DmiAPIServer
50
51//StartDmiAPIServer starts a new grpc server for the Device Manager Interface
52func StartDmiAPIServer() (*grpc.Server, error) {
53 dmiServ = DmiAPIServer{}
54
55 return dmiServ.newDmiAPIServer()
56}
57
58// newDmiAPIServer launches a new grpc server for the Device Manager Interface
59func (dms *DmiAPIServer) newDmiAPIServer() (*grpc.Server, error) {
60 address := common.Config.BBSim.DmiServerAddress
61 lis, err := net.Listen("tcp", address)
62 if err != nil {
63 return nil, err
64 }
65
66 grpcServer := grpc.NewServer()
67
68 dmi.RegisterNativeHWManagementServiceServer(grpcServer, dms)
69 dmi.RegisterNativeSoftwareManagementServiceServer(grpcServer, dms)
70 dmi.RegisterNativeEventsManagementServiceServer(grpcServer, dms)
71 dmi.RegisterNativeMetricsManagementServiceServer(grpcServer, dms)
72
73 reflection.Register(grpcServer)
74
75 go func() { _ = grpcServer.Serve(lis) }()
76 logger.Debugf("DMI grpc Server listening on %v", address)
amit.ghosh258d14c2020-10-02 15:13:38 +020077
78 return grpcServer, nil
79}