blob: 263c3a1667b1d33d6427d3fc5b748f46ba2390b9 [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;
Nicolas Palpacuer58d252c2018-06-06 11:19:04 -040097 bool isConnected = true;
98 while (isConnected) {
Shad Ansari01b0e652018-04-05 21:02:53 +000099 auto oltInd = oltIndQ.pop();
Nicolas Palpacuer58d252c2018-06-06 11:19:04 -0400100 isConnected = writer->Write(oltInd);
101 if (!isConnected) {
102 //Lost connectivity to this Voltha instance
103 //Put the indication back in the queue for next connecting instance
104 oltIndQ.push(oltInd);
105 }
Shad Ansari01b0e652018-04-05 21:02:53 +0000106 //oltInd.release_olt_ind()
107 }
108 return Status::OK;
109 }
nick7be062f2018-05-25 17:52:56 -0400110
111 Status HeartbeatCheck(
112 ServerContext* context,
113 const openolt::Empty* request,
114 openolt::Heartbeat* response) override {
115 response->set_heartbeat_signature(signature);
116
117 return Status::OK;
118 }
Shad Ansari01b0e652018-04-05 21:02:53 +0000119};
120
121void RunServer() {
122 OpenoltService service;
123 std::string server_address(serverPort);
124 ServerBuilder builder;
125
126 builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
127 builder.RegisterService(&service);
128
129 std::unique_ptr<Server> server(builder.BuildAndStart());
130
nick7be062f2018-05-25 17:52:56 -0400131 time_t now;
132 time(&now);
133 signature = (int)now;
134
135 std::cout << "Server listening on " << server_address
136 << ", connection signature : " << signature << std::endl;
137
Shad Ansari01b0e652018-04-05 21:02:53 +0000138
139 server->Wait();
140}