PadicoTM

Documentation

« back to PM2 home.
Topology.h
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
34#ifndef PADICO_TOPOLOGY_H
35#define PADICO_TOPOLOGY_H
36
37#include <Padico/Puk.h>
38#include <stdlib.h>
39#include <netinet/in.h>
40#include <errno.h>
41#include <netinet/tcp.h>
42
44#undef PADICO_LAST_MODULE_NAME
45#define PADICO_LAST_MODULE_NAME Topology
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/* ********************************************************* */
52/* *** Topology *************************************************** */
53
54/* Definitions for topology management:
55 * -- host: a machine, identified by a hostname.
56 * -- node: a computing node (ie. process). There may
57 * be several nodes per host. A node is identified
58 * by a nodename.
59 * -- network: a list (order matters) of nodes or hosts with
60 * bindings between network and nodes/hosts.
61 * Binding address may be rank-based (nodes) or
62 * in_addr-based (hosts).
63 *
64 */
65
66
71/* *** Types */
72
73#define PADICO_TOPO_UUID_SIZE 32
74typedef const struct topo_uuid_s*padico_topo_uuid_t;
83
88
89/* *** Addresses and bindings */
90
98
107
117#define PADICO_TOPO_FILTER_MASK_IN (PADICO_TOPO_FILTER_BLOCK_IN | PADICO_TOPO_FILTER_ALLOW_IN)
118#define PADICO_TOPO_FILTER_MASK_OUT (PADICO_TOPO_FILTER_BLOCK_OUT | PADICO_TOPO_FILTER_ALLOW_OUT)
119#define PADICO_TOPO_FILTER_MASK_BLOCK (PADICO_TOPO_FILTER_BLOCK_IN | PADICO_TOPO_FILTER_BLOCK_OUT)
120#define PADICO_TOPO_FILTER_MASK_ALLOW (PADICO_TOPO_FILTER_ALLOW_IN | PADICO_TOPO_FILTER_ALLOW_AOUT)
121
122#define PORT_ANY 0
123
124 /* *** Host ********************************************** */
125
128 padico_topo_host_t padico_topo_host_create(const char*hostname);
129
133 void padico_topo_host_add_name(padico_topo_host_t host, const char*name, int resolvable);
134
138
141 void padico_topo_host_add_property(padico_topo_host_t host, const char*label, const char*name);
142
145 padico_topo_host_t padico_topo_host_resolve_byinaddr(const struct in_addr*addr);
146
149 padico_topo_host_t padico_topo_host_getbyinaddr(const struct in_addr*addr);
150
154
158
162
166
170
173 const struct in_addr* padico_topo_host_getaddr(padico_topo_host_t host);
174
178
182
186
190
194
197 const char*padico_topo_host_getproperty(padico_topo_host_t host, const char*label);
198
202
206
209
213
216
225
226 /* *** Nodes ********************************************* */
227
231
235
239
243
247
251
255
259
263
267
268
269 /* *** Networks ****************************************** */
270
271 padico_topo_network_t padico_topo_network_create(const char*id, padico_topo_binding_scope_t scope, size_t addr_size, int family);
272
274
278
287
291
293
295
297
299
300 /* *** serialization ************************************* */
301
306
307
308 /* *** address *******************************************/
309
311
312
313 /* *** local info *****************************************/
314
316
317#define padico_topo_nodename() padico_topo_node_getname(padico_topo_getlocalnode())
318#define padico_topo_nodealias() padico_topo_node_getalias(padico_topo_getlocalnode())
319#define padico_topo_getlocalhost() padico_topo_node_gethost(padico_topo_getlocalnode())
320#define padico_topo_hostname() padico_topo_host_getname(padico_topo_getlocalhost())
321#define padico_topo_session() padico_topo_node_getsession(padico_topo_getlocalnode())
322 /* *** backward compatibility */
323#define padico_na_size() padico_topo_network_size(padico_topo_session_getnetwork(padico_topo_session()))
324#define padico_na_rank() padico_topo_session_getrank(padico_topo_session(), padico_topo_getlocalnode())
325
326
327
328 /* *** session ********************************************/
329
352
353 /* *** hwaddr ********************************************/
354
355 padico_topo_hwaddr_t padico_topo_hwaddr_create(const char*name, int index, int type, size_t len, const void*addr);
356
357 void padico_topo_hwaddr_get(padico_topo_hwaddr_t hwaddr, const char**name, int*index, int*type, size_t*len, const void**addr);
358
360
362
363 /* *** bindings ********************************************/
364
365 void padico_topo_binding_add_addr(padico_topo_binding_t binding, const void*addr);
366
368
370
372
374
376
378
380
382
384
386
387 /* *** address visibility ********************************/
388
390
392
393
394
395/* ********************************************************* */
396/* *** Padico addresses as sockaddr ************************ */
397
398/* padico_sockaddr (struct sockaddr_pa) define a new AF_PADICO
399 * address space for Padico-to-Padico communications with
400 * non-interoperable methods.
401 */
402
403typedef union
404{
405 char bytes[4];
408
409#define AF_PADICO (AF_MAX + 1) /* just to make sure that AF_PADICO addresses
410 are never leaked into the OS... */
411#define PF_PADICO AF_PADICO
412
413/* make uint32_t from bytes */
414#define AF_PADICO_MAGIC(B1, B2, B3, B4) \
415 (((padico_address_kind_t){ .bytes = { B1, B2, B3, B4 } }).integer)
416/* make address_kind_t from uint32_t */
417#define AF_PADICO_MAKE(I) \
418 ((padico_address_kind_t){ .integer = (I) })
419/* make bytes from uint32_t */
420#define AF_PADICO_REVERSE(I) \
421 ((AF_PADICO_MAKE(I)).bytes)
422
423/* embed an AF_INET address into an AF_PADICO */
424#define AF_PADICO_INET AF_PADICO_MAGIC('I', 'N', 'E', 'T')
425/* embed an AF_UNIX address into an AF_PADICO */
426#define AF_PADICO_UNIX AF_PADICO_MAGIC('U', 'N', 'I', 'X')
427/* requests an autobind (only suitable as *input* for bind(), should not be returned by bind()). */
428#define AF_PADICO_AUTO AF_PADICO_MAGIC('A', 'U', 'T', 'O')
430#define AF_PADICO_PAYLOAD 64
432struct sockaddr_pa
434 sa_family_t spa_family; /* =AF_PADICO, host byte order */
435 uint32_t spa_magic; /* magic number for sub-family, host byte order */
436 unsigned char spa_payload[AF_PADICO_PAYLOAD];
437};
438
439
440void padico_sockaddr_init(struct sockaddr_pa*addr, socklen_t*addrlen, int magic);
442#define padico_sockaddr_payload(TYPE, ADDRESS) \
443 ( assert(sizeof(TYPE) <= AF_PADICO_PAYLOAD), \
444 (TYPE*)(((struct sockaddr_pa*)(ADDRESS))->spa_payload) )
446#define padico_sockaddr_magic(ADDRESS) \
447 ( assert(((struct sockaddr_pa*)(ADDRESS))->spa_family == AF_PADICO), \
448 ((struct sockaddr_pa*)(ADDRESS))->spa_magic )
449
450int padico_sockaddr_check(const struct sockaddr_pa*addr, int magic);
451
452
453/* ********************************************************* */
454/* *** Padico vaddr **************************************** */
455
456/* Padico vaddr (padico_vaddr_t) is a generic address used for
457 * transmissions. It is mainly a packed, self-contained and
458 * serializable form of struct sockaddr.
459 */
466};
468typedef struct padico_vaddr_s*padico_vaddr_t;
469
472
473/* C++ doesn't like inlined GNU extensions */
474#ifndef __cplusplus
476{
478 *vaddr = (struct padico_vaddr_s)
479 {
480 .addr = addr,
481 .addrlen = addrlen,
482 .proto = proto
483 };
484 return vaddr;
486static inline void padico_vaddr_delete(padico_vaddr_t vaddr)
487{
489}
490#endif /* __cplusplus */
491
492
493
496#ifdef __cplusplus
497} /* extern "C" */
498#endif
499
500#endif /* PADICO_TOPOLOGY_H */
ssize_t n
return NULL
Definition Shm.h:88
PUK_MOD_AUTO_DEP(SysIO, PADICO_LAST_MODULE_NAME)
padico_topo_host_t host
padico_topo_host_t const char * uuid
#define PADICO_LAST_MODULE_NAME
Definition Topology.h:45
static int done
Definition console-mod.c:49
padico_topo_node_vect_t nodes
static int rank
Definition datacheck.c:35
char * name
Definition PadicoTM.h:168
int padico_topo_host_can_output(padico_topo_host_t host, padico_topo_network_t network, uint16_t port, int protocol)
Verify if the port is filtered output between host and network.
Definition topology.c:2154
padico_string_t padico_topo_node_serialize(padico_topo_node_t node)
Definition topo-xml.c:168
static padico_topo_node_t padico_topo_host_getnode(padico_topo_host_t host)
Get the first node of a host.
Definition Topology.h:220
static int padico_topo_session_getrank(const char *session_id, padico_topo_node_t node)
Definition Topology.h:344
#define AF_PADICO_PAYLOAD
Definition Topology.h:429
int padico_sockaddr_check(const struct sockaddr_pa *addr, int magic)
Definition topology.c:337
void padico_topo_network_get_perf(padico_topo_network_t n, int *latency_nsec, int *bandwidth_kbps)
Definition topology.c:2333
padico_topo_host_vect_t padico_topo_gethosts()
Get known hosts.
Definition topology.c:2211
void padico_topo_binding_add_perf(padico_topo_binding_t binding, int latency, int bandwidth)
Definition topology.c:273
padico_topo_node_t padico_topo_network_getnodebyaddr(padico_topo_network_t network, const void *addr)
Get a node descriptor from an address.
Definition topology.c:2382
int padico_topo_network_can_output(padico_topo_network_t subnet, padico_topo_network_t network, uint16_t port, int protocol)
Definition topology.c:2170
const struct topo_uuid_s * padico_topo_uuid_t
Definition Topology.h:74
padico_topo_node_vect_t padico_topo_host_getnodes(padico_topo_host_t host)
Get the nodes on a host.
Definition topology.c:2049
static padico_topo_node_t padico_topo_session_getnodebyrank(const char *session_id, int rank)
Definition Topology.h:338
void padico_topo_binding_add_addr(padico_topo_binding_t binding, const void *addr)
Definition topology.c:183
struct padico_vaddr_s * padico_vaddr_t
Definition Topology.h:467
int padico_topo_host_can_input(padico_topo_host_t host, padico_topo_network_t network, uint16_t port, int protocol)
Verify if the port is filtered input between host and network.
Definition topology.c:2146
void padico_topo_host_add_name(padico_topo_host_t host, const char *name, int resolvable)
Add a name to a host;.
Definition topology.c:1525
static padico_topo_network_t padico_topo_session_getnetwork(const char *session_id)
Definition Topology.h:330
void padico_topo_node_getnetworks(padico_topo_node_t node, padico_topo_network_vect_t networks)
Get the networks a node is connected to.
Definition topology.c:1932
int padico_topo_network_size(padico_topo_network_t network)
Definition topology.c:2237
typdef struct padico_topo_binding_vect_s * padico_topo_binding_vect_t
Definition Topology.h:87
void padico_topo_host_add_service(padico_topo_host_t host, const char *service_name, uint16_t service_port)
Add a service to a host.
Definition topology.c:1570
padico_topo_addr_visibility_t
Definition Topology.h:100
padico_string_t padico_topo_host_serialize(padico_topo_host_t host)
Definition topo-xml.c:184
padico_topo_network_t padico_topo_network_create(const char *id, padico_topo_binding_scope_t scope, size_t addr_size, int family)
Definition topology.c:1853
padico_topo_host_t padico_topo_host_resolve_byinaddr(const struct in_addr *addr)
Get a host description record from an inet address (create if it didn't exist)
Definition topology.c:2452
padico_topo_host_t padico_topo_network_gethostbyaddr(padico_topo_network_t, const void *)
Get a host description record from an address.
Definition topology.c:2414
void padico_sockaddr_init(struct sockaddr_pa *addr, socklen_t *addrlen, int magic)
Definition topology.c:329
padico_string_t padico_na_topology_serialize(padico_topo_binding_scope_t scope)
Definition topo-xml.c:240
static padico_vaddr_t padico_vaddr_new(struct sockaddr *addr, socklen_t addrlen, int proto)
Definition Topology.h:474
padico_topo_node_t padico_topo_getlocalnode(void)
Definition topology.c:1891
const char * padico_topo_node_getname(padico_topo_node_t node)
Get the canonical name of a node.
Definition topology.c:1917
padico_topo_host_t padico_topo_node_gethost(padico_topo_node_t node)
Get the host hosting a node.
Definition topology.c:1927
typdef struct padico_topo_host_vect_s * padico_topo_host_vect_t
Definition Topology.h:86
padico_topo_filter_policy_t
Definition Topology.h:109
const struct topo_address_s * padico_topo_address_t
Definition Topology.h:80
padico_topo_binding_vect_t padico_topo_host_getbindings(padico_topo_host_t host, padico_topo_network_t network)
Get the bindings of a host on a network.
Definition topology.c:2020
padico_topo_host_t padico_topo_host_getbyin6addr(const struct in6_addr *addr)
Get a host from an inet6 address (return NULL if host doesn't exist).
Definition topology.c:2438
padico_string_t padico_vaddr_marshall(const struct padico_vaddr_s *)
Definition topo-vaddr.c:46
padico_topo_address_t padico_topo_node_getaddress(padico_topo_node_t node, padico_topo_network_t network)
Get the address of the node in the given network.
Definition topology.c:1898
padico_topo_network_vect_t padico_topo_networks_getbyfamily(int family)
Get networks of a given address family (e.g.
Definition topology.c:2365
void padico_topo_host_getnetworks(padico_topo_host_t host, padico_topo_network_vect_t networks)
Get the networks a host is connected to.
Definition topology.c:2054
void padico_topo_binding_add_gw_addr(padico_topo_binding_t binding, struct in_addr *inaddr)
Definition topology.c:213
padico_topo_hwaddr_t padico_topo_hwaddr_create(const char *name, int index, int type, size_t len, const void *addr)
Definition topology.c:126
const char * padico_topo_network_getname(padico_topo_network_t network)
Definition topology.c:2233
const char * padico_topo_host_getproperty(padico_topo_host_t host, const char *label)
Get property on a host.
Definition topology.c:2195
struct topo_service_s * padico_topo_service_t
Definition Topology.h:82
padico_topo_network_t padico_topo_network_getbyid(const char *network_id)
Definition topology.c:2351
struct topo_network_s * padico_topo_network_t
Definition Topology.h:77
const char * padico_topo_host_getname2(padico_topo_host_t host, padico_topo_network_t network)
Get the canonical name of a host on a network.
Definition topology.c:1949
void padico_topo_binding_add_hostname(padico_topo_binding_t binding, const char *name)
Definition topology.c:240
void padico_topo_binding_add_filter(padico_topo_binding_t binding, padico_topo_filter_policy_t policy, uint16_t port, int protocol)
Definition topology.c:262
padico_topo_host_t padico_topo_host_getbyinaddr(const struct in_addr *addr)
Get a host from an inet address (return NULL if host doesn't exist).
Definition topology.c:2424
void padico_topo_hwaddr_get(padico_topo_hwaddr_t hwaddr, const char **name, int *index, int *type, size_t *len, const void **addr)
Definition topology.c:139
padico_topo_addr_visibility_t padico_topo_inet6_visibility(const struct in6_addr *in6addr)
Definition topology.c:1215
struct topo_node_s * padico_topo_node_t
Definition Topology.h:76
void padico_topo_network_set_perf(padico_topo_network_t n, int latency_nsec, int bandwidth_kbps)
Definition topology.c:2324
void padico_topo_node_disconnect(padico_topo_node_t node)
Remove a disconnected node from topology.
Definition topology.c:2766
int padico_topo_network_contains_node(padico_topo_network_t network, padico_topo_node_t node)
tests whether the given node belong to the network
Definition topology.c:2259
const struct in_addr * padico_topo_host_getaddr(padico_topo_host_t host)
Get the canonical IP address of a host.
Definition topology.c:1977
const void * padico_topo_address_getbytes(padico_topo_address_t address)
Definition topology.c:2342
typdef struct padico_topo_node_vect_s * padico_topo_node_vect_t
Definition Topology.h:84
void padico_topo_network_gethosts(padico_topo_network_t n, padico_topo_host_vect_t hosts)
Definition topology.c:2284
padico_topo_uuid_t padico_topo_node_getuuid(padico_topo_node_t node)
Get the UUID of a node.
Definition topology.c:1912
padico_topo_host_t padico_topo_host_create(const char *hostname)
Create new host.
Definition topology.c:1463
void padico_topo_network_get_common_host(padico_topo_network_t n1, padico_topo_network_t n2, padico_topo_host_vect_t hosts)
Definition topology.c:2300
padico_topo_binding_scope_t
Definition Topology.h:92
padico_topo_binding_t padico_topo_node_bind(padico_topo_node_t node, padico_topo_network_t network, const void *address)
Declare a new binding for a node.
Definition topology.c:1618
int padico_topo_network_can_input(padico_topo_network_t subnet, padico_topo_network_t network, uint16_t port, int protocol)
Definition topology.c:2162
padico_vaddr_t padico_vaddr_unmarshall(const char *)
Definition topo-vaddr.c:93
void padico_topo_hwaddr_add(padico_topo_host_t host, padico_topo_hwaddr_t *_hwaddr)
Definition topology.c:153
padico_topo_host_t padico_topo_host_resolve_byin6addr(const struct in6_addr *addr)
Get a host description record from an inet6 address (create if it didn't exist)
Definition topology.c:2466
void padico_topo_binding_add_index(padico_topo_binding_t binding, int64_t index)
Definition topology.c:205
void padico_topo_binding_get_perf(padico_topo_binding_t binding, int *latency_nsec, int *bandwidth_kbps)
Definition topology.c:282
padico_string_t padico_topo_network_serialize(padico_topo_network_t net)
Definition topo-xml.c:220
padico_topo_addr_visibility_t padico_topo_inet_visibility(in_addr_t _inaddr)
Definition topology.c:1197
void padico_topo_hwaddr_destroy(padico_topo_hwaddr_t hwaddr)
Definition topology.c:175
int padico_topo_host_getservice(padico_topo_host_t host, char *service_name)
Get the service port of the service on a host.
Definition topology.c:2178
padico_topo_node_t padico_topo_getnodebyname(const char *nodename)
node lookup, by node name
Definition topology.c:2389
struct topo_filter_s * padico_topo_filter_t
Definition Topology.h:81
struct topo_binding_s * padico_topo_binding_t
Definition Topology.h:78
struct topo_host_s * padico_topo_host_t
Definition Topology.h:75
padico_topo_node_t padico_topo_getnodebyuuid(padico_topo_uuid_t uuid)
node lookup, by UUID
Definition topology.c:2407
const char * padico_topo_host_getname(padico_topo_host_t host)
Get the canonical name of a host.
Definition topology.c:1944
padico_topo_binding_t padico_topo_host_bind(padico_topo_host_t host, padico_topo_network_t network, const void *address)
Declare a new binding for a host.
Definition topology.c:1609
void padico_topo_host_add_property(padico_topo_host_t host, const char *label, const char *name)
Add a property to a host.
Definition topology.c:1595
static void padico_vaddr_delete(padico_vaddr_t vaddr)
Definition Topology.h:485
padico_topo_hwaddr_t padico_topo_binding_gethwaddr(padico_topo_binding_t binding)
Definition topology.c:299
const struct in_addr * padico_topo_host_getaddr2(padico_topo_host_t host, padico_topo_network_t network)
Get the canonical IP address of a host on a network.
Definition topology.c:2034
padico_topo_host_t padico_topo_host_resolvebyname(const char *hostname)
Get a host description record (lookup in cache, create if it didn't exist)
Definition topology.c:2681
void padico_topo_binding_add_route(padico_topo_binding_t binding, padico_topo_network_t dest, const void *gwaddr)
Definition topology.c:248
int padico_topo_binding_get_index(padico_topo_binding_t binding, int64_t *index)
Definition topology.c:313
typdef struct padico_topo_network_vect_s * padico_topo_network_vect_t
Definition Topology.h:85
const char * padico_topo_node_getsession(padico_topo_node_t node)
Get the boot session ID.
Definition topology.c:1922
void padico_topo_binding_add_hwaddr(padico_topo_binding_t binding, padico_topo_hwaddr_t hwaddr)
Definition topology.c:196
const struct topo_hwaddr_s * padico_topo_hwaddr_t
Definition Topology.h:79
@ PADICO_TOPO_ADDR_VISIBILITY_PRIVATE
private address- some node/host cannot see it
Definition Topology.h:104
@ PADICO_TOPO_ADDR_VISIBILITY_PUBLIC
public address
Definition Topology.h:105
@ PADICO_TOPO_ADDR_VISIBILITY_NONE
Definition Topology.h:101
@ PADICO_TOPO_ADDR_VISIBILITY_LOOPBACK
loopback address- only local node/host can see it
Definition Topology.h:102
@ PADICO_TOPO_ADDR_VISIBILITY_LINKLOCAL
link-local address- nodes on the same physical link can see it
Definition Topology.h:103
@ PADICO_TOPO_FILTER_ALLOW_OUT
Definition Topology.h:114
@ _PADICO_TOPO_FILTER_MAX
Definition Topology.h:115
@ PADICO_TOPO_FILTER_BLOCK_OUT
Definition Topology.h:112
@ PADICO_TOPO_FILTER_BLOCK_IN
Definition Topology.h:111
@ PADICO_TOPO_FILTER_ALLOW_IN
Definition Topology.h:113
@ _PADICO_TOPO_FILTER_NONE
Definition Topology.h:110
@ PADICO_TOPO_SCOPE_HOST
Definition Topology.h:95
@ PADICO_TOPO_SCOPE_ALL
Definition Topology.h:96
@ PADICO_TOPO_SCOPE_NODE
Definition Topology.h:94
@ PADICO_TOPO_SCOPE_NONE
Definition Topology.h:93
padico_topo_node_t node
Definition na-control.c:65
static const uint8_t magic[4]
Definition ps.c:80
padico_topo_network_t network
Definition psp-mx.c:113
socklen_t addrlen
Definition Topology.h:463
struct sockaddr * addr
Definition Topology.h:462
uint32_t spa_magic
Definition Topology.h:434
sa_family_t spa_family
Definition Topology.h:433
unsigned char spa_payload[64]
Definition Topology.h:435
a network address used in bindings
a binding of an entity with a network (protocol level)
a filter rule, i.e a port number, and a policy
a hardware address- identifies a host
a network, containing entities with bindings
a service which running on a host
Node UUID, in plain text (hex encoding)
static int port
Definition vrp-test.c:15