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