ISSUE ID:- RICAPP-216
[ric-app/bouncer.git] / Bouncer / src / main.cpp
1 #include "bouncer.h"
2 //using namespace xapp;
3 std::unique_ptr<Xapp> xfw;
4
5 void display_json(web::json::value const & jvalue){
6         std::cout<<"\ndisplaying REST Notification\n";
7         std::wcout << jvalue.serialize().c_str() << std::endl;
8 }
9
10
11 void indication_callback( Message& mbuf, int mtype, int subid, int len, Msg_component payload, void* data ) {
12
13         std::cout << "[INFO] indication Callback got a message, type=" << mtype << ", length=" << len << std::endl;
14         //std::string json ((char *)payload.get(), len); // RMR payload might not have a nil terminanted char
15         
16         E2AP_PDU_t* e2pdu = (E2AP_PDU_t*)calloc(1, sizeof(E2AP_PDU));
17         asn_transfer_syntax syntax;
18         syntax = ATS_ALIGNED_BASIC_PER;
19         auto rval =  asn_decode(nullptr, syntax, &asn_DEF_E2AP_PDU, (void**)&e2pdu, (char *)payload.get(), len);
20         if(rval.code == RC_OK)
21         {
22                 std::cout << "[INFO] E2AP indication decode successfull rval.code = "<<rval.code<<std::endl;
23                 asn_fprint(stdout, &asn_DEF_E2AP_PDU, e2pdu);
24         }
25         else
26         {
27                  std::cout << "[INFO] E2AP indication decode failed rval.code = "<<rval.code<<std::endl;
28         }
29
30         asn_fprint(stdout, &asn_DEF_E2AP_PDU, e2pdu);
31         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, e2pdu);
32         //std::cout << "[INFO] Payload is " << json << std::endl;
33
34 }
35
36 void handle_request( web::http::http_request request)
37 {
38 auto answer = web::json::value::object();
39 std::cout<<"\nPrinting POST request content\n";
40 std::cout<<request.to_string()<<"\n";
41    request
42       
43            .extract_json()
44       .then([&answer](pplx::task<web::json::value> task) {
45          try
46          {
47             answer = task.get();
48             display_json(answer);
49             }
50          catch (web::http::http_exception const & e)
51          {
52                 std::wcout << e.what() << std::endl;
53          }
54
55       })
56       .wait();
57
58    request.reply(web::http::status_codes::OK, answer);
59 }
60
61 extern int main( int argc, char** argv ) {
62   
63         int nthreads = 1;
64         char*   port = (char *) "4560";
65         xfw = std::unique_ptr<Xapp>( new Xapp( port, true ) );
66         xfw->Add_msg_cb( RIC_INDICATION , indication_callback, NULL );
67   
68         Bouncer B;
69   
70         
71         while(B.gnb_list.size() ==0){
72                 B.set_gnb();
73         }
74         std::cout << "[INFO] size of gnb list is "<<B.gnb_list.size()<<std::endl;
75         cpprestclient obj("http://service-ricplt-submgr-http.ricplt.svc.cluster.local:8088/ric/v1/subscriptions",handle_request);
76         
77         for(int i=0;i<B.gnb_list.size();i++){
78
79                 subscriptionJson j;
80                 j.jsonObject["Meid"]=B.gnb_list[i];
81                 oresponse_t o;
82                 std::cout << "[INFO] sending subscription for "<<B.gnb_list[i]<<std::endl;
83                 o=obj.post_subscriptions(j.jsonObject,"");
84                 std::cout << "[INFO] status code is " << o.status_code<< std::endl;
85                 std::cout << "[INFO] subscription id is " << o.SubscriptionId<< std::endl;
86
87         }
88
89         xfw->Run( nthreads );
90
91 }