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