3 * Copyright 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.
20 // :vim ts=4 sw=4 noet:
23 Mnemonic: rmr_sender2.c
24 Abstract: Very simple test sender that polls and deals with responses
25 in between sends (from a single process).
27 Date: 18 February 2018
28 Author: E. Scott Daniels
30 Modified: 18 Mar 2019 - changes to support demo
38 #include <sys/epoll.h>
41 #include "dummy_a1_rmr_wrapper.h"
44 void usage( char* argv0 ) {
45 fprintf( stderr, "usage: %s [mtype-max]\n", argv0 );
46 fprintf( stderr, "Sender will send messages with rotating msg types from 0 through mtype-max (if supplied)\n" );
47 fprintf( stderr, "if not supplied, only mtype 0 is sent\n" );
48 fprintf( stderr, "The default listen port for return messages is 43086; this can be changed by setting DUMMY_SENDER_RMR_RCV_PORT in the environment.\n" );
49 fprintf( stderr, "The sender will send forever unless DEMO_SENDER_MAX is set in the environment which causes termination after max messages.\n" );
50 fprintf( stderr, "The sender will poll for received messages after each send. The amount of time waited is controlled with DEMO_SENDER_PTO (ms) in the env. Use 0 for non-blocking poll.\n" );
53 void send_delay_message(struct rmr_context *rmr_c, char* delay_file_path){
57 fp = fopen(delay_file_path, "r");
58 fscanf(fp, "%s", delay);
60 rmr_pure_send(rmr_c, mtype, delay);
61 fprintf( stderr, "Sent delay insert message of type:%d (delay insert) to pendulum control xApp, with content:%s\n",mtype,delay);
65 void send_and_rec_metrics(struct rmr_context *rmr_c, char* metrics_file_path){
67 char* message="--give metrics--";
68 rmr_pure_send(rmr_c, mtype, message );
69 printf("Sent message of type:%d to E2 terminator with content:%s\n",mtype,message);
71 while (got_metrics == 0){
72 if(rmr_poll_for_message(rmr_c) == 1) {
73 if(rmr_c->rbuf->mtype == 103)
77 printf("Recieved metrics from E2 terminator with content:%s\n",rmr_c->rbuf->payload);
80 fp = fopen(metrics_file_path, "w+");
81 fprintf(fp,"%s",rmr_c->rbuf->payload);
85 int main( int argc, char** argv ) {
86 struct rmr_context *rmr_c; //obtain our enhanced rmr_context
87 char* lport = "43086"; // default listen port
88 char* delay_file_path ="";
89 char* metrics_file_path ="";
90 if( (eparm = getenv( "DUMMY_SENDER_RMR_RCV_PORT" )) != NULL ) {
91 lport = strdup( eparm );
94 if( (eparm = getenv( "DELAY_FILE_PATH" )) != NULL ) {
95 delay_file_path = eparm ;
98 if( (eparm = getenv( "METRICS_FILE_PATH" )) != NULL ) {
99 metrics_file_path = eparm ;
102 rmr_c = rmr_init_wrapper(lport);
104 while( ! rmr_ready( rmr_c->mrc ) ) {
105 fprintf( stderr, "<TEST> waiting for RMr to indicate ready\n" );
108 fprintf( stderr, "[OK] initialisation complete\n" );
109 fprintf( stderr, "======================================\n[OK] A1 mediator is up and running!\n==================================\n" );
114 send_delay_message(rmr_c, delay_file_path);
116 send_and_rec_metrics(rmr_c, metrics_file_path);
117 fprintf( stderr, "-------------------------------------------\n");
122 fprintf( stderr, "[INFO] sender is terminating\n");
123 rmr_close_wrapper(rmr_c);