From c8267424e22a35ab6ff715865c3901baa79350a8 Mon Sep 17 00:00:00 2001 From: Tuka Martin Date: Tue, 20 Mar 2012 22:46:30 +0100 Subject: [PATCH] fwp: adaptive test updated Removed deamonization from fake_wifi_agent Added deamonization to receiver and sender Used send_sync function for better synchronization with receiver --- src/fwp/fwp/demo/fake_wifi_agent.c | 11 ----------- src/fwp/fwp/demo/receiver.c | 16 +++++++++++++--- src/fwp/fwp/demo/sender.c | 19 ++++++++++++------- src/fwp/fwp/demo/sender_adaptive.c | 26 ++++++++++++++------------ 4 files changed, 39 insertions(+), 33 deletions(-) diff --git a/src/fwp/fwp/demo/fake_wifi_agent.c b/src/fwp/fwp/demo/fake_wifi_agent.c index 90f36e28..ee78fbb4 100644 --- a/src/fwp/fwp/demo/fake_wifi_agent.c +++ b/src/fwp/fwp/demo/fake_wifi_agent.c @@ -60,23 +60,15 @@ int main(int argc, char **argv) forb_orb fwp_orb; wifi_agent_idl wai; CORBA_Environment env; - int rate; char mac_addr[20]; int opt; - bool opt_daemon = false; - char *opt_pidfile = NULL; rate = 1; - opterr = 0; while ((opt = getopt (argc, argv, "d:a:r:")) != -1) { switch (opt) { - case 'd': - opt_daemon = true; - opt_pidfile = optarg; - break; case 'a': strcpy(mac_addr, optarg); break; @@ -89,9 +81,6 @@ int main(int argc, char **argv) } } - if (opt_daemon) - forb_daemon_prepare(opt_pidfile); - fwp_orb = forb_init(&argc, &argv, NULL); /* FORB initialization */ /* Find our implementation */ diff --git a/src/fwp/fwp/demo/receiver.c b/src/fwp/fwp/demo/receiver.c index 11ddbbe7..5c190632 100644 --- a/src/fwp/fwp/demo/receiver.c +++ b/src/fwp/fwp/demo/receiver.c @@ -13,6 +13,7 @@ #include #include #include +#include char msg[MSGBUFFSIZE]; @@ -58,22 +59,31 @@ int main(int argc, char* argv[]) int opt; opterr = 0; - while ((opt = getopt (argc, argv, "p:m:")) != -1) { + bool opt_daemon = false; + char *opt_pidfile = NULL; + + while ((opt = getopt (argc, argv, "e:p:m:")) != -1) { switch (opt) { + case 'e': + opt_daemon = true; + opt_pidfile = optarg; + break; case 'p': stream_id = atoi(optarg); break; case 'm': num_msg = atoi(optarg); case '?': - printf("Usage: %s -p stream_id -m num_msg\n", + printf("Usage: %s -e -p stream_id -m num_msg\n", argv[0]); } } + + if (opt_daemon) + forb_daemon_prepare(opt_pidfile); WVFRSH(frsh_init()); - WVPASSEQ(pthread_attr_init(&thattr), 0); WVPASSEQ(pthread_create(&thread, &thattr, receiver, NULL), 0); WVPASSEQ(pthread_join(thread, (void**) NULL), 0); diff --git a/src/fwp/fwp/demo/sender.c b/src/fwp/fwp/demo/sender.c index c6bf975e..876b8429 100644 --- a/src/fwp/fwp/demo/sender.c +++ b/src/fwp/fwp/demo/sender.c @@ -39,10 +39,17 @@ int main(int argc, char* argv[]) frsh_rel_time_t budget, period; int count; + bool opt_daemon = false; + char *opt_pidfile = NULL; + opterr = 0; - while ((opt = getopt (argc, argv, "d:p:s:m:t:")) != -1) { + while ((opt = getopt (argc, argv, "e:d:p:s:m:t:")) != -1) { switch (opt) { + case 'e': + opt_daemon = true; + opt_pidfile = optarg; + break; case 'd': dst_ip = inet_addr(optarg); break; @@ -64,15 +71,15 @@ int main(int argc, char* argv[]) } } - WVFRSH(frsh_init()); + if (opt_daemon) + forb_daemon_prepare(opt_pidfile); + WVFRSH(frsh_init()); send_pinfo.body = NULL; - WVPASSNE(frsh_send_endpoint_create(resource_id, dst_ip, port, send_pinfo, &sepoint), 0); /* Contract negotiation */ WVFRSH(frsh_contract_init(&contract)); - WVFRSH(frsh_network_bytes_to_budget(resource_id, msg_size, &budget)); period = fosa_msec_to_rel_time(time_period); WVFRSH(frsh_contract_set_basic_params(&contract, @@ -87,10 +94,8 @@ int main(int argc, char* argv[]) count = 0; while (count != num_msg) { - // TODO: Synchronize with receiver - sleep(1); count++; - WVPASSEQ(frsh_send_async(sepoint, msg, msg_size), msg_size); + WVPASSEQ(frsh_send_sync(sepoint, msg, msg_size), msg_size); } /* TODO: destroy vres and send enpoint */ diff --git a/src/fwp/fwp/demo/sender_adaptive.c b/src/fwp/fwp/demo/sender_adaptive.c index 9b23aa80..50b6092a 100644 --- a/src/fwp/fwp/demo/sender_adaptive.c +++ b/src/fwp/fwp/demo/sender_adaptive.c @@ -81,7 +81,7 @@ long long mac_addr_string_to_number(char * mac) int main(int argc, char* argv[]) { - char *msg; + char msg[MSGBUFFSIZE]; frsh_resource_id_t resource_id = TEST_RESOURCE_ID; frsh_stream_id_t port = TEST_STREAM_ID; @@ -101,10 +101,17 @@ int main(int argc, char* argv[]) struct fwp_vres_params vparam; + bool opt_daemon = false; + char *opt_pidfile = NULL; + opterr = 0; - while ((opt = getopt (argc, argv, "d:p:s:m:t:a:")) != -1) { + while ((opt = getopt (argc, argv, "e:d:p:s:m:t:a:")) != -1) { switch (opt) { + case 'e': + opt_daemon = true; + opt_pidfile = optarg; + break; case 'd': dst_ip = inet_addr(optarg); break; @@ -130,15 +137,15 @@ int main(int argc, char* argv[]) } } - WVFRSH(frsh_init()); + if (opt_daemon) + forb_daemon_prepare(opt_pidfile); + WVFRSH(frsh_init()); send_pinfo.body = NULL; - WVPASSNE(frsh_send_endpoint_create(resource_id, dst_ip, port, send_pinfo, &sepoint), 0); - /* Contract negotiation */ + /* Contract parameters */ WVFRSH(frsh_contract_init(&contract)); - WVFRSH(frsh_network_bytes_to_budget(resource_id, msg_size, &budget)); period = fosa_msec_to_rel_time(time_period); WVFRSH(frsh_contract_set_basic_params(&contract, @@ -168,20 +175,15 @@ int main(int argc, char* argv[]) vparam.period.tv_sec = 0; vparam.period.tv_nsec = time_period*1000*1000; WVPASS(fwp_vres_create(&vparam, (fwp_vres_t**)&vres) == 0); - WVFRSH(frsh_contract_negotiate(&contract, &vres)); WVFRSH(frsh_send_endpoint_bind(vres, sepoint)); count = 0; while (count != num_msg) { - // TODO: If possible, synchronize with receiver - sleep(1); count++; - WVPASS(frsh_vres_get_budget_and_period (vres, &budget, &period) == 0); WVFRSH(frsh_network_budget_to_bytes(resource_id, &budget, &msg_size)); - WVPASS((msg = (char*)malloc((int)msg_size * sizeof(char))) != NULL); - WVPASSEQ(frsh_send_async(sepoint, msg, sizeof(msg)), sizeof(msg)); + WVPASSEQ(frsh_send_sync(sepoint, msg, msg_size), msg_size); } /* TODO: destroy vres and send enpoint */ -- 2.39.2