]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - fwp/lib/fwp/tests/fwp_vrestest/fwp_vrestest1.c
Implemented synchronous and asynchronous sending
[frescor/fwp.git] / fwp / lib / fwp / tests / fwp_vrestest / fwp_vrestest1.c
1 /**
2  * \file fwp_vrestest1.c  
3  *
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
9  * - receives messages
10  * - destroys vres
11  *
12  */
13 #define  CONFIGURE_FWP_MNGT 0
14 #include "fwp_confdefs.h"
15 #include "fwp.h"
16
17 #include <errno.h>
18 #include <stdio.h>
19 #include <arpa/inet.h>
20 #include <time.h>
21
22 #define  NUM  10000
23
24 int main()
25 {
26 //      struct sockaddr_in local_addr, rem_addr, from;
27         ssize_t len;
28         fwp_vres_t *vres1, *vres2;
29         struct fwp_vres_params vparam1;
30         char msg1[15];
31         char buffer[30];
32         struct fwp_endpoint *sepoint, *repoint;
33         int count;
34         struct timespec  sendtime;
35         fwp_endpoint_attr_t attr;
36         unsigned int from;
37         
38         fwp_endpoint_attr_init(&attr);
39
40         vparam1.ac_id = FWP_AC_VO; 
41         vparam1.budget = 100;
42         vparam1.period.tv_sec = 2; 
43         vparam1.period.tv_nsec = 111111; 
44
45         printf("Start\n");
46         if (fwp_init() != 0) {
47                 printf("fwp_init failed!\n");
48                 return -1;
49         }       
50         
51         printf("Create vres1\n");
52         if ((fwp_vres_create(&vparam1, &vres1) < 0)) {
53                 printf("Unable to create vres1\n");
54                 return -1;
55         }
56         printf("Vres1 created\n");
57         
58         printf("Create vres2\n");
59         if ((fwp_vres_create(&vparam1, &vres2) < 0)) {
60                 printf("Unable to create vres2\n");
61                 return -1;
62         }
63         printf("Vres2 created\n");
64         /* local_addr should be handled when creating socket */
65         if (fwp_receive_endpoint_create(7777, &attr, &repoint) < 0) {
66                 return -1;
67         }
68         printf("Receive endpoint created\n");
69         
70         if (fwp_send_endpoint_create(inet_addr("127.0.0.1"), 7777, &attr, 
71                                      &sepoint) < 0){
72                 return -1;
73         }
74         printf("Send endpoint 1 created\n");
75         fwp_send_endpoint_bind(sepoint, vres1);
76         
77         for (count = 0; count < NUM; count++) { 
78                 sprintf(msg1,"msg%d",count);
79                 fwp_send_sync(sepoint, msg1, sizeof(msg1));
80                 
81                 clock_gettime(CLOCK_MONOTONIC, &sendtime);
82                 printf("Sent: sec = %ld nsec = %ld \n", sendtime.tv_sec,
83                        sendtime.tv_nsec);
84                 
85                 if ((len = fwp_recv(repoint, buffer, sizeof(buffer), &from, 0)) < 0) {
86                         perror("Error while receiving data");
87                         return -1;
88                 } 
89                         else printf("Received - %s\n", buffer);
90         }
91
92         if (fwp_vres_destroy(vres1) < 0) {
93                 perror("Unable to destroy vres1\n");
94                 return -1;
95         }
96         printf("Vres1 detroyed\n");
97         printf("Test PASSED!\n");
98         return 0;
99 }