]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - fwp/tests/fwp_mngrtest/fwp_mngrtest.c
FWP tests got to the functional state
[frescor/fwp.git] / fwp / tests / fwp_mngrtest / fwp_mngrtest.c
1 #define CONFIGURE_FWP_MNGR_ADDR "127.0.0.1"
2 #include "fwp_confdefs.h"
3 #include "fwp.h"
4
5 #include <errno.h>
6 #include <stdio.h>
7
8 fwp_endpoint_attr_t  attr;
9
10 void* receiver(void *arg)
11 {
12         fwp_endpoint_d_t repoint_d1;
13         int i,len;
14         char buffer[30];
15
16         FWP_DEBUG("Creating receive endpoint\n");
17         if (fwp_receive_endpoint_create(7777, &attr,&repoint_d1) < 0){
18                 perror("Error while creating receive endpoint\n");
19                 return NULL;
20         }
21                 
22         FWP_DEBUG("Receive endpoint created \n");
23         for (i = 0; i < 3; i++) {
24                 if ((len = fwp_recv(repoint_d1, buffer, sizeof(buffer), 0)) < 0) {
25                         perror("Error while receiving data::");
26                         return NULL;
27                 } else {
28                         printf("Received %s\n",buffer);
29                         //for (j = 0 ; j < 10; i++)
30                         //      printf("%c", buffer[i]);
31
32                 }
33                 printf("END\n");
34         }
35
36         return NULL;
37 }
38
39 int main()
40 {
41         int i,rc,len; 
42         fwp_vres_d_t vres_d1, vres_d2, vres_d3;
43         fwp_contract_d_t cnt1d, cnt2d, cnt3d;
44         fwp_endpoint_d_t sepoint_d1, sepoint_d2, repoint_d1, repoint_d2;
45         char msg1[] = "Hello1";
46         char msg2[] = "Hello2";
47         fwp_contract_t cnt1;
48         fwp_contract_t cnt2;
49         fwp_contract_t cnt3;
50         pthread_t       id;
51         struct fwp_vres_params vparam1;
52         
53         cnt1.budget = 100;
54         cnt1.period_usec = 10000;
55
56         cnt2.budget = 120;
57         cnt2.period_usec = 1000;
58
59         cnt3.budget = 130;
60         cnt3.period_usec = 2000;
61         
62         printf("Start\n");
63         if (fwp_init() != 0) {
64                 printf("fwp_init failed!\n");
65                 return -1;
66         }       
67         
68         fwp_endpoint_attr_init(&attr);
69         fwp_endpoint_attr_setreliability(&attr, FWP_EPOINT_RELIABLE);
70         pthread_create(&id, NULL, &receiver, (void*) NULL);
71         
72         cnt1d = fwp_contract_create(&cnt1);
73         fwp_contract_negotiate(cnt1d, &vres_d1);
74         if (fwp_contract_is_negotiated(cnt1d)) {
75                 printf("Contract1 negotiated.\n");
76         }else 
77                 printf("Contract1 not negotiated.\n");
78
79 /*      cnt2d = fwp_contract_create(&cnt2);
80         fwp_contract_negotiate(cnt2d, &vres_d2);
81         if (fwp_contract_is_negotiated(cnt2d)) {
82                 printf("Contract2 negotiated.\n");
83         }else 
84                 printf("Contract2 not negotiated.\n");
85         
86         cnt3d = fwp_contract_create(&cnt3);
87         fwp_contract_negotiate(cnt3d, &vres_d3);
88         if (fwp_contract_is_negotiated(cnt3d)) {
89                 printf("Contract3 negotiated.\n");
90         }else 
91                 printf("Contract3 not negotiated.\n");
92 */      
93         if (fwp_send_endpoint_create(inet_addr("127.0.0.1"), 7777, 
94                 &attr, &sepoint_d1) < 0) {
95                 return -1;
96         }
97         printf("Send endpoint 1 created\n");
98         
99         fwp_send_endpoint_bind(sepoint_d1, vres_d1);
100
101         fwp_send(sepoint_d1, msg1, sizeof(msg1), 0);
102         printf("Sent msg 1\n");
103         fwp_send(sepoint_d1, msg2, sizeof(msg2), 0);
104         printf("Sent msg 2\n");
105
106
107         printf("Test PASSED!\n");
108         
109         scanf("Press key");     
110
111         return 0;
112 }