* under the terms of the license (GNU LGPL) which comes with this package. */
#include "network_gtnets_private.h"
+#include "gtnets/gtnets_interface.h"
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network_gtnets);
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network_gtnets, surf,
+ "Logging specific to the SURF network module");
/* surf_network_resource_t surf_network_resource = NULL; */
-static xbt_dict_t network_link_set = NULL;
+/*static xbt_dict_t network_link_set = NULL;*/
/* xbt_dict_t network_card_set = NULL; */
#endif
/** QUESTIONS for GTNetS integration
- ** 1. What's the deal with name_service and get_resource_name
- ** Right now our local dictionaries contain only integers
- ** and not structures, but it seems that surf_network_resource->common_public
- ** needs something in it, for the above.
+ ** 1. Check that we did the right thing with name_service and get_resource_name
** 2. Right now there is no "kill flow" in our GTNetS implementation. Do we
** need to do something about this?
- ** 3. We didn't reall do anything with the "action" stuff, which we assume
- ** is fine.
- ** 4. We ignore the fact there is some max_duration on flows (see #2 above)
- ** 5. share_resources() returns a duration, not a date, right?
- ** 6. How do we tell the user that "rates" are not supported?
- ** 7. We don't update "remaining" for ongoing flows. Is it bad?
+ ** 3. We ignore the fact there is some max_duration on flows (see #2 above)
+ ** 4. share_resources() returns a duration, not a date, right?
+ ** 5. We don't suppoer "rates"
+ ** 6. We don't update "remaining" for ongoing flows. Is it bad?
**/
-/* Free memory for a network link: REMOVED BY KF */
+/* Free memory for a network link */
static void network_link_free(void *nw_link)
{
free(((network_link_GTNETS_t)nw_link)->name);
free(nw_link);
}
-/* Instantiate a new network link: UNMODIFIED BY HC */
+/* Instantiate a new network link */
/* name: some name for the link, from the XML */
-/* bw_initial: The bandwidth value */
-/* bw_trace: unused here */
-/* lat_initial: The latency value */
-/* lat_trace: not used here */
-/* state_initial: SURF_NETWORK_LINK_ON */
-/* state_trace: not used here */
+/* bw: The bandwidth value */
+/* lat: The latency value */
static void network_link_new(char *name,
double bw,
double lat)
*/
/* KF: Add the link to the GTNetS simulation */
- if (GTNetS_add_link(link_count, bw, lat)) {
+ if (gtnets_add_link(link_count, bw, lat)) {
xbt_assert0(0,"Cannot create GTNetS link");
}
/* KF: Insert entry in the dictionary */
gtnets_link = xbt_new0(s_network_link_GTNETS_t,1);
- gtnets_link->name = strcpy(name);
+ gtnets_link->name = name;
gtnets_link->bw_current = bw;
gtnets_link->lat_current = lat;
gtnets_link->id = link_count;
return;
}
-/* free the network card: REMOVED by KF */
+/* free the network card */
static void network_card_free(void *nw_card)
{
free(((network_card_GTNETS_t)nw_card)->name);
static int card_count=-1;
/* KF: Check that we haven't seen the network card before */
- if (xbt_dict_get_or_null(network_card_set, name))
- return;
+ network_card_GTNETS_t card = xbt_dict_get_or_null(network_card_set, name);
- /* KF: Increment the card counter for GTNetS */
- card_count++;
+ if (!card){
+ /* KF: Increment the card counter for GTNetS */
+ card_count++;
- /* KF: just use the dictionary to map link names to link indices */
- gtnets_network_card = xbt_new0(s_network_card_GTNETS_t,1);
- gtnets_network_card->name = strcpy(name);
- gtnets_network_card->id = card_count;
- xbt_dict_set(network_card_set, name, gtnets_network_card, network_card_free);
+ /* KF: just use the dictionary to map link names to link indices */
+ card = xbt_new0(s_network_card_GTNETS_t,1);
+ card->name = xbt_strdup(name);
+ card->id = card_count;
+ xbt_dict_set(network_card_set, name, card, network_card_free);
+ }
/* KF: just return the GTNetS ID as the SURF ID */
- return card_count;
+ return card->id;
}
/* Instantiate a new route: MODIFY BY KF */
#endif
int i;
int *gtnets_links;
-
+
/* KF: Build the list of gtnets link IDs */
gtnets_links = (int *)calloc(nb_link, sizeof(int));
for (i=0; i<nb_link; i++) {
- gtnets_links[i]=(int)(xbt_dict_get(network_link_set, links[i]))
+ gtnets_links[i]=
+ ((network_link_GTNETS_t)(xbt_dict_get(network_link_set, links[i])))->id;
+ }
+
+ /* KF: Create the GTNets route */
+ if (gtnets_add_route(src_id, dst_id, gtnets_links, nb_link)) {
+ xbt_assert0(0,"Cannot create GTNetS route");
}
+}
+
+/* Instantiate a new route: MODIFY BY KF */
+static void route_onehop_new(int src_id, int dst_id, char **links, int nb_link)
+{
+ int linkid;
+
+ if (nb_link != 1){
+ xbt_assert0(0, "In onehop_new, nb_link should be 1");
+ }
+
+ /* KF: Build the list of gtnets link IDs */
+ linkid =
+ ((network_link_GTNETS_t)(xbt_dict_get(network_link_set, links[0])))->id;
/* KF: Create the GTNets route */
- if (GTNetS_add_route(src_id, dst_id, gtnets_links, nb_link)) {
+ if (gtnets_add_onehop_route(src_id, dst_id, linkid)) {
xbt_assert0(0,"Cannot create GTNetS route");
}
}
/* Print values when no traces are specified */
{
tmgr_trace_t bw_trace;
- tmgr_trace_t state;
+ tmgr_trace_t state_trace;
tmgr_trace_t lat_trace;
surf_parse_get_trace(&bw_trace, A_surfxml_network_link_bandwidth_file);
surf_parse_get_trace(&lat_trace, A_surfxml_network_link_latency_file);
surf_parse_get_trace(&state_trace,A_surfxml_network_link_state_file);
-
+
+ /*TODO Where is WARNING0 defined???*/
+#if 0
if (bw_trace)
WARNING0("The GTNetS network model doesn't support bandwidth state traces");
if (lat_trace)
WARNING0("The GTNetS network model doesn't support latency state traces");
if (state_trace)
WARNING0("The GTNetS network model doesn't support link state traces");
+#endif
}
+
/* KF: remove several arguments to network_link_new */
network_link_new(name, bw, lat);
}
link_name = NULL;
}
+/* KF*/
+static void parse_route_set_routers(void)
+{
+ int id = network_card_new(A_surfxml_router_name);
+
+ /* KF: Create the GTNets router */
+ if (gtnets_add_router(id)) {
+ xbt_assert0(0,"Cannot add GTNetS router");
+ }
+}
+
/* Parses a route element from the XML: UNMODIFIED BY HC */
static void parse_route_elem(void)
{
link_name[(nb_link) - 1] = xbt_strdup(A_surfxml_route_element_name);
}
-/* Create the route: UNMODIFIED BY HC */
+/* Create the route (more than one hops): MODIFIED BY KF */
static void parse_route_set_route(void)
{
- route_new(src_id, dst_id, link_name, nb_link);
+ if (nb_link > 1)
+ route_new(src_id, dst_id, link_name, nb_link);
+}
+
+/* Create the one-hope route: BY KF */
+static void parse_route_set_onehop_route(void)
+{
+ if (nb_link == 1)
+ route_onehop_new(src_id, dst_id, link_name, nb_link);
}
/* Main XML parsing */
surf_parse_close();
/* Figuring out the network cards used */
+ /* KF
+ surf_parse_reset_parser();
+ STag_surfxml_route_fun=parse_route_set_endpoints;
+ surf_parse_open(file);
+ xbt_assert1((!surf_parse()),"Parse error in %s",file);
+ surf_parse_close();
+ */
+
+ /* KF: Figuring out the router (considered as part of
+ network cards) used.*/
+ surf_parse_reset_parser();
+ STag_surfxml_router_fun=parse_route_set_routers;
+ surf_parse_open(file);
+ xbt_assert1((!surf_parse()),"Parse error in %s",file);
+ surf_parse_close();
+
+ /* Building the one-hop routes */
surf_parse_reset_parser();
STag_surfxml_route_fun=parse_route_set_endpoints;
+ ETag_surfxml_route_element_fun=parse_route_elem;
+ ETag_surfxml_route_fun=parse_route_set_onehop_route;
surf_parse_open(file);
xbt_assert1((!surf_parse()),"Parse error in %s",file);
surf_parse_close();
xbt_swag_remove(action, action->state_set);
/* KF: No explicit freeing needed for GTNeTS here */
free(action);
+ return 1;
}
- return 1;
+ return 0;
}
static void action_use(surf_action_t action)
static void action_cancel(surf_action_t action)
{
+ xbt_assert0(0,"Cannot cancel GTNetS flow");
return;
}
static void action_recycle(surf_action_t action)
{
+ xbt_assert0(0,"Cannot recycle GTNetS flow");
return;
}
xbt_swag_t running_actions = surf_network_resource->common_public->states.running_action_set;
#endif
- return GTNetS_get_time_to_next_flow_completion();
+ return gtnets_get_time_to_next_flow_completion();
}
/* delta: by how many time units the simulation must advance */
static void update_actions_state(double now, double delta)
{
+#if 0
surf_action_network_GTNETS_t action = NULL;
surf_action_network_GTNETS_t next_action = NULL;
xbt_swag_t running_actions =
surf_network_resource->common_public->states.running_action_set;
+#endif
- double time_to_next_flow_completion = GTNetS_get_time_to_next_flow_completion();
-
- if (time_to_next_flow_completion < delta) {
- void *metadata;
- surf_action_t action;
+ double time_to_next_flow_completion = gtnets_get_time_to_next_flow_completion();
+
+ /* If there are no renning flows, just return */
+ if (time_to_next_flow_completion < 0.0) {
+ return;
+ }
- if (GTNetS_run_until_next_flow_completion(&metadata)) {
+ /*KF: if delta == time_to_next_flow_completion, too.*/
+ if (time_to_next_flow_completion <= delta) { /* run until the first flow completes */
+ void **metadata;
+ int i,num_flows;
+
+ num_flows = 0;
+
+ if (gtnets_run_until_next_flow_completion(&metadata, &num_flows)) {
xbt_assert0(0,"Cannot run GTNetS simulation until next flow completion");
}
+ if (num_flows < 1) {
+ xbt_assert0(0,"GTNetS simulation couldn't find a flow that would complete");
+ }
- action = (surf_action_t)metadata;
+ for (i=0; i<num_flows; i++) {
+ surf_action_network_GTNETS_t action =
+ (surf_action_network_GTNETS_t)(metadata[i]);
- action->generic_action.remains = 0;
- action->generic_action.finish = now + time_to_next_flow_completion;
- action->generic_action.finish = SURF_ACTION_DONE;
- /* TODO: Anything else here? */
- } else {
- if (GTNetS_run(delta)) {
+ action->generic_action.remains = 0;
+ action->generic_action.finish = now + time_to_next_flow_completion;
+ action_change_state((surf_action_t) action, SURF_ACTION_DONE);
+ /* TODO: Anything else here? */
+ }
+ } else { /* run for a given number of seconds */
+ if (gtnets_run(delta)) {
xbt_assert0(0,"Cannot run GTNetS simulation");
}
}
tmgr_trace_event_t event_type,
double value)
{
+ xbt_assert0(0,"Cannot update resource state for GTNetS simulation");
return;
}
surf_action_network_GTNETS_t action = NULL;
network_card_GTNETS_t card_src = src;
network_card_GTNETS_t card_dst = dst;
+/*
int route_size = ROUTE_SIZE(card_src->id, card_dst->id);
network_link_GTNETS_t *route = ROUTE(card_src->id, card_dst->id);
- int i;
+*/
+/*
xbt_assert2(route_size,"You're trying to send data from %s to %s but there is no connexion between these two cards.", card_src->name, card_dst->name);
+*/
action = xbt_new0(s_surf_action_network_GTNETS_t, 1);
action->generic_action.using = 1;
action->generic_action.cost = size;
action->generic_action.remains = size;
+ /* Max durations are not supported */
action->generic_action.max_duration = NO_MAX_DURATION;
action->generic_action.start = surf_get_clock();
action->generic_action.finish = -1.0;
xbt_swag_insert(action, action->generic_action.state_set);
/* KF: Add a flow to the GTNets Simulation, associated to this action */
- GTNetS_create_flow(src->id, dst->id, size, (void *)action);
+ if (gtnets_create_flow(card_src->id, card_dst->id, size, (void *)action) < 0) {
+ xbt_assert2(0,"Not route between host %s and host %s", card_src->name, card_dst->name);
+ }
return (surf_action_t) action;
}
static void finalize(void)
{
+#if 0
int i,j;
-
+#endif
xbt_dict_free(&network_card_set);
xbt_dict_free(&network_link_set);
xbt_swag_free(surf_network_resource->common_public->states.
#endif
/* ADDED BY KF */
- GTNetS_finalize();
+ gtnets_finalize();
/* END ADDITION */
}
xbt_assert0(maxmin_system, "surf_init has to be called first!");
/* KF: Added the initialization for GTNetS interface */
- if (GTNetS_initialize()) {
+ if (gtnets_initialize()) {
xbt_assert0(0, "impossible to initialize GTNetS interface");
}
}
-/* HC: I put this prototype here for now but it will have to go in
- src/include/surf.h when it is functionnal. */
-void surf_network_resource_init_GTNETS(const char *filename);
-
void surf_network_resource_init_GTNETS(const char *filename)
{
if (surf_network_resource)
surf_network_resource_init_internal();
parse_file(filename);
xbt_dynar_push(resource_list, &surf_network_resource);
+
+ update_resource_description(surf_network_resource_description,
+ surf_network_resource_description_size,
+ "GTNets",
+ (surf_resource_t) surf_network_resource);
}