PadicoTM

Documentation

« back to PM2 home.
ns-basic-common.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#include <fnmatch.h>
32
33PADICO_MODULE_HOOK(NetSelector_basic);
34
38/* ********************************************************* */
39
40static inline int ns_host_in_entity(padico_topo_host_t host, struct ns_entity_s*entity, void**cookie)
41{
42 switch(entity->kind)
43 {
44 case NS_ENTITY_NODE:
45 {
46 return 0;
47 }
48 break;
49
50 case NS_ENTITY_HOST:
51 {
52 struct ns_host_s*const h = &entity->host;
53 if(h->host)
54 {
55 /* regular host */
56 return h->host == host;
57 }
58 else if( (fnmatch(h->name, padico_topo_host_getname(host), 0) == 0) &&
59 ((!cookie) ||
60 (cookie && ((!*cookie) || (host == *cookie)))))
61 {
62 /* wildcard host */
63 if(cookie)
64 *cookie = host;
65 return 1;
66 }
67 }
68 break;
69
70 case NS_ENTITY_GROUP:
71 {
74 {
76 return 1;
77 }
78 }
79 break;
80
81 default:
82 break;
83 }
84 return 0;
85}
86
88static inline int ns_node_in_entity(padico_topo_node_t node, struct ns_entity_s*entity, void**cookie)
89{
90 switch(entity->kind)
91 {
92 case NS_ENTITY_NODE:
93 {
94 const struct ns_node_s*const n = &entity->node;
95 if(n->node)
96 {
97 /* regular node */
98 return n->node == node;
99 }
100 else
101 {
102 /* wildcard node */
103 if(cookie && (*cookie == NULL || node == *cookie))
104 {
105 *cookie = node;
106 return 1;
107 }
108 else
109 return 0;
110 }
111 }
112 break;
113
114 case NS_ENTITY_HOST:
115 {
117 return ns_host_in_entity(host, entity, cookie);
118 }
119 break;
120
121 case NS_ENTITY_GROUP:
122 {
123 const char*const node_name = padico_topo_node_getname(node);
125 const int matches =
126 (self_node && (ns_entity_vect_find(&self_node->contained, entity) != NULL));
127 return matches || ns_host_in_entity(padico_topo_node_gethost(node), entity, cookie);
128 }
129 break;
130
131 default:
132 break;
133 }
134 return 0;
135}
136
138 const char* profile, puk_iface_t iface)
139{
140 const struct ns_rule_bucket_s rulebucket =
141 {
142 .iface = iface,
144 };
146 if(rules)
147 {
150 {
153 {
154 switch(target->kind)
155 {
156 case NS_TARGET_CLIQUE:
157 {
158 ns_entity_t entity = target->clique.entity;
159 void*cookie = NULL;
160 if(ns_node_in_entity(n1, entity, &cookie) &&
161 ns_node_in_entity(n2, entity, &cookie))
162 return rule->assembly;
163 }
164 break;
165 case NS_TARGET_ARROW:
166 {
167 if(ns_node_in_entity(n1, target->arrow.tail, NULL) &&
168 ns_node_in_entity(n2, target->arrow.head, NULL))
169 return rule->assembly;
170 }
171 break;
172 case NS_TARGET_MULTIPARTITE:
173 {
175 void*cookie1 = NULL, *cookie2 = NULL;
177 puk_vect_foreach(_i, ns_entity, target->multipartite.subsets)
178 {
179 ns_entity_t i = *_i;
182 }
184 return rule->assembly;
185 }
186 break;
187 case NS_TARGET_NONE:
188 padico_fatal("target type=NONE. We shouldn't be here.\n");
189 break;
190 case NS_TARGET_UNKNOWN:
191 break;
192 }
193 }
194 }
195#if 0
196 padico_fatal("no assembly found for iface=%s; profile=%s on link %s -- %s\n",
197 iface->name, rulebucket.profile,
200#endif
201 return NULL;
202 }
203 else
204 {
205 return NULL;
206 }
207}
208
210 const char* profile, puk_iface_t iface)
211{
212 if(!host)
213 {
214 /* NetSelector_basic does not support (yet) NULL host */
215 return NULL;
216 }
218 const struct ns_rule_bucket_s rulebucket = {
219 .iface = iface,
221 };
223 if(!rules)
224 {
225 return NULL;
226 }
229 {
232 {
233 switch(target->kind)
234 {
235 case NS_TARGET_CLIQUE:
236 {
237 ns_entity_t entity = target->clique.entity;
238 void*cookie = NULL;
239 if(ns_node_in_entity(n1, entity, &cookie) &&
240 ns_host_in_entity(host, entity, &cookie))
241 return rule->assembly;
242 }
243 break;
244 case NS_TARGET_ARROW:
245 {
246 if(ns_node_in_entity(n1, target->arrow.tail, NULL) &&
247 ns_host_in_entity(host, target->arrow.head, NULL))
248 return rule->assembly;
249 }
250 break;
251 case NS_TARGET_MULTIPARTITE:
252 {
254 void*cookie1 = NULL, *cookie2 = NULL;
256 puk_vect_foreach(_i, ns_entity, target->multipartite.subsets)
257 {
258 ns_entity_t i = *_i;
261 }
263 return rule->assembly;
264 }
265 break;
266 case NS_TARGET_NONE:
267 padico_fatal("target type=NONE. We shouldn't be here.\n");
268 break;
269 case NS_TARGET_UNKNOWN:
270 break;
271 }
272 }
273 }
274 return NULL;
275}
Internal structures for NS-basic.
padico_topo_node_t const char * profile
ns_rulebucket_hashtable_t h
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
ssize_t n
padico_topo_node_t const char puk_iface_t iface
return NULL
Definition Shm.h:88
padico_topo_host_t host
static int done
Definition console-mod.c:49
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
const char * padico_topo_host_getname(padico_topo_host_t host)
Get the canonical name of a host.
Definition topology.c:1944
padico_topo_node_t node
Definition na-control.c:65
puk_component_t ns_basic_host_assembly(padico_topo_host_t host, const char *profile, puk_iface_t iface)
static int ns_node_in_entity(padico_topo_node_t node, struct ns_entity_s *entity, void **cookie)
puk_component_t ns_basic_assembly(padico_topo_node_t n1, padico_topo_node_t n2, const char *profile, puk_iface_t iface)
struct nsbe_rule_hashtable_s rules
hash: iface -> rule_vect
struct ns_group_s group
enum ns_entity_s::ns_entity_kind_e kind
struct ns_node_s node
struct ns_host_s host
struct ns_entity_vect_s leaves
flattened vector of all contained terminal entities
padico_topo_node_t node
puk_iface_t iface
Iface matched by this rule.
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 ]