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;
118 bool opt_daemon = false;
119 char *opt_pidfile = NULL;
120 frsh_rel_time_t zero = fosa_msec_to_rel_time(0);
122 frsh_utilization_set_t utilization_set;
123 utilization_set.size = 3;
124 utilization_set.utilizations[0].period = fosa_msec_to_rel_time(100);
125 WVFRSH(frsh_network_bytes_to_budget(resource_id, 1000, &utilization_set.utilizations[0].budget));
126 utilization_set.utilizations[0].deadline = fosa_msec_to_rel_time(100);
127 utilization_set.utilizations[1].period = fosa_msec_to_rel_time(100);
128 WVFRSH(frsh_network_bytes_to_budget(resource_id, 14000, &utilization_set.utilizations[1].budget));
129 utilization_set.utilizations[1].deadline = fosa_msec_to_rel_time(100);
130 utilization_set.utilizations[2].period = fosa_msec_to_rel_time(100);
131 WVFRSH(frsh_network_bytes_to_budget(resource_id, 35000, &utilization_set.utilizations[2].budget));
132 utilization_set.utilizations[2].deadline = fosa_msec_to_rel_time(100);
135 while ((opt = getopt (argc, argv, "e:d:p:s:m:t:a:")) != -1) {
140 opt_pidfile = optarg;
143 dst_ip = inet_addr(optarg);
149 num_msg = atoi(optarg);
152 msg_size = atoi(optarg);
155 time_period = atoi(optarg);
158 strcpy(mac_addr, optarg);
161 printf("Usage: %s -e -d dst_ip_addr -p port"
162 "-m num_msg -s msg_size -a mac_addr\n",
168 forb_daemon_prepare(opt_pidfile);
171 send_pinfo.body = NULL;
173 WVPASSNE(frsh_send_endpoint_create(resource_id, dst_ip, port, send_pinfo, &sepoint), 0);
175 /* Contract parameters */
176 WVFRSH(frsh_contract_init(&contract));
177 utilization_set.utilizations[0].period = fosa_msec_to_rel_time(time_period);
178 WVFRSH(frsh_contract_set_basic_params(&contract,
179 &utilization_set.utilizations[0].budget,
180 &utilization_set.utilizations[0].period,
183 WVFRSH(frsh_contract_set_resource_and_label(&contract,FRSH_RT_NETWORK,
184 resource_id, "net_cont"));
186 /* Add fwp block with MAC address */
187 fres_block_fwp *fwp_block;
188 WVPASS((fwp_block = (fres_block_fwp*)malloc(sizeof(fres_block_fwp))) != NULL);
189 fwp_block->mac_address = mac_addr_string_to_number(mac_addr);
191 WVPASS(fres_contract_add_block(contract, FRES_BLOCK_FWP, fwp_block) == 0);
193 WVFRSH(frsh_contract_set_reclamation_params(&contract,
195 &utilization_set.utilizations[utilization_set.size-1].budget,
196 &utilization_set.utilizations[utilization_set.size-1].period,
202 WVFRSH(frsh_contract_negotiate(&contract, &vres));
203 WVFRSH(frsh_send_endpoint_bind(vres, sepoint));
209 while (count != num_msg) {
211 WVPASS(frsh_vres_get_budget_and_period (vres, &budget, &period) == 0);
212 WVFRSH(frsh_network_budget_to_bytes(resource_id, &budget, &msg_size));
213 ul_logmsg("Message %d with size %d\n", count, msg_size);
215 msg = prepare_msg(msg_size);
217 WVPASSEQ(frsh_send_sync(sepoint, msg, msg_size), msg_size);
220 frsh_contract_cancel(vres);
221 frsh_contract_destroy((struct fres_contract **)contract);
222 ul_logmsg("Test finished\n");