PadicoTM

Documentation

« back to PM2 home.
ns-basic-parse.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 "Ns-basic-internals.h"
31
32PADICO_MODULE_HOOK(NetSelector_basic);
33
34
35/* *** NS db *********************************************** */
36/* Note: these functions are used only once.
37 * 'inline' to get a more compact binary code.
38 */
39
40static inline ns_entity_t ns_entity_new(enum ns_entity_kind_e kind)
41{
42 ns_entity_t entity = padico_malloc(sizeof(struct ns_entity_s));
43 entity->kind = kind;
45 return entity;
46}
47
49{
51 puk_vect_foreach(_i, ns_entity, &group->group.entities)
52 {
53 ns_entity_t i = *_i;
54 switch(i->kind)
55 {
56 case NS_ENTITY_NODE:
57 case NS_ENTITY_HOST:
58 ns_entity_vect_push_back(&group->group.leaves, i);
59 break;
60 case NS_ENTITY_GROUP:
61 {
63 puk_vect_foreach(_e, ns_entity, &i->group.leaves)
64 {
65 ns_entity_t e = *_e;
66 ns_entity_vect_push_back(&group->group.leaves, e);
67 ns_entity_vect_push_back(&e->contained, group);
68 }
69 }
70 break;
71 default:
72 padico_fatal("bad entity type in group.\n");
73 break;
74 }
75 ns_entity_vect_push_back(&i->contained, group);
76 }
77}
78
79static inline ns_entity_t nsdb_create_node(const char*_node_name)
80{
82 const char*node_name = node?padico_topo_node_getname(node):_node_name;
84 if(!entity)
85 {
86 entity = ns_entity_new(NS_ENTITY_NODE);
87 entity->node.name = strcmp(node_name, "*") == 0?NULL:padico_strdup(node_name);
88 entity->node.node = node;
89 if(entity->node.name)
91 }
92 return entity;
93}
94
95static inline ns_entity_t nsdb_create_host(const char*name, const char*addr)
96{
97 ns_entity_t entity = NULL;
98 const int is_wildcard = name && (strchr(name, '*') || strchr(name, '?') || strchr(name, '['));
100 if(addr)
101 {
102 struct in_addr inaddr;
103 inet_aton(addr, &inaddr);
104 if(host)
105 {
107 }
108 else
109 {
111 }
112 }
115 if(!entity)
116 {
117 entity = ns_entity_new(NS_ENTITY_HOST);
118 entity->host.host = host;
119 entity->host.name = host_name;
120 if(entity->host.name)
122 }
123 return entity;
124}
125
126static inline ns_entity_t nsdb_create_group(const char*group_name)
127{
128 ns_entity_t entity = ns_entity_new(NS_ENTITY_GROUP);
133 return entity;
134}
135
136static inline ns_rule_t nsdb_create_rule(const char*profile,
139{
141 static const char*const default_profile = PADICO_NS_DEFAULT_PROFILE;
142 const char*const p = profile?:default_profile;
144 {
145 .profile = p,
146 .iface = iface
147 };
150 if(rl == NULL)
151 {
152 struct ns_rule_bucket_s*rb = padico_malloc(sizeof(struct ns_rule_bucket_s));
154 *rb = rulebucket;
156 }
157 rule->assembly = assembly;
158 ns_target_vect_init(&rule->targets);
160 return rule;
161}
162
163
164/* ********************************************************* */
165/* *** Parsing ********************************************* */
166
167
168/* *** <NS:rule-set> */
169
171{
172 padico_out(40, "Start of parsing \n");
173}
175{
176 padico_out(40, "End of parsing \n");
177}
179{
180 .xml_tag = "NS:rule-set",
181 .start_handler = &ns_ruleset_start_handler,
182 .end_handler = &ns_ruleset_end_handler,
183 .required_level = PUK_TRUST_CONTROL
184};
185
186/* *** <NS:group> */
187
189{
190 const char*group_id = puk_parse_getattr(e, "id");
191 const char*group_ref = puk_parse_getattr(e, "ref");
193 assert((group_id != NULL) ^ (group_ref != NULL));
194 if(group_id)
195 {
196 /* new group */
197 group = nsdb_create_group(group_id);
198 padico_out(40, "created cluster %s\n", group_id);
199 }
200 else
201 {
202 /* group reference. Register according to the container nature */
204 if(group == NULL)
205 {
206 padico_fatal("unknown group: %s\n", group_ref);
207 puk_parse_set_rc(e, padico_rc_error("Unknown group: %s\n", group_ref));
208 return;
209 }
210 }
211 assert(group != NULL && group->kind == NS_ENTITY_GROUP);
213}
215{
219 assert(group != NULL);
220 /* TODO- we don't check that only 'id' groups contain sub-entities */
222 {
223 /* add sub-entity to group */
226 ns_entity_vect_push_back(&group->group.entities, sub_entity);
227 }
229}
231{
232 .xml_tag = "NS:group",
233 .start_handler = &ns_basic_group_start_handler,
234 .end_handler = &ns_basic_group_end_handler,
235 .required_level = PUK_TRUST_CONTROL
236};
237
238/* *** <NS:node> */
239
241{
242 const char*name = puk_parse_getattr(e, "name");
245 padico_out(40, "node=%s\n", name);
246}
248{
249 .xml_tag = "NS:node",
250 .start_handler = &ns_basic_node_start_handler,
251 .end_handler = NULL,
252 .required_level = PUK_TRUST_CONTROL
253};
254
255/* *** <NS:host> */
256
258{
259 const char*name = puk_parse_getattr(e, "name");
260 const char*addr = puk_parse_getattr(e, "addr");
263 padico_out(40, "host=%s\n", name);
264}
266{
267 .xml_tag = "NS:host",
268 .start_handler = &ns_basic_host_start_handler,
269 .end_handler = NULL,
270 .required_level = PUK_TRUST_CONTROL
271};
272
273/* *** <NS:rule> */
274
276{
277 int i;
282 if(component)
283 {
284 if(!puk_parse_is(as_entity, "puk:component") && !puk_parse_is(as_entity, "puk:composite"))
285 {
286 padico_warning("syntax error- rule contains no component.\n");
287 puk_parse_set_rc(e, padico_rc_error("Syntax error: rule contains no component.\n"));
288 return;
289 }
290 for(i = 1; i < puk_parse_entity_vect_size(v); i++)
291 {
293 int j;
294 for(j = 0; j < puk_facet_vect_size(&component->provides); j++)
295 {
297 puk_facet_vect_at(&component->provides, j).iface);
298 padico_out(40, "register facet %s of component %s.\n",
299 (puk_facet_vect_at(&component->provides, j).iface)->name,
300 component->name);
302 }
304 }
305 }
306 else
307 {
308 padico_warning("invalid rule (no component)- skipping.\n");
309 puk_parse_set_rc(e, padico_rc_error("Syntax error: rule contains no component.\n"));
310 }
311}
313{
314 .xml_tag = "NS:rule",
315 .start_handler = NULL,
316 .end_handler = &ns_basic_rule_end_handler,
317 .required_level = PUK_TRUST_CONTROL
318};
319
320
321/* *** <NS:target> */
322
324{
325 struct ns_target_s*target = padico_malloc(sizeof(struct ns_target_s));
326 const char*profile = puk_parse_getattr(e, "profile");
327 const char*kind = puk_parse_getattr(e, "kind");
328 if(strcmp(kind, "clique") == 0)
329 {
330 target->kind = NS_TARGET_CLIQUE;
331 target->clique.entity = NULL;
332 }
333 else if(strcmp(kind, "arrow") == 0)
334 {
335 target->kind = NS_TARGET_ARROW;
336 target->arrow.tail = NULL;
337 target->arrow.head = NULL;
338 }
339 else if(strcmp(kind, "multipartite") == 0)
340 {
342 target->multipartite.subsets = ns_entity_vect_new();
343 }
344 else if(strcmp(kind, "unknown") == 0)
345 {
347 padico_warning("target kind=unknown not supported yet. Ignored.\n");
348 }
349 else
350 padico_fatal("unknown target kind: *%s*\n", kind);
353 padico_out(40, "created target kind=%s\n", kind);
354}
356{
359 switch(target->kind)
360 {
361 case NS_TARGET_CLIQUE:
363 {
364 puk_parse_set_rc(e, padico_rc_error("NetSelector_basic: target kind='clique' requires only 1 entity.\n"));
365 return;
366 }
368 break;
370 {
371 int i;
373 for(i = 0; i < puk_parse_entity_vect_size(v); i++)
374 {
376 ns_entity_vect_put(target->multipartite.subsets, entity, i);
377 }
378 }
379 break;
380 case NS_TARGET_ARROW:
381 {
383 padico_fatal("target kind='arrow' requires 2 entities.\n");
386 }
387 break;
389 break;
390 default:
391 padico_fatal("bad target type in parsing.\n");
392 break;
393 }
394}
396{
397 .xml_tag = "NS:target",
398 .start_handler = &ns_basic_target_start_handler,
399 .end_handler = &ns_basic_target_end_handler,
400 .required_level = PUK_TRUST_CONTROL
401};
402
403/* *** Main parts ****************************************** */
404
415
Internal structures for NS-basic.
assert(slab_size > 0)
padico_topo_node_t const char * profile
puk_component_t assembly
Serial assembly used.
struct padico_ns_database_s nsdb
the internal database of rules and nodes/hosts/groups
#define PADICO_NS_DEFAULT_PROFILE
struct ns_rulebucket_hash_entry_s * e
padico_topo_node_t const char puk_iface_t iface
return NULL
Definition Shm.h:88
puk_tagged_ptr_t p
Definition Shm.h:88
padico_topo_host_t host
static padico_group_t group
void *static bench_vect_buffer_queue_t v
Definition bench_vect.c:22
static int done
Definition console-mod.c:49
puk_component_t component
component used for listening
char * name
Definition PadicoTM.h:168
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
const char * padico_topo_node_getname(padico_topo_node_t node)
Get the canonical name of a node.
Definition topology.c:1917
padico_topo_network_t padico_topo_network_getbyid(const char *network_id)
Definition topology.c:2351
padico_topo_node_t padico_topo_getnodebyname(const char *nodename)
node lookup, by node name
Definition topology.c:2389
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
padico_topo_host_t padico_topo_host_resolvebyname(const char *hostname)
resolve a host from name
Definition topology.c:2681
padico_topo_node_t node
Definition na-control.c:65
static void ns_ruleset_start_handler(puk_parse_entity_t e)
static struct puk_tag_action_s action_target
static struct puk_tag_action_s action_node
static struct puk_tag_action_s action_host
static void ns_ruleset_end_handler(puk_parse_entity_t e)
static ns_entity_t nsdb_create_group(const char *group_name)
static void nsdb_group_flatten(ns_entity_t group)
static void ns_basic_target_end_handler(puk_parse_entity_t e)
static ns_entity_t ns_entity_new(enum ns_entity_kind_e kind)
static struct puk_tag_action_s action_ruleset
static struct puk_tag_action_s action_rule
static void ns_basic_group_end_handler(puk_parse_entity_t e)
static ns_entity_t nsdb_create_node(const char *_node_name)
static struct puk_tag_action_s action_cluster
static ns_rule_t nsdb_create_rule(const char *profile, puk_component_t assembly, puk_iface_t iface)
int ns_basic_parse_init(void)
static void ns_basic_group_start_handler(puk_parse_entity_t e)
static ns_entity_t nsdb_create_host(const char *name, const char *addr)
static void ns_basic_rule_end_handler(puk_parse_entity_t e)
static void ns_basic_node_start_handler(puk_parse_entity_t e)
static void ns_basic_target_start_handler(puk_parse_entity_t e)
int ns_basic_parse_finalize(void)
static void ns_basic_host_start_handler(puk_parse_entity_t e)
static const char default_profile[]
struct ns_group_s group
struct ns_entity_vect_s contained
enum ns_entity_s::ns_entity_kind_e kind
struct ns_node_s node
struct ns_host_s host
struct ns_entity_vect_s entities
enclosed entities as described in the rules
const char * name
struct ns_entity_vect_s leaves
flattened vector of all contained terminal entities
const char * name
padico_topo_host_t host
const char * name
padico_topo_node_t node
const char * profile
Profile matched by this set of rules.
ns_entity_t entity
enum ns_target_s::@36 kind
@ NS_TARGET_CLIQUE
communication between all nodes of a set
@ NS_TARGET_ARROW
directed edge between two sets
@ NS_TARGET_MULTIPARTITE
communication between sets
@ NS_TARGET_UNKNOWN
default assembly, when the node is unknown
struct ns_entity_byname_hashtable_s nodes_by_name
nodes found in the config- hashed by nodename
struct ns_rulebucket_hashtable_s rulebuckets
rules hashed by bucket [ (iface,profile) -> rule_list ]
struct ns_entity_byname_hashtable_s hosts_by_name
hosts found in the config- hashed by hostname
struct ns_entity_byname_hashtable_s groups_by_name
groups found in the config- hashed by group name