2 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */
9 #include "xbt/sysdep.h" /* calloc */
11 /* Create a log channel to have nice outputs. */
13 #include "xbt/asserts.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example");
17 int sender(int argc, char *argv[]);
18 int receiver(int argc, char *argv[]);
20 MSG_error_t test_all(const char *platform_file, const char *application_file);
28 double task_comm_size_lat = 10e0;
29 double task_comm_size_bw = 10e8;
31 /** Emitter function */
32 int sender(int argc,char *argv[] )
36 m_task_t task_la=NULL;
37 m_task_t task_bw=NULL;
38 char sprintf_buffer_la[64];
39 char sprintf_buffer_bw[64];
43 host = calloc(1, sizeof(m_host_t));
45 INFO1("host = %s", argv[1]);
47 host = MSG_get_host_by_name(argv[1]);
50 INFO1("Unknown host %s. Stopping Now! ", argv[1]);
55 time= MSG_get_clock();
56 sprintf(sprintf_buffer_la, "latency task");
57 task_la = MSG_task_create(sprintf_buffer_la, 0.0, task_comm_size_lat, NULL);
58 task_la->data = xbt_new(double, 1);
59 *(double *)task_la->data = time;
60 INFO1("task_la = %p", task_la);
61 INFO1("task_la->data = %le", *((double *)task_la->data));
62 MSG_task_put(task_la, host,PORT_22);
66 sprintf(sprintf_buffer_bw, "bandwidth task");
67 task_bw = MSG_task_create(sprintf_buffer_bw, 0.0, task_comm_size_bw, NULL);
68 task_bw->data = xbt_new(double, 1);
69 *(double *)task_bw->data = time;
70 INFO1("task_bw = %p", task_bw);
71 INFO1("task_bw->data = %le", *((double *)task_bw->data) );
72 MSG_task_put(task_bw, host,PORT_22);
77 /** Receiver function */
78 int receiver(int argc, char *argv[])
80 double time, time1, sender_time;
81 m_task_t task_la = NULL;
82 m_task_t task_bw = NULL;
84 double communication_time=0;
88 time = MSG_get_clock();
91 a = MSG_task_get(&task_la,PORT_22);
93 time1=MSG_get_clock();
94 sender_time= *((double*)(task_la->data));
96 communication_time=time1-time;
97 INFO1("Task received : %s", task_la->name);
98 MSG_task_destroy(task_la);
99 INFO1("Communic. time %le",communication_time);
100 INFO1("--- la %f ----",task_comm_size_bw/communication_time);
102 xbt_assert0(0,"Unexpected behavior");
107 a=MSG_task_get(&task_bw,PORT_22);
109 time1=MSG_get_clock();
110 sender_time= *((double*)(task_bw->data));
112 communication_time=time1-time;
113 INFO1("Task received : %s", task_bw->name);
114 MSG_task_destroy(task_bw);
115 INFO1("Communic. time %le",communication_time);
116 INFO1("--- bw %f ----",task_comm_size_bw/communication_time);
118 xbt_assert0(0,"Unexpected behavior");
123 }/* end_of_receiver */
127 MSG_error_t test_all(const char *platform_file,
128 const char *application_file)
131 MSG_error_t res = MSG_OK;
135 /* Simulation setting */
136 MSG_set_channel_number(MAX_CHANNEL);
137 MSG_paje_output("msg_test.trace");
138 MSG_create_environment(platform_file);
140 /* Application deployment */
141 MSG_function_register("sender", sender);
142 MSG_function_register("receiver", receiver);
144 MSG_launch_application(application_file);
148 } /* end_of_test_all */
152 int main(int argc, char *argv[])
154 MSG_error_t res = MSG_OK;
157 MSG_global_init(&argc,argv);
161 CRITICAL1 ("Usage: %s platform_file deployment_file <model>\n",argv[0]);
162 CRITICAL1 ("example: %s msg_platform.xml msg_deployment.xml KCCFLN05_Vegas\n",argv[0]);
166 /* Options for the workstation_model:
168 KCCFLN05 => for maxmin
169 KCCFLN05_proportional => for proportional (Vegas)
170 KCCFLN05_Vegas => for TCP Vegas
171 KCCFLN05_Reno => for TCP Reno
173 MSG_config("surf_workstation_model", argv[3]);
175 res = test_all(argv[1],argv[2]);
177 INFO1("Total simulation time: %le", MSG_get_clock());
181 if(res==MSG_OK) return 0;