amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package dmiserver |
| 18 | |
| 19 | import ( |
Humera Kouser | a444295 | 2020-11-23 23:51:19 +0530 | [diff] [blame] | 20 | "context" |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 21 | "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 | |
| 31 | var logger = log.WithFields(log.Fields{ |
| 32 | "module": "DmiServer", |
| 33 | }) |
| 34 | |
| 35 | //DmiAPIServer has the attributes for the Server handling the Device Management Interface |
| 36 | type DmiAPIServer struct { |
| 37 | deviceSerial string |
| 38 | deviceName string |
| 39 | ipAddress string |
| 40 | uuid string |
| 41 | ponTransceiverUuids []string |
| 42 | ponTransceiverCageUuids []string |
Humera Kouser | a444295 | 2020-11-23 23:51:19 +0530 | [diff] [blame] | 43 | root *dmi.Component |
| 44 | metricChannel chan interface{} |
| 45 | kafkaEndpoint string |
| 46 | mPublisherCancelFunc context.CancelFunc |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | var dmiServ DmiAPIServer |
| 50 | |
| 51 | //StartDmiAPIServer starts a new grpc server for the Device Manager Interface |
| 52 | func 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 |
| 59 | func (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.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 77 | |
| 78 | return grpcServer, nil |
| 79 | } |