Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add ns3 level to libraries.
authorNavarrop <Pierre.Navarro@imag.fr>
Fri, 22 Apr 2011 09:33:52 +0000 (11:33 +0200)
committerNavarrop <Pierre.Navarro@imag.fr>
Fri, 22 Apr 2011 09:35:20 +0000 (11:35 +0200)
Add interface for ns3.

buildtools/Cmake/DefinePackages.cmake
src/include/surf/surf.h
src/simdag/sd_global.c
src/surf/network_ns3.c
src/surf/ns3/ns3_interface.cc
src/surf/ns3/ns3_interface.h
src/surf/ns3/ns3_simulator.cc [new file with mode: 0644]
src/surf/ns3/ns3_simulator.h [new file with mode: 0644]

index db5d97f..b3852c4 100644 (file)
@@ -187,6 +187,7 @@ set(GTNETS_SRC
 set(NS3_SRC
        src/surf/network_ns3.c
        src/surf/ns3/ns3_interface.cc
+       src/surf/ns3/ns3_simulator.cc
        )
 
 set(SURF_SRC 
index 6aecbc5..e115793 100644 (file)
@@ -24,14 +24,17 @@ int SIMIX_HOST_LEVEL;       //Simix level
 int    MSG_HOST_LEVEL;         //Msg level
 int    SD_HOST_LEVEL;          //Simdag level
 int    COORD_HOST_LEVEL;       //Coordinates level
+int NS3_HOST_LEVEL;            //host node for ns3
 
 xbt_lib_t link_lib;
 int SD_LINK_LEVEL;             //Simdag level
 int SURF_LINK_LEVEL;   //Surf level
+int NS3_LINK_LEVEL;            //link for ns3
 
 xbt_lib_t as_router_lib;
 int ROUTING_ASR_LEVEL; //Routing level
 int COORD_ASR_LEVEL;   //Coordinates level
+int NS3_ASR_LEVEL;             //host node for ns3
 
 SG_BEGIN_DECL()
 /* Actions and models are highly connected structures... */
@@ -516,6 +519,7 @@ 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);
+XBT_PUBLIC(void) parse_ns3_end_platform(void);
 
 #endif
 
index f0f168f..762d002 100644 (file)
@@ -202,6 +202,7 @@ void SD_create_environment(const char *platform_file)
   }
 
   xbt_lib_foreach(link_lib, cursor, name, surf_link) {
+       if(surf_link[SURF_LINK_LEVEL])
     __SD_link_create(surf_link[SURF_LINK_LEVEL], NULL);
   }
 
index b2e7470..01a4336 100644 (file)
@@ -6,6 +6,11 @@
 
 #include "surf_private.h"
 #include "surf/ns3/ns3_interface.h"
+#include "xbt/lib.h"
+
+extern xbt_lib_t host_lib;
+extern xbt_lib_t link_lib;
+extern xbt_lib_t as_router_lib;
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network_ns3, surf,
                                 "Logging specific to the SURF network NS3 module");
@@ -14,35 +19,83 @@ 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);
+       XBT_DEBUG("NS3_ADD_HOST '%s'",A_surfxml_host_id);
+       xbt_lib_set(host_lib,
+                               A_surfxml_host_id,
+                               NS3_HOST_LEVEL,
+                               ns3_add_host(A_surfxml_host_id)
+                               );
 }
-void parse_ns3_add_router(void)
+void parse_ns3_add_link(void)
 {
-       XBT_INFO("NS3_ADD_ROUTER '%s'",A_surfxml_router_id);
+       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)
+                               );
 }
-void parse_ns3_add_link(void)
+void parse_ns3_add_router(void)
 {
-       XBT_INFO("NS3_ADD_LINK '%s'",A_surfxml_link_id);
+       XBT_DEBUG("NS3_ADD_ROUTER '%s'",A_surfxml_router_id);
+       xbt_lib_set(as_router_lib,
+                               A_surfxml_router_id,
+                               NS3_ASR_LEVEL,
+                               ns3_add_router(A_surfxml_router_id)
+                               );
 }
 void parse_ns3_add_AS(void)
 {
-       XBT_INFO("NS3_ADD_AS '%s'",A_surfxml_AS_id);
+       XBT_DEBUG("NS3_ADD_AS '%s'",A_surfxml_AS_id);
+       xbt_lib_set(as_router_lib,
+                               A_surfxml_AS_id,
+                               NS3_ASR_LEVEL,
+                               ns3_add_AS(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);
+       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);
 }
 void parse_ns3_add_ASroute(void)
 {
-       XBT_INFO("NS3_ADD_ASROUTE from '%s' to '%s'",A_surfxml_ASroute_src,A_surfxml_ASroute_dst);
+       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);
 }
 void parse_ns3_add_cluster(void)
 {
-       XBT_INFO("NS3_ADD_CLUSTER '%s'",A_surfxml_cluster_id);
+       XBT_DEBUG("NS3_ADD_CLUSTER '%s'",A_surfxml_cluster_id);
        routing_parse_Scluster();
 }
 
+void parse_ns3_end_platform(void)
+{
+         xbt_lib_cursor_t cursor = NULL;
+         char *name = NULL;
+         void **data = NULL;
+         XBT_INFO("link_lib");
+         xbt_lib_foreach(link_lib, cursor, name, data) {
+                       XBT_INFO("\tSee link '%s'\t--> NS3_LEVEL %p",
+                                       name,
+                                       data[NS3_LINK_LEVEL]);
+         }
+         XBT_INFO(" ");
+         XBT_INFO("host_lib");
+         xbt_lib_foreach(host_lib, cursor, name, data) {
+                       XBT_INFO("\tSee host '%s'\t--> NS3_LEVEL %p",
+                                       name,
+                                       data[NS3_HOST_LEVEL]);
+         }
+         XBT_INFO(" ");
+         XBT_INFO("as_router_lib");
+         xbt_lib_foreach(as_router_lib, cursor, name, data) {
+                       XBT_INFO("\tSee ASR '%s'\t--> NS3_LEVEL %p",
+                                       name,
+                                       data[NS3_ASR_LEVEL]);
+         }
+}
+
 static void define_callbacks_ns3(const char *filename)
 {
   surfxml_add_callback(STag_surfxml_host_cb_list, &parse_ns3_add_host);        //HOST
@@ -52,6 +105,8 @@ static void define_callbacks_ns3(const char *filename)
   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(ETag_surfxml_platform_cb_list, &parse_ns3_end_platform); //DEBUG
 }
 
 void surf_network_model_init_NS3(const char *filename)
@@ -60,6 +115,10 @@ void surf_network_model_init_NS3(const char *filename)
        surf_network_model = surf_model_init();
        surf_network_model->name = "network NS3";
 
+       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);
+
        update_model_description(surf_network_model_description,
                    "NS3", surf_network_model);
 }
index 2688f63..404f321 100644 (file)
@@ -1,22 +1,78 @@
+/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
 
-#include "surf/ns3/ns3_interface.h"
+/* 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/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"
+using namespace ns3;
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(interface_ns3, surf,
                                 "Logging specific to the SURF network NS3 module");
 
-//NodeContainer nodes;
+NodeContainer nodes;
+int number_of_nodes = 0;
+
+void * ns3_add_host(char * id)
+{
+       ns3_nodes_t host  = xbt_new0(s_ns3_nodes_t,1);
+       XBT_INFO("Interface ns3 add host '%s'",id);
+       Ptr<Node> node =  CreateObject<Node> (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);
+       number_of_nodes++;
+       return host;
+}
+
+void * ns3_add_router(char * id)
+{
+       ns3_nodes_t router  = xbt_new0(s_ns3_nodes_t,1);
+       XBT_INFO("Interface ns3 add router '%s'",id);
+       Ptr<Node> node =  CreateObject<Node> (0);
+       nodes.Add(node);
+       router->node_num = number_of_nodes;
+       router->type = NS3_NETWORK_ELEMENT_ROUTER;
+       router->data = node;
+       number_of_nodes++;
+       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 ns3_add_host(char * id)
+void free_ns3_elmts(void * elmts)
 {
-       XBT_INFO("Interface ns3 add host");
-//     Ptr<Node> a =  CreateObject<Node> (0);
-//     nodes.Add(a);
+       XBT_INFO("Free ns3 elmts");
 }
index 76c43d5..fa1a630 100644 (file)
@@ -4,6 +4,41 @@
 /* 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 _NS3_INTERFACE_H
+#define _NS3_INTERFACE_H
+
+#include "xbt/log.h"
 #include "xbt/misc.h"
+#include "xbt/sysdep.h"
+
+typedef enum {
+       NS3_NETWORK_ELEMENT_NULL = 0,    /* NULL */
+       NS3_NETWORK_ELEMENT_HOST,       /* host type */
+       NS3_NETWORK_ELEMENT_ROUTER,     /* router type */
+       NS3_NETWORK_ELEMENT_AS,         /* AS type */
+} e_ns3_network_element_type_t;
+
+typedef struct ns3_nodes{
+       int node_num;
+       e_ns3_network_element_type_t type;
+       void * data;
+}s_ns3_nodes_t, *ns3_nodes_t;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+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
 
-XBT_PUBLIC(void) ns3_add_host(char * id);
+#endif
diff --git a/src/surf/ns3/ns3_simulator.cc b/src/surf/ns3/ns3_simulator.cc
new file mode 100644 (file)
index 0000000..29fd20e
--- /dev/null
@@ -0,0 +1,14 @@
+/* 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 "surf/ns3/ns3_simulator.h"
+
+// Constructor.
+NS3Sim::NS3Sim(){
+}
+//Destructor.
+NS3Sim::~NS3Sim(){
+}
diff --git a/src/surf/ns3/ns3_simulator.h b/src/surf/ns3/ns3_simulator.h
new file mode 100644 (file)
index 0000000..dce821b
--- /dev/null
@@ -0,0 +1,25 @@
+/* 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 _NS3_SIM_H
+#define _NS3_SIM_H
+
+#ifdef __cplusplus
+
+//Simulator s;
+class NS3Sim {
+       NS3Sim();
+       ~NS3Sim();
+
+private:
+
+public:
+
+};
+
+#endif                          /* __cplusplus */
+
+#endif