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 { |
Burak Gurdag | 9c03998 | 2021-11-23 11:23:57 +0000 | [diff] [blame] | 263 | return CreateTrafficSchedulers_(request); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 264 | }; |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 265 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 266 | Status RemoveTrafficSchedulers( |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 267 | ServerContext* context, |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 268 | const tech_profile::TrafficSchedulers* request, |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 269 | openolt::Empty* response) override { |
Burak Gurdag | 9c03998 | 2021-11-23 11:23:57 +0000 | [diff] [blame] | 270 | return RemoveTrafficSchedulers_(request); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 271 | }; |
| 272 | |
| 273 | Status CreateTrafficQueues( |
| 274 | ServerContext* context, |
| 275 | const tech_profile::TrafficQueues* request, |
| 276 | openolt::Empty* response) override { |
Burak Gurdag | 9c03998 | 2021-11-23 11:23:57 +0000 | [diff] [blame] | 277 | return CreateTrafficQueues_(request); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 278 | }; |
| 279 | |
| 280 | Status RemoveTrafficQueues( |
| 281 | ServerContext* context, |
| 282 | const tech_profile::TrafficQueues* request, |
| 283 | openolt::Empty* response) override { |
Burak Gurdag | 9c03998 | 2021-11-23 11:23:57 +0000 | [diff] [blame] | 284 | return RemoveTrafficQueues_(request); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 285 | }; |
Nicolas Palpacuer | 4518066 | 2018-08-02 14:01:51 -0400 | [diff] [blame] | 286 | |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 287 | Status PerformGroupOperation( |
| 288 | ServerContext* context, |
| 289 | const openolt::Group* request, |
| 290 | openolt::Empty* response) override { |
| 291 | return PerformGroupOperation_(request); |
| 292 | }; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 293 | |
Burak Gurdag | eb4ca2e | 2020-06-15 07:48:26 +0000 | [diff] [blame] | 294 | Status DeleteGroup( |
| 295 | ServerContext* context, |
| 296 | const openolt::Group* request, |
| 297 | openolt::Empty* response) override { |
| 298 | return DeleteGroup_(request->group_id()); |
| 299 | }; |
| 300 | |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 301 | Status OnuItuPonAlarmSet( |
| 302 | ServerContext* context, |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 303 | const config::OnuItuPonAlarm* request, |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 304 | openolt::Empty* response) override { |
| 305 | return OnuItuPonAlarmSet_(request); |
| 306 | }; |
Jason Huang | 1d9cfce | 2020-05-20 22:58:47 +0800 | [diff] [blame] | 307 | |
| 308 | Status GetLogicalOnuDistanceZero( |
| 309 | ServerContext* context, |
| 310 | const openolt::Onu* request, |
| 311 | openolt::OnuLogicalDistance* response) override { |
| 312 | return GetLogicalOnuDistanceZero_( |
| 313 | request->intf_id(), |
| 314 | response); |
| 315 | }; |
| 316 | |
| 317 | Status GetLogicalOnuDistance( |
| 318 | ServerContext* context, |
| 319 | const openolt::Onu* request, |
| 320 | openolt::OnuLogicalDistance* response) override { |
| 321 | return GetLogicalOnuDistance_( |
| 322 | request->intf_id(), |
| 323 | request->onu_id(), |
| 324 | response); |
| 325 | }; |
Burak Gurdag | 74e3ab8 | 2020-12-17 13:35:06 +0000 | [diff] [blame] | 326 | |
| 327 | Status GetOnuStatistics( |
| 328 | ServerContext* context, |
| 329 | const openolt::Onu* request, |
| 330 | openolt::OnuStatistics* response) override { |
| 331 | return GetOnuStatistics_( |
| 332 | request->intf_id(), |
| 333 | request->onu_id(), |
| 334 | response); |
| 335 | } |
| 336 | |
| 337 | Status GetGemPortStatistics( |
| 338 | ServerContext* context, |
| 339 | const openolt::OnuPacket* request, |
| 340 | openolt::GemPortStatistics* response) override { |
| 341 | return GetGemPortStatistics_( |
| 342 | request->intf_id(), |
| 343 | request->gemport_id(), |
| 344 | response); |
| 345 | } |
Orhan Kupusoglu | ec57af0 | 2021-05-12 12:38:17 +0000 | [diff] [blame] | 346 | |
| 347 | Status GetPonRxPower( |
| 348 | ServerContext* context, |
| 349 | const openolt::Onu* request, |
| 350 | openolt::PonRxPowerData* response) override { |
| 351 | return GetPonRxPower_( |
| 352 | request->intf_id(), |
| 353 | request->onu_id(), |
| 354 | response); |
| 355 | } |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 356 | }; |
| 357 | |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 358 | bool RunServer(int argc, char** argv) { |
Thiyagarajan Subramani | 03bc66f | 2020-04-01 15:58:53 +0530 | [diff] [blame] | 359 | std::string ipAddress = "0.0.0.0"; |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 360 | bool tls_enabled = false; |
| 361 | std::pair<grpc_ssl_client_certificate_request_type, bool> grpc_security; |
| 362 | std::shared_ptr<grpc::ServerCredentials> credentials; |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 363 | |
Thiyagarajan Subramani | 03bc66f | 2020-04-01 15:58:53 +0530 | [diff] [blame] | 364 | for (int i = 1; i < argc; ++i) { |
| 365 | if(strcmp(argv[i-1], "--interface") == 0 || (strcmp(argv[i-1], "--intf") == 0)) { |
| 366 | ipAddress = get_ip_address(argv[i]); |
| 367 | break; |
| 368 | } |
| 369 | } |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 370 | |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 371 | for (int i = 1; i < argc; ++i) { |
| 372 | if (strcmp(argv[i-1], "--enable-tls") == 0) { |
| 373 | grpc_security = get_grpc_tls_option(argv[i]); |
| 374 | if (grpc_security.second) { |
| 375 | tls_enabled = true; |
| 376 | } else { |
| 377 | std::cerr << "unknown security option: \"" << argv[i-1] << " " << argv[i] << "\"\n"; |
| 378 | return false; |
| 379 | }; |
| 380 | break; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | if (tls_enabled) { |
| 385 | std::string dir_cert{"./keystore"}; |
| 386 | auto read_root_crt = read_from_txt_file(dir_cert + "/root.crt"); |
| 387 | auto read_server_key = read_from_txt_file(dir_cert + "/server.key"); |
| 388 | auto read_server_crt = read_from_txt_file(dir_cert + "/server.crt"); |
| 389 | |
| 390 | if (read_root_crt.second && read_server_key.second && read_server_crt.second) { |
| 391 | std::cout << "certificate files read successfully\n"; |
| 392 | } else { |
| 393 | std::cerr << std::boolalpha << "certificate files read failed - root.crt: " << read_root_crt.second |
| 394 | << ", server.key: " << read_server_key.second |
| 395 | << ", server.crt: " << read_server_crt.second << '\n'; |
| 396 | return false; |
| 397 | } |
| 398 | |
| 399 | std::string root_crt = read_root_crt.first; |
| 400 | std::string server_key = read_server_key.first; |
| 401 | std::string server_crt = read_server_crt.first; |
| 402 | |
| 403 | grpc::SslServerCredentialsOptions ssl_opts{grpc_security.first}; |
| 404 | ssl_opts.pem_root_certs = root_crt; |
| 405 | grpc::SslServerCredentialsOptions::PemKeyCertPair keycert = {server_key, server_crt}; |
| 406 | ssl_opts.pem_key_cert_pairs.push_back(keycert); |
| 407 | credentials = grpc::SslServerCredentials(ssl_opts); |
| 408 | } else { |
| 409 | credentials = grpc::InsecureServerCredentials(); |
| 410 | } |
| 411 | |
Thiyagarajan Subramani | 03bc66f | 2020-04-01 15:58:53 +0530 | [diff] [blame] | 412 | serverPort = ipAddress.append(":9191").c_str(); |
| 413 | OpenoltService service; |
| 414 | std::string server_address(serverPort); |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 415 | ::ServerBuilder builder; |
| 416 | ::ResourceQuota quota; |
| 417 | quota.SetMaxThreads(GRPC_THREAD_POOL_SIZE); |
| 418 | builder.SetResourceQuota(quota); |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 419 | builder.AddListeningPort(server_address, credentials); |
Thiyagarajan Subramani | 03bc66f | 2020-04-01 15:58:53 +0530 | [diff] [blame] | 420 | builder.RegisterService(&service); |
nick | 7be062f | 2018-05-25 17:52:56 -0400 | [diff] [blame] | 421 | |
Thiyagarajan Subramani | 03bc66f | 2020-04-01 15:58:53 +0530 | [diff] [blame] | 422 | std::unique_ptr<Server> server(builder.BuildAndStart()); |
nick | 7be062f | 2018-05-25 17:52:56 -0400 | [diff] [blame] | 423 | |
Thiyagarajan Subramani | 03bc66f | 2020-04-01 15:58:53 +0530 | [diff] [blame] | 424 | time_t now; |
| 425 | time(&now); |
| 426 | signature = (int)now; |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 427 | |
Thiyagarajan Subramani | 03bc66f | 2020-04-01 15:58:53 +0530 | [diff] [blame] | 428 | std::cout << "Server listening on " << server_address |
| 429 | << ", connection signature : " << signature << std::endl; |
| 430 | |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 431 | #ifdef TEST_MODE |
| 432 | server->Shutdown(); |
| 433 | #else |
Thiyagarajan Subramani | 03bc66f | 2020-04-01 15:58:53 +0530 | [diff] [blame] | 434 | server->Wait(); |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 435 | #endif |
| 436 | |
| 437 | return true; |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 438 | } |