blob: cfd6f3f035279d4e830335547695fb5363a14402 [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"
Shad Ansari01b0e652018-04-05 21:02:53 +000032
Shad Ansarib7b0ced2018-05-11 21:53:32 +000033#include <grpc++/grpc++.h>
Shad Ansari01b0e652018-04-05 21:02:53 +000034#include <openolt.grpc.pb.h>
35
36using grpc::Server;
37using grpc::ServerBuilder;
38using grpc::ServerContext;
39using grpc::ServerWriter;
Shad Ansarib7b0ced2018-05-11 21:53:32 +000040using grpc::Status;
Shad Ansari01b0e652018-04-05 21:02:53 +000041
42const char *serverPort = "0.0.0.0:9191";
nick7be062f2018-05-25 17:52:56 -040043int signature;
Shad Ansari01b0e652018-04-05 21:02:53 +000044
45class OpenoltService final : public openolt::Openolt::Service {
46
47 Status ActivateOnu(
48 ServerContext* context,
49 const openolt::Onu* request,
50 openolt::Empty* response) override {
51 return ActivateOnu_(
52 request->intf_id(),
53 request->onu_id(),
54 ((request->serial_number()).vendor_id()).c_str(),
55 ((request->serial_number()).vendor_specific()).c_str());
56 }
57
58 Status OmciMsgOut(
59 ServerContext* context,
60 const openolt::OmciMsg* request,
61 openolt::Empty* response) override {
62 return OmciMsgOut_(
63 request->intf_id(),
64 request->onu_id(),
65 request->pkt());
66 }
67
Shad Ansarif2e27a42018-04-26 22:37:38 +000068 Status OnuPacketOut(
69 ServerContext* context,
70 const openolt::OnuPacket* request,
71 openolt::Empty* response) override {
72 return OnuPacketOut_(
73 request->intf_id(),
74 request->onu_id(),
75 request->pkt());
76 }
77
Nicolas Palpacuerb78def42018-06-07 12:55:26 -040078 Status UplinkPacketOut(
79 ServerContext* context,
80 const openolt::UplinkPacket* request,
81 openolt::Empty* response) override {
82 return UplinkPacketOut_(
83 request->intf_id(),
84 request->pkt());
85 }
86
Shad Ansari01b0e652018-04-05 21:02:53 +000087 Status FlowAdd(
88 ServerContext* context,
89 const openolt::Flow* request,
90 openolt::Empty* response) override {
91 return FlowAdd_(
92 request->onu_id(),
93 request->flow_id(),
94 request->flow_type(),
95 request->access_intf_id(),
96 request->network_intf_id(),
97 request->gemport_id(),
98 request->classifier(),
99 request->action());
100 }
101
102 Status EnableIndication(
103 ServerContext* context,
104 const ::openolt::Empty* request,
105 ServerWriter<openolt::Indication>* writer) override {
nick7be062f2018-05-25 17:52:56 -0400106 std::cout << "Connection to Voltha established. Indications enabled"
107 << std::endl;
Nicolas Palpacuer58d252c2018-06-06 11:19:04 -0400108 bool isConnected = true;
109 while (isConnected) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000110 auto oltInd = oltIndQ.pop();
Nicolas Palpacuer58d252c2018-06-06 11:19:04 -0400111 isConnected = writer->Write(oltInd);
112 if (!isConnected) {
113 //Lost connectivity to this Voltha instance
114 //Put the indication back in the queue for next connecting instance
115 oltIndQ.push(oltInd);
116 }
Shad Ansari01b0e652018-04-05 21:02:53 +0000117 //oltInd.release_olt_ind()
118 }
119 return Status::OK;
120 }
nick7be062f2018-05-25 17:52:56 -0400121
122 Status HeartbeatCheck(
123 ServerContext* context,
124 const openolt::Empty* request,
125 openolt::Heartbeat* response) override {
126 response->set_heartbeat_signature(signature);
127
128 return Status::OK;
129 }
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400130
131
Shad Ansari01b0e652018-04-05 21:02:53 +0000132};
133
134void RunServer() {
135 OpenoltService service;
136 std::string server_address(serverPort);
137 ServerBuilder builder;
138
139 builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
140 builder.RegisterService(&service);
141
142 std::unique_ptr<Server> server(builder.BuildAndStart());
143
nick7be062f2018-05-25 17:52:56 -0400144 time_t now;
145 time(&now);
146 signature = (int)now;
147
148 std::cout << "Server listening on " << server_address
149 << ", connection signature : " << signature << std::endl;
150
Shad Ansari01b0e652018-04-05 21:02:53 +0000151
152 server->Wait();
153}