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