PadicoTM

Documentation

« back to PM2 home.
nsbe-route.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
30#include <Padico/Puk.h>
31#include <Padico/Topology.h>
32#include <Padico/Module.h>
33
34PADICO_MODULE_HOOK(NetSelector_besteffort);
35
36/* ********************************************************* */
37
39
41#define NSBE_UNREACHABLE (1024*1024)
42
51
52
61
65
67{
68 assert((host == NULL) || (network == NULL));
69 assert(!((host == NULL) && (network == NULL)));
70 void*entity = (host == NULL) ? (void*)network : (void*)host;
72 if(v == NULL)
73 {
74 v = padico_malloc(sizeof(struct nsbe_dijkstra_vertex_s));
75 v->weight = NSBE_UNREACHABLE;
76 v->host = host;
77 v->network = network;
78 v->previous = NULL;
81 }
82 return v;
83}
84
87{
88 struct nsbe_dijkstra_s*d = padico_malloc(sizeof(struct nsbe_dijkstra_s));
92 /* add local and dest hosts */
93 d->dest_v = nsbe_dijkstra_vertex_add(vertices, dest, NULL);
95 d->local_v->weight = 0;
96 /* add known hosts running sshd */
100 {
101 if(padico_topo_host_getservice(*h, "ssh"))
102 {
104 }
105 }
107 /* add known networks */
111 {
118 {
120 if(v_host)
121 {
123 {
125 }
127 {
129 }
130 }
131 }
135 {
138 {
140 }
142 {
144 }
145 }
146 }
148 /* flatten hashtable */
153 while(v)
154 {
157 }
160 return d;
161}
162
164{
165 int min = NSBE_UNREACHABLE;
169 {
170 struct nsbe_dijkstra_vertex_s*v = *i;
171 if((min == NSBE_UNREACHABLE) || ((v->weight < min) && (v->weight != NSBE_UNREACHABLE)))
172 {
173 min = v->weight;
174 min_v = v;
175 }
176 }
180 return min_v;
181}
182
201
204{
205 int rc = 0;
206 struct nsbe_dijkstra_s*d = nsbe_dijkstra_init(dest);
208 {
210 padico_out(10, "loop min = %d (%p [%s])\n", v?v->weight:NSBE_UNREACHABLE, v,
211 (v && v->host)?padico_topo_host_getname(v->host):((v && v->network)?padico_topo_network_getname(v->network):"-"));
212 if(v == d->dest_v && padico_topo_host_getservice(dest, "ssh"))
213 {
214 padico_out(10, "reached destination host %s.\n", padico_topo_host_getname(v->host));
215 break;
216 }
217 if(v && v->network)
218 {
219 /* check whether network (previous host) can connect to destination */
220 if(padico_topo_host_can_input(dest, v->network, PORT_ANY, IPPROTO_TCP) &&
221 padico_topo_host_can_output(v->previous->host, v->network, PORT_ANY, IPPROTO_TCP))
222 {
223 padico_out(10, "network %s (%p) can reach destination node.\n", padico_topo_network_getname(v->network), v);
224 d->dest_v->weight = v->weight + 1;
225 d->dest_v->previous = v;
226 break;
227 }
228 }
229 if(v == d->dest_v)
230 {
231 padico_out(10, "destination host without ssh service. Skip.\n");
232 continue;
233 }
236 {
237 struct nsbe_dijkstra_vertex_s*v2 = *i;
238 if((v2->weight > v->weight + 1) || (v2->weight == NSBE_UNREACHABLE))
239 {
240 v2->weight = v->weight + 1;
241 v2->previous = v;
242 }
243 }
244 }
245 padico_out(10, "exit loop- weight = %d. Rolling back route:\n", d->dest_v->weight);
246 if(d->dest_v->weight != NSBE_UNREACHABLE)
247 {
248 /* build route from annotated graph */
250 assert(d->dest_v->previous != NULL);
251 *dest_n = d->dest_v->previous->network;
252 struct nsbe_dijkstra_vertex_s*v = d->dest_v;
253 while(v->previous)
254 {
255 if(v->host)
256 {
257 padico_out(40, " - push host %s (%p)\n", padico_topo_host_getname(v->host), v);
259 }
260 else if(v->network)
261 {
262 padico_out(40, " - network %s (%p)\n", padico_topo_network_getname(v->network), v);
263 }
264 assert(v->previous != v);
265 v = v->previous;
266 }
267 padico_out(40, " - source host %s (%p)\n", padico_topo_host_getname(v->host), v);
268 assert(v == d->local_v);
269 /* build ssh config string from route */
272 {
273 v = *i;
274 if(v->host != padico_topo_getlocalhost() && padico_topo_host_getservice(v->host, "ssh"))
275 {
276 const char*user = padico_topo_host_getproperty(v->host, "login");
277 if(padico_string_size(hosts) != 0)
278 {
281 }
282 padico_string_catf(hosts, "%s", padico_topo_host_getname2(v->host, v->previous->network));
283 padico_string_catf(users, "%s", user?user:getenv("USER"));
284 }
285 }
287 padico_out(40, "hosts: %s\n", padico_string_get(hosts));
288 padico_out(40, "users: %s\n", padico_string_get(users));
289 rc = 1;
290 }
291 else
292 {
293 padico_warning("no route found.\n");
294 }
296 return rc;
297}
assert(slab_size > 0)
ns_rulebucket_hashtable_t h
struct ns_rulebucket_hash_entry_s * e
ssize_t n
return NULL
Definition Shm.h:88
padico_topo_host_t host
void *static bench_vect_buffer_queue_t v
Definition bench_vect.c:22
#define min(a, b)
Definition calc.c:136
static int done
Definition console-mod.c:49
padico_rc_t rc
Definition PadicoTM.h:146
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_topo_host_vect_t padico_topo_gethosts(void)
Get known hosts.
Definition topology.c:2211
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
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
typdef struct padico_topo_host_vect_s * padico_topo_host_vect_t
Definition Topology.h:86
padico_topo_network_vect_t padico_topo_networks_getbyfamily(int family)
Get networks of a given address family (e.g.
Definition topology.c:2365
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
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
#define padico_topo_getlocalhost()
Definition Topology.h:319
void padico_topo_network_gethosts(padico_topo_network_t n, padico_topo_host_vect_t hosts)
Definition topology.c:2284
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
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
const char * padico_topo_host_getname(padico_topo_host_t host)
Get the canonical name of a host.
Definition topology.c:1944
typdef struct padico_topo_network_vect_s * padico_topo_network_vect_t
Definition Topology.h:85
#define PORT_ANY
Definition Topology.h:122
#define NSBE_UNREACHABLE
distance for unreachable vertices; do not use -1, it confuses algorithm.
Definition nsbe-route.c:41
static void nsbe_dijkstra_destroy(struct nsbe_dijkstra_s *d)
Definition nsbe-route.c:183
static struct nsbe_dijkstra_vertex_s * nsbe_dijkstra_getmin(struct nsbe_dijkstra_s *d)
Definition nsbe-route.c:163
static struct nsbe_dijkstra_s * nsbe_dijkstra_init(padico_topo_host_t dest)
builds the routing graph from the known topology
Definition nsbe-route.c:86
typdef struct nsbe_dijkstra_vertex_vect_s * nsbe_dijkstra_vertex_vect_t
Definition nsbe-route.c:38
static struct nsbe_dijkstra_vertex_s * nsbe_dijkstra_vertex_add(nsbe_vertex_hashtable_t vertices, padico_topo_host_t host, padico_topo_network_t network)
Definition nsbe-route.c:66
int ns_besteffort_selector_dijkstra(padico_string_t hosts, padico_string_t users, padico_topo_host_t dest, padico_topo_network_t *dest_n)
Definition nsbe-route.c:202
padico_topo_network_t network
Definition psp-mx.c:113
int route
internal state of the Dijkstra algorithm
Definition nsbe-route.c:55
nsbe_dijkstra_vertex_vect_t done
vertices already inserted into working set
Definition nsbe-route.c:56
nsbe_dijkstra_vertex_vect_t todo
vertices not processed yet
Definition nsbe-route.c:57
struct nsbe_dijkstra_vertex_s * dest_v
vertex for dest host
Definition nsbe-route.c:59
struct nsbe_dijkstra_vertex_s * local_v
vertex for local host
Definition nsbe-route.c:58
padico_topo_host_t host
host for this vertex (NULL if vertex is a network)
Definition nsbe-route.c:46
padico_topo_network_t network
network for this vertex (NULL if vertex is a host)
Definition nsbe-route.c:47
int weight
distance from local vertex (NSBE_UNREACHABLE, if unreachable)
Definition nsbe-route.c:45
struct nsbe_dijkstra_vertex_s * previous
ancestor in the computed route
Definition nsbe-route.c:48
nsbe_dijkstra_vertex_vect_t outputs
vertex outputs, computed at init
Definition nsbe-route.c:49
a network, containing entities with bindings