2 ==================================================================================
4 Copyright (c) 2018-2019 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
19 /* Author : Ashwin Sridharan
21 A sample test client to demonstrate A1 functionality.
22 Sends different kind of policy requests (valid/invalid) and prints out response
30 #include <xapp_utils.hpp>
32 #include <rmr/RIC_message_types.h>
34 std::string gNodeB = "";
36 bool rcv_message(rmr_mbuf_t *message){
38 switch(message->mtype){
39 case DC_ADM_INT_CONTROL_ACK:
40 std::cout <<"Received response = " << (char *)message->payload << " of len = " << strlen((char *)message->payload) << "Actual = " << message->len << std::endl;
43 case DC_ADM_GET_POLICY_ACK:
44 std::cout <<"Received Policy = " << (char *)message->payload << " of len = " << strlen((char *)message->payload) << "Actual = " << message->len << std::endl;
48 std::cout <<"Unknown RMR message of type " << message->mtype << " received" << std::endl;
55 void usage(char *command){
56 std::cout <<"Usage : " << command << " ";
57 std::cout <<" --name[-n] xapp_instance_name ";
58 std::cout <<" --port[-p] port to listen on (default is tcp:4561) ";
59 std::cout <<"--schema[-s] schema file";
61 std::cout << std::endl;
65 void msg_error(rmr_mbuf_t *message){
66 mdclog_write(MDCLOG_ERR, "Error sending message of length %d and type %d, Reason %d", message->len, message->mtype, errno );
70 int main(int argc, char *argv[]){
72 char name[128] = "test_a1_client";
73 char port[16] = "tcp:4560";
74 unsigned int num_threads = 1;
75 std::unique_ptr<XaPP> my_xapp;
77 // Parse command line options
78 static struct option long_options[] =
81 /* Thse options require arguments */
82 {"name", required_argument, 0, 'n'},
83 {"port", required_argument, 0, 'p'},
91 char c = getopt_long(argc, argv, "n:p:", long_options, &option_index);
101 /* An option flag was set.
102 Do nothing for now */
106 strcpy(name, optarg);
110 strcpy(port, optarg);
124 init_logger(name, MDCLOG_INFO);
126 mdclog_write(MDCLOG_INFO, "XaPP name specified = %s", name);
127 mdclog_write(MDCLOG_INFO, "XaPP port specified = %s", port);
129 mdclog_write(MDCLOG_INFO,"XaPP listener threads specified = auto");
130 my_xapp = std::make_unique<XaPP>(name, port, 1024, 1);
133 // Start receiving loop ...
134 std::vector<int> thread_ids(num_threads);
135 for(unsigned int i = 0; i < num_threads; i++){
136 thread_ids[i] = (*my_xapp).StartThread(&rcv_message, msg_error);
142 int window_length = 20;
143 int trigger_threshold = 40;
147 // Send a valid config
148 std::string message_string ;
149 std::string start = "{";
150 std::string end = "}";
152 message_string = start + "\"enforce\":" + (enforce? "true":"false") + ",";
153 message_string += std::string("\"blocking_rate\":") + std::to_string(block_rate) + ",";
154 message_string += std::string("\"window_length\":") + std::to_string(window_length) + ",";
155 message_string += std::string("\"trigger_threshold\":") + std::to_string(trigger_threshold) + end;
156 memcpy(buffer, message_string.c_str(), message_string.length());
157 my_xapp.get()->Send(DC_ADM_INT_CONTROL, message_string.length(), buffer);
162 // // Send an invalid config
163 message_string = start + "\"enfce\":" + (enforce? "true":"false") + ",";
164 message_string += std::string("\"blocking_rate\":") + std::to_string(block_rate) + ",";
165 message_string += std::string("\"window_length\":") + std::to_string(window_length) + end;
166 memcpy(buffer, message_string.c_str(), message_string.length());
167 my_xapp.get()->Send(DC_ADM_INT_CONTROL, message_string.length(), buffer);
171 message_string.assign("\"enforce\":false,");
172 message_string += std::string("\"blocking_rate\":") + std::to_string(block_rate) + ",";
173 message_string += std::string("\"window_length\":") + std::to_string(window_length) + end;
174 memcpy(buffer, message_string.c_str(), message_string.length());
175 my_xapp.get()->Send(DC_ADM_INT_CONTROL, message_string.length(), buffer);
180 // Send request for policy
181 // we don't care about contents of request for now ...
182 std::cout <<"Sending request to get policy" << std::endl;
183 my_xapp.get()->Send(DC_ADM_GET_POLICY, message_string.length(), buffer);