Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
01a4336eb06a815bc76f3cfbcb3f9d0af6773ad4
[simgrid.git] / src / surf / network_ns3.c
1 /* Copyright (c) 2007, 2008, 2009, 2010, 2011. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "surf_private.h"
8 #include "surf/ns3/ns3_interface.h"
9 #include "xbt/lib.h"
10
11 extern xbt_lib_t host_lib;
12 extern xbt_lib_t link_lib;
13 extern xbt_lib_t as_router_lib;
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network_ns3, surf,
16                                 "Logging specific to the SURF network NS3 module");
17
18 extern routing_global_t global_routing;
19
20 void parse_ns3_add_host(void)
21 {
22         XBT_DEBUG("NS3_ADD_HOST '%s'",A_surfxml_host_id);
23         xbt_lib_set(host_lib,
24                                 A_surfxml_host_id,
25                                 NS3_HOST_LEVEL,
26                                 ns3_add_host(A_surfxml_host_id)
27                                 );
28 }
29 void parse_ns3_add_link(void)
30 {
31         XBT_DEBUG("NS3_ADD_LINK '%s'",A_surfxml_link_id);
32         xbt_lib_set(link_lib,
33                                 A_surfxml_link_id,
34                                 NS3_LINK_LEVEL,
35                                 ns3_add_link(A_surfxml_link_id)
36                                 );
37 }
38 void parse_ns3_add_router(void)
39 {
40         XBT_DEBUG("NS3_ADD_ROUTER '%s'",A_surfxml_router_id);
41         xbt_lib_set(as_router_lib,
42                                 A_surfxml_router_id,
43                                 NS3_ASR_LEVEL,
44                                 ns3_add_router(A_surfxml_router_id)
45                                 );
46 }
47 void parse_ns3_add_AS(void)
48 {
49         XBT_DEBUG("NS3_ADD_AS '%s'",A_surfxml_AS_id);
50         xbt_lib_set(as_router_lib,
51                                 A_surfxml_AS_id,
52                                 NS3_ASR_LEVEL,
53                                 ns3_add_AS(A_surfxml_AS_id)
54                                 );
55 }
56 void parse_ns3_add_route(void)
57 {
58         XBT_DEBUG("NS3_ADD_ROUTE from '%s' to '%s'",A_surfxml_route_src,A_surfxml_route_dst);
59         ns3_add_route(A_surfxml_route_src,A_surfxml_route_dst);
60 }
61 void parse_ns3_add_ASroute(void)
62 {
63         XBT_DEBUG("NS3_ADD_ASROUTE from '%s' to '%s'",A_surfxml_ASroute_src,A_surfxml_ASroute_dst);
64         ns3_add_ASroute(A_surfxml_ASroute_src,A_surfxml_ASroute_dst);
65 }
66 void parse_ns3_add_cluster(void)
67 {
68         XBT_DEBUG("NS3_ADD_CLUSTER '%s'",A_surfxml_cluster_id);
69         routing_parse_Scluster();
70 }
71
72 void parse_ns3_end_platform(void)
73 {
74           xbt_lib_cursor_t cursor = NULL;
75           char *name = NULL;
76           void **data = NULL;
77           XBT_INFO("link_lib");
78           xbt_lib_foreach(link_lib, cursor, name, data) {
79                         XBT_INFO("\tSee link '%s'\t--> NS3_LEVEL %p",
80                                         name,
81                                         data[NS3_LINK_LEVEL]);
82           }
83           XBT_INFO(" ");
84           XBT_INFO("host_lib");
85           xbt_lib_foreach(host_lib, cursor, name, data) {
86                         XBT_INFO("\tSee host '%s'\t--> NS3_LEVEL %p",
87                                         name,
88                                         data[NS3_HOST_LEVEL]);
89           }
90           XBT_INFO(" ");
91           XBT_INFO("as_router_lib");
92           xbt_lib_foreach(as_router_lib, cursor, name, data) {
93                         XBT_INFO("\tSee ASR '%s'\t--> NS3_LEVEL %p",
94                                         name,
95                                         data[NS3_ASR_LEVEL]);
96           }
97 }
98
99 static void define_callbacks_ns3(const char *filename)
100 {
101   surfxml_add_callback(STag_surfxml_host_cb_list, &parse_ns3_add_host); //HOST
102   surfxml_add_callback(STag_surfxml_router_cb_list, &parse_ns3_add_router);     //ROUTER
103   surfxml_add_callback(STag_surfxml_link_cb_list, &parse_ns3_add_link); //LINK
104   surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_ns3_add_AS);             //AS
105   surfxml_add_callback(STag_surfxml_route_cb_list, &parse_ns3_add_route);       //ROUTE
106   surfxml_add_callback(STag_surfxml_ASroute_cb_list, &parse_ns3_add_ASroute);   //ASROUTE
107   surfxml_add_callback(STag_surfxml_cluster_cb_list, &parse_ns3_add_cluster); //CLUSTER
108
109   surfxml_add_callback(ETag_surfxml_platform_cb_list, &parse_ns3_end_platform); //DEBUG
110 }
111
112 void surf_network_model_init_NS3(const char *filename)
113 {
114         define_callbacks_ns3(filename);
115         surf_network_model = surf_model_init();
116         surf_network_model->name = "network NS3";
117
118         NS3_HOST_LEVEL = xbt_lib_add_level(host_lib,(void_f_pvoid_t)free_ns3_elmts);
119         NS3_ASR_LEVEL  = xbt_lib_add_level(as_router_lib,(void_f_pvoid_t)free_ns3_elmts);
120         NS3_LINK_LEVEL = xbt_lib_add_level(link_lib,(void_f_pvoid_t)free_ns3_elmts);
121
122         update_model_description(surf_network_model_description,
123                     "NS3", surf_network_model);
124 }