blob: 272f3c90c4e582d0bb6d4ed46b8aa5115a0f6dec [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
48 mPublisherCancelFunc context.CancelFunc
amit.ghosh258d14c2020-10-02 15:13:38 +020049}
50
51var dmiServ DmiAPIServer
52
53//StartDmiAPIServer starts a new grpc server for the Device Manager Interface
54func StartDmiAPIServer() (*grpc.Server, error) {
55 dmiServ = DmiAPIServer{}
56
57 return dmiServ.newDmiAPIServer()
58}
59
60// newDmiAPIServer launches a new grpc server for the Device Manager Interface
61func (dms *DmiAPIServer) newDmiAPIServer() (*grpc.Server, error) {
62 address := common.Config.BBSim.DmiServerAddress
63 lis, err := net.Listen("tcp", address)
64 if err != nil {
65 return nil, err
66 }
67
68 grpcServer := grpc.NewServer()
69
70 dmi.RegisterNativeHWManagementServiceServer(grpcServer, dms)
71 dmi.RegisterNativeSoftwareManagementServiceServer(grpcServer, dms)
72 dmi.RegisterNativeEventsManagementServiceServer(grpcServer, dms)
73 dmi.RegisterNativeMetricsManagementServiceServer(grpcServer, dms)
hkouser24361d42020-12-14 19:21:47 +053074 bbsim.RegisterBBsimDmiServer(grpcServer, dms)
amit.ghosh258d14c2020-10-02 15:13:38 +020075
76 reflection.Register(grpcServer)
77
78 go func() { _ = grpcServer.Serve(lis) }()
79 logger.Debugf("DMI grpc Server listening on %v", address)
amit.ghosh258d14c2020-10-02 15:13:38 +020080
81 return grpcServer, nil
82}