]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - fwp/lib/core/tests/fwp_prototest/fwp_sendrecv_test1.c
Fixing bugs related to tcp tranfer. Still not working
[frescor/fwp.git] / fwp / lib / core / tests / fwp_prototest / fwp_sendrecv_test1.c
1 /**
2  * \file fwp_sendrecv_test1.c  
3  *
4  * This a test application that:
5  * - creates two vres without negotiation
6  * - creates send and receive endpoint 
7  * - binds that endpoint to vres
8  * - sends two messages
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 int main()
21 {
22 //      struct sockaddr_in local_addr, rem_addr, from;
23         ssize_t len;
24         fwp_vres_d_t vres_d1, vres_d2;
25         int i;
26         struct fwp_vres_params vparam1, vparam2;
27         char msg1[] = "Hello1";
28         char msg2[] = "Hello2";
29         char buffer[30];
30         fwp_endpoint_d_t sepoint_d1, sepoint_d2, repoint_d1, repoint_d2;
31         fwp_endpoint_attr_t attr;
32         fwp_addr_t from;
33         
34         fwp_endpoint_attr_init(&attr);
35
36         vparam1.ac_id = FWP_AC_VO; 
37         vparam1.budget = 100;
38         vparam1.period_usec = 2000000; 
39
40         vparam2.ac_id = FWP_AC_BK; 
41         vparam2.budget = 100;
42         vparam2.period_usec = 100;
43
44         printf("Start\n");
45         fwp_init();
46         
47         printf("Create vres1, vres2\n");
48         if (fwp_vres_create(&vparam1, &vres_d1) < 0) {
49                 printf("Unable to create vres1\n");
50                 return -1;
51         }
52         printf("Vres1 created \n");
53         
54         if (fwp_vres_create(&vparam2, &vres_d2) < 0){
55                 fprintf(stderr,"Unable to create vres2\n");
56                 return -1;
57         }
58         printf("Vres2 created\n");
59         
60         /* local_addr should be handled when creating socket */
61         if (fwp_receive_endpoint_create(7777, &attr,&repoint_d1) < 0){
62                 return -1;
63         }
64         printf("Receive endpoint created\n");
65         
66         if (fwp_receive_endpoint_create(7778, &attr,&repoint_d2) < 0){
67                 return -1;
68         }
69         printf("Receive endpoint created\n");
70         
71         if (fwp_send_endpoint_create(inet_addr("127.0.0.1"), 7777, 0, 
72                                         &sepoint_d1) < 0) {
73                 return -1;
74         }
75         printf("Send endpoint 1 created\n");
76         fwp_send_endpoint_bind(sepoint_d1, vres_d1);
77         
78         if (fwp_send_endpoint_create(inet_addr("127.0.0.1"), 7778, 0, 
79                                         &sepoint_d2) < 0){
80                 return -1;
81         }
82         printf("Send endpoint 2 created\n");
83         fwp_send_endpoint_bind(sepoint_d2, vres_d2);
84         
85         fwp_send(sepoint_d1, msg1, sizeof(msg1), 0);
86         fwp_send(sepoint_d1, msg2, sizeof(msg2), 0);
87
88         for (i = 0; i < 2; i++) {
89                 if ((len = fwp_recv(repoint_d1, buffer, sizeof(buffer), &from, 
90                         0)) < 0) {
91                         perror("Error while receiving data");
92                         return -1;
93                 } 
94                         else printf("Received - %s\n", buffer);
95         }
96
97         if (fwp_vres_destroy(vres_d1) < 0) {
98                 perror("Unable to destroy vres1\n");
99                 return -1;
100         }
101         printf("Vres1 destroyed\n");
102         
103         if (fwp_vres_destroy(vres_d2) < 0){
104                 perror("Unable to destroy vres2\n");
105                 return -1;
106         }       
107         printf("Vres2 destroyed\n");
108
109         printf("Test PASSED!\n");
110         return 0;
111 }