blob: 9f926e8fe730f07e19a2ab3d58073bf48a885d48 [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
Nicolas Palpacuerb78def42018-06-07 12:55:26 -040076 Status UplinkPacketOut(
77 ServerContext* context,
78 const openolt::UplinkPacket* request,
79 openolt::Empty* response) override {
80 return UplinkPacketOut_(
81 request->intf_id(),
82 request->pkt());
83 }
84
Shad Ansari01b0e652018-04-05 21:02:53 +000085 Status FlowAdd(
86 ServerContext* context,
87 const openolt::Flow* request,
88 openolt::Empty* response) override {
89 return FlowAdd_(
90 request->onu_id(),
91 request->flow_id(),
92 request->flow_type(),
93 request->access_intf_id(),
94 request->network_intf_id(),
95 request->gemport_id(),
96 request->classifier(),
97 request->action());
98 }
99
100 Status EnableIndication(
101 ServerContext* context,
102 const ::openolt::Empty* request,
103 ServerWriter<openolt::Indication>* writer) override {
nick7be062f2018-05-25 17:52:56 -0400104 std::cout << "Connection to Voltha established. Indications enabled"
105 << std::endl;
Nicolas Palpacuer58d252c2018-06-06 11:19:04 -0400106 bool isConnected = true;
107 while (isConnected) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000108 auto oltInd = oltIndQ.pop();
Nicolas Palpacuer58d252c2018-06-06 11:19:04 -0400109 isConnected = writer->Write(oltInd);
110 if (!isConnected) {
111 //Lost connectivity to this Voltha instance
112 //Put the indication back in the queue for next connecting instance
113 oltIndQ.push(oltInd);
114 }
Shad Ansari01b0e652018-04-05 21:02:53 +0000115 //oltInd.release_olt_ind()
116 }
117 return Status::OK;
118 }
nick7be062f2018-05-25 17:52:56 -0400119
120 Status HeartbeatCheck(
121 ServerContext* context,
122 const openolt::Empty* request,
123 openolt::Heartbeat* response) override {
124 response->set_heartbeat_signature(signature);
125
126 return Status::OK;
127 }
Shad Ansari01b0e652018-04-05 21:02:53 +0000128};
129
130void RunServer() {
131 OpenoltService service;
132 std::string server_address(serverPort);
133 ServerBuilder builder;
134
135 builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
136 builder.RegisterService(&service);
137
138 std::unique_ptr<Server> server(builder.BuildAndStart());
139
nick7be062f2018-05-25 17:52:56 -0400140 time_t now;
141 time(&now);
142 signature = (int)now;
143
144 std::cout << "Server listening on " << server_address
145 << ", connection signature : " << signature << std::endl;
146
Shad Ansari01b0e652018-04-05 21:02:53 +0000147
148 server->Wait();
149}