blob: 46b8bfffbffa9917d7ebbb411f8c494462b4ed78 [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
48 Status ActivateOnu(
49 ServerContext* context,
50 const openolt::Onu* request,
51 openolt::Empty* response) override {
52 return ActivateOnu_(
53 request->intf_id(),
54 request->onu_id(),
55 ((request->serial_number()).vendor_id()).c_str(),
Shad Ansari06101952018-07-25 00:22:09 +000056 ((request->serial_number()).vendor_specific()).c_str(),
57 request->pir());
Shad Ansari01b0e652018-04-05 21:02:53 +000058 }
59
Jonathan Davis70c21812018-07-19 15:32:10 -040060 Status DeactivateOnu(
61 ServerContext* context,
62 const openolt::Onu* request,
63 openolt::Empty* response) override {
64 return DeactivateOnu_(
65 request->intf_id(),
66 request->onu_id(),
67 ((request->serial_number()).vendor_id()).c_str(),
68 ((request->serial_number()).vendor_specific()).c_str());
69 }
70
71 Status DeleteOnu(
72 ServerContext* context,
73 const openolt::Onu* request,
74 openolt::Empty* response) override {
75 return DeleteOnu_(
76 request->intf_id(),
77 request->onu_id(),
78 ((request->serial_number()).vendor_id()).c_str(),
79 ((request->serial_number()).vendor_specific()).c_str());
80 }
81
Shad Ansari01b0e652018-04-05 21:02:53 +000082 Status OmciMsgOut(
83 ServerContext* context,
84 const openolt::OmciMsg* request,
85 openolt::Empty* response) override {
86 return OmciMsgOut_(
87 request->intf_id(),
88 request->onu_id(),
89 request->pkt());
90 }
91
Shad Ansarif2e27a42018-04-26 22:37:38 +000092 Status OnuPacketOut(
93 ServerContext* context,
94 const openolt::OnuPacket* request,
95 openolt::Empty* response) override {
96 return OnuPacketOut_(
97 request->intf_id(),
98 request->onu_id(),
99 request->pkt());
100 }
101
Nicolas Palpacuerb78def42018-06-07 12:55:26 -0400102 Status UplinkPacketOut(
103 ServerContext* context,
104 const openolt::UplinkPacket* request,
105 openolt::Empty* response) override {
106 return UplinkPacketOut_(
107 request->intf_id(),
108 request->pkt());
109 }
110
Shad Ansari01b0e652018-04-05 21:02:53 +0000111 Status FlowAdd(
112 ServerContext* context,
113 const openolt::Flow* request,
114 openolt::Empty* response) override {
115 return FlowAdd_(
116 request->onu_id(),
117 request->flow_id(),
118 request->flow_type(),
119 request->access_intf_id(),
120 request->network_intf_id(),
121 request->gemport_id(),
Nicolas Palpacuerd6cf5aa2018-07-16 15:14:39 -0400122 request->priority(),
Shad Ansari01b0e652018-04-05 21:02:53 +0000123 request->classifier(),
124 request->action());
125 }
126
127 Status EnableIndication(
128 ServerContext* context,
129 const ::openolt::Empty* request,
130 ServerWriter<openolt::Indication>* writer) override {
nick7be062f2018-05-25 17:52:56 -0400131 std::cout << "Connection to Voltha established. Indications enabled"
132 << std::endl;
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400133 state::connect();
134
135 while (state::is_connected) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000136 auto oltInd = oltIndQ.pop();
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400137 bool isConnected = writer->Write(oltInd);
Nicolas Palpacuer58d252c2018-06-06 11:19:04 -0400138 if (!isConnected) {
139 //Lost connectivity to this Voltha instance
140 //Put the indication back in the queue for next connecting instance
141 oltIndQ.push(oltInd);
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400142 state::disconnect();
Nicolas Palpacuer58d252c2018-06-06 11:19:04 -0400143 }
Shad Ansari01b0e652018-04-05 21:02:53 +0000144 //oltInd.release_olt_ind()
145 }
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400146
Shad Ansari01b0e652018-04-05 21:02:53 +0000147 return Status::OK;
148 }
nick7be062f2018-05-25 17:52:56 -0400149
150 Status HeartbeatCheck(
151 ServerContext* context,
152 const openolt::Empty* request,
153 openolt::Heartbeat* response) override {
154 response->set_heartbeat_signature(signature);
155
156 return Status::OK;
157 }
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400158
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400159 Status EnablePonIf(
160 ServerContext* context,
161 const openolt::Interface* request,
162 openolt::Empty* response) override {
163
164 return EnablePonIf_(request->intf_id());
165 }
166
167 Status DisablePonIf(
168 ServerContext* context,
169 const openolt::Interface* request,
170 openolt::Empty* response) override {
171
172 return DisablePonIf_(request->intf_id());
173 }
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400174
Nicolas Palpacuer45180662018-08-02 14:01:51 -0400175 Status Reboot(
176 ServerContext* context,
177 const openolt::Empty* request,
178 openolt::Empty* response) override {
179
180 system("shutdown -r now");
181
182 return Status::OK;
183
184 }
185
186
Shad Ansari01b0e652018-04-05 21:02:53 +0000187};
188
189void RunServer() {
190 OpenoltService service;
191 std::string server_address(serverPort);
192 ServerBuilder builder;
193
194 builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
195 builder.RegisterService(&service);
196
197 std::unique_ptr<Server> server(builder.BuildAndStart());
198
nick7be062f2018-05-25 17:52:56 -0400199 time_t now;
200 time(&now);
201 signature = (int)now;
202
203 std::cout << "Server listening on " << server_address
204 << ", connection signature : " << signature << std::endl;
205
Shad Ansari01b0e652018-04-05 21:02:53 +0000206
207 server->Wait();
208}