Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add cluster to ns3.
authorNavarrop <Pierre.Navarro@imag.fr>
Wed, 15 Jun 2011 14:13:43 +0000 (16:13 +0200)
committerNavarrop <Pierre.Navarro@imag.fr>
Wed, 15 Jun 2011 14:17:17 +0000 (16:17 +0200)
src/surf/network_ns3.c
src/surf/network_ns3_private.h
src/surf/ns3/ns3_interface.cc
src/surf/ns3/ns3_interface.h
src/surf/surf_routing_dijkstra.c
src/surf/surf_routing_rulebased.c
teshsuite/simdag/platforms/four_hosts_Dijkstra_ns3.xml
teshsuite/simdag/platforms/four_hosts_floyd_ns3.xml

index 07649cd..481c575 100644 (file)
@@ -19,6 +19,61 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network_ns3, surf,
 
 extern routing_global_t global_routing;
 
+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)
+{
+//     replace_str(bdw,".00","");
+//     char *temp = xbt_strdup(bdw);
+//
+//     replace_str(bdw,"000000000","Gbps");
+//     if(strcmp(bdw,temp)) {xbt_free(temp);return;}
+//     replace_str(bdw,"00000000","00Mbps");
+//     if(strcmp(bdw,temp)) {xbt_free(temp);return;}
+//     replace_str(bdw,"0000000","0Mbps");
+//     if(strcmp(bdw,temp)) {xbt_free(temp);return;}
+//     replace_str(bdw,"000000","Mbps");
+//     if(strcmp(bdw,temp)) {xbt_free(temp);return;}
+//     replace_str(bdw,"00000","00Kbps");
+//     if(strcmp(bdw,temp)) {xbt_free(temp);return;}
+//     replace_str(bdw,"0000","0Kbps");
+//     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);
+
+       char *temp = xbt_strdup(bdw);
+       xbt_free(bdw);
+       bdw = bprintf("%fbps",atof(temp));
+       xbt_free(temp);
+
+}
+
+static void replace_lat_ns3(char * lat)
+{
+       char *temp = xbt_strdup(lat);
+       xbt_free(lat);
+       lat = bprintf("%fs",atof(temp));
+       xbt_free(temp);
+}
+
 void parse_ns3_add_host(void)
 {
        XBT_DEBUG("NS3_ADD_HOST '%s'",A_surfxml_host_id);
@@ -56,6 +111,7 @@ void parse_ns3_add_link(void)
        link->generic_resource.name = xbt_strdup(A_surfxml_link_id);
        link->generic_resource.properties = current_property_set;
        link->data = link_ns3;
+       link->created = 1;
 
        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);
@@ -80,21 +136,114 @@ void parse_ns3_add_AS(void)
 }
 void parse_ns3_add_cluster(void)
 {
-       XBT_DEBUG("NS3_ADD_CLUSTER '%s'",A_surfxml_cluster_id);
-       routing_parse_Scluster();
+       char *cluster_prefix = A_surfxml_cluster_prefix;
+       char *cluster_suffix = A_surfxml_cluster_suffix;
+       char *cluster_radical = A_surfxml_cluster_radical;
+       char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
+       char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
+       char *cluster_bw = A_surfxml_cluster_bw;
+       char *cluster_lat = A_surfxml_cluster_lat;
+       char *groups = NULL;
+
+       int start, end, i;
+       unsigned int iter;
+
+       xbt_dynar_t radical_elements;
+       xbt_dynar_t radical_ends;
+       xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
+
+       char *router_id,*host_id;
+
+       radical_elements = xbt_str_split(cluster_radical, ",");
+       xbt_dynar_foreach(radical_elements, iter, groups) {
+               radical_ends = xbt_str_split(groups, "-");
+
+               switch (xbt_dynar_length(radical_ends)) {
+               case 1:
+                 surf_parse_get_int(&start,xbt_dynar_get_as(radical_ends, 0, char *));
+                 xbt_dynar_push_as(tab_elements_num, int, start);
+                 router_id = bprintf("ns3_%s%d%s", cluster_prefix, start, cluster_suffix);
+                 xbt_lib_set(host_lib,
+                                               router_id,
+                                               NS3_HOST_LEVEL,
+                                               ns3_add_host_cluster(router_id)
+                                               );
+                 XBT_DEBUG("NS3_ADD_ROUTER '%s'",router_id);
+                 free(router_id);
+                 break;
+
+               case 2:
+                 surf_parse_get_int(&start,xbt_dynar_get_as(radical_ends, 0, char *));
+                 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
+                 for (i = start; i <= end; i++){
+                       xbt_dynar_push_as(tab_elements_num, int, i);
+                       router_id = bprintf("ns3_%s%d%s", cluster_prefix, i, cluster_suffix);
+                       xbt_lib_set(host_lib,
+                                               router_id,
+                                               NS3_HOST_LEVEL,
+                                               ns3_add_host_cluster(router_id)
+                                               );
+                       XBT_DEBUG("NS3_ADD_ROUTER '%s'",router_id);
+                       free(router_id);
+                 }
+                 break;
+
+               default:
+                 XBT_DEBUG("Malformed radical");
+               }
+       }
+
+
+
+       //Create links
+       unsigned int cpt;
+       int elmts;
+       char * lat = xbt_strdup(cluster_lat);
+       char * bw =  xbt_strdup(cluster_bw);
+       replace_lat_ns3(lat);
+       replace_bdw_ns3(bw);
+
+       xbt_dynar_foreach(tab_elements_num,cpt,elmts)
+       {
+               host_id   = bprintf("%s%d%s", cluster_prefix, elmts, cluster_suffix);
+               router_id = bprintf("ns3_%s%d%s", cluster_prefix, elmts, cluster_suffix);
+               XBT_DEBUG("Create link from '%s' to '%s'",host_id,router_id);
+
+               ns3_nodes_t host_src = xbt_lib_get_or_null(host_lib,host_id,  NS3_HOST_LEVEL);
+               ns3_nodes_t host_dst = xbt_lib_get_or_null(host_lib,router_id,NS3_HOST_LEVEL);
+
+               if(host_src && host_dst){}
+               else xbt_die("\tns3_add_link from %d to %d",host_src->node_num,host_dst->node_num);
+
+               ns3_add_link(host_src->node_num,host_dst->node_num,bw,lat);
+
+               free(router_id);
+               free(host_id);
+       }
+       xbt_dynar_free(&tab_elements_num);
+
+
+       //Create link backbone
+       lat = xbt_strdup(cluster_bb_lat);
+       bw =  xbt_strdup(cluster_bb_bw);
+       replace_lat_ns3(lat);
+       replace_bdw_ns3(bw);
+       ns3_add_cluster(bw,lat,A_surfxml_cluster_id);
+       xbt_free(lat);
+       xbt_free(bw);   
 }
 
 double ns3_get_link_latency (const void *link)
 {
        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);
+       //XBT_DEBUG("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;
 }
 double ns3_get_link_bandwidth (const void *link)
 {
        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);
+       //XBT_DEBUG("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;
 }
@@ -106,103 +255,47 @@ static xbt_dynar_t ns3_get_route(const char *src, const char *dst)
 
 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 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);
+       ns3_end_platform();
+
+//       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]);
+//       }
+//
+//       XBT_INFO(" ");
 }
 
 /* Create the ns3 topology based on routing strategy */
 void create_ns3_topology()
 {
-   int src_id,dst_id;
+//   int src_id,dst_id;
 
-   XBT_DEBUG("Starting topology generation");
+   XBT_INFO("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!");
-
+   XBT_INFO("Have get_onelink_routes, found %ld routes",onelink_routes->used);
    //save them in trace file
    onelink_t onelink;
    unsigned int iter;
@@ -210,19 +303,37 @@ void create_ns3_topology()
      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);
+//TODO need to uncomment those two line
+//     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) && ((surf_ns3_link_t)link)->created){
+     if( strcmp(src,dst) && ((surf_ns3_link_t)link)->created){
+     XBT_INFO("Route from '%s' to '%s' with link '%s'",src,dst,((surf_ns3_link_t)link)->data->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);
+        ((surf_ns3_link_t)link)->created = 0;
+
+        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
                 );
+
+     //create link ns3
+     ns3_nodes_t host_src = xbt_lib_get_or_null(host_lib,src,NS3_HOST_LEVEL);
+     if(!host_src) host_src = xbt_lib_get_or_null(as_router_lib,src,NS3_ASR_LEVEL);
+     ns3_nodes_t host_dst = xbt_lib_get_or_null(host_lib,dst,NS3_HOST_LEVEL);
+     if(!host_dst) host_dst = xbt_lib_get_or_null(as_router_lib,dst,NS3_ASR_LEVEL);
+
+     if(host_src && host_dst){}
+     else xbt_die("\tns3_add_link from %d to %d",host_src->node_num,host_dst->node_num);
+
+     ns3_add_link(host_src->node_num,host_dst->node_num,link_bdw,link_lat);
+
      xbt_free(link_bdw);
      xbt_free(link_lat);
      }
@@ -231,14 +342,14 @@ void create_ns3_topology()
 
 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_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);
+  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_cluster_cb_list, &parse_ns3_add_cluster); //CLUSTER
+
+  surfxml_add_callback(ETag_surfxml_platform_cb_list, &create_ns3_topology);    //get_one_link_routes
+  surfxml_add_callback(ETag_surfxml_platform_cb_list, &parse_ns3_end_platform); //InitializeRoutes
 }
 
 static void free_ns3_elmts(void * elmts)
@@ -262,13 +373,13 @@ static void free_ns3_host(void * elmts)
 
 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);
+       define_callbacks_ns3(filename);
 
        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);
index 8472102..03a27ee 100644 (file)
@@ -19,6 +19,7 @@ typedef struct ns3_link{
 typedef struct surf_ns3_link{
        s_surf_resource_t generic_resource;
        ns3_link_t data;
+       int created;
 }s_surf_ns3_link_t, *surf_ns3_link_t;
 
 #endif                          /* _SURF_NETWORK_NS3_PRIVATE_H */
index f0556bb..d961c69 100644 (file)
 #include "ns3/node-module.h"
 #include "ns3/helper-module.h"
 #include "ns3/global-route-manager.h"
+#include "ns3/global-route-manager.h"
+#include "ns3/ipv4-global-routing-helper.h"
 
 using namespace ns3;
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(interface_ns3, surf,
                                 "Logging specific to the SURF network NS3 module");
 
+InternetStackHelper stack;
 NodeContainer nodes;
+NodeContainer Cluster_nodes;
+Ipv4InterfaceContainer interfaces;
+
 int number_of_nodes = 0;
+int number_of_clusters_nodes = 0;
+int number_of_links = 1;
+int number_of_networks = 1;
 
 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);
+       XBT_INFO("Interface ns3 add host[%d] '%s'",number_of_nodes,id);
+       Ptr<Node> node =  CreateObject<Node> (0);
+       stack.Install(node);
+       nodes.Add(node);
+       host->node_num = number_of_nodes;
+       host->type = NS3_NETWORK_ELEMENT_HOST;
+       host->data = node;
+       number_of_nodes++;
+       return host;
+}
+
+void * ns3_add_host_cluster(char * id)
+{
+       ns3_nodes_t host  = xbt_new0(s_ns3_nodes_t,1);
+       XBT_INFO("Interface ns3 add host[%d] '%s'",number_of_nodes,id);
        Ptr<Node> node =  CreateObject<Node> (0);
+       stack.Install(node);
+       Cluster_nodes.Add(node);
        nodes.Add(node);
        host->node_num = number_of_nodes;
        host->type = NS3_NETWORK_ELEMENT_HOST;
@@ -35,8 +60,9 @@ void * ns3_add_host(char * id)
 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);
+       XBT_INFO("Interface ns3 add router[%d] '%s'",number_of_nodes,id);
        Ptr<Node> node =  CreateObject<Node> (0);
+       stack.Install(node);
        nodes.Add(node);
        router->node_num = number_of_nodes;
        router->type = NS3_NETWORK_ELEMENT_ROUTER;
@@ -45,8 +71,137 @@ void * ns3_add_router(char * id)
        return router;
 }
 
+void * ns3_add_cluster(char * bw,char * lat,char *id)
+{
+
+       XBT_DEBUG("cluster_id: %s",id);
+       XBT_DEBUG("bw: %s lat: %s",bw,lat);
+       XBT_DEBUG("Number of %s nodes: %d",id,Cluster_nodes.GetN() - number_of_clusters_nodes);
+
+       NodeContainer Nodes;
+       int i;
+
+       for(i = number_of_clusters_nodes; i < Cluster_nodes.GetN() ; i++){
+               Nodes.Add(Cluster_nodes.Get(i));
+               XBT_DEBUG("Add node %d to cluster",i);
+       }
+       number_of_clusters_nodes = Cluster_nodes.GetN();
+
+       XBT_DEBUG("Add router %d to cluster",nodes.GetN()-Nodes.GetN()-1);
+       Nodes.Add(nodes.Get(nodes.GetN()-Nodes.GetN()-1));
+
+       if(Nodes.GetN() > 254)
+               xbt_die("Cluster with NS3 is limited to 254 nodes");
+       CsmaHelper csma;
+       csma.SetChannelAttribute ("DataRate", StringValue (bw));
+       csma.SetChannelAttribute ("Delay", StringValue (lat));
+       NetDeviceContainer devices = csma.Install (Nodes);
+       XBT_DEBUG("Create CSMA");
+
+
+       char * adr = bprintf("10.%d.%d.0",number_of_networks,number_of_links);
+       XBT_DEBUG("Assign IP Addresses %s to CSMA.",adr);
+       Ipv4AddressHelper ipv4;
+       ipv4.SetBase (adr, "255.255.255.0");
+       interfaces.Add(ipv4.Assign (devices));
+
+       if(number_of_links == 255){
+               if(number_of_networks == 255)
+                       xbt_die("Number of links and networks exceed 255*255");
+               number_of_links = 1;
+               number_of_networks++;
+       }else{
+               number_of_links++;
+       }
+       XBT_DEBUG("Number of nodes in Cluster_nodes: %d",Cluster_nodes.GetN());
+}
+
 void * ns3_add_AS(char * id)
 {
        XBT_INFO("Interface ns3 add AS '%s'",id);
        return NULL;
 }
+
+void * ns3_add_link(int src,int dst,char * bw,char * lat)
+{
+       if(number_of_links == 1 ) {
+               LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
+               LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
+       }
+
+       PointToPointHelper pointToPoint;
+       NetDeviceContainer netA;
+       Ipv4AddressHelper address;
+
+       Ptr<Node> a = nodes.Get(src);
+       Ptr<Node> b = nodes.Get(dst);
+
+       XBT_DEBUG("\tAdd PTP from %d to %d bw:'%s' lat:'%s'",src,dst,bw,lat);
+       pointToPoint.SetDeviceAttribute ("DataRate", StringValue (bw));
+       pointToPoint.SetChannelAttribute ("Delay", StringValue (lat));
+       //pointToPoint.EnablePcapAll("test_ns3_trace"); //DEBUG
+
+       netA.Add(pointToPoint.Install (a, b));
+
+       char * adr = bprintf("10.%d.%d.0",number_of_networks,number_of_links);
+       address.SetBase (adr, "255.255.255.0");
+       XBT_DEBUG("\tInterface stack '%s'",adr);
+       interfaces.Add(address.Assign (netA));
+
+       XBT_DEBUG(" ");
+       if(number_of_links == 255){
+               if(number_of_networks == 255)
+                       xbt_die("Number of links and networks exceed 255*255");
+               number_of_links = 1;
+               number_of_networks++;
+       }else{
+               number_of_links++;
+       }
+}
+
+void * ns3_end_platform(void)
+{
+       XBT_INFO("InitializeRoutes");
+       GlobalRouteManager::BuildGlobalRoutingDatabase();
+       GlobalRouteManager::InitializeRoutes();
+       //TODO REMOVE ;)
+       Ptr<Node> a = nodes.Get(0);
+       Ptr<Node> b = nodes.Get(11);
+       Ptr<Node> c = nodes.Get(12);
+       Ptr<Node> d = nodes.Get(13);
+
+       UdpEchoServerHelper echoServer (9);
+
+       ApplicationContainer serverApps = echoServer.Install (a);
+       serverApps.Start (Seconds (1.0));
+       serverApps.Stop (Seconds (20.0));
+
+       UdpEchoClientHelper echoClient (interfaces.GetAddress (0), 9);
+       echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
+       echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
+       echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
+       ApplicationContainer clientApps_b = echoClient.Install (b);
+       clientApps_b.Start (Seconds (2.0));
+       clientApps_b.Stop (Seconds (10.0));
+
+       UdpEchoClientHelper echoClient2 (interfaces.GetAddress (0), 9);
+       echoClient2.SetAttribute ("MaxPackets", UintegerValue (1));
+       echoClient2.SetAttribute ("Interval", TimeValue (Seconds (1.)));
+       echoClient2.SetAttribute ("PacketSize", UintegerValue (512));
+       ApplicationContainer clientApps_c = echoClient2.Install (c);
+       clientApps_c.Start (Seconds (3.0));
+       clientApps_c.Stop (Seconds (10.0));
+
+       UdpEchoClientHelper echoClient3 (interfaces.GetAddress (0), 9);
+       echoClient3.SetAttribute ("MaxPackets", UintegerValue (1));
+       echoClient3.SetAttribute ("Interval", TimeValue (Seconds (1.)));
+       echoClient3.SetAttribute ("PacketSize", UintegerValue (256));
+       ApplicationContainer clientApps_d = echoClient3.Install (d);
+       clientApps_d.Start (Seconds (4.0));
+       clientApps_d.Stop (Seconds (10.0));
+
+       Simulator::Run ();
+       Simulator::Destroy ();
+
+       //HEEEEEEE
+}
index bbcb219..73780c0 100644 (file)
@@ -30,9 +30,12 @@ extern "C" {
 #endif
 
 XBT_PUBLIC(void *) ns3_add_host(char * id);
+XBT_PUBLIC(void *) ns3_add_host_cluster(char * id);
 XBT_PUBLIC(void *) ns3_add_router(char * id);
 XBT_PUBLIC(void *) ns3_add_AS(char * id);
-XBT_PUBLIC(void) ns3_add_cluster(char * id);
+XBT_PUBLIC(void *) ns3_add_link(int src,int dst,char * bw,char * lat);
+XBT_PUBLIC(void *) ns3_end_platform(void);
+XBT_PUBLIC(void *) ns3_add_cluster(char * bw,char * lat,char *id);
 #ifdef __cplusplus
 }
 #endif
index 4a049a4..6a89c34 100644 (file)
@@ -180,10 +180,43 @@ static void add_loopback_dijkstra(routing_component_dijkstra_t rc)
   }
 }
 
-/* Business methods */
+static route_extended_t dijkstra_get_route(routing_component_t rc,
+        const char *src,
+        const char *dst);
+
 static xbt_dynar_t dijkstra_get_onelink_routes(routing_component_t rc)
 {
-  xbt_die("\"dijkstra_get_onelink_routes\" function not implemented yet");
+ // xbt_die("\"dijkstra_get_onelink_routes\" function not implemented yet");
+         xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
+
+         routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc;
+         //size_t table_size = xbt_dict_length(routing->generic_routing.to_index);
+         xbt_dict_cursor_t c1 = NULL, c2 = NULL;
+         char *k1, *d1, *k2, *d2;
+         xbt_dict_foreach(routing->generic_routing.to_index, c1, k1, d1) {
+           xbt_dict_foreach(routing->generic_routing.to_index, c2, k2, d2) {
+             route_extended_t route = dijkstra_get_route(rc, k1, k2);
+             if (route) {
+               if (xbt_dynar_length(route->generic_route.link_list) == 1) {
+                 void *link =
+                     *(void **) xbt_dynar_get_ptr(route->generic_route.link_list,
+                                                  0);
+                 onelink_t onelink = xbt_new0(s_onelink_t, 1);
+                 onelink->link_ptr = link;
+                 if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE) {
+                   onelink->src = xbt_strdup(k1);
+                   onelink->dst = xbt_strdup(k2);
+                 } else if (routing->generic_routing.hierarchy ==
+                            SURF_ROUTING_RECURSIVE) {
+                   onelink->src = xbt_strdup(route->src_gateway);
+                   onelink->dst = xbt_strdup(route->dst_gateway);
+                 }
+                 xbt_dynar_push(ret, &onelink);
+               }
+             }
+           }
+         }
+         return ret;
 }
 
 static route_extended_t dijkstra_get_route(routing_component_t rc,
index a74ae31..fad6426 100644 (file)
@@ -221,6 +221,11 @@ static route_extended_t rulebased_get_route(routing_component_t rc,
 static xbt_dynar_t rulebased_get_onelink_routes(routing_component_t rc)
 {
   xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free);
+
+  //We have already bypass cluster routes with network NS3
+  if(!strcmp(surf_network_model->name,"network NS3"))
+       return ret;
+
   routing_component_rulebased_t routing = (routing_component_rulebased_t)rc;
 
   xbt_dict_cursor_t c1 = NULL;
index 3e99345..a700f82 100644 (file)
    <route src="host3" dst="host1" symmetrical="NO">
      <link_ctn id="link2"/>
    </route>
-      
-   <route src="host2" dst="host3" symmetrical="NO">
-     <link_ctn id="link3"/>
-   </route>
-   <route src="host3" dst="host2" symmetrical="NO">
-     <link_ctn id="link3"/>
-   </route>
-         
-   <route src="host3" dst="host4" symmetrical="NO">
-     <link_ctn id="link4"/>
-   </route>
-   <route src="host4" dst="host3" symmetrical="NO">
-     <link_ctn id="link4"/>
-   </route>
    
  </AS>
  </platform>
\ No newline at end of file
index 71843dc..381e5e4 100644 (file)
        <link id="link1" bandwidth="125000000000" latency="5E-5"/>
        <link id="link2" bandwidth="125000000" latency="5E-6"/>
        <link id="link3" bandwidth="125000" latency="5E-7"/>
-       <link id="link4" bandwidth="125" latency="5E-9"/>  
+       <link id="link4" bandwidth="1250" latency="5E-9"/>  
         
    <route src="host1" dst="host2">
      <link_ctn id="link1"/>
    </route>
-      
-   <route src="host1" dst="host3">
-     <link_ctn id="link2"/>
-   </route>
    
    <route src="host2" dst="host3">
      <link_ctn id="link3"/>