blob: 980124c25d6c61f3a273ada80584bfac1d66ef41 [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(),
56 ((request->serial_number()).vendor_specific()).c_str());
57 }
58
Jonathan Davis70c21812018-07-19 15:32:10 -040059 Status DeactivateOnu(
60 ServerContext* context,
61 const openolt::Onu* request,
62 openolt::Empty* response) override {
63 return DeactivateOnu_(
64 request->intf_id(),
65 request->onu_id(),
66 ((request->serial_number()).vendor_id()).c_str(),
67 ((request->serial_number()).vendor_specific()).c_str());
68 }
69
70 Status DeleteOnu(
71 ServerContext* context,
72 const openolt::Onu* request,
73 openolt::Empty* response) override {
74 return DeleteOnu_(
75 request->intf_id(),
76 request->onu_id(),
77 ((request->serial_number()).vendor_id()).c_str(),
78 ((request->serial_number()).vendor_specific()).c_str());
79 }
80
Shad Ansari01b0e652018-04-05 21:02:53 +000081 Status OmciMsgOut(
82 ServerContext* context,
83 const openolt::OmciMsg* request,
84 openolt::Empty* response) override {
85 return OmciMsgOut_(
86 request->intf_id(),
87 request->onu_id(),
88 request->pkt());
89 }
90
Shad Ansarif2e27a42018-04-26 22:37:38 +000091 Status OnuPacketOut(
92 ServerContext* context,
93 const openolt::OnuPacket* request,
94 openolt::Empty* response) override {
95 return OnuPacketOut_(
96 request->intf_id(),
97 request->onu_id(),
98 request->pkt());
99 }
100
Nicolas Palpacuerb78def42018-06-07 12:55:26 -0400101 Status UplinkPacketOut(
102 ServerContext* context,
103 const openolt::UplinkPacket* request,
104 openolt::Empty* response) override {
105 return UplinkPacketOut_(
106 request->intf_id(),
107 request->pkt());
108 }
109
Shad Ansari01b0e652018-04-05 21:02:53 +0000110 Status FlowAdd(
111 ServerContext* context,
112 const openolt::Flow* request,
113 openolt::Empty* response) override {
114 return FlowAdd_(
115 request->onu_id(),
116 request->flow_id(),
117 request->flow_type(),
118 request->access_intf_id(),
119 request->network_intf_id(),
120 request->gemport_id(),
Nicolas Palpacuerd6cf5aa2018-07-16 15:14:39 -0400121 request->priority(),
Shad Ansari01b0e652018-04-05 21:02:53 +0000122 request->classifier(),
123 request->action());
124 }
125
126 Status EnableIndication(
127 ServerContext* context,
128 const ::openolt::Empty* request,
129 ServerWriter<openolt::Indication>* writer) override {
nick7be062f2018-05-25 17:52:56 -0400130 std::cout << "Connection to Voltha established. Indications enabled"
131 << std::endl;
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400132 state::connect();
133
134 while (state::is_connected) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000135 auto oltInd = oltIndQ.pop();
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400136 bool isConnected = writer->Write(oltInd);
Nicolas Palpacuer58d252c2018-06-06 11:19:04 -0400137 if (!isConnected) {
138 //Lost connectivity to this Voltha instance
139 //Put the indication back in the queue for next connecting instance
140 oltIndQ.push(oltInd);
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400141 state::disconnect();
Nicolas Palpacuer58d252c2018-06-06 11:19:04 -0400142 }
Shad Ansari01b0e652018-04-05 21:02:53 +0000143 //oltInd.release_olt_ind()
144 }
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400145
Shad Ansari01b0e652018-04-05 21:02:53 +0000146 return Status::OK;
147 }
nick7be062f2018-05-25 17:52:56 -0400148
149 Status HeartbeatCheck(
150 ServerContext* context,
151 const openolt::Empty* request,
152 openolt::Heartbeat* response) override {
153 response->set_heartbeat_signature(signature);
154
155 return Status::OK;
156 }
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400157
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400158 Status EnablePonIf(
159 ServerContext* context,
160 const openolt::Interface* request,
161 openolt::Empty* response) override {
162
163 return EnablePonIf_(request->intf_id());
164 }
165
166 Status DisablePonIf(
167 ServerContext* context,
168 const openolt::Interface* request,
169 openolt::Empty* response) override {
170
171 return DisablePonIf_(request->intf_id());
172 }
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400173
Shad Ansari01b0e652018-04-05 21:02:53 +0000174};
175
176void RunServer() {
177 OpenoltService service;
178 std::string server_address(serverPort);
179 ServerBuilder builder;
180
181 builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
182 builder.RegisterService(&service);
183
184 std::unique_ptr<Server> server(builder.BuildAndStart());
185
nick7be062f2018-05-25 17:52:56 -0400186 time_t now;
187 time(&now);
188 signature = (int)now;
189
190 std::cout << "Server listening on " << server_address
191 << ", connection signature : " << signature << std::endl;
192
Shad Ansari01b0e652018-04-05 21:02:53 +0000193
194 server->Wait();
195}