|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* Copyright © 2013-2014 University of Wisconsin-La Crosse.
|
|
Packit Service |
c5cf8c |
* All rights reserved.
|
|
Packit Service |
c5cf8c |
* Copyright © 2013 Cisco Systems, Inc. All rights reserved.
|
|
Packit Service |
c5cf8c |
* Copyright © 2015-2017 Inria. All rights reserved.
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* $COPYRIGHT$
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* Additional copyrights may follow
|
|
Packit Service |
c5cf8c |
* See COPYING in top-level directory.
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* $HEADER$
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define _GNU_SOURCE /* See feature_test_macros(7) */
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#include <private/autogen/config.h>
|
|
Packit Service |
c5cf8c |
#include <private/netloc.h>
|
|
Packit Service |
c5cf8c |
#include <netloc.h>
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
static UT_icd node_physical_links_icd = {
|
|
Packit Service |
c5cf8c |
sizeof(netloc_physical_link_t *), NULL, NULL, NULL
|
|
Packit Service |
c5cf8c |
};
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
static UT_icd node_physical_nodes_icd = {
|
|
Packit Service |
c5cf8c |
sizeof(netloc_node_t *), NULL, NULL, NULL
|
|
Packit Service |
c5cf8c |
};
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
static UT_icd node_partitions_icd = { sizeof(int), NULL, NULL, NULL };
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
static int node_or_subnode_destruct(netloc_node_t * node, int is_node);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
netloc_node_t * netloc_node_construct(void)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
netloc_node_t *node = NULL;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
node = (netloc_node_t*)malloc(sizeof(netloc_node_t));
|
|
Packit Service |
c5cf8c |
if (NULL == node) {
|
|
Packit Service |
c5cf8c |
return NULL;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
node->physical_id[0] = '\0';
|
|
Packit Service |
c5cf8c |
node->logical_id = -1;
|
|
Packit Service |
c5cf8c |
node->type = NETLOC_NODE_TYPE_INVALID;
|
|
Packit Service |
c5cf8c |
utarray_new(node->physical_links, &node_physical_links_icd);
|
|
Packit Service |
c5cf8c |
node->description = NULL;
|
|
Packit Service |
c5cf8c |
node->userdata = NULL;
|
|
Packit Service |
c5cf8c |
node->edges = NULL;
|
|
Packit Service |
c5cf8c |
utarray_new(node->subnodes, &node_physical_nodes_icd);
|
|
Packit Service |
c5cf8c |
node->paths = NULL;
|
|
Packit Service |
c5cf8c |
node->hostname = NULL;
|
|
Packit Service |
c5cf8c |
utarray_new(node->partitions, &node_partitions_icd);
|
|
Packit Service |
c5cf8c |
node->hwlocTopo = NULL;
|
|
Packit Service |
c5cf8c |
node->hwlocTopoIdx = -1;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
return node;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int netloc_node_destruct(netloc_node_t * node)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
return node_or_subnode_destruct(node, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
static int node_or_subnode_destruct(netloc_node_t * node, int is_node)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
utarray_free(node->physical_links);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Description */
|
|
Packit Service |
c5cf8c |
free(node->description);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Edges */
|
|
Packit Service |
c5cf8c |
netloc_edge_t *edge, *edge_tmp;
|
|
Packit Service |
c5cf8c |
HASH_ITER(hh, node->edges, edge, edge_tmp) {
|
|
Packit Service |
c5cf8c |
HASH_DEL(node->edges, edge); /* delete; edge advances to next */
|
|
Packit Service |
c5cf8c |
netloc_edge_destruct(edge);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Subnodes */
|
|
Packit Service |
c5cf8c |
for (unsigned int n = 0; n < utarray_len(node->subnodes); n++) {
|
|
Packit Service |
c5cf8c |
netloc_node_t *subnode = *(netloc_node_t **)
|
|
Packit Service |
c5cf8c |
utarray_eltptr(node->subnodes, n);
|
|
Packit Service |
c5cf8c |
node_or_subnode_destruct(subnode, 0);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
utarray_free(node->subnodes);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Paths */
|
|
Packit Service |
c5cf8c |
netloc_path_t *path, *path_tmp;
|
|
Packit Service |
c5cf8c |
HASH_ITER(hh, node->paths, path, path_tmp) {
|
|
Packit Service |
c5cf8c |
HASH_DEL(node->paths, path); /* delete; path advances to next */
|
|
Packit Service |
c5cf8c |
netloc_path_destruct(path);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Hostname */
|
|
Packit Service |
c5cf8c |
free(node->hostname);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Partitions */
|
|
Packit Service |
c5cf8c |
utarray_free(node->partitions);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* hwlocTopo: nothing to do beacause the pointer is stored also in the topology */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
free(node);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
return NETLOC_SUCCESS;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
char *netloc_node_pretty_print(netloc_node_t* node)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
char * str = NULL;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
asprintf(&str, " [%23s]/[%d] -- %s (%d links)",
|
|
Packit Service |
c5cf8c |
node->physical_id,
|
|
Packit Service |
c5cf8c |
node->logical_id,
|
|
Packit Service |
c5cf8c |
node->description,
|
|
Packit Service |
c5cf8c |
utarray_len(node->physical_links));
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
return str;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int netloc_node_is_in_partition(netloc_node_t *node, int partition)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
for (unsigned int i = 0; i < netloc_get_num_partitions(node); i++) {
|
|
Packit Service |
c5cf8c |
if (netloc_get_partition(node, i) == partition)
|
|
Packit Service |
c5cf8c |
return 1;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
return NETLOC_SUCCESS;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|