summaryrefslogtreecommitdiff
path: root/ospf6d/ospf6_spf.c
diff options
context:
space:
mode:
Diffstat (limited to 'ospf6d/ospf6_spf.c')
-rw-r--r--ospf6d/ospf6_spf.c66
1 files changed, 41 insertions, 25 deletions
diff --git a/ospf6d/ospf6_spf.c b/ospf6d/ospf6_spf.c
index f94252991c..7652d71c59 100644
--- a/ospf6d/ospf6_spf.c
+++ b/ospf6d/ospf6_spf.c
@@ -43,6 +43,8 @@
#include "ospf6d.h"
#include "ospf6_abr.h"
+DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_VERTEX, "OSPF6 vertex");
+
unsigned char conf_debug_ospf6_spf = 0;
static void ospf6_spf_copy_nexthops_to_route(struct ospf6_route *rt,
@@ -86,7 +88,7 @@ static int ospf6_vertex_cmp(const struct ospf6_vertex *va,
return 0;
}
DECLARE_SKIPLIST_NONUNIQ(vertex_pqueue, struct ospf6_vertex, pqi,
- ospf6_vertex_cmp)
+ ospf6_vertex_cmp);
static int ospf6_vertex_id_cmp(void *a, void *b)
{
@@ -649,14 +651,10 @@ static int ospf6_spf_calculation_thread(struct thread *t)
ospf6_spf_reason_string(ospf6->spf_reason, rbuf, sizeof(rbuf));
if (IS_OSPF6_DEBUG_SPF(PROCESS) || IS_OSPF6_DEBUG_SPF(TIME))
- zlog_debug("SPF runtime: %lld sec %lld usec",
- (long long)runtime.tv_sec,
- (long long)runtime.tv_usec);
-
- zlog_info(
- "SPF processing: # Areas: %d, SPF runtime: %lld sec %lld usec, Reason: %s",
- areas_processed, (long long)runtime.tv_sec,
- (long long)runtime.tv_usec, rbuf);
+ zlog_debug(
+ "SPF processing: # Areas: %d, SPF runtime: %lld sec %lld usec, Reason: %s",
+ areas_processed, (long long)runtime.tv_sec,
+ (long long)runtime.tv_usec, rbuf);
ospf6->last_spf_reason = ospf6->spf_reason;
ospf6_reset_spf_reason(ospf6);
@@ -718,9 +716,7 @@ void ospf6_spf_schedule(struct ospf6 *ospf6, unsigned int reason)
}
if (IS_OSPF6_DEBUG_SPF(PROCESS) || IS_OSPF6_DEBUG_SPF(TIME))
- zlog_debug("SPF: calculation timer delay = %ld", delay);
-
- zlog_info("SPF: Scheduled in %ld msec", delay);
+ zlog_debug("SPF: Rescheduling in %ld msec", delay);
ospf6->t_spf_calc = NULL;
thread_add_timer_msec(master, ospf6_spf_calculation_thread, ospf6,
@@ -728,16 +724,24 @@ void ospf6_spf_schedule(struct ospf6 *ospf6, unsigned int reason)
}
void ospf6_spf_display_subtree(struct vty *vty, const char *prefix, int rest,
- struct ospf6_vertex *v)
+ struct ospf6_vertex *v, json_object *json_obj,
+ bool use_json)
{
struct listnode *node, *nnode;
struct ospf6_vertex *c;
char *next_prefix;
int len;
int restnum;
+ json_object *json_childs = NULL;
+ json_object *json_child = NULL;
- /* "prefix" is the space prefix of the display line */
- vty_out(vty, "%s+-%s [%d]\n", prefix, v->name, v->cost);
+ if (use_json) {
+ json_childs = json_object_new_object();
+ json_object_int_add(json_obj, "cost", v->cost);
+ } else {
+ /* "prefix" is the space prefix of the display line */
+ vty_out(vty, "%s+-%s [%d]\n", prefix, v->name, v->cost);
+ }
len = strlen(prefix) + 4;
next_prefix = (char *)malloc(len);
@@ -749,10 +753,27 @@ void ospf6_spf_display_subtree(struct vty *vty, const char *prefix, int rest,
restnum = listcount(v->child_list);
for (ALL_LIST_ELEMENTS(v->child_list, node, nnode, c)) {
- restnum--;
- ospf6_spf_display_subtree(vty, next_prefix, restnum, c);
- }
+ if (use_json)
+ json_child = json_object_new_object();
+ else
+ restnum--;
+ ospf6_spf_display_subtree(vty, next_prefix, restnum, c,
+ json_child, use_json);
+
+ if (use_json)
+ json_object_object_add(json_childs, c->name,
+ json_child);
+ }
+ if (use_json) {
+ json_object_boolean_add(json_obj, "isLeafNode",
+ !listcount(v->child_list));
+ if (listcount(v->child_list))
+ json_object_object_add(json_obj, "children",
+ json_childs);
+ else
+ json_object_free(json_childs);
+ }
free(next_prefix);
}
@@ -1002,13 +1023,8 @@ struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area,
return NULL;
}
- /* Allocate memory for this LSA */
- new_header = XMALLOC(MTYPE_OSPF6_LSA_HEADER, total_lsa_length);
-
- /* LSA information structure */
- lsa = XCALLOC(MTYPE_OSPF6_LSA, sizeof(struct ospf6_lsa));
-
- lsa->header = (struct ospf6_lsa_header *)new_header;
+ lsa = ospf6_lsa_alloc(total_lsa_length);
+ new_header = (uint8_t *)lsa->header;
lsa->lsdb = area->temp_router_lsa_lsdb;