Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 1 | /* |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 3 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 7 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 9 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 16 | |
| 17 | #include <iostream> |
| 18 | #include <memory> |
| 19 | #include <string> |
nick | 7be062f | 2018-05-25 17:52:56 -0400 | [diff] [blame] | 20 | #include <time.h> |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 21 | #include <pthread.h> |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 22 | |
| 23 | #include "Queue.h" |
| 24 | #include <iostream> |
| 25 | #include <sstream> |
| 26 | |
| 27 | #include "server.h" |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 28 | #include "core.h" |
Nicolas Palpacuer | 3cad49d | 2018-07-02 14:03:24 -0400 | [diff] [blame] | 29 | #include "state.h" |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 30 | #include "../src/core_utils.h" |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 31 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 32 | #include <grpc++/grpc++.h> |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 33 | #include <voltha_protos/openolt.grpc.pb.h> |
| 34 | #include <voltha_protos/tech_profile.grpc.pb.h> |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 35 | |
| 36 | using grpc::Server; |
| 37 | using grpc::ServerBuilder; |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 38 | using grpc::ResourceQuota; |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 39 | using grpc::ServerContext; |
| 40 | using grpc::ServerWriter; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 41 | using grpc::Status; |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 42 | |
| 43 | const char *serverPort = "0.0.0.0:9191"; |
nick | 7be062f | 2018-05-25 17:52:56 -0400 | [diff] [blame] | 44 | int signature; |
Arthur Syu | 094df16 | 2022-04-21 17:50:06 +0800 | [diff] [blame] | 45 | std::unique_ptr<Server> server; |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 46 | |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 47 | Queue<openolt::Indication> oltIndQ; |
| 48 | |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 49 | class OpenoltService final : public openolt::Openolt::Service { |
| 50 | |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 51 | Status DisableOlt( |
| 52 | ServerContext* context, |
| 53 | const openolt::Empty* request, |
| 54 | openolt::Empty* response) override { |
| 55 | return Disable_(); |
| 56 | } |
| 57 | |
| 58 | Status ReenableOlt( |
| 59 | ServerContext* context, |
| 60 | const openolt::Empty* request, |
| 61 | openolt::Empty* response) override { |
| 62 | return Reenable_(); |
| 63 | } |
| 64 | |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 65 | Status ActivateOnu( |
| 66 | ServerContext* context, |
| 67 | const openolt::Onu* request, |
| 68 | openolt::Empty* response) override { |
| 69 | return ActivateOnu_( |
| 70 | request->intf_id(), |
| 71 | request->onu_id(), |
| 72 | ((request->serial_number()).vendor_id()).c_str(), |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 73 | ((request->serial_number()).vendor_specific()).c_str(), request->pir(), request->omcc_encryption()); |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 76 | Status DeactivateOnu( |
| 77 | ServerContext* context, |
| 78 | const openolt::Onu* request, |
| 79 | openolt::Empty* response) override { |
| 80 | return DeactivateOnu_( |
| 81 | request->intf_id(), |
| 82 | request->onu_id(), |
| 83 | ((request->serial_number()).vendor_id()).c_str(), |
| 84 | ((request->serial_number()).vendor_specific()).c_str()); |
| 85 | } |
| 86 | |
| 87 | Status DeleteOnu( |
| 88 | ServerContext* context, |
| 89 | const openolt::Onu* request, |
| 90 | openolt::Empty* response) override { |
| 91 | return DeleteOnu_( |
| 92 | request->intf_id(), |
| 93 | request->onu_id(), |
| 94 | ((request->serial_number()).vendor_id()).c_str(), |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 95 | ((request->serial_number()).vendor_specific()).c_str()); |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 96 | } |
| 97 | |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 98 | Status OmciMsgOut( |
| 99 | ServerContext* context, |
| 100 | const openolt::OmciMsg* request, |
| 101 | openolt::Empty* response) override { |
| 102 | return OmciMsgOut_( |
| 103 | request->intf_id(), |
| 104 | request->onu_id(), |
| 105 | request->pkt()); |
| 106 | } |
| 107 | |
Shad Ansari | f2e27a4 | 2018-04-26 22:37:38 +0000 | [diff] [blame] | 108 | Status OnuPacketOut( |
| 109 | ServerContext* context, |
| 110 | const openolt::OnuPacket* request, |
| 111 | openolt::Empty* response) override { |
| 112 | return OnuPacketOut_( |
| 113 | request->intf_id(), |
| 114 | request->onu_id(), |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 115 | request->port_no(), |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 116 | request->gemport_id(), |
Shad Ansari | f2e27a4 | 2018-04-26 22:37:38 +0000 | [diff] [blame] | 117 | request->pkt()); |
| 118 | } |
| 119 | |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 120 | Status UplinkPacketOut( |
| 121 | ServerContext* context, |
| 122 | const openolt::UplinkPacket* request, |
| 123 | openolt::Empty* response) override { |
| 124 | return UplinkPacketOut_( |
| 125 | request->intf_id(), |
| 126 | request->pkt()); |
| 127 | } |
| 128 | |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 129 | Status FlowAdd( |
| 130 | ServerContext* context, |
| 131 | const openolt::Flow* request, |
| 132 | openolt::Empty* response) override { |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 133 | return FlowAddWrapper_(request); |
| 134 | |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 137 | Status FlowRemove( |
| 138 | ServerContext* context, |
| 139 | const openolt::Flow* request, |
| 140 | openolt::Empty* response) override { |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 141 | return FlowRemoveWrapper_(request); |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 142 | } |
| 143 | |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 144 | Status EnableIndication( |
| 145 | ServerContext* context, |
| 146 | const ::openolt::Empty* request, |
| 147 | ServerWriter<openolt::Indication>* writer) override { |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 148 | |
nick | 7be062f | 2018-05-25 17:52:56 -0400 | [diff] [blame] | 149 | std::cout << "Connection to Voltha established. Indications enabled" |
| 150 | << std::endl; |
Nicolas Palpacuer | 3cad49d | 2018-07-02 14:03:24 -0400 | [diff] [blame] | 151 | |
Burak Gurdag | 30db482 | 2021-03-10 21:30:01 +0000 | [diff] [blame] | 152 | if (state.previously_connected()) { |
Nicolas Palpacuer | fbc0d7d | 2018-08-23 14:46:42 -0400 | [diff] [blame] | 153 | // Reconciliation / recovery case |
Nicolas Palpacuer | 135ce81 | 2018-08-30 09:04:34 -0400 | [diff] [blame] | 154 | std::cout << "Reconciliation / Recovery case" << std::endl; |
Nicolas Palpacuer | fbc0d7d | 2018-08-23 14:46:42 -0400 | [diff] [blame] | 155 | if (state.is_activated()){ |
| 156 | // Adding extra olt indication of current state |
| 157 | openolt::Indication ind; |
| 158 | openolt::OltIndication* oltInd = new openolt::OltIndication(); |
| 159 | if (state.is_activated()) { |
| 160 | oltInd->set_oper_state("up"); |
Nicolas Palpacuer | 135ce81 | 2018-08-30 09:04:34 -0400 | [diff] [blame] | 161 | std::cout << "Extra OLT indication up" << std::endl; |
Nicolas Palpacuer | fbc0d7d | 2018-08-23 14:46:42 -0400 | [diff] [blame] | 162 | } else { |
| 163 | oltInd->set_oper_state("down"); |
Nicolas Palpacuer | 135ce81 | 2018-08-30 09:04:34 -0400 | [diff] [blame] | 164 | std::cout << "Extra OLT indication down" << std::endl; |
Nicolas Palpacuer | fbc0d7d | 2018-08-23 14:46:42 -0400 | [diff] [blame] | 165 | } |
| 166 | ind.set_allocated_olt_ind(oltInd); |
| 167 | oltIndQ.push(ind); |
| 168 | } |
| 169 | } |
| 170 | |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 171 | state.connect(); |
| 172 | |
| 173 | while (state.is_connected()) { |
Girish Gowdra | 9646105 | 2019-11-22 20:13:59 +0530 | [diff] [blame] | 174 | std::pair<openolt::Indication, bool> ind = oltIndQ.pop(COLLECTION_PERIOD*1000, 1000); |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 175 | if (ind.second == false) { |
| 176 | /* timeout - do lower priority periodic stuff like stats */ |
| 177 | stats_collection(); |
| 178 | continue; |
| 179 | } |
| 180 | openolt::Indication oltInd = ind.first; |
Nicolas Palpacuer | 3cad49d | 2018-07-02 14:03:24 -0400 | [diff] [blame] | 181 | bool isConnected = writer->Write(oltInd); |
Nicolas Palpacuer | 58d252c | 2018-06-06 11:19:04 -0400 | [diff] [blame] | 182 | if (!isConnected) { |
| 183 | //Lost connectivity to this Voltha instance |
| 184 | //Put the indication back in the queue for next connecting instance |
| 185 | oltIndQ.push(oltInd); |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 186 | state.disconnect(); |
Nicolas Palpacuer | 58d252c | 2018-06-06 11:19:04 -0400 | [diff] [blame] | 187 | } |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 188 | //oltInd.release_olt_ind() |
| 189 | } |
Nicolas Palpacuer | 3cad49d | 2018-07-02 14:03:24 -0400 | [diff] [blame] | 190 | |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 191 | return Status::OK; |
| 192 | } |
nick | 7be062f | 2018-05-25 17:52:56 -0400 | [diff] [blame] | 193 | |
| 194 | Status HeartbeatCheck( |
| 195 | ServerContext* context, |
| 196 | const openolt::Empty* request, |
| 197 | openolt::Heartbeat* response) override { |
| 198 | response->set_heartbeat_signature(signature); |
| 199 | |
| 200 | return Status::OK; |
| 201 | } |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 202 | |
Nicolas Palpacuer | 05ea0ea | 2018-07-06 11:47:21 -0400 | [diff] [blame] | 203 | Status EnablePonIf( |
| 204 | ServerContext* context, |
| 205 | const openolt::Interface* request, |
| 206 | openolt::Empty* response) override { |
| 207 | |
| 208 | return EnablePonIf_(request->intf_id()); |
| 209 | } |
| 210 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 211 | /*Status GetPonIf( |
Shad Ansari | cb20878 | 2019-07-02 20:53:40 +0000 | [diff] [blame] | 212 | ServerContext* context, |
| 213 | const openolt::Interface* request, |
| 214 | openolt::IntfIndication* response) override { |
| 215 | |
| 216 | // TODO - Return the oper status of the pon interface |
| 217 | return Status::OK; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 218 | }*/ |
Shad Ansari | cb20878 | 2019-07-02 20:53:40 +0000 | [diff] [blame] | 219 | |
Nicolas Palpacuer | 05ea0ea | 2018-07-06 11:47:21 -0400 | [diff] [blame] | 220 | Status DisablePonIf( |
| 221 | ServerContext* context, |
| 222 | const openolt::Interface* request, |
| 223 | openolt::Empty* response) override { |
| 224 | |
| 225 | return DisablePonIf_(request->intf_id()); |
| 226 | } |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 227 | |
Nicolas Palpacuer | 65d0447 | 2018-09-06 15:53:37 -0400 | [diff] [blame] | 228 | Status CollectStatistics( |
| 229 | ServerContext* context, |
| 230 | const openolt::Empty* request, |
| 231 | openolt::Empty* response) override { |
| 232 | |
| 233 | stats_collection(); |
| 234 | |
| 235 | return Status::OK; |
| 236 | } |
| 237 | |
Nicolas Palpacuer | 4518066 | 2018-08-02 14:01:51 -0400 | [diff] [blame] | 238 | Status Reboot( |
| 239 | ServerContext* context, |
| 240 | const openolt::Empty* request, |
| 241 | openolt::Empty* response) override { |
| 242 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 243 | uint8_t ret = system("shutdown -r now"); |
Arthur Syu | 094df16 | 2022-04-21 17:50:06 +0800 | [diff] [blame] | 244 | server->Shutdown(); |
Nicolas Palpacuer | 4518066 | 2018-08-02 14:01:51 -0400 | [diff] [blame] | 245 | |
| 246 | return Status::OK; |
| 247 | |
| 248 | } |
| 249 | |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 250 | Status GetDeviceInfo( |
| 251 | ServerContext* context, |
| 252 | const openolt::Empty* request, |
| 253 | openolt::DeviceInfo* response) override { |
| 254 | |
| 255 | GetDeviceInfo_(response); |
| 256 | |
| 257 | return Status::OK; |
| 258 | |
| 259 | } |
| 260 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 261 | Status CreateTrafficSchedulers( |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 262 | ServerContext* context, |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 263 | const tech_profile::TrafficSchedulers* request, |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 264 | openolt::Empty* response) override { |
Burak Gurdag | 9c03998 | 2021-11-23 11:23:57 +0000 | [diff] [blame] | 265 | return CreateTrafficSchedulers_(request); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 266 | }; |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 267 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 268 | Status RemoveTrafficSchedulers( |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 269 | ServerContext* context, |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 270 | const tech_profile::TrafficSchedulers* request, |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 271 | openolt::Empty* response) override { |
Burak Gurdag | 9c03998 | 2021-11-23 11:23:57 +0000 | [diff] [blame] | 272 | return RemoveTrafficSchedulers_(request); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 273 | }; |
| 274 | |
| 275 | Status CreateTrafficQueues( |
| 276 | ServerContext* context, |
| 277 | const tech_profile::TrafficQueues* request, |
| 278 | openolt::Empty* response) override { |
Burak Gurdag | 9c03998 | 2021-11-23 11:23:57 +0000 | [diff] [blame] | 279 | return CreateTrafficQueues_(request); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 280 | }; |
| 281 | |
| 282 | Status RemoveTrafficQueues( |
| 283 | ServerContext* context, |
| 284 | const tech_profile::TrafficQueues* request, |
| 285 | openolt::Empty* response) override { |
Burak Gurdag | 9c03998 | 2021-11-23 11:23:57 +0000 | [diff] [blame] | 286 | return RemoveTrafficQueues_(request); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 287 | }; |
Nicolas Palpacuer | 4518066 | 2018-08-02 14:01:51 -0400 | [diff] [blame] | 288 | |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 289 | Status PerformGroupOperation( |
| 290 | ServerContext* context, |
| 291 | const openolt::Group* request, |
| 292 | openolt::Empty* response) override { |
| 293 | return PerformGroupOperation_(request); |
| 294 | }; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 295 | |
Burak Gurdag | eb4ca2e | 2020-06-15 07:48:26 +0000 | [diff] [blame] | 296 | Status DeleteGroup( |
| 297 | ServerContext* context, |
| 298 | const openolt::Group* request, |
| 299 | openolt::Empty* response) override { |
| 300 | return DeleteGroup_(request->group_id()); |
| 301 | }; |
| 302 | |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 303 | Status OnuItuPonAlarmSet( |
| 304 | ServerContext* context, |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 305 | const config::OnuItuPonAlarm* request, |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 306 | openolt::Empty* response) override { |
| 307 | return OnuItuPonAlarmSet_(request); |
| 308 | }; |
Jason Huang | 1d9cfce | 2020-05-20 22:58:47 +0800 | [diff] [blame] | 309 | |
| 310 | Status GetLogicalOnuDistanceZero( |
| 311 | ServerContext* context, |
| 312 | const openolt::Onu* request, |
| 313 | openolt::OnuLogicalDistance* response) override { |
| 314 | return GetLogicalOnuDistanceZero_( |
| 315 | request->intf_id(), |
| 316 | response); |
| 317 | }; |
| 318 | |
| 319 | Status GetLogicalOnuDistance( |
| 320 | ServerContext* context, |
| 321 | const openolt::Onu* request, |
| 322 | openolt::OnuLogicalDistance* response) override { |
| 323 | return GetLogicalOnuDistance_( |
| 324 | request->intf_id(), |
| 325 | request->onu_id(), |
| 326 | response); |
| 327 | }; |
Burak Gurdag | 74e3ab8 | 2020-12-17 13:35:06 +0000 | [diff] [blame] | 328 | |
| 329 | Status GetOnuStatistics( |
| 330 | ServerContext* context, |
| 331 | const openolt::Onu* request, |
| 332 | openolt::OnuStatistics* response) override { |
| 333 | return GetOnuStatistics_( |
| 334 | request->intf_id(), |
| 335 | request->onu_id(), |
| 336 | response); |
| 337 | } |
| 338 | |
| 339 | Status GetGemPortStatistics( |
| 340 | ServerContext* context, |
| 341 | const openolt::OnuPacket* request, |
| 342 | openolt::GemPortStatistics* response) override { |
| 343 | return GetGemPortStatistics_( |
| 344 | request->intf_id(), |
| 345 | request->gemport_id(), |
| 346 | response); |
| 347 | } |
Orhan Kupusoglu | ec57af0 | 2021-05-12 12:38:17 +0000 | [diff] [blame] | 348 | |
| 349 | Status GetPonRxPower( |
| 350 | ServerContext* context, |
| 351 | const openolt::Onu* request, |
| 352 | openolt::PonRxPowerData* response) override { |
| 353 | return GetPonRxPower_( |
| 354 | request->intf_id(), |
| 355 | request->onu_id(), |
| 356 | response); |
| 357 | } |
nikesh.krishnan | 331d38c | 2023-04-06 03:24:53 +0530 | [diff] [blame] | 358 | |
| 359 | Status GetOnuInfo( |
| 360 | ServerContext* context, |
| 361 | const openolt::Onu* request, |
| 362 | openolt::OnuInfo* response) override { |
| 363 | return GetOnuInfo_( |
| 364 | request->intf_id(), |
| 365 | request->onu_id(), |
| 366 | response); |
| 367 | } |
| 368 | |
| 369 | |
| 370 | Status GetPonInterfaceInfo( |
| 371 | ServerContext* context, |
| 372 | const openolt::Interface* request, |
| 373 | openolt::PonIntfInfo* response) override { |
| 374 | return GetPonInterfaceInfo_( |
| 375 | request->intf_id(), |
| 376 | response); |
| 377 | } |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 382 | }; |
| 383 | |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 384 | bool RunServer(int argc, char** argv) { |
Thiyagarajan Subramani | 03bc66f | 2020-04-01 15:58:53 +0530 | [diff] [blame] | 385 | std::string ipAddress = "0.0.0.0"; |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 386 | bool tls_enabled = false; |
| 387 | std::pair<grpc_ssl_client_certificate_request_type, bool> grpc_security; |
| 388 | std::shared_ptr<grpc::ServerCredentials> credentials; |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 389 | |
Thiyagarajan Subramani | 03bc66f | 2020-04-01 15:58:53 +0530 | [diff] [blame] | 390 | for (int i = 1; i < argc; ++i) { |
| 391 | if(strcmp(argv[i-1], "--interface") == 0 || (strcmp(argv[i-1], "--intf") == 0)) { |
| 392 | ipAddress = get_ip_address(argv[i]); |
| 393 | break; |
| 394 | } |
| 395 | } |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 396 | |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 397 | for (int i = 1; i < argc; ++i) { |
| 398 | if (strcmp(argv[i-1], "--enable-tls") == 0) { |
| 399 | grpc_security = get_grpc_tls_option(argv[i]); |
| 400 | if (grpc_security.second) { |
| 401 | tls_enabled = true; |
| 402 | } else { |
| 403 | std::cerr << "unknown security option: \"" << argv[i-1] << " " << argv[i] << "\"\n"; |
| 404 | return false; |
| 405 | }; |
| 406 | break; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | if (tls_enabled) { |
| 411 | std::string dir_cert{"./keystore"}; |
| 412 | auto read_root_crt = read_from_txt_file(dir_cert + "/root.crt"); |
| 413 | auto read_server_key = read_from_txt_file(dir_cert + "/server.key"); |
| 414 | auto read_server_crt = read_from_txt_file(dir_cert + "/server.crt"); |
| 415 | |
| 416 | if (read_root_crt.second && read_server_key.second && read_server_crt.second) { |
| 417 | std::cout << "certificate files read successfully\n"; |
| 418 | } else { |
| 419 | std::cerr << std::boolalpha << "certificate files read failed - root.crt: " << read_root_crt.second |
| 420 | << ", server.key: " << read_server_key.second |
| 421 | << ", server.crt: " << read_server_crt.second << '\n'; |
| 422 | return false; |
| 423 | } |
| 424 | |
| 425 | std::string root_crt = read_root_crt.first; |
| 426 | std::string server_key = read_server_key.first; |
| 427 | std::string server_crt = read_server_crt.first; |
| 428 | |
| 429 | grpc::SslServerCredentialsOptions ssl_opts{grpc_security.first}; |
| 430 | ssl_opts.pem_root_certs = root_crt; |
| 431 | grpc::SslServerCredentialsOptions::PemKeyCertPair keycert = {server_key, server_crt}; |
| 432 | ssl_opts.pem_key_cert_pairs.push_back(keycert); |
| 433 | credentials = grpc::SslServerCredentials(ssl_opts); |
| 434 | } else { |
| 435 | credentials = grpc::InsecureServerCredentials(); |
| 436 | } |
| 437 | |
Thiyagarajan Subramani | 03bc66f | 2020-04-01 15:58:53 +0530 | [diff] [blame] | 438 | serverPort = ipAddress.append(":9191").c_str(); |
| 439 | OpenoltService service; |
| 440 | std::string server_address(serverPort); |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 441 | ::ServerBuilder builder; |
| 442 | ::ResourceQuota quota; |
| 443 | quota.SetMaxThreads(GRPC_THREAD_POOL_SIZE); |
| 444 | builder.SetResourceQuota(quota); |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 445 | builder.AddListeningPort(server_address, credentials); |
Thiyagarajan Subramani | 03bc66f | 2020-04-01 15:58:53 +0530 | [diff] [blame] | 446 | builder.RegisterService(&service); |
nick | 7be062f | 2018-05-25 17:52:56 -0400 | [diff] [blame] | 447 | |
Arthur Syu | 094df16 | 2022-04-21 17:50:06 +0800 | [diff] [blame] | 448 | server = builder.BuildAndStart(); |
nick | 7be062f | 2018-05-25 17:52:56 -0400 | [diff] [blame] | 449 | |
Thiyagarajan Subramani | 03bc66f | 2020-04-01 15:58:53 +0530 | [diff] [blame] | 450 | time_t now; |
| 451 | time(&now); |
| 452 | signature = (int)now; |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 453 | |
Thiyagarajan Subramani | 03bc66f | 2020-04-01 15:58:53 +0530 | [diff] [blame] | 454 | std::cout << "Server listening on " << server_address |
| 455 | << ", connection signature : " << signature << std::endl; |
| 456 | |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 457 | #ifdef TEST_MODE |
| 458 | server->Shutdown(); |
| 459 | #else |
Thiyagarajan Subramani | 03bc66f | 2020-04-01 15:58:53 +0530 | [diff] [blame] | 460 | server->Wait(); |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 461 | #endif |
| 462 | |
| 463 | return true; |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 464 | } |