From: Navarrop Date: Tue, 7 Jun 2011 09:26:29 +0000 (+0200) Subject: Add functions for ns3 X-Git-Tag: v3_6_rc3~2^2~5 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f4c4bb0050ab968a35369d8e844cda166782869a Add functions for ns3 create_ns3_topology ns3_get_link_latency ns3_get_link_bandwith --- diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 4601fb642a..10e9b3a7d6 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -501,6 +501,9 @@ XBT_PUBLIC(void) parse_ns3_add_route(void); XBT_PUBLIC(void) parse_ns3_add_ASroute(void); XBT_PUBLIC(void) parse_ns3_add_cluster(void); XBT_PUBLIC(void) parse_ns3_end_platform(void); +XBT_PUBLIC(void) create_ns3_topology(void); +XBT_PUBLIC(double) ns3_get_link_latency(const void *link); +XBT_PUBLIC(double) ns3_get_link_bandwidth(const void *link); #endif diff --git a/src/surf/network_ns3.c b/src/surf/network_ns3.c index 01a4336eb0..07649cdb90 100644 --- a/src/surf/network_ns3.c +++ b/src/surf/network_ns3.c @@ -7,6 +7,8 @@ #include "surf_private.h" #include "surf/ns3/ns3_interface.h" #include "xbt/lib.h" +#include "surf/network_ns3_private.h" +#include "xbt/str.h" extern xbt_lib_t host_lib; extern xbt_lib_t link_lib; @@ -29,11 +31,34 @@ void parse_ns3_add_host(void) void parse_ns3_add_link(void) { XBT_DEBUG("NS3_ADD_LINK '%s'",A_surfxml_link_id); - xbt_lib_set(link_lib, - A_surfxml_link_id, - NS3_LINK_LEVEL, - ns3_add_link(A_surfxml_link_id) - ); + + tmgr_trace_t bw_trace; + tmgr_trace_t state_trace; + tmgr_trace_t lat_trace; + + bw_trace = tmgr_trace_new(A_surfxml_link_bandwidth_file); + lat_trace = tmgr_trace_new(A_surfxml_link_latency_file); + state_trace = tmgr_trace_new(A_surfxml_link_state_file); + + if (bw_trace) + XBT_INFO("The NS3 network model doesn't support bandwidth state traces"); + if (lat_trace) + XBT_INFO("The NS3 network model doesn't support latency state traces"); + if (state_trace) + XBT_INFO("The NS3 network model doesn't support link state traces"); + + ns3_link_t link_ns3 = xbt_new0(s_ns3_link_t,1);; + link_ns3->id = xbt_strdup(A_surfxml_link_id); + link_ns3->bdw = xbt_strdup(A_surfxml_link_bandwidth); + link_ns3->lat = xbt_strdup(A_surfxml_link_latency); + + surf_ns3_link_t link = xbt_new0(s_surf_ns3_link_t,1); + link->generic_resource.name = xbt_strdup(A_surfxml_link_id); + link->generic_resource.properties = current_property_set; + link->data = link_ns3; + + xbt_lib_set(link_lib,A_surfxml_link_id,NS3_LINK_LEVEL,link_ns3); + xbt_lib_set(link_lib,A_surfxml_link_id,SURF_LINK_LEVEL,link); } void parse_ns3_add_router(void) { @@ -53,20 +78,30 @@ void parse_ns3_add_AS(void) ns3_add_AS(A_surfxml_AS_id) ); } -void parse_ns3_add_route(void) +void parse_ns3_add_cluster(void) { - XBT_DEBUG("NS3_ADD_ROUTE from '%s' to '%s'",A_surfxml_route_src,A_surfxml_route_dst); - ns3_add_route(A_surfxml_route_src,A_surfxml_route_dst); + XBT_DEBUG("NS3_ADD_CLUSTER '%s'",A_surfxml_cluster_id); + routing_parse_Scluster(); } -void parse_ns3_add_ASroute(void) + +double ns3_get_link_latency (const void *link) { - XBT_DEBUG("NS3_ADD_ASROUTE from '%s' to '%s'",A_surfxml_ASroute_src,A_surfxml_ASroute_dst); - ns3_add_ASroute(A_surfxml_ASroute_src,A_surfxml_ASroute_dst); + double lat; + XBT_INFO("link_id:%s link_lat:%s link_bdw:%s",((surf_ns3_link_t)link)->data->id,((surf_ns3_link_t)link)->data->lat,((surf_ns3_link_t)link)->data->bdw); + sscanf(((surf_ns3_link_t)link)->data->lat,"%lg",&lat); + return lat; } -void parse_ns3_add_cluster(void) +double ns3_get_link_bandwidth (const void *link) { - XBT_DEBUG("NS3_ADD_CLUSTER '%s'",A_surfxml_cluster_id); - routing_parse_Scluster(); + double bdw; + XBT_INFO("link_id:%s link_lat:%s link_bdw:%s",((surf_ns3_link_t)link)->data->id,((surf_ns3_link_t)link)->data->lat,((surf_ns3_link_t)link)->data->bdw); + sscanf(((surf_ns3_link_t)link)->data->bdw,"%lg",&bdw); + return bdw; +} + +static xbt_dynar_t ns3_get_route(const char *src, const char *dst) +{ + return global_routing->get_route(src, dst); } void parse_ns3_end_platform(void) @@ -96,17 +131,133 @@ void parse_ns3_end_platform(void) } } +static void replace_str(char *str, const char *orig, const char *rep) +{ + char buffer[30]; + char *p; + + if(!(p = strstr(str, orig))) // Is 'orig' even in 'str'? + return; + + strncpy(buffer, str, p-str); // Copy characters from 'str' start to 'orig' st$ + buffer[p-str] = '\0'; + + sprintf(buffer+(p-str), "%s%s", rep, p+strlen(orig)); + xbt_free(str); + str = xbt_strdup(buffer); +} + +static void replace_bdw_ns3(char * bdw) +{ + char *temp = xbt_strdup(bdw); + + replace_str(bdw,"000000000","Gbps"); + if(strcmp(bdw,temp)) {xbt_free(temp);return;} + replace_str(bdw,"000000","Mbps"); + if(strcmp(bdw,temp)) {xbt_free(temp);return;} + replace_str(bdw,"000","Kbps"); + if(strcmp(bdw,temp)) {xbt_free(temp);return;} + + xbt_free(bdw); + bdw = bprintf("%s%s",temp,"bps"); + xbt_free(temp); +} + +static void replace_lat_ns3(char * lat) +{ + char *temp = xbt_strdup(lat); + + replace_str(lat,"E-1","00ms"); + if(strcmp(lat,temp)) {xbt_free(temp);return;} + replace_str(lat,"E-2","0ms"); + if(strcmp(lat,temp)) {xbt_free(temp);return;} + replace_str(lat,"E-3","ms"); + if(strcmp(lat,temp)) {xbt_free(temp);return;} + replace_str(lat,"E-4","00us"); + if(strcmp(lat,temp)) {xbt_free(temp);return;} + replace_str(lat,"E-5","0us"); + if(strcmp(lat,temp)) {xbt_free(temp);return;} + replace_str(lat,"E-6","us"); + if(strcmp(lat,temp)) {xbt_free(temp);return;} + replace_str(lat,"E-7","00ns"); + if(strcmp(lat,temp)) {xbt_free(temp);return;} + replace_str(lat,"E-8","0ns"); + if(strcmp(lat,temp)) {xbt_free(temp);return;} + replace_str(lat,"E-9","ns"); + if(strcmp(lat,temp)) {xbt_free(temp);return;} + + xbt_free(lat); + lat = bprintf("%s%s",temp,"s"); + xbt_free(temp); +} + +/* Create the ns3 topology based on routing strategy */ +void create_ns3_topology() +{ + int src_id,dst_id; + + XBT_DEBUG("Starting topology generation"); + + //get the onelinks from the parsed platform + xbt_dynar_t onelink_routes = global_routing->get_onelink_routes(); + if (!onelink_routes) + xbt_die("There is no routes!"); + + //save them in trace file + onelink_t onelink; + unsigned int iter; + xbt_dynar_foreach(onelink_routes, iter, onelink) { + char *src = onelink->src; + char *dst = onelink->dst; + void *link = onelink->link_ptr; + src_id = *((int *) xbt_dict_get_or_null(global_routing->root->to_index,src)); + dst_id = *((int *) xbt_dict_get_or_null(global_routing->root->to_index,dst)); + + if(src_id != dst_id){ + char * link_bdw = xbt_strdup(((surf_ns3_link_t)link)->data->bdw); + char * link_lat = xbt_strdup(((surf_ns3_link_t)link)->data->lat); + // replace_bdw_ns3(link_bdw); + // replace_lat_ns3(link_lat); + XBT_INFO("src (%s), dst (%s), src_id = %d, dst_id = %d",src,dst, src_id, dst_id); + XBT_INFO("\tLink (%s) bdw:%s->%s lat:%s->%s",((surf_ns3_link_t)link)->data->id, + ((surf_ns3_link_t)link)->data->bdw,link_bdw, + ((surf_ns3_link_t)link)->data->lat,link_lat + ); + xbt_free(link_bdw); + xbt_free(link_lat); + } + } +} + static void define_callbacks_ns3(const char *filename) { surfxml_add_callback(STag_surfxml_host_cb_list, &parse_ns3_add_host); //HOST surfxml_add_callback(STag_surfxml_router_cb_list, &parse_ns3_add_router); //ROUTER surfxml_add_callback(STag_surfxml_link_cb_list, &parse_ns3_add_link); //LINK surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_ns3_add_AS); //AS - surfxml_add_callback(STag_surfxml_route_cb_list, &parse_ns3_add_route); //ROUTE - surfxml_add_callback(STag_surfxml_ASroute_cb_list, &parse_ns3_add_ASroute); //ASROUTE - surfxml_add_callback(STag_surfxml_cluster_cb_list, &parse_ns3_add_cluster); //CLUSTER + //surfxml_add_callback(STag_surfxml_cluster_cb_list, &parse_ns3_add_cluster); //CLUSTER surfxml_add_callback(ETag_surfxml_platform_cb_list, &parse_ns3_end_platform); //DEBUG + surfxml_add_callback(ETag_surfxml_platform_cb_list, &create_ns3_topology); +} + +static void free_ns3_elmts(void * elmts) +{ +} + +static void free_ns3_link(void * elmts) +{ + ns3_link_t link = elmts; + free(link->id); + free(link->bdw); + free(link->lat); + free(link); +} + +static void free_ns3_host(void * elmts) +{ + ns3_nodes_t host = elmts; + free(host); } void surf_network_model_init_NS3(const char *filename) @@ -114,10 +265,14 @@ void surf_network_model_init_NS3(const char *filename) define_callbacks_ns3(filename); surf_network_model = surf_model_init(); surf_network_model->name = "network NS3"; + surf_network_model->extension.network.get_link_latency = ns3_get_link_latency; + surf_network_model->extension.network.get_link_bandwidth = ns3_get_link_bandwidth; + surf_network_model->extension.network.get_route = ns3_get_route; + routing_model_create(sizeof(s_surf_ns3_link_t), NULL, NULL); - NS3_HOST_LEVEL = xbt_lib_add_level(host_lib,(void_f_pvoid_t)free_ns3_elmts); - NS3_ASR_LEVEL = xbt_lib_add_level(as_router_lib,(void_f_pvoid_t)free_ns3_elmts); - NS3_LINK_LEVEL = xbt_lib_add_level(link_lib,(void_f_pvoid_t)free_ns3_elmts); + NS3_HOST_LEVEL = xbt_lib_add_level(host_lib,(void_f_pvoid_t)free_ns3_host); + NS3_ASR_LEVEL = xbt_lib_add_level(as_router_lib,(void_f_pvoid_t)free_ns3_host); + NS3_LINK_LEVEL = xbt_lib_add_level(link_lib,(void_f_pvoid_t)free_ns3_link); update_model_description(surf_network_model_description, "NS3", surf_network_model); diff --git a/src/surf/network_ns3_private.h b/src/surf/network_ns3_private.h new file mode 100644 index 0000000000..84721023d7 --- /dev/null +++ b/src/surf/network_ns3_private.h @@ -0,0 +1,24 @@ +/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef _SURF_NETWORK_NS3_PRIVATE_H +#define _SURF_NETWORK_NS3_PRIVATE_H + +#include "surf_private.h" +#include "xbt/dict.h" + +typedef struct ns3_link{ + char * id; + char * lat; + char * bdw; +}s_ns3_link_t, *ns3_link_t; + +typedef struct surf_ns3_link{ + s_surf_resource_t generic_resource; + ns3_link_t data; +}s_surf_ns3_link_t, *surf_ns3_link_t; + +#endif /* _SURF_NETWORK_NS3_PRIVATE_H */ diff --git a/src/surf/ns3/ns3_interface.cc b/src/surf/ns3/ns3_interface.cc index 404f321813..f0556bbe50 100644 --- a/src/surf/ns3/ns3_interface.cc +++ b/src/surf/ns3/ns3_interface.cc @@ -4,7 +4,7 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "surf/ns3/ns3_interface.h" +#include "ns3_interface.h" #include "ns3/core-module.h" #include "ns3/simulator-module.h" #include "ns3/node-module.h" @@ -25,11 +25,9 @@ void * ns3_add_host(char * id) XBT_INFO("Interface ns3 add host '%s'",id); Ptr node = CreateObject (0); nodes.Add(node); - host->node_num = number_of_nodes; host->type = NS3_NETWORK_ELEMENT_HOST; - host->data = nodes.Get(number_of_nodes); - XBT_INFO("node %p",host->data); + host->data = node; number_of_nodes++; return host; } @@ -47,32 +45,8 @@ void * ns3_add_router(char * id) return router; } -void * ns3_add_link(char * id) -{ - XBT_INFO("Interface ns3 add link '%s'",id); - PointToPointHelper pointToPoint_5Mbps; - pointToPoint_5Mbps.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); - pointToPoint_5Mbps.SetChannelAttribute ("Delay", StringValue ("2ms")); - return NULL;//&pointToPoint_5Mbps; -} - void * ns3_add_AS(char * id) { XBT_INFO("Interface ns3 add AS '%s'",id); return NULL; } - -void ns3_add_route(char * src,char * dst) -{ - XBT_INFO("Interface ns3 add route from '%s' to '%s'",src,dst); -} - -void ns3_add_ASroute(char * src,char * dst) -{ - XBT_INFO("Interface ns3 add ASroute from '%s' to '%s'",src,dst); -} - -void free_ns3_elmts(void * elmts) -{ - XBT_INFO("Free ns3 elmts"); -} diff --git a/src/surf/ns3/ns3_interface.h b/src/surf/ns3/ns3_interface.h index fa1a630fc3..bbcb2196cf 100644 --- a/src/surf/ns3/ns3_interface.h +++ b/src/surf/ns3/ns3_interface.h @@ -8,6 +8,7 @@ #define _NS3_INTERFACE_H #include "xbt/log.h" +#include "xbt/dynar.h" #include "xbt/misc.h" #include "xbt/sysdep.h" @@ -30,13 +31,8 @@ extern "C" { XBT_PUBLIC(void *) ns3_add_host(char * id); XBT_PUBLIC(void *) ns3_add_router(char * id); -XBT_PUBLIC(void *) ns3_add_link(char * id); XBT_PUBLIC(void *) ns3_add_AS(char * id); XBT_PUBLIC(void) ns3_add_cluster(char * id); -XBT_PUBLIC(void) ns3_add_route(char * src,char * dst); -XBT_PUBLIC(void) ns3_add_ASroute(char * src,char * dst); -XBT_PUBLIC(void) free_ns3_elmts(void *); - #ifdef __cplusplus } #endif diff --git a/teshsuite/simdag/platforms/four_hosts_Dijkstra_ns3.xml b/teshsuite/simdag/platforms/four_hosts_Dijkstra_ns3.xml new file mode 100644 index 0000000000..3e99345028 --- /dev/null +++ b/teshsuite/simdag/platforms/four_hosts_Dijkstra_ns3.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/teshsuite/simdag/platforms/four_hosts_floyd_ns3.xml b/teshsuite/simdag/platforms/four_hosts_floyd_ns3.xml new file mode 100644 index 0000000000..71843dcfa1 --- /dev/null +++ b/teshsuite/simdag/platforms/four_hosts_floyd_ns3.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file