2 * \file fwp_vrestest1.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 and prints send time
13 #define CONFIGURE_FWP_MNGT 0
14 #include "fwp_confdefs.h"
19 #include <arpa/inet.h>
21 #define WVTEST_CONFIGURED
27 WVTEST_MAIN("FWP VRES synchronous communication")
29 // struct sockaddr_in local_addr, rem_addr, from;
31 fwp_vres_t *vres1, *vres2;
32 struct fwp_vres_params vparam1;
35 struct fwp_endpoint *sepoint, *repoint;
37 struct timespec sendtime;
38 fwp_endpoint_attr_t attr;
41 fwp_endpoint_attr_init(&attr);
43 vparam1.ac_id = FWP_AC_VO;
45 vparam1.period.tv_sec = 2;
46 vparam1.period.tv_nsec = 111111;
48 if (WVFAIL(fwp_init() != 0)) {
49 printf("fwp_init failed!\n");
53 if (WVFAIL(fwp_vres_create(&vparam1, &vres1) < 0)) {
54 printf("Unable to create vres1\n");
58 if (WVFAIL(fwp_vres_create(&vparam1, &vres2) < 0)) {
59 printf("Unable to create vres2\n");
63 /* local_addr should be handled when creating socket */
64 if (WVFAIL(fwp_receive_endpoint_create(7777, &attr, &repoint) < 0)) {
68 if (WVFAIL(fwp_send_endpoint_create(inet_addr("127.0.0.1"), 7777, &attr,
73 WVPASS(fwp_send_endpoint_bind(sepoint, vres1) == 0);
75 for (count = 0; count < NUM; count++) {
76 sprintf(msg1,"msg%d",count);
77 WVPASSEQ(fwp_send_sync(sepoint, msg1, sizeof(msg1)), sizeof(msg1));
79 clock_gettime(CLOCK_MONOTONIC, &sendtime);
80 printf("Sent: sec = %ld nsec = %ld \n", sendtime.tv_sec,
83 if (WVFAIL((len = fwp_recv(repoint, buffer, sizeof(buffer), &from, 0)) < 0)) {
84 perror("Error while receiving data");
87 else printf("Received - %s\n", buffer);
88 WVPASSEQSTR(msg1, buffer);
91 if (WVFAIL(fwp_vres_destroy(vres1) < 0)) {
92 perror("Unable to destroy vres1\n");
95 if (WVFAIL(fwp_vres_destroy(vres2) < 0)) {
96 perror("Unable to destroy vres1\n");
99 WVPASSEQ(fwp_endpoint_destroy(sepoint), 0);
100 WVPASSEQ(fwp_endpoint_destroy(repoint), 0);
101 printf("Vres1 detroyed\n");
102 printf("Test PASSED!\n");