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"
26 fwp_endpoint_attr_t attr;
30 fwp_endpoint_d_t sepoint_d1;
32 struct fwp_vres_params vparam1;
35 /*struct timespec sendtime;*/
37 vparam1.ac_id = FWP_AC_VO;
39 vparam1.period.tv_sec = 5;
40 vparam1.period.tv_nsec = 0;
42 printf("Create vres1\n");
43 if (fwp_vres_create(&vparam1, &vres_d1) < 0) {
44 printf("Unable to open vres1\n");
47 printf("Vres1 created\n");
49 if (fwp_send_endpoint_create(inet_addr("127.0.0.1"), PORT, &attr,
53 printf("Send endpoint 1 created\n");
54 fwp_send_endpoint_bind(sepoint_d1, vres_d1);
57 //for (count = 0; count < NUM; count++) {
63 sprintf(msg1,"msg%d sent\n",count);
64 fwp_send(sepoint_d1, msg1, sizeof(msg1), 0);
67 /*clock_gettime(CLOCK_MONOTONIC, &sendtime);
68 FWP_DEBUG("Sent %d: sec = %ld nsec = %ld \n", count,
69 sendtime.tv_sec, sendtime.tv_nsec);
73 while (!(exit_flag)) {
77 if (fwp_vres_destroy(vres_d1) < 0) {
78 perror("Unable to destroy vres1\n");
81 printf("Vres1 destroyed\n");
90 fwp_endpoint_d_t repoint_d;
92 struct timespec recvtime;
95 /* local_addr should be handled when creating socket */
96 if (fwp_receive_endpoint_create(PORT, &attr, &repoint_d) < 0){
97 perror("Not initialized\n");
100 printf("Receive endpoint created\n");
102 for (count = 1; count <= NUM; count++) {
104 if ((len = fwp_recv(repoint_d, buffer, sizeof(buffer), &from, 0)) < 0){
105 perror("Error while receiving data");
108 else printf("Received - %s\n", buffer);
110 clock_gettime(CLOCK_MONOTONIC, &recvtime);
111 FWP_DEBUG("Received %d: sec = %ld nsec = %ld \n", count,
112 recvtime.tv_sec, recvtime.tv_nsec);
122 // struct sockaddr_in local_addr, rem_addr, from;
123 pthread_attr_t thattr;
129 fwp_endpoint_attr_init(&attr);
130 pthread_attr_init(&thattr);
131 pthread_create(&thread, &thattr, sender, NULL);
132 pthread_create(&thread, &thattr, receiver, NULL);
133 pthread_join(thread, (void**) NULL);
135 printf("Test PASSED!\n");