]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - fwp/lib/fwp/tests/fwp_vrestest/fwp_vrestest1.c
Rename lib/core to lib/fwp. Clean-ups
[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
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
38         vparam1.ac_id = FWP_AC_VO; 
39         vparam1.budget = 100;
40         vparam1.period.tv_sec = 2; 
41         vparam1.period.tv_nsec = 111111; 
42
43         printf("Start\n");
44         if (fwp_init() != 0) {
45                 printf("fwp_init failed!\n");
46                 return -1;
47         }       
48         
49         printf("Create vres1\n");
50         if ((fwp_vres_create(&vparam1, &vresd1) < 0)) {
51                 printf("Unable to create vres1\n");
52                 return -1;
53         }
54         printf("Vres1 created\n");
55         
56         printf("Create vres2\n");
57         if ((fwp_vres_create(&vparam1, &vresd2) < 0)) {
58                 printf("Unable to create vres2\n");
59                 return -1;
60         }
61         printf("Vres2 created\n");
62         /* local_addr should be handled when creating socket */
63         if (fwp_receive_endpoint_create(7777, &attr, &repoint_d) < 0) {
64                 return -1;
65         }
66         printf("Receive endpoint created\n");
67         
68         if (fwp_send_endpoint_create(inet_addr("127.0.0.1"), 7777, &attr, 
69                                         &sepoint_d1) < 0){
70                 return -1;
71         }
72         printf("Send endpoint 1 created\n");
73         fwp_send_endpoint_bind(sepoint_d1, vresd1);
74         
75         for (count = 0; count < NUM; count++) { 
76                 sprintf(msg1,"msg%d",count);
77                 fwp_send(sepoint_d1, msg1, sizeof(msg1), 0);
78                 
79                 clock_gettime(CLOCK_MONOTONIC, &sendtime);
80                 FWP_DEBUG("Sent: sec = %ld nsec = %ld \n", sendtime.tv_sec,
81                                 sendtime.tv_nsec);
82                 
83                 if ((len = fwp_recv(repoint_d, buffer, sizeof(buffer), &from, 0)) < 0) {
84                         perror("Error while receiving data");
85                         return -1;
86                 } 
87                         else printf("Received - %s\n", buffer);
88         }
89
90         if (fwp_vres_destroy(vresd1) < 0) {
91                 perror("Unable to destroy vres1\n");
92                 return -1;
93         }
94         printf("Vres1 detroyed\n");
95         printf("Test PASSED!\n");
96         return 0;
97 }