]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - fwp/lib/core/tests/fwp_vrestest/fwp_vrestest1.c
e5efad98b25d30ffe1166654b211819819098193
[frescor/fwp.git] / fwp / lib / core / 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
20 #define  NUM  10000
21
22 int main()
23 {
24 //      struct sockaddr_in local_addr, rem_addr, from;
25         ssize_t len;
26         fwp_vres_d_t vresd1, vresd2;
27         struct fwp_vres_params vparam1;
28         char msg1[15];
29         char buffer[30];
30         fwp_endpoint_d_t sepoint_d1, repoint_d;
31         int count;
32         struct timespec  sendtime;
33         fwp_endpoint_attr_t attr ;
34         unsigned int from;
35         
36         fwp_endpoint_attr_init(&attr);
37         vparam1.ac_id = FWP_AC_VO; 
38         vparam1.budget = 100;
39         vparam1.period_usec = 2111111; 
40
41         printf("Start\n");
42         if (fwp_init() != 0) {
43                 printf("fwp_init failed!\n");
44                 return -1;
45         }       
46         
47         printf("Create vres1\n");
48         if ((fwp_vres_create(&vparam1, &vresd1) < 0)) {
49                 printf("Unable to create vres1\n");
50                 return -1;
51         }
52         printf("Vres1 created\n");
53         
54         printf("Create vres2\n");
55         if ((fwp_vres_create(&vparam1, &vresd2) < 0)) {
56                 printf("Unable to create vres2\n");
57                 return -1;
58         }
59         printf("Vres2 created\n");
60         /* local_addr should be handled when creating socket */
61         if (fwp_receive_endpoint_create(7777, &attr, &repoint_d) < 0) {
62                 return -1;
63         }
64         printf("Receive endpoint created\n");
65         
66         if (fwp_send_endpoint_create(inet_addr("127.0.0.1"), 7777, &attr, 
67                                         &sepoint_d1) < 0){
68                 return -1;
69         }
70         printf("Send endpoint 1 created\n");
71         fwp_send_endpoint_bind(sepoint_d1, vresd1);
72         
73         for (count = 0; count < NUM; count++) { 
74                 sprintf(msg1,"msg%d",count);
75                 fwp_send(sepoint_d1, msg1, sizeof(msg1), 0);
76                 
77                 clock_gettime(CLOCK_MONOTONIC, &sendtime);
78                 FWP_DEBUG("Sent: sec = %ld nsec = %ld \n", sendtime.tv_sec,
79                                 sendtime.tv_nsec);
80                 
81                 if ((len = fwp_recv(repoint_d, buffer, sizeof(buffer), &from, 0)) < 0) {
82                         perror("Error while receiving data");
83                         return -1;
84                 } 
85                         else printf("Received - %s\n", buffer);
86         }
87
88         if (fwp_vres_destroy(vresd1) < 0) {
89                 perror("Unable to destroy vres1\n");
90                 return -1;
91         }
92         printf("Vres1 detroyed\n");
93         printf("Test PASSED!\n");
94         return 0;
95 }