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