blob: 800047615c6d040cfea819db7a284d94e9d6b4b3 [file] [log] [blame]
Shad Ansari01b0e652018-04-05 21:02:53 +00001/*
2 Copyright (C) 2018 Open Networking Foundation
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <iostream>
19#include <memory>
20#include <string>
21
22#include "Queue.h"
23#include <iostream>
24#include <sstream>
25
26#include "server.h"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000027#include "core.h"
Shad Ansari01b0e652018-04-05 21:02:53 +000028#include "indications.h"
29
Shad Ansarib7b0ced2018-05-11 21:53:32 +000030#include <grpc++/grpc++.h>
Shad Ansari01b0e652018-04-05 21:02:53 +000031#include <openolt.grpc.pb.h>
32
33using grpc::Server;
34using grpc::ServerBuilder;
35using grpc::ServerContext;
36using grpc::ServerWriter;
Shad Ansarib7b0ced2018-05-11 21:53:32 +000037using grpc::Status;
Shad Ansari01b0e652018-04-05 21:02:53 +000038
39const char *serverPort = "0.0.0.0:9191";
40
41class OpenoltService final : public openolt::Openolt::Service {
42
43 Status ActivateOnu(
44 ServerContext* context,
45 const openolt::Onu* request,
46 openolt::Empty* response) override {
47 return ActivateOnu_(
48 request->intf_id(),
49 request->onu_id(),
50 ((request->serial_number()).vendor_id()).c_str(),
51 ((request->serial_number()).vendor_specific()).c_str());
52 }
53
54 Status OmciMsgOut(
55 ServerContext* context,
56 const openolt::OmciMsg* request,
57 openolt::Empty* response) override {
58 return OmciMsgOut_(
59 request->intf_id(),
60 request->onu_id(),
61 request->pkt());
62 }
63
Shad Ansarif2e27a42018-04-26 22:37:38 +000064 Status OnuPacketOut(
65 ServerContext* context,
66 const openolt::OnuPacket* request,
67 openolt::Empty* response) override {
68 return OnuPacketOut_(
69 request->intf_id(),
70 request->onu_id(),
71 request->pkt());
72 }
73
Shad Ansari01b0e652018-04-05 21:02:53 +000074 Status FlowAdd(
75 ServerContext* context,
76 const openolt::Flow* request,
77 openolt::Empty* response) override {
78 return FlowAdd_(
79 request->onu_id(),
80 request->flow_id(),
81 request->flow_type(),
82 request->access_intf_id(),
83 request->network_intf_id(),
84 request->gemport_id(),
85 request->classifier(),
86 request->action());
87 }
88
89 Status EnableIndication(
90 ServerContext* context,
91 const ::openolt::Empty* request,
92 ServerWriter<openolt::Indication>* writer) override {
93 while (1) {
94 auto oltInd = oltIndQ.pop();
95 writer->Write(oltInd);
96 //oltInd.release_olt_ind()
97 }
98 return Status::OK;
99 }
100};
101
102void RunServer() {
103 OpenoltService service;
104 std::string server_address(serverPort);
105 ServerBuilder builder;
106
107 builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
108 builder.RegisterService(&service);
109
110 std::unique_ptr<Server> server(builder.BuildAndStart());
111
112 std::cout << "Server listening on " << server_address << std::endl;
113
114 server->Wait();
115}