]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/blob - src/fwp/fwp/demo/sender.c
fwp transmit/receive test update
[frescor/frsh-forb.git] / src / fwp / fwp / demo / sender.c
1 /**
2  * \file fwpsender.c
3  *
4  */
5 #include <frsh.h>
6 #include "test_config.h"
7
8 #include <errno.h>
9 #include <stdio.h>
10 #include <pthread.h>
11
12 #include <sys/socket.h>
13 #include <netinet/in.h>
14 #include <arpa/inet.h>
15
16 #include <wvtest.h>
17 #include "fwp_confdefs.h"
18 #include <fres_sa_scenario.h>
19 #include <fwp_res.h>
20 #include <fwp_vres.h>
21
22 int main(int argc, char* argv[])
23 {
24         char msg[MSGBUFFSIZE];
25
26         frsh_resource_id_t resource_id = TEST_RESOURCE_ID;
27         frsh_stream_id_t port = TEST_STREAM_ID;
28         long int num_msg = TEST_NUM_MSG;
29         size_t msg_size = MSGBUFFSIZE;
30         int time_period = 1000;
31         int dst_ip = 0;
32
33         bool opt_daemon = false;
34         char *opt_pidfile = NULL;
35
36         int opt;
37         frsh_send_endpoint_t sepoint;
38         frsh_vres_id_t vres;
39         frsh_send_endpoint_protocol_info_t send_pinfo;
40         frsh_contract_t contract;
41         frsh_rel_time_t budget, period;
42         int count;
43
44         opterr = 0;
45         while ((opt = getopt (argc, argv, "e:d:p:s:m:t:")) != -1) {
46
47                 switch (opt) {
48                         case 'e':
49                                 opt_daemon = true;
50                                 opt_pidfile = optarg;
51                                 break;
52                         case 'd':
53                                 dst_ip = inet_addr(optarg);
54                                 break;
55                         case 'p':
56                                 port = atoi(optarg);
57                                 break;
58                         case 'm':
59                                 num_msg = atoi(optarg);
60                                 break;
61                         case 's':
62                                 msg_size = atoi(optarg);
63                                 break;
64                         case 't':
65                                 time_period = atoi(optarg);
66                         case '?':
67                                 printf("Usage: %s -e -d dst_ip_addr -p port"
68                                                 "-m num_msg -s msg_size\n",
69                                                 argv[0]);
70                 }
71         }
72
73         if (opt_daemon)
74                 forb_daemon_prepare(opt_pidfile);
75
76         WVFRSH(frsh_init());
77
78         send_pinfo.body = NULL;
79         
80         //TODO: What's the return value?        
81         if (frsh_send_endpoint_create(resource_id, dst_ip, port,
82                                         send_pinfo, &sepoint)< 0) {
83                 return 1;
84         }
85
86         /* Contract negotiation */
87         WVFRSH(frsh_contract_init(&contract));
88
89         WVFRSH(frsh_network_bytes_to_budget(resource_id, msg_size, &budget));
90         period = fosa_msec_to_rel_time(time_period);
91         WVFRSH(frsh_contract_set_basic_params(&contract,
92                                              &budget,
93                                              &period,
94                                              FRSH_WT_BOUNDED,
95                                              FRSH_CT_REGULAR));
96         WVFRSH(frsh_contract_set_resource_and_label(&contract,FRSH_RT_NETWORK,
97                                                 resource_id, "net_cont1"));
98         WVFRSH(frsh_contract_negotiate(&contract, &vres));
99
100         printf("Send endpoint created\n");
101         WVFRSH(frsh_send_endpoint_bind(vres, sepoint));
102         printf("Send endpoint bounded\n");
103
104         count = 0;
105         while (count != num_msg) {
106                 // TODO: Synchronize with receiver
107                 sleep(1);
108                 count++;
109                 sprintf(msg,"msg%d",count);
110                 WVPASSEQ(frsh_send_async(sepoint, msg, msg_size), msg_size);
111                 printf("%s sent\n",msg);
112         }
113
114         /* TODO: destroy vres and send enpoint */
115
116         printf("Test PASSED!\n");
117         return 0;
118 }
119