| 380 | } |
| 381 | |
| 382 | rte_graph_t |
| 383 | rte_graph_create(const char *name, struct rte_graph_param *prm) |
| 384 | { |
| 385 | rte_node_t src_node_count; |
| 386 | struct graph *graph; |
| 387 | const char *pattern; |
| 388 | uint16_t i; |
| 389 | |
| 390 | graph_spinlock_lock(); |
| 391 | |
| 392 | /* Check arguments sanity */ |
| 393 | if (prm == NULL) |
| 394 | SET_ERR_JMP(EINVAL, fail, "Param should not be NULL"); |
| 395 | |
| 396 | if (name == NULL) |
| 397 | SET_ERR_JMP(EINVAL, fail, "Graph name should not be NULL"); |
| 398 | |
| 399 | /* Check for existence of duplicate graph */ |
| 400 | STAILQ_FOREACH(graph, &graph_list, next) |
| 401 | if (strncmp(name, graph->name, RTE_GRAPH_NAMESIZE) == 0) |
| 402 | SET_ERR_JMP(EEXIST, fail, "Found duplicate graph %s", |
| 403 | name); |
| 404 | |
| 405 | /* Create graph object */ |
| 406 | graph = calloc(1, sizeof(*graph)); |
| 407 | if (graph == NULL) |
| 408 | SET_ERR_JMP(ENOMEM, fail, "Failed to calloc graph object"); |
| 409 | |
| 410 | /* Initialize the graph object */ |
| 411 | STAILQ_INIT(&graph->node_list); |
| 412 | if (rte_strscpy(graph->name, name, RTE_GRAPH_NAMESIZE) < 0) |
| 413 | SET_ERR_JMP(E2BIG, free, "Too big name=%s", name); |
| 414 | |
| 415 | /* Expand node pattern and add the nodes to the graph */ |
| 416 | for (i = 0; i < prm->nb_node_patterns; i++) { |
| 417 | pattern = prm->node_patterns[i]; |
| 418 | if (expand_pattern_to_node(graph, pattern)) |
| 419 | goto graph_cleanup; |
| 420 | } |
| 421 | |
| 422 | /* Go over all the nodes edges and add them to the graph */ |
| 423 | if (graph_node_edges_add(graph)) |
| 424 | goto graph_cleanup; |
| 425 | |
| 426 | /* Update adjacency list of all nodes in the graph */ |
| 427 | if (graph_adjacency_list_update(graph)) |
| 428 | goto graph_cleanup; |
| 429 | |
| 430 | /* Make sure at least a source node present in the graph */ |
| 431 | src_node_count = graph_src_nodes_count(graph); |
| 432 | if (src_node_count == 0) |
| 433 | goto graph_cleanup; |
| 434 | |
| 435 | /* Make sure no node is pointing to source node */ |
| 436 | if (graph_node_has_edge_to_src_node(graph)) |
| 437 | goto graph_cleanup; |
| 438 | |
| 439 | /* Don't allow node has loop to self */ |