PadicoTM

Documentation

« back to PM2 home.
control-router.c
Go to the documentation of this file.
1/*
2 * Padico -- a High Performance Parallel and Distributed Computing Environment
3 * Copyright (c) 2002-2026 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/Module.h>
32#include <Padico/PadicoTM.h>
33#include <Padico/PadicoControl.h>
34#include <Padico/Topology.h>
35
36static int control_router_init(void);
37static void control_router_finalize(void);
38
40 "PadicoControl", "Topology", "NetSelector");
41
46/* ********************************************************* */
47
50
53static struct
54{
60} router_control = { .running = 0, .component = NULL, .instance = NULL };
61
65{
67 const char*from;
68 char*bytes;
69 size_t size;
70};
71
75{
76 char*recipient;
77 char*from;
78};
79
80
82static void control_router_event_listener(void*arg);
83
84/* *** PadicoControl driver ******************************** */
85
87
95
98{
99 .instantiate = NULL,
100 .destroy = NULL
101};
102
103
104/* ********************************************************* */
105/* *** PadicoControl *************************************** */
106
123
124
126{
127 assert(recipient);
129 if(next_hop == recipient)
130 {
131 padico_fatal("trying to route a message to node %s with an existing direct route.\n",
132 padico_topo_node_getname(recipient));
133 }
134 if(recipient == padico_topo_getlocalnode())
135 {
136 padico_fatal("trying to route a message to self.\n");
137 }
138 /* encode message */
139 const struct iovec v = padico_control_msg_get_bytes(msg);
141 {
143 .from = padico_topo_nodename(),
144 .bytes = v.iov_base,
145 .size = v.iov_len
146 };
148}
149
150
152{
154 /* We have to warn the sender that the node
155 he tried to send a message to is no more reachable */
157 if(node != NULL)
158 {
161 padico_string_catf(dmessage, "<Control_Router:disap name=\"%s\" />\n", message->recipient);
165 }
166 padico_free(message->from);
167 padico_free(message->recipient);
169 padico_out(20, "done.\n");
170 return NULL;
171}
172
176{
177 /* local node is final recipient- decode and deliver message */
178 if(message->recipient == padico_topo_getlocalnode())
179 {
180 padico_out(50, "deliver message from=%s\n", message->from);
183 message->bytes = NULL; /* padico_control_deliver_message() takes ownership of msg body */
184 }
185 else
186 {
191 /* send to the next hop */
192 if(next_hop != NULL)
193 {
194 padico_out(50, "message from=%s to recipient=%s, send to next hop=%s\n",
197 padico_control_msg_add_cmd(msg, "<Control_Router:message from=\"%s\" recipient=\"%s\">",
198 message->from, padico_topo_node_getname(message->recipient));
200 padico_control_msg_add_cmd(msg, "</Control_Router:message>");
202 msg = NULL; /* control_send_msg() takes ownership of msg */
203 }
204 else
205 {
206 padico_warning("no route found for message- from=%s; recipient=%s\n",
207 message->from, padico_topo_node_getname(message->recipient));
209 dmess->from = padico_strdup(message->from);
210 dmess->recipient = padico_strdup(padico_topo_node_getname(message->recipient));
211 padico_tm_bgthread_start(router_control.pool, &control_router_disappeared, (void*)dmess, "Control-router:node_disappeared");
212 }
213 padico_free(message->bytes);
214 }
215}
216
218{
219 const char*s_from = puk_parse_getattr(e, "from");
220 const char*s_recipient = puk_parse_getattr(e, "recipient");
225 padico_out(40, "received message from node=%s\n", s_from);
227 char*bytes = padico_malloc(part.iov_len);
228 memcpy(bytes, part.iov_base, part.iov_len);
229 if(node != NULL)
230 {
232 {
233 .from = s_from,
234 .recipient = node,
235 .bytes = bytes,
236 .size = part.iov_len
237 };
239 }
240 else
241 {
243 dmess->from = padico_strdup(s_from);
244 dmess->recipient = padico_strdup(s_recipient);
245 padico_tm_bgthread_start(router_control.pool, &control_router_disappeared, (void*)dmess, "Control-router:node_disappeared");
246 }
247}
248
249
250/* ********************************************************* */
251/* *** Discovery */
252
253/* *********************************************************
254 * -1- update: node -> new node:
255 * # update( {known nodes (of the node)} - node - new node)
256 * -2- broadcast: new node -> {known nodes (of the new node)} - {known nodes (of the node)}
257 * # announce( {known nodes (of the node)} + node )
258 * *********************************************************
259 */
260
262{
268 /* build a list of dest nodes */
269 padico_out(40, "announce=*%s*\n", padico_string_get(announce));
271 while(node)
272 {
274 {
275 padico_out(20, "announcing to node: %s\n", padico_topo_node_getname(node));
277 padico_out(20, "announce to node %s done.\n", padico_topo_node_getname(node));
278 }
280 }
282 /* send announce *after* building the list since control_send()
283 * may generate control events that may crash the hashtable enumerator.
284 */
285 int i;
286 for(i = 0; i < padico_topo_node_vect_size(dests); i++)
287 {
290 }
292}
293
308
310{
311 const char*hop_name = puk_parse_getattr(e, "hop");
312 padico_out(20, "received a Control_Router:announce from node=%s\n", hop_name);
318 {
319 if(puk_parse_is(*i, "Topology:node"))
320 {
323 }
324 }
326}
327
329{
330 const char*hop_name = puk_parse_getattr(e, "hop");
331 padico_out(20, "received a Control_Router:update- hop=%s\n", hop_name);
332 assert(hop_name != NULL);
334 /* build announce message */
336 padico_string_catf(announce, "<Control_Router:announce hop=\"%s\">\n", padico_topo_nodename());
337 /* handle embedded entities & on the fly re-serialize */
342 {
344 if(puk_parse_is(*i, "Topology:node"))
345 {
349 }
350 else if(puk_parse_is(*i, "Topology:host"))
351 {
354 }
355 else if(puk_parse_is(*i, "Topology:network"))
356 {
359 }
360 else
361 {
362 padico_fatal("unexpected entity *%s* in announce.\n", (*i)->tag);
363 }
366 }
367 padico_string_catf(announce, "</Control_Router:announce>\n");
372 padico_out(20, "done.\n");
373}
374
376{
377 padico_out(20, "received a Control_Router:delete\n");
381 {
382 if(puk_parse_is(*i, "Topology:node"))
383 {
384 /* Remove concerned routes */
386 padico_out(20,"Removing node %s\n", padico_topo_node_getname(node));
391 while(start_hop)
392 {
396 if(this_next == node || this_start == node)
397 {
399 }
400 }
404 }
405 else
406 {
407 padico_fatal("unexpected entity *%s* in delete.\n", (*i)->tag);
408 }
409 }
410}
411
413{
414 padico_out(20, "received a Control_Router:disap\n");
415 const char*node_name = puk_parse_getattr(e, "name");
416 assert(node_name != NULL);
419}
420
422{
424 padico_out(20, "event kind: %d\n", event->kind);
425 switch(event->kind)
426 {
428 {
429 const padico_topo_node_vect_t nodes = event->INIT_CONTROLER.nodes;
430 const puk_instance_t controler __attribute__((unused)) = event->INIT_CONTROLER.controler;
433 {
434 const padico_topo_node_t node = *i;
435 /* if the node and the next_hop are the same : the node is directly reachable */
437 padico_out(40, "INIT_CONTROLER: register new node: %s from controler: %s\n",
438 padico_topo_node_getname(node), controler->component->name);
439 }
440 }
441 break;
442
444 {
445 const puk_instance_t controler = event->NODE.controler;
446 const padico_topo_node_t node = event->NODE.node;
447 padico_out(20, "NEW_NODE: %s\n", padico_topo_node_getname(node));
448 assert(node != NULL);
449 if(controler->component != router_control.component) /* avoid recursion */
450 {
452 if(next_hop == NULL)
453 {
454 padico_out(40, "NEW_NODE: register new node: %s from controler: %s\n",
455 padico_topo_node_getname(node), controler->component->name);
457 /* force all control events flush- following event listeners in the queue
458 * are likely to update NetSelector needed to send requests (announce/update) */
460 /* build & send an update request */
463 padico_out(20, "send topology to new node %s \n", padico_topo_node_getname(node));
464 padico_string_catf(request, "<Control_Router:update hop=\"%s\">\n", padico_topo_nodename());
466 padico_string_catf(request, "</Control_Router:update>\n");
468 const char*msg = padico_string_get(request);
469 padico_out(60, "request: %s\n", msg);
470 padico_out(20, "sending.\n");
472 padico_out(20, "sent.\n");
474 }
475 }
476 }
477 break;
478
480 {
481 padico_out(10, "node event- delete node *%s*\n", padico_topo_node_getname(event->NODE.node));
486 while(node)
487 {
488 if(next_hop == event->NODE.node)
489 {
491 }
493 }
495 /* cascade delete */
496 int i = 0;
499 padico_string_catf(delete, "<Control_Router:delete hop=\"%s\">\n", padico_topo_nodename());
501 {
507 }
508 padico_string_catf(delete, "</Control_Router:delete>\n");
509 if(router_control.running)
510 {
512 }
513 padico_string_delete(delete);
516 padico_out(20, "done.\n");
517 }
518 break;
519
521 router_control.running = 0;
522 break;
523
524 default:
525 break;
526 }
527}
528
529
530/* ********************************************************* */
531
532static int control_router_init(void)
533{
534 router_control.pool = padico_tm_bgthread_pool_create("Control-router");
535 router_control.component =
536 puk_component_declare("Control_Router",
537 puk_component_provides("PadicoComponent", "component", &router_component_driver),
538 puk_component_provides("PadicoControl", "control", &router_control_driver));
539
541 .xml_tag = "Control_Router:update",
542 .start_handler = NULL,
543 .end_handler = &router_update_end_handler,
544 .required_level = PUK_TRUST_CONTROL
545 });
547 .xml_tag = "Control_Router:announce",
548 .start_handler = NULL,
549 .end_handler = &router_announce_end_handler,
550 .required_level = PUK_TRUST_CONTROL
551 });
553 .xml_tag = "Control_Router:message",
554 .start_handler = NULL,
555 .end_handler = &router_message_end_handler,
556 .required_level = PUK_TRUST_CONTROL
557 });
559 .xml_tag = "Control_Router:delete",
560 .start_handler = NULL,
561 .end_handler = &cascade_delete_end_handler,
562 .required_level = PUK_TRUST_CONTROL
563 });
565 .xml_tag = "Control_Router:disap",
566 .start_handler = NULL,
567 .end_handler = &disappear_end_handler,
568 .required_level = PUK_TRUST_CONTROL
569 });
570
574
576
577 router_control.running = 1;
578
579 return 0;
580}
581
582static void control_router_finalize(void)
583{
591 puk_xml_delete_action("Control_Router:update");
592 puk_xml_delete_action("Control_Router:announce");
593 puk_xml_delete_action("Control_Router:message");
594 puk_xml_delete_action("Control_Router:delete");
595 puk_xml_delete_action("Control_Router:disap");
597}
void hop()
Definition HelloMPI.c:23
assert(slab_size > 0)
struct ns_rulebucket_hash_entry_s * e
return NULL
Definition Shm.h:88
padico_topo_host_t host
void *static bench_vect_buffer_queue_t v
Definition bench_vect.c:22
static int done
Definition console-mod.c:49
padico_topo_node_vect_t nodes
static void * control_router_disappeared(void *arg)
puk_component_t component
component for control router
static void router_update_end_handler(puk_parse_entity_t e)
int running
static void disappear_end_handler(puk_parse_entity_t e)
static void router_announce_end_handler(puk_parse_entity_t e)
padico_tm_bgthread_pool_t pool
static int control_router_init(void)
static struct @17 router_control
private data used internally by the Control_Router module.
static const struct puk_component_driver_s router_component_driver
component driver to make the component instanciable
static void router_control_send_common(void *_status, padico_topo_node_t node, padico_control_msg_t msg)
static void control_router_broadcast(padico_topo_node_t new_hop, padico_string_t announce)
struct router_node_hashtable_s directory
node -> next hop node
struct router_node_hash_entry_block_lfstack_s __attribute__
static void control_router_event_listener(void *arg)
puk_instance_t instance
singleton instance of the control router
void control_router_table_print(void)
static void control_router_finalize(void)
static void router_message_end_handler(puk_parse_entity_t e)
static void router_new_node(padico_topo_node_t node, padico_topo_node_t hop)
static void router_message_process(struct router_message_s *message)
Process a message received on a router: forward or deliver locally.
static void cascade_delete_end_handler(puk_parse_entity_t e)
static char * request(const char *url)
Definition g5k-topo.c:122
static const struct padico_control_driver_s router_control_driver
'Control' facet for the Control/Router component
struct iovec padico_control_msg_get_bytes(padico_control_msg_t msg)
get a (contiguous) copy of the content of the control message; caller takes ownership of the copy
Definition na-control.c:229
static void padico_control_new_node(puk_instance_t controler, padico_topo_node_t node)
void padico_control_msg_add_part(padico_control_msg_t msg, const void *text, size_t len)
add an attached binary part to a control message
Definition na-control.c:189
static void padico_control_plug_controler(puk_instance_t controler, puk_instance_t server)
static void padico_control_event_enable(void)
#define padico_control_msg_add_cmd(MSG, TEXT,...)
static void padico_control_send_oneway(padico_topo_node_t node, const char *msg)
Send a "one way" message on the control channel.
static void padico_control_event_disable(void)
static void padico_control_event_flush(void)
static void padico_control_event_unsubscribe(padico_event_listener_t l)
static void padico_control_event_subscribe(padico_event_listener_t l)
static void padico_control_unplug_controler(puk_instance_t controler)
static void padico_control_delete_node(puk_instance_t controler, padico_topo_node_t node)
void padico_control_deliver_message(puk_instance_t controler, padico_topo_node_t from, char *cmd, size_t size)
Deliver an incoming control message from an component to PadicoControl.
Definition na-control.c:388
int padico_control_send_msg(padico_topo_node_t node, padico_control_msg_t msg)
the real function to send a message on control channel- most of the time, we use a wraper,...
Definition na-control.c:252
static void padico_control_event_sync(void)
padico_control_msg_t padico_control_msg_new(void)
create a new empty control message
Definition na-control.c:161
void padico_tm_bgthread_start(padico_tm_bgthread_pool_t pool, padico_thread_fun_t f, void *arg, const char *name)
Definition tm-rttask.c:126
void padico_tm_bgthread_pool_wait(padico_tm_bgthread_pool_t pool)
finalize a pool of threads: waits for all thread to complete
Definition tm-rttask.c:78
padico_tm_bgthread_pool_t padico_tm_bgthread_pool_create(const char *name)
create a new thread pool
Definition tm-rttask.c:56
void * arg
Definition PadicoTM.h:167
#define padico_topo_nodename()
Definition Topology.h:317
padico_string_t padico_topo_node_serialize(padico_topo_node_t node)
Definition topo-xml.c:168
padico_string_t padico_topo_host_serialize(padico_topo_host_t host)
Definition topo-xml.c:184
padico_string_t padico_na_topology_serialize(padico_topo_binding_scope_t scope)
Definition topo-xml.c:240
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
typdef struct padico_topo_node_vect_s * padico_topo_node_vect_t
Definition Topology.h:84
padico_string_t padico_topo_network_serialize(padico_topo_network_t network)
Definition topo-xml.c:220
padico_topo_node_t padico_topo_getnodebyname(const char *nodename)
node lookup, by node name
Definition topology.c:2389
@ PADICO_TOPO_SCOPE_ALL
Definition Topology.h:96
padico_topo_node_t node
Definition na-control.c:65
const char * message
Definition psp-ibv.c:209
padico_topo_network_t network
Definition psp-mx.c:113
notification for a lost node
char * recipient
final recipient (receiver)
char * from
name of the originating node
Interface: "PadicoControl".
void(* send_common)(void *_status, padico_topo_node_t node, padico_control_msg_t msg)
puk_instance_t controler
@ PADICO_CONTROL_EVENT_SHUTDOWN
local node is shuting down, stop processing some events
@ PADICO_CONTROL_EVENT_INIT_CONTROLER
initial event sent to new controlers to get the past events and current topology state
@ PADICO_CONTROL_EVENT_DELETE_NODE
a node was deleted/disconnected/became unreachable
@ PADICO_CONTROL_EVENT_NEW_NODE
a new node appeared in the known topology
A control message.
Definition na-control.c:57
a thread pool, to control and wait running threads
Definition PadicoTM.h:174
a received and/or to-send message
size_t size
message size
char * bytes
message body
const char * from
name of the originating node
padico_topo_node_t recipient
final recipient (receiver)
a network, containing entities with bindings
marcel_cond_t event
Definition tm-boot.c:65