From e93257dad9c24c211ccdfcb64e36c8805f0ff832 Mon Sep 17 00:00:00 2001 From: Navarrop Date: Thu, 21 Apr 2011 14:31:40 +0200 Subject: [PATCH] Put ns3 sources in place. --- buildtools/Cmake/DefinePackages.cmake | 12 +++++ buildtools/Cmake/Modules/FindNS3.cmake | 5 ++ buildtools/Cmake/gras_config.h.in | 3 ++ src/include/surf/surf.h | 22 +++++++++ src/surf/network_ns3.c | 65 ++++++++++++++++++++++++++ src/surf/ns3/ns3_interface.cc | 22 +++++++++ src/surf/ns3/ns3_interface.h | 9 ++++ src/surf/surf.c | 5 ++ src/surf/surf_private.h | 2 + src/surf/surf_routing.c | 3 +- 10 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 src/surf/network_ns3.c create mode 100644 src/surf/ns3/ns3_interface.cc create mode 100644 src/surf/ns3/ns3_interface.h diff --git a/buildtools/Cmake/DefinePackages.cmake b/buildtools/Cmake/DefinePackages.cmake index 3371adbe6e..db5d97f2c3 100644 --- a/buildtools/Cmake/DefinePackages.cmake +++ b/buildtools/Cmake/DefinePackages.cmake @@ -184,6 +184,11 @@ set(GTNETS_SRC src/surf/network_gtnets.c ) +set(NS3_SRC + src/surf/network_ns3.c + src/surf/ns3/ns3_interface.cc + ) + set(SURF_SRC src/surf/surf_model.c src/surf/surf_action.c @@ -478,6 +483,13 @@ if(HAVE_MC) ) endif(HAVE_MC) +if(HAVE_NS3) + set(simgrid_sources + ${simgrid_sources} + ${NS3_SRC} + ) +endif(HAVE_NS3) + # WINDOWS if(WIN32) set(simgrid_sources diff --git a/buildtools/Cmake/Modules/FindNS3.cmake b/buildtools/Cmake/Modules/FindNS3.cmake index 8906d1f0ae..aca50fd101 100644 --- a/buildtools/Cmake/Modules/FindNS3.cmake +++ b/buildtools/Cmake/Modules/FindNS3.cmake @@ -59,6 +59,11 @@ if(HAVE_NS3_LIB AND HAVE_CORE_MODULE_H) if(NOT operation1) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-L${HAVE_NS3_LIB} ") endif(NOT operation1) + + string(REGEX MATCH "-I${HAVE_CORE_MODULE_H} " operation1 "${CMAKE_C_FLAGS}") + if(NOT operation1) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-I${HAVE_CORE_MODULE_H} ") + endif(NOT operation1) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-I${HAVE_CORE_MODULE_H} -L${HAVE_NS3_LIB} ") endif(NOT operation) diff --git a/buildtools/Cmake/gras_config.h.in b/buildtools/Cmake/gras_config.h.in index a39a90f474..4777ae1576 100644 --- a/buildtools/Cmake/gras_config.h.in +++ b/buildtools/Cmake/gras_config.h.in @@ -141,6 +141,9 @@ /* Indicates that we have GTNETS support */ #cmakedefine HAVE_GTNETS @HAVE_GTNETS@ +/* Indicates that we have NS3 support */ +#cmakedefine HAVE_NS3 @HAVE_NS3@ + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_INTTYPES_H @HAVE_INTTYPES_H@ diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 5672742cb9..6aecbc5bd5 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -497,6 +497,28 @@ XBT_PUBLIC(void) surf_network_model_init_bypass(const char *id, XBT_PUBLIC(void) surf_network_model_init_GTNETS(const char *filename); #endif +#ifdef HAVE_NS3 +/** \brief Initializes the platform with the network model NS3 + * \ingroup SURF_models + * \param filename XML platform file name + * + * This function is called by surf_workstation_model_init_NS3 + * or by yourself only if you plan using surf_workstation_model_init_compound + * + * \see surf_workstation_model_init_NS3() + */ +XBT_PUBLIC(void) surf_network_model_init_NS3(const char *filename); + +XBT_PUBLIC(void) parse_ns3_add_host(void); +XBT_PUBLIC(void) parse_ns3_add_router(void); +XBT_PUBLIC(void) parse_ns3_add_link(void); +XBT_PUBLIC(void) parse_ns3_add_AS(void); +XBT_PUBLIC(void) parse_ns3_add_route(void); +XBT_PUBLIC(void) parse_ns3_add_ASroute(void); +XBT_PUBLIC(void) parse_ns3_add_cluster(void); + +#endif + /** \brief Initializes the platform with the network model Reno * \ingroup SURF_models * \param filename XML platform file name diff --git a/src/surf/network_ns3.c b/src/surf/network_ns3.c new file mode 100644 index 0000000000..b2e747039b --- /dev/null +++ b/src/surf/network_ns3.c @@ -0,0 +1,65 @@ +/* Copyright (c) 2007, 2008, 2009, 2010, 2011. 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. */ + +#include "surf_private.h" +#include "surf/ns3/ns3_interface.h" + +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network_ns3, surf, + "Logging specific to the SURF network NS3 module"); + +extern routing_global_t global_routing; + +void parse_ns3_add_host(void) +{ + XBT_INFO("NS3_ADD_HOST '%s'",A_surfxml_host_id); + //ns3_add_host(A_surfxml_host_id); +} +void parse_ns3_add_router(void) +{ + XBT_INFO("NS3_ADD_ROUTER '%s'",A_surfxml_router_id); +} +void parse_ns3_add_link(void) +{ + XBT_INFO("NS3_ADD_LINK '%s'",A_surfxml_link_id); +} +void parse_ns3_add_AS(void) +{ + XBT_INFO("NS3_ADD_AS '%s'",A_surfxml_AS_id); +} +void parse_ns3_add_route(void) +{ + XBT_INFO("NS3_ADD_ROUTE from '%s' to '%s'",A_surfxml_route_src,A_surfxml_route_dst); +} +void parse_ns3_add_ASroute(void) +{ + XBT_INFO("NS3_ADD_ASROUTE from '%s' to '%s'",A_surfxml_ASroute_src,A_surfxml_ASroute_dst); +} +void parse_ns3_add_cluster(void) +{ + XBT_INFO("NS3_ADD_CLUSTER '%s'",A_surfxml_cluster_id); + routing_parse_Scluster(); +} + +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 +} + +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"; + + update_model_description(surf_network_model_description, + "NS3", surf_network_model); +} diff --git a/src/surf/ns3/ns3_interface.cc b/src/surf/ns3/ns3_interface.cc new file mode 100644 index 0000000000..2688f639c8 --- /dev/null +++ b/src/surf/ns3/ns3_interface.cc @@ -0,0 +1,22 @@ + +#include "surf/ns3/ns3_interface.h" + +#include "ns3/core-module.h" +#include "ns3/simulator-module.h" +#include "ns3/node-module.h" +#include "ns3/helper-module.h" +#include "ns3/global-route-manager.h" + +#include "xbt/log.h" + +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(interface_ns3, surf, + "Logging specific to the SURF network NS3 module"); + +//NodeContainer nodes; + +void ns3_add_host(char * id) +{ + XBT_INFO("Interface ns3 add host"); +// Ptr a = CreateObject (0); +// nodes.Add(a); +} diff --git a/src/surf/ns3/ns3_interface.h b/src/surf/ns3/ns3_interface.h new file mode 100644 index 0000000000..76c43d5ea3 --- /dev/null +++ b/src/surf/ns3/ns3_interface.h @@ -0,0 +1,9 @@ +/* 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. */ + +#include "xbt/misc.h" + +XBT_PUBLIC(void) ns3_add_host(char * id); diff --git a/src/surf/surf.c b/src/surf/surf.c index 74f7519327..bd4660229c 100644 --- a/src/surf/surf.c +++ b/src/surf/surf.c @@ -131,6 +131,11 @@ s_surf_model_description_t surf_network_model_description[] = { {"GTNets", "Network Pseudo-model using the GTNets simulator instead of an analytic model", NULL, surf_network_model_init_GTNETS}, +#endif +#ifdef HAVE_NS3 + {"NS3", + "TODO", + NULL, surf_network_model_init_NS3}, #endif {"Reno", "Model using lagrange_solve instead of lmm_solve (experts only)", NULL, diff --git a/src/surf/surf_private.h b/src/surf/surf_private.h index ac3fae8ef6..42ec82ab90 100644 --- a/src/surf/surf_private.h +++ b/src/surf/surf_private.h @@ -194,6 +194,8 @@ struct s_routing_global { XBT_PUBLIC(void) routing_model_create(size_t size_of_link, void *loopback, double_f_cpvoid_t get_link_latency_fun); +XBT_PUBLIC(void) routing_parse_Scluster(void); /* cluster bypass */ + /** * Resource protected methods */ diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 3d1fd6ab31..5d1e078eb4 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -27,7 +27,6 @@ static double_f_cpvoid_t get_link_latency = NULL; XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf"); -static void routing_parse_Scluster(void); /* cluster bypass */ static void routing_parse_Speer(void); /* peer bypass */ static void routing_parse_Srandom(void); /* random bypass */ static void routing_parse_Erandom(void); /* random bypass */ @@ -1529,7 +1528,7 @@ static void routing_parse_Econfig(void) XBT_DEBUG("End configuration name = %s",A_surfxml_config_id); } -static void routing_parse_Scluster(void) +void routing_parse_Scluster(void) { static int AX_ptr = 0; -- 2.20.1