Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright (C) 2018 Open Networking Foundation |
| 3 | |
| 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> |
| 21 | |
| 22 | #include "Queue.h" |
| 23 | #include <iostream> |
| 24 | #include <sstream> |
| 25 | |
| 26 | #include "server.h" |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 27 | #include "core.h" |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 28 | #include "indications.h" |
| 29 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 30 | #include <grpc++/grpc++.h> |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 31 | #include <openolt.grpc.pb.h> |
| 32 | |
| 33 | using grpc::Server; |
| 34 | using grpc::ServerBuilder; |
| 35 | using grpc::ServerContext; |
| 36 | using grpc::ServerWriter; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 37 | using grpc::Status; |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 38 | |
| 39 | const char *serverPort = "0.0.0.0:9191"; |
| 40 | |
| 41 | class OpenoltService final : public openolt::Openolt::Service { |
| 42 | |
| 43 | Status ActivateOnu( |
| 44 | ServerContext* context, |
| 45 | const openolt::Onu* request, |
| 46 | openolt::Empty* response) override { |
| 47 | return ActivateOnu_( |
| 48 | request->intf_id(), |
| 49 | request->onu_id(), |
| 50 | ((request->serial_number()).vendor_id()).c_str(), |
| 51 | ((request->serial_number()).vendor_specific()).c_str()); |
| 52 | } |
| 53 | |
| 54 | Status OmciMsgOut( |
| 55 | ServerContext* context, |
| 56 | const openolt::OmciMsg* request, |
| 57 | openolt::Empty* response) override { |
| 58 | return OmciMsgOut_( |
| 59 | request->intf_id(), |
| 60 | request->onu_id(), |
| 61 | request->pkt()); |
| 62 | } |
| 63 | |
Shad Ansari | f2e27a4 | 2018-04-26 22:37:38 +0000 | [diff] [blame] | 64 | Status OnuPacketOut( |
| 65 | ServerContext* context, |
| 66 | const openolt::OnuPacket* request, |
| 67 | openolt::Empty* response) override { |
| 68 | return OnuPacketOut_( |
| 69 | request->intf_id(), |
| 70 | request->onu_id(), |
| 71 | request->pkt()); |
| 72 | } |
| 73 | |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 74 | Status FlowAdd( |
| 75 | ServerContext* context, |
| 76 | const openolt::Flow* request, |
| 77 | openolt::Empty* response) override { |
| 78 | return FlowAdd_( |
| 79 | request->onu_id(), |
| 80 | request->flow_id(), |
| 81 | request->flow_type(), |
| 82 | request->access_intf_id(), |
| 83 | request->network_intf_id(), |
| 84 | request->gemport_id(), |
| 85 | request->classifier(), |
| 86 | request->action()); |
| 87 | } |
| 88 | |
| 89 | Status EnableIndication( |
| 90 | ServerContext* context, |
| 91 | const ::openolt::Empty* request, |
| 92 | ServerWriter<openolt::Indication>* writer) override { |
| 93 | while (1) { |
| 94 | auto oltInd = oltIndQ.pop(); |
| 95 | writer->Write(oltInd); |
| 96 | //oltInd.release_olt_ind() |
| 97 | } |
| 98 | return Status::OK; |
| 99 | } |
| 100 | }; |
| 101 | |
| 102 | void RunServer() { |
| 103 | OpenoltService service; |
| 104 | std::string server_address(serverPort); |
| 105 | ServerBuilder builder; |
| 106 | |
| 107 | builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); |
| 108 | builder.RegisterService(&service); |
| 109 | |
| 110 | std::unique_ptr<Server> server(builder.BuildAndStart()); |
| 111 | |
| 112 | std::cout << "Server listening on " << server_address << std::endl; |
| 113 | |
| 114 | server->Wait(); |
| 115 | } |