anjana_sreekumar@infosys.com | 991c206 | 2020-01-08 11:42:57 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2019, Infosys Ltd. |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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 | */ |
| 16 | |
| 17 | #include <iostream> |
| 18 | #include <memory> |
| 19 | #include <string> |
| 20 | #include <sstream> |
| 21 | #include <time.h> |
| 22 | #include <grpcpp/grpcpp.h> |
| 23 | #include <google/protobuf/text_format.h> |
| 24 | #include <../mmeGrpcProtos/mmeGrpc.grpc.pb.h> |
| 25 | |
| 26 | using grpc::Channel; |
| 27 | using grpc::ClientContext; |
| 28 | using grpc::ClientReader; |
| 29 | using grpc::ClientReaderWriter; |
| 30 | using grpc::ClientWriter; |
| 31 | using grpc::Status; |
| 32 | using mmeGrpc::UeContextReqBuf; |
| 33 | using mmeGrpc::UeContextRespBuf; |
| 34 | using mmeGrpc::UeContextRespBuf_SessionContextRespBuf; |
| 35 | using mmeGrpc::MmeGrpcCli; |
| 36 | using mmeGrpc::Empty; |
| 37 | using mmeGrpc::ProcedureStatsRespBuf; |
| 38 | using mmeGrpc::EventInfoRespBuf; |
| 39 | using mmeGrpc::EventInfoRespBuf_EventInfoBuf; |
| 40 | |
| 41 | using namespace std; |
| 42 | |
| 43 | class MmeGrpcCliClient { |
| 44 | public: |
| 45 | MmeGrpcCliClient(std::shared_ptr<Channel> channel) |
| 46 | : stub_(MmeGrpcCli::NewStub(channel)) {} |
| 47 | |
| 48 | // Assembles the client's payload, sends it and presents the response back |
| 49 | // from the server. |
| 50 | void GetUeContext(const int32_t id) { |
| 51 | // Data we are sending to the server. |
| 52 | UeContextReqBuf request; |
| 53 | request.set_id(id); |
| 54 | |
| 55 | // Container for the data we expect from the server. |
| 56 | UeContextRespBuf reply; |
| 57 | |
| 58 | // Context for the client. It could be used to convey extra information to |
| 59 | // the server and/or tweak certain RPC behaviors. |
| 60 | ClientContext context; |
| 61 | |
| 62 | // The actual RPC. |
| 63 | Status status = stub_->GetUeContext(&context, request, &reply); |
| 64 | |
| 65 | // Act upon its status. |
| 66 | if (status.ok()) { |
| 67 | |
| 68 | /*std::string textString; |
| 69 | google::protobuf::TextFormat::PrintToString(reply, &textString); |
| 70 | std::cout << textString << std::endl; |
| 71 | */ |
| 72 | cout << "-----mobile context----- " << id << endl; |
| 73 | cout << "IMSI " << reply.imsi() << endl; |
| 74 | cout << "MSISDN " << reply.msisdn() << endl; |
| 75 | cout << "TAI " << reply.tai() << endl; |
| 76 | cout << "EUTRAN CGI " << reply.eutran_cgi() << endl; |
| 77 | cout << "Context ID " << reply.context_id() << endl; |
| 78 | cout << "Enb UE s1ap Teid " << reply.enb_ue_s1ap_id() << endl; |
| 79 | cout << "UE State " << reply.ue_state() << endl; |
| 80 | |
| 81 | int sessioncontext_size=reply.sessioncontext_size(); |
| 82 | for(int i=0;i<sessioncontext_size;i++) |
| 83 | { |
| 84 | const UeContextRespBuf_SessionContextRespBuf& sessioncontext = reply.sessioncontext(i); |
| 85 | |
| 86 | cout << "-----session context------ " << i+1 << endl; |
| 87 | cout << " apn " << sessioncontext.apn() << endl; |
| 88 | cout << " PDN address " << sessioncontext.pdn_address() << endl; |
| 89 | cout << " Bearer ID " << sessioncontext.bearer_id() << endl; |
| 90 | cout << " s11 sgw gtpc teid " << sessioncontext.s11_sgw_gtpc_teid() << endl; |
| 91 | cout << " s5 pgw gtpc teid " << sessioncontext.s5_pgw_gtpc_teid() << endl; |
| 92 | cout << " s1u enb teid " << sessioncontext.s1u_enb_teid() << endl; |
| 93 | cout << " s1u sgw teid " << sessioncontext.s1u_sgw_teid() << endl; |
| 94 | cout << " s5u pgw teid " << sessioncontext.s5u_pgw_teid() << endl; |
| 95 | } |
| 96 | |
| 97 | } else { |
| 98 | std::cout << status.error_code() << ": " << status.error_message() |
| 99 | << std::endl; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | void ShowAllMobileContexts() { |
| 104 | UeContextRespBuf reply; |
| 105 | |
| 106 | Empty request; |
| 107 | ClientContext context; |
| 108 | |
| 109 | std::unique_ptr<ClientReader<UeContextRespBuf> > reader( |
| 110 | stub_->ShowAllMobileContexts(&context, request)); |
| 111 | |
| 112 | while (reader->Read(&reply)) |
| 113 | { |
| 114 | cout << "-----mobile context----- " << endl; |
| 115 | cout << "IMSI " << reply.imsi() << endl; |
| 116 | cout << "MSISDN " << reply.msisdn() << endl; |
| 117 | cout << "TAI " << reply.tai() << endl; |
| 118 | cout << "EUTRAN CGI " << reply.eutran_cgi() << endl; |
| 119 | cout << "Context ID " << reply.context_id() << endl; |
| 120 | cout << "Enb UE s1ap Teid " << reply.enb_ue_s1ap_id() << endl; |
| 121 | cout << "UE State " << reply.ue_state() << endl; |
| 122 | |
| 123 | int sessioncontext_size=reply.sessioncontext_size(); |
| 124 | for(int i=0;i<sessioncontext_size;i++) |
| 125 | { |
| 126 | const UeContextRespBuf_SessionContextRespBuf& sessioncontext = reply.sessioncontext(i); |
| 127 | |
| 128 | cout << "-----session context------ " << i+1 << endl; |
| 129 | cout << " apn " << sessioncontext.apn() << endl; |
| 130 | cout << " PDN address " << sessioncontext.pdn_address() << endl; |
| 131 | cout << " Bearer ID " << sessioncontext.bearer_id() << endl; |
| 132 | cout << " s11 sgw gtpc teid " << sessioncontext.s11_sgw_gtpc_teid() << endl; |
| 133 | cout << " s5 pgw gtpc teid " << sessioncontext.s5_pgw_gtpc_teid() << endl; |
| 134 | cout << " s1u enb teid " << sessioncontext.s1u_enb_teid() << endl; |
| 135 | cout << " s1u sgw teid " << sessioncontext.s1u_sgw_teid() << endl; |
| 136 | cout << " s5u pgw teid " << sessioncontext.s5u_pgw_teid() << endl; |
| 137 | } |
| 138 | |
| 139 | } |
| 140 | Status status = reader->Finish(); |
| 141 | if (status.ok()) { |
| 142 | std::cout << "show all mobile-contexts rpc succeeded." << std::endl; |
| 143 | } else { |
| 144 | std::cout << "show all mobile-contexts rpc failed." << std::endl; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | |
| 149 | void GetProcStats(){ |
| 150 | // Container for the data we expect from the server. |
| 151 | ProcedureStatsRespBuf reply; |
| 152 | |
| 153 | Empty request; |
| 154 | |
| 155 | // Context for the client. It could be used to convey extra information to |
| 156 | // the server and/or tweak certain RPC behaviors. |
| 157 | ClientContext context; |
| 158 | // The actual RPC. |
| 159 | Status status = stub_->GetProcStats(&context, request, &reply); |
| 160 | |
| 161 | // Act upon its status. |
| 162 | if (status.ok()) { |
| 163 | cout << endl << "-----procedure stats-----" << endl; |
| 164 | cout << "num_of_subs_attached " << reply.num_of_subscribers_attached() << endl; |
| 165 | cout << "num_of_air_sent " << reply.num_of_air_sent() << endl; |
| 166 | cout << "num_of_ulr_sent " << reply.num_of_ulr_sent() << endl; |
| 167 | cout << "num_of_processed_aia " << reply.num_of_processed_aia() << endl; |
| 168 | cout << "num_of_processed_ula " << reply.num_of_processed_ula() << endl; |
| 169 | cout << "num_of_auth_req_to_ue_sent " << reply.num_of_auth_req_to_ue_sent() << endl; |
| 170 | cout << "num_of_processed_auth_response " << reply.num_of_processed_auth_response() << endl; |
| 171 | cout << "num_of_sec_mode_cmd_to_ue_sent " << reply.num_of_sec_mode_cmd_to_ue_sent() << endl; |
| 172 | cout << "num_of_processed_sec_mode_resp " << reply.num_of_processed_sec_mode_resp() << endl; |
| 173 | cout << "num_of_esm_info_req_to_ue_sent " << reply.num_of_esm_info_req_to_ue_sent() << endl; |
| 174 | cout << "num_of_handled_esm_info_resp " << reply.num_of_handled_esm_info_resp() << endl; |
| 175 | cout << "num_of_cs_req_to_sgw_sent " << reply.num_of_cs_req_to_sgw_sent() << endl; |
| 176 | cout << "num_of_processed_cs_resp " << reply.num_of_processed_cs_resp() << endl; |
| 177 | cout << "num_of_init_ctxt_req_to_ue_sent " << reply.num_of_init_ctxt_req_to_ue_sent() << endl; |
| 178 | cout << "num_of_processed_init_ctxt_resp " << reply.num_of_processed_init_ctxt_resp() << endl; |
| 179 | cout << "num_of_mb_req_to_sgw_sent " << reply.num_of_mb_req_to_sgw_sent() << endl; |
| 180 | cout << "num_of_processed_attach_cmp_from_ue " << reply.num_of_processed_attach_cmp_from_ue() << endl; |
| 181 | cout << "num_of_processed_mb_resp " << reply.num_of_processed_mb_resp() << endl; |
| 182 | cout << "num_of_attach_done " << reply.num_of_attach_done() << endl; |
| 183 | cout << "num_of_del_session_req_sent " << reply.num_of_del_session_req_sent() << endl; |
| 184 | cout << "num_of_purge_req_sent " << reply.num_of_purge_req_sent() << endl; |
| 185 | cout << "num_of_processed_del_session_resp " << reply.num_of_processed_del_session_resp() << endl; |
| 186 | cout << "num_of_processed_pur_resp " << reply.num_of_processed_pur_resp() << endl; |
| 187 | cout << "num_of_detach_accept_to_ue_sent " << reply.num_of_detach_accept_to_ue_sent() << endl; |
| 188 | cout << "num_of_processed_detach_accept " << reply.num_of_processed_detach_accept() << endl; |
| 189 | cout << "num_of_ue_ctxt_release " << reply.num_of_ue_ctxt_release() << endl; |
| 190 | cout << "num_of_processed_ctxt_rel_resp " << reply.num_of_processed_ctxt_rel_resp() << endl; |
| 191 | cout << "num_of_rel_access_bearer_req_sent " << reply.num_of_rel_access_bearer_req_sent() << endl; cout << "num_of_rel_access_bearer_resp_received " << reply.num_of_rel_access_bearer_resp_received() << endl; |
| 192 | cout << "num_of_s1_rel_req_received " << reply.num_of_s1_rel_req_received() << endl; |
| 193 | cout << "num_of_s1_rel_cmd_sent " << reply.num_of_s1_rel_cmd_sent() << endl; |
| 194 | cout << "num_of_s1_rel_comp_received " << reply.num_of_s1_rel_comp_received() << endl; |
| 195 | cout << "num_of_clr_received " << reply.num_of_clr_received() << endl; |
| 196 | cout << "num_of_cla_sent " << reply.num_of_cla_sent() << endl; |
| 197 | cout << "num_of_detach_req_to_ue_sent " << reply.num_of_detach_req_to_ue_sent() << endl; |
| 198 | cout << "num_of_detach_accept_from_ue " << reply.num_of_detach_accept_from_ue() << endl; |
| 199 | cout << "total_num_of_subscribers " << reply.total_num_of_subscribers() << endl; |
| 200 | cout << "num_of_subscribers_detached " << reply.num_of_subscribers_detached() << endl; |
| 201 | cout << "num_of_tau_response_to_ue_sent " << reply.num_of_tau_response_to_ue_sent() << endl; |
| 202 | |
| 203 | } else { |
| 204 | std::cout << status.error_code() << ": " << status.error_message() |
| 205 | << std::endl; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | void GetDebugUeContext(const int32_t id){ |
| 210 | // Container for the data we expect from the server. |
| 211 | EventInfoRespBuf reply; |
| 212 | |
| 213 | UeContextReqBuf request; |
| 214 | request.set_id(id); |
| 215 | |
| 216 | // Context for the client. It could be used to convey extra information to |
| 217 | // the server and/or tweak certain RPC behaviors. |
| 218 | ClientContext context; |
| 219 | // The actual RPC. |
| 220 | Status status = stub_->GetDebugUeContext(&context, request, &reply); |
| 221 | |
| 222 | // Act upon its status. |
| 223 | if (status.ok()) |
| 224 | { |
| 225 | int event_info_buf_size=reply.eventinfo_size(); |
| 226 | cout << "EVENT\t\t\t\t\t\tSTATE\t\t\t\t\t\tTIMESTAMP" << endl; |
| 227 | cout << "-----------------------------------------------------------------" << endl; |
| 228 | for(int i=0; i<event_info_buf_size; i++) |
| 229 | { |
| 230 | const EventInfoRespBuf_EventInfoBuf& event_info=reply.eventinfo(i); |
| 231 | |
| 232 | cout << event_info.event() << "\t\t\t\t\t\t" |
| 233 | << event_info.state() << "\t\t\t\t\t\t" |
| 234 | << event_info.time() << endl; |
| 235 | } |
| 236 | } else { |
| 237 | cout << status.error_code() << ": " << status.error_message() << endl; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | |
| 242 | private: |
| 243 | std::unique_ptr<MmeGrpcCli::Stub> stub_; |
| 244 | }; |
| 245 | |
| 246 | int main(int argc, char** argv) { |
| 247 | // Instantiate the client. It requires a channel, out of which the actual RPCs |
| 248 | // are created. This channel models a connection to an endpoint (in this case, |
| 249 | // localhost at port 50051). We indicate that the channel isn't authenticated |
| 250 | // (use of InsecureChannelCredentials()). |
| 251 | |
| 252 | if((0==strcmp(argv[1],"mme-app"))&&(0==strcmp(argv[2],"show"))&&(0==strcmp(argv[3],"mobile-context"))) |
| 253 | { |
| 254 | MmeGrpcCliClient MmeGrpcCli(grpc::CreateChannel( |
| 255 | "localhost:50051", grpc::InsecureChannelCredentials())); |
| 256 | stringstream sid; |
| 257 | sid << argv[4]; |
| 258 | int32_t id = 1; |
| 259 | sid >> id; |
| 260 | |
| 261 | MmeGrpcCli.GetUeContext(id); |
| 262 | } |
| 263 | else if((0==strcmp(argv[1],"mme-app"))&&(0==strcmp(argv[2],"show"))&&(0==strcmp(argv[3],"procedure-stats"))) |
| 264 | { |
| 265 | MmeGrpcCliClient MmeGrpcCli(grpc::CreateChannel( |
| 266 | "localhost:50051", grpc::InsecureChannelCredentials())); |
| 267 | |
| 268 | MmeGrpcCli.GetProcStats(); |
| 269 | } |
| 270 | else if((0==strcmp(argv[1],"mme-app"))&&(0==strcmp(argv[2],"show"))&&(0==strcmp(argv[3],"mobile-contexts-all"))) |
| 271 | { |
| 272 | MmeGrpcCliClient MmeGrpcCli(grpc::CreateChannel( |
| 273 | "localhost:50051", grpc::InsecureChannelCredentials())); |
| 274 | |
| 275 | MmeGrpcCli.ShowAllMobileContexts(); |
| 276 | } |
| 277 | |
| 278 | else if((0==strcmp(argv[1],"mme-app"))&&(0==strcmp(argv[2],"debug"))&&(0==strcmp(argv[3],"show")) &&(0==strcmp(argv[4],"mobile-context"))) |
| 279 | { |
| 280 | MmeGrpcCliClient MmeGrpcCli(grpc::CreateChannel( |
| 281 | "localhost:50051", grpc::InsecureChannelCredentials())); |
| 282 | stringstream sid; |
| 283 | sid << argv[5]; |
| 284 | int32_t id = 1; |
| 285 | sid >> id; |
| 286 | cout << endl << "-----debug mobile context----- " << id << endl; |
| 287 | MmeGrpcCli.GetUeContext(id); |
| 288 | MmeGrpcCli.GetDebugUeContext(id); |
| 289 | } |
| 290 | return 0; |
| 291 | } |