2 * \file sender_adaptive.c
3 * sends data according to the actual budget and period
7 #include "test_config.h"
13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <arpa/inet.h>
18 #include "fwp_confdefs.h"
19 #include <fres_sa_scenario.h>
24 * Mac address conversion functions
27 * Char to number conversion
31 if( (a >= '0') && (a <= '9') )
33 else if ( (a >= 'A') && (a <= 'F') )
35 else if ( (a >= 'a') && (a <= 'f') )
41 * Mac addres char to number conversion
42 * @param mac mac address in string format
44 * @return Mac address in long long format
46 long long mac_addr_string_to_number(char * mac)
64 mac_num[10] = mac[15];
65 mac_num[11] = mac[16];
69 for(ix = 0; ix <= 12 ; ix++)
72 for(ix2 = 1; ix2 < 12 - ix; ix2++)
74 number += atoint(mac_num[ix]) * help;
78 printf("%llu \n", number);
82 int main(int argc, char* argv[])
84 char msg[MSGBUFFSIZE];
86 frsh_resource_id_t resource_id = TEST_RESOURCE_ID;
87 frsh_stream_id_t port = TEST_STREAM_ID;
88 long int num_msg = TEST_NUM_MSG;
89 size_t msg_size = MSGBUFFSIZE;
90 int time_period = 1000;
95 frsh_send_endpoint_t sepoint;
97 frsh_send_endpoint_protocol_info_t send_pinfo;
98 frsh_contract_t contract;
99 frsh_rel_time_t budget, period;
102 struct fwp_vres_params vparam;
104 bool opt_daemon = false;
105 char *opt_pidfile = NULL;
108 while ((opt = getopt (argc, argv, "e:d:p:s:m:t:a:")) != -1) {
113 opt_pidfile = optarg;
116 dst_ip = inet_addr(optarg);
122 num_msg = atoi(optarg);
125 msg_size = atoi(optarg);
128 time_period = atoi(optarg);
131 strcpy(mac_addr, optarg);
134 printf("Usage: %s -e -d dst_ip_addr -p port"
135 "-m num_msg -s msg_size -a mac_addr\n",
141 forb_daemon_prepare(opt_pidfile);
144 send_pinfo.body = NULL;
145 WVPASSNE(frsh_send_endpoint_create(resource_id, dst_ip, port, send_pinfo, &sepoint), 0);
147 /* Contract parameters */
148 WVFRSH(frsh_contract_init(&contract));
149 WVFRSH(frsh_network_bytes_to_budget(resource_id, msg_size, &budget));
150 period = fosa_msec_to_rel_time(time_period);
151 WVFRSH(frsh_contract_set_basic_params(&contract,
156 WVFRSH(frsh_contract_set_resource_and_label(&contract,FRSH_RT_NETWORK,
157 resource_id, "net_cont"));
159 /* Add fwp block with MAC address */
160 fres_block_fwp *fwp_block;
161 WVPASS((fwp_block = (fres_block_fwp*)malloc(sizeof(fres_block_fwp))) != NULL);
162 fwp_block->mac_address = mac_addr_string_to_number(mac_addr);
163 WVPASS(fres_contract_add_block(contract, FRES_BLOCK_FWP, fwp_block) == 0);
165 /* Add spare capacity block */
166 fres_block_spare_capacity *s;
167 WVPASS((s = malloc(sizeof(*s))) != NULL);
168 s->budget = (fosa_rel_time_t)budget;
169 s->period = (fosa_rel_time_t)period;
170 WVPASS(fres_contract_add_spare_capacity(contract, s) == 0);
172 /* Create virtual resource */
173 vparam.ac_id = FWP_AC_VO;
174 vparam.budget = msg_size;
175 vparam.period.tv_sec = 0;
176 vparam.period.tv_nsec = time_period*1000*1000;
177 WVPASS(fwp_vres_create(&vparam, (fwp_vres_t**)&vres) == 0);
178 WVFRSH(frsh_contract_negotiate(&contract, &vres));
179 WVFRSH(frsh_send_endpoint_bind(vres, sepoint));
182 while (count != num_msg) {
184 WVPASS(frsh_vres_get_budget_and_period (vres, &budget, &period) == 0);
185 WVFRSH(frsh_network_budget_to_bytes(resource_id, &budget, &msg_size));
186 WVPASSEQ(frsh_send_sync(sepoint, msg, msg_size), msg_size);
189 /* TODO: destroy vres and send enpoint */
191 printf("Test PASSED!\n");