PadicoTM

Documentation

« back to PM2 home.
topo-print.c
Go to the documentation of this file.
1/*
2 * Padico -- a High Performance Parallel and Distributed Computing Environment
3 * Copyright (c) 2002-2025 INRIA and the University of Rennes 1
4 * Alexandre DENIS <Alexandre.Denis@inria.fr>
5 * Christian PEREZ <Christian.Perez@inria.fr>
6 *
7 * The software has been registered at the Agency for the Protection of
8 * Programs (APP) under the number IDDN.FR.001.260013.000.S.P.2002.000.10000.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
31#include "Topology.h"
32#include "Topology-internals.h"
33#include <Padico/Puk.h>
34#include <Padico/PadicoTM.h>
35#include <Padico/Module.h>
36
37#include <stdio.h>
38#include <arpa/inet.h>
39#include <netdb.h>
40#ifdef HAVE_CGRAPH
41#include <graphviz/cgraph.h>
42#endif /* HAVE_CGRAPH */
43
44static int padico_topo_print_main(int argc, char**argv);
45
47
48static FILE* padico_topo_print_open_file(const char*filename, char*wanted)
49{
50 FILE*f = NULL;
51 const char*ext = strrchr(filename, '.');
52 if(strcmp(filename, "-") == 0)
53 return stdout;
54 else if(!ext || (ext && strncmp(ext+1, wanted, strlen(wanted))))
55 {
57 padico_string_catf(filename_s,"%s.%s", filename, wanted);
60 }
61 else
62 f = fopen(filename, "w+");
63 return f;
64}
65
67{
69 fprintf(f, "<Topology:topology xmlns:Topology=\"http://runtime.bordeaux.inria.fr/PadicoTM/Topology\">\n"
70 "%s"
71 "</Topology:topology>\n", padico_string_get(topology));
73}
74
75#ifdef HAVE_CGRAPH
77{
80 {
81 if((*p)->kind == TOPO_PROPERTY_ADDR)
82 {
83 const struct topo_address_s*addr = &(*p)->content.ADDR.addr;
84 size_t addr_size = b->network->addr_size;
85 return puk_hex_encode(addr->_addr_storage, &addr_size, NULL);
86 }
87 }
88 return NULL;
89}
90
92{
94 agsafeset(host_node, "shape", "record", "");
97 padico_string_catf(label, "|{");
99 int first = 1;
101 {
102 const struct topo_binding_s*b = *i;
105 {
106 if((*p)->kind == TOPO_PROPERTY_ADDR)
107 {
108 char*s_addr = NULL;
109 const char*ret = NULL;
110 const struct topo_address_s*addr = &(*p)->content.ADDR.addr;
111 if(addr->family == AF_INET)
112 {
115 }
116 else if(addr->family == AF_INET6)
117 {
120 }
121 else
122 {
123 s_addr = padico_strdup(" ");
124 ret = s_addr;
125 }
126 if(ret != NULL)
127 {
128 char*find= NULL;
130 size_t addr_size = b->network->addr_size;
131 char*hex_addr = puk_hex_encode(addr->_addr_storage, &addr_size, NULL);
135 if(!find)
136 {
137 if(first)
138 {
140 first = 0;
141 }
142 else
144 }
146 }
147 if(s_addr != NULL)
149 }
150 }
151 }
152 padico_string_catf(label, "}");
153 agsafeset(host_node, "label", padico_string_get(label), "");
155 return host_node;
156}
157
159{
160 setprotoent(1);
164 {
165 if((*p)->kind == TOPO_PROPERTY_FILTER)
166 {
167 const padico_topo_filter_t filter = &(*p)->content.FILTER.filter;
168 const char*proto_name = topo_filter_protocol_getname(filter->protocol);
169 padico_string_catf(label, "%s: %s port %d\\n",
171 }
172 }
173 endprotoent();
174 return label;
175}
176
177static void padico_topo_print_dot(FILE*f)
178{
179 Agraph_t* topo = agopen("topology", Agstrictundirected, NULL);
180 /* graph attributes*/
181 agattr(topo, AGRAPH, "ranksep", "5");
182 agattr(topo, AGRAPH, "rankdir", "RL");
183 /* node attributes*/
184 agattr(topo, AGNODE, "color", "");
185 agattr(topo, AGNODE, "shape", "");
186 agattr(topo, AGNODE, "style", "");
187 agattr(topo, AGNODE, "label", "");
188 agattr(topo, AGNODE, "fontsize", "");
189 /* edge attributes*/
190 agattr(topo, AGEDGE, "labelfontsize", "5");
191 agattr(topo, AGEDGE, "label", "");
192 agattr(topo, AGEDGE, "labeldistance", "2");
193 agattr(topo, AGEDGE, "headlabel", "");
194 agattr(topo, AGEDGE, "taillabel", "");
195 agattr(topo, AGEDGE, "headport", "");
196 agattr(topo, AGEDGE, "len", "3");
197 agattr(topo, AGEDGE, "dir", "");
198 agattr(topo, AGEDGE, "arrowhead", "");
202 {
204 agsafeset(host_node, "fontsize", "5", "");
206 puk_vect_foreach(i, padico_topo_binding, &((*h)->bindings))
207 {
208 const padico_topo_binding_t b = *i;
209 if(b->network->scope == PADICO_TOPO_SCOPE_HOST)
210 {
212 agsafeset(network_node, "shape", "hexagon","");
213 agsafeset(network_node, "style", "filled", "");
214 agsafeset(network_node, "color", "lightskyblue1", "");
217 if(headport)
218 {
219 agsafeset(edge, "headport", headport, "");
221 }
222 if(b->network->uplink != NULL)
223 {
224 Agnode_t*uplink_node = agnode(topo, (char*)padico_topo_network_getname(b->network->uplink->network), 1);
225 agsafeset(uplink_node, "shape", "hexagon","");
226 agsafeset(uplink_node, "style", "filled", "");
227 agsafeset(uplink_node, "color", "lightskyblue1", "");
230 agsafeset(edge, "taillabel", padico_string_get(filter), "");
232 }
233 }
234 }
235 }
237
238 agwrite(topo, f);
239 agclose(topo);
240}
241#endif /* HAVE_CGRAPH */
242
243static int padico_topo_print_main(int argc, char**argv)
244{
245 if(padico_na_rank() == 0)
246 {
247 FILE*f = stdout;
248 if(argc < 2)
249 {
250 printf("Topo_Print: Usage: Topo_Print <format> <filename>\n");
251 printf("Topo_Print: <format> can be:\n"
252 "Topo_Print: padico: the native PadicoTM Topology format\n"
254 "Topo_Print: dot: a representation of topology usable by graphviz tools\n"
255#else
256 " (graphviz not detected)\n"
257#endif /* HAVE_CGRAPH */
258 "Topo_Print: <filename>: file to write to. Give '-' for stdout.\n"
259 );
260 return 0;
261 }
262 const char* format = argv[1];
263 if(!strncmp(format, "padico", 6))
264 {
265 if(argc >= 3)
266 f = padico_topo_print_open_file(argv[2], "xml");
267 if(f == NULL)
268 {
269 printf("Topo_Print: cannot open file:%s\n", argv[2]);
270 return 1;
271 }
273 }
274#ifdef HAVE_CGRAPH
275 else if(!strncmp(format, "dot", 3))
276 {
277 if(argc >= 3)
278 f = padico_topo_print_open_file(argv[2], "dot");
279 if(f == NULL)
280 {
281 printf("Topo_Print: cannot open file:%s\n", argv[2]);
282 return 1;
283 }
285 }
286#endif /* HAVE_CGRAPH */
287 else
288 {
289 printf("Topo_Print: unrecognized output format *%s*\n", format);
290 }
291 if(f != stdout)
292 fclose(f);
293 }
294 return 0;
295}
ns_rulebucket_hashtable_t h
struct ns_rulebucket_hash_entry_s * b
return NULL
Definition Shm.h:88
puk_tagged_ptr_t p
Definition Shm.h:88
internal definitions for module Topology
padico_topo_host_t host
@ TOPO_PROPERTY_ADDR
protocol address for the binding
@ TOPO_PROPERTY_FILTER
filtering- TODO
static const char * topo_filter_policy_getname(padico_topo_filter_policy_t policy)
static const char * topo_filter_protocol_getname(int protocol)
frontend for getprotobynumber(), working even in the absence of /etc/protocols
Topology description API.
static int done
Definition console-mod.c:49
padico_thread_fun_t f
Definition PadicoTM.h:166
padico_topo_host_vect_t padico_topo_gethosts(void)
Get known hosts.
Definition topology.c:2211
padico_string_t padico_na_topology_serialize(padico_topo_binding_scope_t scope)
Definition topo-xml.c:240
typdef struct padico_topo_host_vect_s * padico_topo_host_vect_t
Definition Topology.h:86
const char * padico_topo_network_getname(padico_topo_network_t network)
Definition topology.c:2233
const char * padico_topo_host_getname(padico_topo_host_t host)
Get the canonical name of a host.
Definition topology.c:1944
#define padico_na_rank()
Definition Topology.h:324
@ PADICO_TOPO_SCOPE_HOST
Definition Topology.h:95
const uint32_t filter
Definition psp-mx.c:118
a network address used in bindings
char _addr_storage[1]
placeholder for address- more bytes are actually allocated
int family
address family, using AF_*
a binding of an entity with a network (protocol level)
a filter rule, i.e a port number, and a policy
struct padico_topo_binding_vect_s bindings
protocol bindings
static int padico_topo_print_main(int argc, char **argv)
Definition topo-print.c:243
static FILE * padico_topo_print_open_file(const char *filename, char *wanted)
Definition topo-print.c:48
static void padico_topo_print_padico(FILE *f)
Definition topo-print.c:66