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