blob: 46bdf81a0e89e58c92f7dc4487cca19f6d1b898c [file] [log] [blame]
onkarkundargi72cfd362020-02-27 12:34:37 +05301/*
2 *
3 * Copyright 2015 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19// Package main implements a server for nem-ondemand-proxy
20package main
21
22import (
23 "context"
24 "github.com/opencord/nem-ondemand-proxy/protos/nem_ondemand_api"
25 "google.golang.org/grpc"
26 "google.golang.org/grpc/reflection"
27 "log"
28 "net"
29)
30
31const (
32 port = ":50052"
33)
34
35//server is used to implement the grpc server for the proxy
36type server struct {
37}
38
39func (s *server) OmciTest(ctx context.Context, id *nem_ondemand_api.OnuID) (*nem_ondemand_api.ResponseTest, error) {
40 log.Printf("Request Received from operator client: %s", id.Id)
41 resp, err := connect(&id.Id)
42 if err != nil {
43 log.Printf("%s", err)
44 return nil, err
45 }
46 log.Printf("Result received from voltha-grpc-client: %s", resp.String())
47 if len(resp.String()) > 0 {
48 return &nem_ondemand_api.ResponseTest{Result: resp.String()}, nil
49 }
50 return &nem_ondemand_api.ResponseTest{Result: "FAILURE"}, nil
51}
52
53func main() {
54 log.Printf("Starting nem_grpc_server")
55 lis, err := net.Listen("tcp", port)
56 if err != nil {
57 log.Fatalf("failed to listen: %v", err)
58 }
59 s := grpc.NewServer()
60 nem_ondemand_api.RegisterNemServiceServer(s, &server{})
61 reflection.Register(s)
62 if err := s.Serve(lis); err != nil {
63 log.Fatalf("failed to serve: %v", err)
64 }
65}