]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - fwp/tests/fwp_prototest/fwp_sendrecv_test1.c
4b9e07c8f5fcbbedd6b2dbb51e252690989059e4
[frescor/fwp.git] / fwp / tests / fwp_prototest / fwp_sendrecv_test1.c
1 #define CONFIGURE_FWP_MNGT 0
2 #include "fwp_confdefs.h"
3 #include "fwp.h"
4
5 #include <errno.h>
6 #include <stdio.h>
7
8 int main()
9 {
10 //      struct sockaddr_in local_addr, rem_addr, from;
11         ssize_t len;
12         fwp_vres_d_t vres_d1, vres_d2;
13         int i;
14         struct fwp_vres_params vparam1, vparam2;
15         char msg1[] = "Hello1";
16         char msg2[] = "Hello2";
17         char buffer[30];
18         fwp_endpoint_d_t sepoint_d1, sepoint_d2, repoint_d1, repoint_d2;
19         fwp_endpoint_attr_t attr;
20         
21         fwp_endpoint_attr_init(&attr);
22
23         vparam1.ac_id = FWP_AC_VO; 
24         vparam1.budget = 100;
25         vparam1.period_usec = 2000000; 
26
27         vparam2.ac_id = FWP_AC_BK; 
28         vparam2.budget = 100;
29         vparam2.period_usec = 100;
30
31         printf("Start\n");
32         fwp_init();
33         
34         printf("Create vres1, vres2\n");
35         if (fwp_vres_create(&vparam1, &vres_d1) < 0) {
36                 printf("Unable to create vres1\n");
37                 return -1;
38         }
39         printf("Vres1 created \n");
40         
41         if (fwp_vres_create(&vparam2, &vres_d2) < 0){
42                 fprintf(stderr,"Unable to create vres2\n");
43                 return -1;
44         }
45         printf("Vres2 created\n");
46         
47         /* local_addr should be handled when creating socket */
48         if (fwp_receive_endpoint_create(7777, &attr,&repoint_d1) < 0){
49                 return -1;
50         }
51         printf("Receive endpoint created\n");
52         
53         if (fwp_receive_endpoint_create(7778, &attr,&repoint_d2) < 0){
54                 return -1;
55         }
56         printf("Receive endpoint created\n");
57         
58         if (fwp_send_endpoint_create(inet_addr("127.0.0.1"), 7777, 0, 
59                                         &sepoint_d1) < 0) {
60                 return -1;
61         }
62         printf("Send endpoint 1 created\n");
63         fwp_send_endpoint_bind(sepoint_d1, vres_d1);
64         
65         if (fwp_send_endpoint_create(inet_addr("127.0.0.1"), 7778, 0, 
66                                         &sepoint_d2) < 0){
67                 return -1;
68         }
69         printf("Send endpoint 2 created\n");
70         fwp_send_endpoint_bind(sepoint_d2, vres_d2);
71         
72         fwp_send(sepoint_d1, msg1, sizeof(msg1), 0);
73         fwp_send(sepoint_d1, msg2, sizeof(msg2), 0);
74
75         for (i = 0; i < 2; i++) {
76                 if ((len = fwp_recv(repoint_d1, buffer, sizeof(buffer), 0)) < 0) {
77                         perror("Error while receiving data");
78                         return -1;
79                 } 
80                         else printf("Received - %s\n", buffer);
81         }
82
83         if (fwp_vres_destroy(vres_d1) < 0) {
84                 perror("Unable to destroy vres1\n");
85                 return -1;
86         }
87         printf("Vres1 destroyed\n");
88         
89         if (fwp_vres_destroy(vres_d2) < 0){
90                 perror("Unable to destroy vres2\n");
91                 return -1;
92         }       
93         printf("Vres2 destroyed\n");
94
95         printf("Test PASSED!\n");
96         return 0;
97 }