blob: 2e8bc1b084827bcf33f73ea8d98bc31489cc26bc [file] [log] [blame]
Shad Ansari01b0e652018-04-05 21:02:53 +00001/*
nick7be062f2018-05-25 17:52:56 -04002 Copyright (C) 2018 Open Networking Foundation
Shad Ansari01b0e652018-04-05 21:02:53 +00003
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>
nick7be062f2018-05-25 17:52:56 -040021#include <time.h>
Shad Ansari01b0e652018-04-05 21:02:53 +000022
23#include "Queue.h"
24#include <iostream>
25#include <sstream>
26
27#include "server.h"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000028#include "core.h"
Shad Ansari01b0e652018-04-05 21:02:53 +000029#include "indications.h"
30
Shad Ansarib7b0ced2018-05-11 21:53:32 +000031#include <grpc++/grpc++.h>
Shad Ansari01b0e652018-04-05 21:02:53 +000032#include <openolt.grpc.pb.h>
33
34using grpc::Server;
35using grpc::ServerBuilder;
36using grpc::ServerContext;
37using grpc::ServerWriter;
Shad Ansarib7b0ced2018-05-11 21:53:32 +000038using grpc::Status;
Shad Ansari01b0e652018-04-05 21:02:53 +000039
40const char *serverPort = "0.0.0.0:9191";
nick7be062f2018-05-25 17:52:56 -040041int signature;
Shad Ansari01b0e652018-04-05 21:02:53 +000042
43class OpenoltService final : public openolt::Openolt::Service {
44
45 Status ActivateOnu(
46 ServerContext* context,
47 const openolt::Onu* request,
48 openolt::Empty* response) override {
49 return ActivateOnu_(
50 request->intf_id(),
51 request->onu_id(),
52 ((request->serial_number()).vendor_id()).c_str(),
53 ((request->serial_number()).vendor_specific()).c_str());
54 }
55
56 Status OmciMsgOut(
57 ServerContext* context,
58 const openolt::OmciMsg* request,
59 openolt::Empty* response) override {
60 return OmciMsgOut_(
61 request->intf_id(),
62 request->onu_id(),
63 request->pkt());
64 }
65
Shad Ansarif2e27a42018-04-26 22:37:38 +000066 Status OnuPacketOut(
67 ServerContext* context,
68 const openolt::OnuPacket* request,
69 openolt::Empty* response) override {
70 return OnuPacketOut_(
71 request->intf_id(),
72 request->onu_id(),
73 request->pkt());
74 }
75
Shad Ansari01b0e652018-04-05 21:02:53 +000076 Status FlowAdd(
77 ServerContext* context,
78 const openolt::Flow* request,
79 openolt::Empty* response) override {
80 return FlowAdd_(
81 request->onu_id(),
82 request->flow_id(),
83 request->flow_type(),
84 request->access_intf_id(),
85 request->network_intf_id(),
86 request->gemport_id(),
87 request->classifier(),
88 request->action());
89 }
90
91 Status EnableIndication(
92 ServerContext* context,
93 const ::openolt::Empty* request,
94 ServerWriter<openolt::Indication>* writer) override {
nick7be062f2018-05-25 17:52:56 -040095 std::cout << "Connection to Voltha established. Indications enabled"
96 << std::endl;
Shad Ansari01b0e652018-04-05 21:02:53 +000097 while (1) {
98 auto oltInd = oltIndQ.pop();
99 writer->Write(oltInd);
100 //oltInd.release_olt_ind()
101 }
102 return Status::OK;
103 }
nick7be062f2018-05-25 17:52:56 -0400104
105 Status HeartbeatCheck(
106 ServerContext* context,
107 const openolt::Empty* request,
108 openolt::Heartbeat* response) override {
109 response->set_heartbeat_signature(signature);
110
111 return Status::OK;
112 }
Shad Ansari01b0e652018-04-05 21:02:53 +0000113};
114
115void RunServer() {
116 OpenoltService service;
117 std::string server_address(serverPort);
118 ServerBuilder builder;
119
120 builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
121 builder.RegisterService(&service);
122
123 std::unique_ptr<Server> server(builder.BuildAndStart());
124
nick7be062f2018-05-25 17:52:56 -0400125 time_t now;
126 time(&now);
127 signature = (int)now;
128
129 std::cout << "Server listening on " << server_address
130 << ", connection signature : " << signature << std::endl;
131
Shad Ansari01b0e652018-04-05 21:02:53 +0000132
133 server->Wait();
134}