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 char * prepare_msg(int size) {
84 char * ret = (char*)malloc(size*sizeof(char));
85 for(i=0; i<size; i++) {
86 ret[i] = '0'; //just insert some characters
91 int main(int argc, char* argv[])
95 frsh_resource_id_t resource_id = TEST_RESOURCE_ID;
96 frsh_stream_id_t port = TEST_STREAM_ID;
97 long int num_msg = TEST_NUM_MSG;
98 size_t msg_size = MSGBUFFSIZE;
99 int time_period = 100;
104 frsh_send_endpoint_t sepoint;
106 frsh_send_endpoint_protocol_info_t send_pinfo;
107 frsh_contract_t contract;
108 frsh_rel_time_t budget, period;
111 bool opt_daemon = false;
112 char *opt_pidfile = NULL;
113 frsh_rel_time_t zero = fosa_msec_to_rel_time(0);
115 frsh_utilization_set_t utilization_set;
116 utilization_set.size = 3;
117 utilization_set.utilizations[1].period = fosa_msec_to_rel_time(100);
118 WVFRSH(frsh_network_bytes_to_budget(resource_id, 3000, &utilization_set.utilizations[1].budget));
119 utilization_set.utilizations[1].deadline = fosa_msec_to_rel_time(100);
120 utilization_set.utilizations[2].period = fosa_msec_to_rel_time(100);
121 WVFRSH(frsh_network_bytes_to_budget(resource_id, 14000, &utilization_set.utilizations[2].budget));
122 utilization_set.utilizations[2].deadline = fosa_msec_to_rel_time(100);
125 while ((opt = getopt (argc, argv, "e:d:p:s:m:t:a:")) != -1) {
130 opt_pidfile = optarg;
133 dst_ip = inet_addr(optarg);
139 num_msg = atoi(optarg);
142 msg_size = atoi(optarg);
145 time_period = atoi(optarg);
148 strcpy(mac_addr, optarg);
151 printf("Usage: %s -e -d dst_ip_addr -p port"
152 "-m num_msg -s msg_size -a mac_addr\n",
158 forb_daemon_prepare(opt_pidfile);
161 send_pinfo.body = NULL;
162 WVPASSNE(frsh_send_endpoint_create(resource_id, dst_ip, port, send_pinfo, &sepoint), 0);
164 /* Contract parameters */
165 WVFRSH(frsh_contract_init(&contract));
166 WVFRSH(frsh_network_bytes_to_budget(resource_id, msg_size, &utilization_set.utilizations[0].budget));
167 utilization_set.utilizations[0].period = fosa_msec_to_rel_time(time_period);
168 WVFRSH(frsh_contract_set_basic_params(&contract,
169 &utilization_set.utilizations[0].budget,
170 &utilization_set.utilizations[0].period,
173 WVFRSH(frsh_contract_set_resource_and_label(&contract,FRSH_RT_NETWORK,
174 resource_id, "net_cont"));
176 /* Add fwp block with MAC address */
177 fres_block_fwp *fwp_block;
178 WVPASS((fwp_block = (fres_block_fwp*)malloc(sizeof(fres_block_fwp))) != NULL);
179 fwp_block->mac_address = mac_addr_string_to_number(mac_addr);
181 WVPASS(fres_contract_add_block(contract, FRES_BLOCK_FWP, fwp_block) == 0);
183 /* Add spare capacity block */
184 //TODO: Delete extra spare capacity block initialization, since spare capacity is initialized in set_reclamation_params function
185 //fres_block_spare_capacity *s;
186 //WVPASS((s = malloc(sizeof(*s))) != NULL);
187 //s->budget = (fosa_rel_time_t)budget;
188 //s->budget = (fosa_rel_time_t)utilization_set.utilizations[0].budget;
189 //s->period = (fosa_rel_time_t)utilization_set.utilizations[0].period;
190 //WVPASS(fres_contract_add_spare_capacity(contract, s) == 0);
192 WVFRSH(frsh_contract_set_reclamation_params(&contract,
194 &utilization_set.utilizations[utilization_set.size-1].budget,
195 &utilization_set.utilizations[utilization_set.size-1].period,
201 WVFRSH(frsh_contract_negotiate(&contract, &vres));
202 WVFRSH(frsh_send_endpoint_bind(vres, sepoint));
208 while (count != num_msg) {
210 WVPASS(frsh_vres_get_budget_and_period (vres, &budget, &period) == 0);
211 WVFRSH(frsh_network_budget_to_bytes(resource_id, &budget, &msg_size));
213 //TODO: Delete printf below
214 printf("msg_size....%d\n", msg_size);
215 printf("count....%d\n", count);
217 msg = prepare_msg(msg_size);
218 WVPASSEQ(frsh_send_sync(sepoint, msg, msg_size), msg_size);
221 frsh_contract_cancel(vres);
222 frsh_contract_destroy((struct fres_contract **)contract);
223 printf("Test PASSED!\n");