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