blob: 5c46332bcb480562895f77bf3b25d47ae7a2121b [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>
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040022#include <pthread.h>
Shad Ansari01b0e652018-04-05 21:02:53 +000023
24#include "Queue.h"
25#include <iostream>
26#include <sstream>
27
28#include "server.h"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000029#include "core.h"
Shad Ansari01b0e652018-04-05 21:02:53 +000030#include "indications.h"
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040031#include "stats_collection.h"
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -040032#include "state.h"
Shad Ansari01b0e652018-04-05 21:02:53 +000033
Shad Ansarib7b0ced2018-05-11 21:53:32 +000034#include <grpc++/grpc++.h>
Shad Ansari01b0e652018-04-05 21:02:53 +000035#include <openolt.grpc.pb.h>
36
37using grpc::Server;
38using grpc::ServerBuilder;
39using grpc::ServerContext;
40using grpc::ServerWriter;
Shad Ansarib7b0ced2018-05-11 21:53:32 +000041using grpc::Status;
Shad Ansari01b0e652018-04-05 21:02:53 +000042
43const char *serverPort = "0.0.0.0:9191";
nick7be062f2018-05-25 17:52:56 -040044int signature;
Shad Ansari01b0e652018-04-05 21:02:53 +000045
46class OpenoltService final : public openolt::Openolt::Service {
47
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040048 Status DisableOlt(
49 ServerContext* context,
50 const openolt::Empty* request,
51 openolt::Empty* response) override {
52 return Disable_();
53 }
54
55 Status ReenableOlt(
56 ServerContext* context,
57 const openolt::Empty* request,
58 openolt::Empty* response) override {
59 return Reenable_();
60 }
61
Shad Ansari01b0e652018-04-05 21:02:53 +000062 Status ActivateOnu(
63 ServerContext* context,
64 const openolt::Onu* request,
65 openolt::Empty* response) override {
66 return ActivateOnu_(
67 request->intf_id(),
68 request->onu_id(),
69 ((request->serial_number()).vendor_id()).c_str(),
Shad Ansari06101952018-07-25 00:22:09 +000070 ((request->serial_number()).vendor_specific()).c_str(),
71 request->pir());
Shad Ansari01b0e652018-04-05 21:02:53 +000072 }
73
Jonathan Davis70c21812018-07-19 15:32:10 -040074 Status DeactivateOnu(
75 ServerContext* context,
76 const openolt::Onu* request,
77 openolt::Empty* response) override {
78 return DeactivateOnu_(
79 request->intf_id(),
80 request->onu_id(),
81 ((request->serial_number()).vendor_id()).c_str(),
82 ((request->serial_number()).vendor_specific()).c_str());
83 }
84
85 Status DeleteOnu(
86 ServerContext* context,
87 const openolt::Onu* request,
88 openolt::Empty* response) override {
89 return DeleteOnu_(
90 request->intf_id(),
91 request->onu_id(),
92 ((request->serial_number()).vendor_id()).c_str(),
93 ((request->serial_number()).vendor_specific()).c_str());
94 }
95
Shad Ansari01b0e652018-04-05 21:02:53 +000096 Status OmciMsgOut(
97 ServerContext* context,
98 const openolt::OmciMsg* request,
99 openolt::Empty* response) override {
100 return OmciMsgOut_(
101 request->intf_id(),
102 request->onu_id(),
103 request->pkt());
104 }
105
Shad Ansarif2e27a42018-04-26 22:37:38 +0000106 Status OnuPacketOut(
107 ServerContext* context,
108 const openolt::OnuPacket* request,
109 openolt::Empty* response) override {
110 return OnuPacketOut_(
111 request->intf_id(),
112 request->onu_id(),
113 request->pkt());
114 }
115
Nicolas Palpacuerb78def42018-06-07 12:55:26 -0400116 Status UplinkPacketOut(
117 ServerContext* context,
118 const openolt::UplinkPacket* request,
119 openolt::Empty* response) override {
120 return UplinkPacketOut_(
121 request->intf_id(),
122 request->pkt());
123 }
124
Shad Ansari01b0e652018-04-05 21:02:53 +0000125 Status FlowAdd(
126 ServerContext* context,
127 const openolt::Flow* request,
128 openolt::Empty* response) override {
129 return FlowAdd_(
130 request->onu_id(),
131 request->flow_id(),
132 request->flow_type(),
133 request->access_intf_id(),
134 request->network_intf_id(),
135 request->gemport_id(),
Nicolas Palpacuerd6cf5aa2018-07-16 15:14:39 -0400136 request->priority(),
Shad Ansari01b0e652018-04-05 21:02:53 +0000137 request->classifier(),
138 request->action());
139 }
140
141 Status EnableIndication(
142 ServerContext* context,
143 const ::openolt::Empty* request,
144 ServerWriter<openolt::Indication>* writer) override {
nick7be062f2018-05-25 17:52:56 -0400145 std::cout << "Connection to Voltha established. Indications enabled"
146 << std::endl;
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400147 state::connect();
148
149 while (state::is_connected) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000150 auto oltInd = oltIndQ.pop();
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400151 bool isConnected = writer->Write(oltInd);
Nicolas Palpacuer58d252c2018-06-06 11:19:04 -0400152 if (!isConnected) {
153 //Lost connectivity to this Voltha instance
154 //Put the indication back in the queue for next connecting instance
155 oltIndQ.push(oltInd);
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400156 state::disconnect();
Nicolas Palpacuer58d252c2018-06-06 11:19:04 -0400157 }
Shad Ansari01b0e652018-04-05 21:02:53 +0000158 //oltInd.release_olt_ind()
159 }
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400160
Shad Ansari01b0e652018-04-05 21:02:53 +0000161 return Status::OK;
162 }
nick7be062f2018-05-25 17:52:56 -0400163
164 Status HeartbeatCheck(
165 ServerContext* context,
166 const openolt::Empty* request,
167 openolt::Heartbeat* response) override {
168 response->set_heartbeat_signature(signature);
169
170 return Status::OK;
171 }
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400172
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400173 Status EnablePonIf(
174 ServerContext* context,
175 const openolt::Interface* request,
176 openolt::Empty* response) override {
177
178 return EnablePonIf_(request->intf_id());
179 }
180
181 Status DisablePonIf(
182 ServerContext* context,
183 const openolt::Interface* request,
184 openolt::Empty* response) override {
185
186 return DisablePonIf_(request->intf_id());
187 }
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400188
Nicolas Palpacuer45180662018-08-02 14:01:51 -0400189 Status Reboot(
190 ServerContext* context,
191 const openolt::Empty* request,
192 openolt::Empty* response) override {
193
194 system("shutdown -r now");
195
196 return Status::OK;
197
198 }
199
200
Shad Ansari01b0e652018-04-05 21:02:53 +0000201};
202
203void RunServer() {
204 OpenoltService service;
205 std::string server_address(serverPort);
206 ServerBuilder builder;
207
208 builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
209 builder.RegisterService(&service);
210
211 std::unique_ptr<Server> server(builder.BuildAndStart());
212
nick7be062f2018-05-25 17:52:56 -0400213 time_t now;
214 time(&now);
215 signature = (int)now;
216
217 std::cout << "Server listening on " << server_address
218 << ", connection signature : " << signature << std::endl;
219
Shad Ansari01b0e652018-04-05 21:02:53 +0000220
221 server->Wait();
222}