]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - fwp/lib/fwp/tests/fwp_prototest/fwp_sendrecv_test1.c
d32bd338aaa2ffca50843691f884babe34a7222e
[frescor/fwp.git] / fwp / lib / fwp / 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 #include <arpa/inet.h>
20
21 int main()
22 {
23 //      struct sockaddr_in local_addr, rem_addr, from;
24         ssize_t len;
25         fwp_vres_t *vres1, *vres2;
26         int i;
27         struct fwp_vres_params vparam1, vparam2;
28         char msg1[] = "Hello1";
29         char msg2[] = "Hello2";
30         char buffer[30];
31         fwp_endpoint_t *sepoint1, *sepoint2, *repoint1, *repoint2;
32         fwp_endpoint_attr_t attr;
33         fwp_addr_t from;
34         
35         fwp_endpoint_attr_init(&attr);
36
37         vparam1.ac_id = FWP_AC_VO; 
38         vparam1.budget = 100;
39         vparam1.period.tv_sec = 2; 
40         vparam1.period.tv_nsec = 0; 
41
42         vparam2.ac_id = FWP_AC_BK; 
43         vparam2.budget = 100;
44         vparam2.period.tv_sec = 0;
45         vparam2.period.tv_nsec = 100000;
46
47         printf("Start\n");
48         fwp_init();
49         
50         printf("Create vres1, vres2\n");
51         if (fwp_vres_create(&vparam1, &vres1) < 0) {
52                 printf("Unable to create vres1\n");
53                 return -1;
54         }
55         printf("Vres1 created \n");
56         
57         if (fwp_vres_create(&vparam2, &vres2) < 0){
58                 fprintf(stderr,"Unable to create vres2\n");
59                 return -1;
60         }
61         printf("Vres2 created\n");
62         
63         /* local_addr should be handled when creating socket */
64         if (fwp_receive_endpoint_create(7777, &attr,&repoint1) < 0){
65                 return -1;
66         }
67         printf("Receive endpoint created\n");
68         
69         if (fwp_receive_endpoint_create(7778, &attr,&repoint2) < 0){
70                 return -1;
71         }
72         printf("Receive endpoint created\n");
73         
74         if (fwp_send_endpoint_create(inet_addr("127.0.0.1"), 7777, 0, 
75                                         &sepoint1) < 0) {
76                 return -1;
77         }
78         printf("Send endpoint 1 created\n");
79         fwp_send_endpoint_bind(sepoint1, vres1);
80         
81         if (fwp_send_endpoint_create(inet_addr("127.0.0.1"), 7778, 0, 
82                                         &sepoint2) < 0){
83                 return -1;
84         }
85         printf("Send endpoint 2 created\n");
86         fwp_send_endpoint_bind(sepoint2, vres2);
87         
88         fwp_send(sepoint1, msg1, sizeof(msg1));
89         fwp_send(sepoint1, msg2, sizeof(msg2));
90
91         for (i = 0; i < 2; i++) {
92                 if ((len = fwp_recv(repoint1, buffer, sizeof(buffer), &from, 
93                         0)) < 0) {
94                         perror("Error while receiving data");
95                         return -1;
96                 } 
97                         else printf("Received - %s\n", buffer);
98         }
99
100         if (fwp_vres_destroy(vres1) < 0) {
101                 perror("Unable to destroy vres1\n");
102                 return -1;
103         }
104         printf("Vres1 destroyed\n");
105         
106         if (fwp_vres_destroy(vres2) < 0){
107                 perror("Unable to destroy vres2\n");
108                 return -1;
109         }       
110         printf("Vres2 destroyed\n");
111
112         printf("Test PASSED!\n");
113         return 0;
114 }