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 #include <ul_logreg.h>
26 UL_LOG_CUST(ulogd_sender_adaptive);
27 ul_log_domain_t ulogd_sender_adaptive = {UL_LOGL_MSG, "sender_adaptive"};
28 UL_LOGREG_SINGLE_DOMAIN_INIT_FUNCTION(sender_adaptive_logreg_domains, ulogd_sender_adaptive);
31 * Mac address conversion functions
34 * Char to number conversion
38 if( (a >= '0') && (a <= '9') )
40 else if ( (a >= 'A') && (a <= 'F') )
42 else if ( (a >= 'a') && (a <= 'f') )
48 * Mac addres char to number conversion
49 * @param mac mac address in string format
51 * @return Mac address in long long format
53 long long mac_addr_string_to_number(char * mac)
71 mac_num[10] = mac[15];
72 mac_num[11] = mac[16];
76 for(ix = 0; ix <= 12 ; ix++)
79 for(ix2 = 1; ix2 < 12 - ix; ix2++)
81 number += atoint(mac_num[ix]) * help;
85 ul_logmsg("MAC address in decimal %llu\n", number);
89 char * prepare_msg(int size) {
91 char * ret = (char*)malloc(size*sizeof(char));
92 for(i=0; i<size; i++) {
93 ret[i] = '0'; //just insert some characters to send
98 int main(int argc, char* argv[])
102 frsh_resource_id_t resource_id = TEST_RESOURCE_ID;
103 frsh_stream_id_t port = TEST_STREAM_ID;
104 long int num_msg = TEST_NUM_MSG;
105 size_t msg_size = MSGBUFFSIZE;
106 int time_period = 100;
111 frsh_send_endpoint_t sepoint;
113 frsh_send_endpoint_protocol_info_t send_pinfo;
114 frsh_contract_t contract;
115 frsh_rel_time_t budget, period;
119 bool opt_daemon = false;
120 char *opt_pidfile = NULL;
121 frsh_rel_time_t zero = fosa_msec_to_rel_time(0);
123 frsh_utilization_set_t utilization_set;
124 utilization_set.size = 3;
125 utilization_set.utilizations[0].period = fosa_msec_to_rel_time(100);
126 WVFRSH(frsh_network_bytes_to_budget(resource_id, 1000, &utilization_set.utilizations[0].budget));
127 utilization_set.utilizations[0].deadline = fosa_msec_to_rel_time(100);
128 utilization_set.utilizations[1].period = fosa_msec_to_rel_time(100);
129 WVFRSH(frsh_network_bytes_to_budget(resource_id, 14000, &utilization_set.utilizations[1].budget));
130 utilization_set.utilizations[1].deadline = fosa_msec_to_rel_time(100);
131 utilization_set.utilizations[2].period = fosa_msec_to_rel_time(100);
132 WVFRSH(frsh_network_bytes_to_budget(resource_id, 35000, &utilization_set.utilizations[2].budget));
133 utilization_set.utilizations[2].deadline = fosa_msec_to_rel_time(100);
136 while ((opt = getopt (argc, argv, "i:e:d:p:s:m:t:a:")) != -1) {
144 opt_pidfile = optarg;
147 dst_ip = inet_addr(optarg);
153 num_msg = atoi(optarg);
156 msg_size = atoi(optarg);
159 time_period = atoi(optarg);
162 strcpy(mac_addr, optarg);
165 printf("Usage: %s -i id -e -d dst_ip_addr -p port"
166 "-m num_msg -s msg_size -a mac_addr\n",
172 forb_daemon_prepare(opt_pidfile);
175 send_pinfo.body = NULL;
177 WVPASSNE(frsh_send_endpoint_create(resource_id, dst_ip, port, send_pinfo, &sepoint), 0);
179 /* Contract parameters */
180 WVFRSH(frsh_contract_init(&contract));
181 utilization_set.utilizations[0].period = fosa_msec_to_rel_time(time_period);
182 WVFRSH(frsh_contract_set_basic_params(&contract,
183 &utilization_set.utilizations[0].budget,
184 &utilization_set.utilizations[0].period,
187 WVFRSH(frsh_contract_set_resource_and_label(&contract,FRSH_RT_NETWORK,
188 resource_id, "net_cont"));
190 /* Add fwp block with MAC address */
191 fres_block_fwp *fwp_block;
192 WVPASS((fwp_block = (fres_block_fwp*)malloc(sizeof(fres_block_fwp))) != NULL);
193 fwp_block->mac_address = mac_addr_string_to_number(mac_addr);
195 WVPASS(fres_contract_add_block(contract, FRES_BLOCK_FWP, fwp_block) == 0);
197 WVFRSH(frsh_contract_set_reclamation_params(&contract,
199 &utilization_set.utilizations[utilization_set.size-1].budget,
200 &utilization_set.utilizations[utilization_set.size-1].period,
206 WVFRSH(frsh_contract_negotiate(&contract, &vres));
207 WVFRSH(frsh_send_endpoint_bind(vres, sepoint));
213 while (count != num_msg) {
215 WVPASS(frsh_vres_get_budget_and_period (vres, &budget, &period) == 0);
216 WVFRSH(frsh_network_budget_to_bytes(resource_id, &budget, &msg_size));
217 ul_logmsg("Station ID %d: Message %d with size: %d\n", id, count, msg_size);
219 msg = prepare_msg(msg_size);
221 WVPASSEQ(frsh_send_sync(sepoint, msg, msg_size), msg_size);
224 frsh_contract_cancel(vres);
225 frsh_contract_destroy((struct fres_contract **)contract);
226 ul_logmsg("Test finished\n");