2 * \file fwp_vrestest2.c
4 * This a test application that:
5 * - creates vres without negotiation
6 * - creates send and receive endpoint
7 * - binds that endpoint to vres
8 * - in cycle (NUM loops) sends messages in separate thread and
10 * - receives messages in separate receiver thread
14 #define CONFIGURE_FWP_MNGT 0
15 #include "fwp_confdefs.h"
23 #include <arpa/inet.h>
24 #include <fwp_utils.h>
30 fwp_endpoint_attr_t attr;
34 fwp_endpoint_d_t sepoint_d1;
36 struct fwp_vres_params vparam1;
39 /*struct timespec sendtime;*/
41 vparam1.ac_id = FWP_AC_VO;
43 vparam1.period.tv_sec = 5;
44 vparam1.period.tv_nsec = 0;
46 printf("Create vres1\n");
47 if (fwp_vres_create(&vparam1, &vres_d1) < 0) {
48 printf("Unable to open vres1\n");
51 printf("Vres1 created\n");
53 if (fwp_send_endpoint_create(inet_addr("127.0.0.1"), PORT, &attr,
57 printf("Send endpoint 1 created\n");
58 fwp_send_endpoint_bind(sepoint_d1, vres_d1);
61 //for (count = 0; count < NUM; count++) {
67 sprintf(msg1,"msg%d sent\n",count);
68 fwp_send(sepoint_d1, msg1, sizeof(msg1), 0);
71 /*clock_gettime(CLOCK_MONOTONIC, &sendtime);
72 FWP_DEBUG("Sent %d: sec = %ld nsec = %ld \n", count,
73 sendtime.tv_sec, sendtime.tv_nsec);
77 while (!(exit_flag)) {
81 if (fwp_vres_destroy(vres_d1) < 0) {
82 perror("Unable to destroy vres1\n");
85 printf("Vres1 destroyed\n");
94 fwp_endpoint_d_t repoint_d;
96 struct timespec recvtime;
99 /* local_addr should be handled when creating socket */
100 if (fwp_receive_endpoint_create(PORT, &attr, &repoint_d) < 0){
101 perror("Not initialized\n");
104 printf("Receive endpoint created\n");
106 for (count = 1; count <= NUM; count++) {
108 if ((len = fwp_recv(repoint_d, buffer, sizeof(buffer), &from, 0)) < 0){
109 perror("Error while receiving data");
112 else printf("Received - %s\n", buffer);
114 clock_gettime(CLOCK_MONOTONIC, &recvtime);
115 printf("Received %d: sec = %ld nsec = %ld \n", count,
116 recvtime.tv_sec, recvtime.tv_nsec);
126 // struct sockaddr_in local_addr, rem_addr, from;
127 pthread_attr_t thattr;
133 fwp_endpoint_attr_init(&attr);
134 pthread_attr_init(&thattr);
135 pthread_create(&thread, &thattr, sender, NULL);
136 pthread_create(&thread, &thattr, receiver, NULL);
137 pthread_join(thread, (void**) NULL);
139 printf("Test PASSED!\n");