Skip to content

Commit

Permalink
ospf6d: add json attributes to 'show ipv6 ospf6 neighbor'
Browse files Browse the repository at this point in the history
Add the following attributes in each neighbor of the vty command:
'show ipv6 ospf6 neighbor json':
- nbrPriority : integer
- Role: DR, BDR, DROther, or PointToPoint
- nbrState : <state>/<Role> where:
   o Role is the above attribute
   o state is "None",    "Down",     "Attempt", "Init", "Twoway",
              "ExStart", "ExChange", "Loading", "Full"
- routerDeadIntervalTimerDueMsec: integer value otherwise "inactive"

Enter in a deprecation workflow for state and priority values, which
are replaced by nbrState.

Signed-off-by: Philippe Guibert <[email protected]>
  • Loading branch information
pguibert6WIND authored and root committed Dec 14, 2023
1 parent a1b7c86 commit c5c41e5
Showing 1 changed file with 51 additions and 52 deletions.
103 changes: 51 additions & 52 deletions ospf6d/ospf6_neighbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,39 +846,25 @@ DEFPY(ipv6_ospf6_p2xp_neigh_poll_interval,

p2xp_unicast_hello_sched(p2xp_cfg);
return CMD_SUCCESS;

}

/* build state value */
static void ospf6_neighbor_state_message(struct ospf6_neighbor *on,
char *nstate, size_t nstate_len)
static const char *ospf6_neighbor_role_message(struct ospf6_neighbor *on)
{
/* Neighbor State */
if (on->ospf6_if->type == OSPF_IFTYPE_POINTOPOINT)
snprintf(nstate, nstate_len, "PointToPoint");
else {
if (on->router_id == on->drouter)
snprintf(nstate, nstate_len, "DR");
else if (on->router_id == on->bdrouter)
snprintf(nstate, nstate_len, "BR");
else
snprintf(nstate, nstate_len, "DROther");
}
if (on->router_id == on->drouter)
return "DR";
if (on->router_id == on->bdrouter)
return "BR";
return "DROther";
}

/* build nbrState value */
static void ospf6_neighbor_nstate_message(struct ospf6_neighbor *on,
char *nstate, size_t nstate_len)
static const char *ospf6_neighbor_state_message(struct ospf6_neighbor *on)
{
char state[16];

memset(state, 0, sizeof(state));
memset(nstate, 0, nstate_len);

ospf6_neighbor_state_message(on, state, sizeof(state));

snprintf(nstate, nstate_len, "%s/%s", state,
ospf6_neighbor_state_str[on->state]);
if (on->ospf6_if->type == OSPF_IFTYPE_POINTOMULTIPOINT)
return "PtMultipoint";
if (on->ospf6_if->type == OSPF_IFTYPE_POINTOPOINT)
return "PointToPoint";
return ospf6_neighbor_role_message(on);
}

/* show neighbor structure */
Expand All @@ -890,7 +876,7 @@ static void ospf6_neighbor_show(struct vty *vty, struct ospf6_neighbor *on,
struct timeval res;
char nstate[17];
char deadtime[64];
long h, m, s;
long h, m, s, time_store;
json_object *json_route;

/* Router-ID (Name) */
Expand All @@ -912,21 +898,6 @@ static void ospf6_neighbor_show(struct vty *vty, struct ospf6_neighbor *on,
}
snprintf(deadtime, sizeof(deadtime), "%02ld:%02ld:%02ld", h, m, s);

/* Neighbor State */
if (on->ospf6_if->type == OSPF_IFTYPE_POINTOPOINT)
snprintf(nstate, sizeof(nstate), "PointToPoint");
else if (on->ospf6_if->type == OSPF_IFTYPE_POINTOMULTIPOINT)
snprintf(nstate, sizeof(nstate), "PtMultipoint");
else {
if (on->router_id == on->drouter)
snprintf(nstate, sizeof(nstate), "DR");
else if (on->router_id == on->bdrouter)
snprintf(nstate, sizeof(nstate), "BDR");
else
snprintf(nstate, sizeof(nstate), "DROther");
}
ospf6_neighbor_state_message(on, nstate, sizeof(nstate));

/* Duration */
monotime_since(&on->last_changed, &res);
timerstring(&res, duration, sizeof(duration));
Expand All @@ -940,11 +911,34 @@ static void ospf6_neighbor_show(struct vty *vty, struct ospf6_neighbor *on,
json_route = json_object_new_object();

json_object_string_add(json_route, "neighborId", router_id);
#if CONFDATE > 20241129
CPP_NOTICE(
"Remove %s() JSON keys: state, priority", __func__)
#endif
json_object_int_add(json_route, "priority", on->priority);
json_object_string_add(json_route, "deadTime", deadtime);
json_object_string_add(json_route, "state",
ospf6_neighbor_state_str[on->state]);
json_object_string_add(json_route, "ifState", nstate);
json_object_int_add(json_route, "nbrPriority", on->priority);
json_object_string_addf(json_route, "nbrState", "%s/%s",
ospf6_neighbor_state_str[on->state],
ospf6_neighbor_role_message(on));
json_object_string_add(json_route, "role",
ospf6_neighbor_role_message(on));
if (on->inactivity_timer) {
time_store =
monotime_until(&on->inactivity_timer->u.sands,
NULL)
/ 1000LL;
json_object_int_add(json_route,
"routerDeadIntervalTimerDueMsec",
time_store);
} else
json_object_string_add(json_route,
"routerDeadIntervalTimerDueMsec",
"inactive");
json_object_string_add(json_route, "ifState",
ospf6_neighbor_state_message(on));
json_object_string_add(json_route, "duration", duration);
json_object_string_add(json_route, "interfaceName",
on->ospf6_if->interface->name);
Expand Down Expand Up @@ -1018,15 +1012,13 @@ static void ospf6_neighbor_show_detail(struct vty *vty,
json_object *json_neighbor;
json_object *json_array;
char db_desc_str[20];
char nstate[25];
long time_store;

inet_ntop(AF_INET6, &on->linklocal_addr, linklocal_addr,
sizeof(linklocal_addr));
inet_ntop(AF_INET, &on->drouter, drouter, sizeof(drouter));
inet_ntop(AF_INET, &on->bdrouter, bdrouter, sizeof(bdrouter));

ospf6_neighbor_nstate_message(on, nstate, sizeof(nstate));
monotime(&now);
timersub(&now, &on->last_changed, &res);
timerstring(&res, duration, sizeof(duration));
Expand All @@ -1050,9 +1042,11 @@ static void ospf6_neighbor_show_detail(struct vty *vty,
json_object_string_add(json_neighbor, "neighborState",
ospf6_neighbor_state_str[on->state]);
json_object_int_add(json_neighbor, "nbrPriority", on->priority);
json_object_string_add(json_neighbor, "nbrState", nstate);
json_object_string_add(json_neighbor, "Role",
ospf6_neighbor_state_str[on->state]);
json_object_string_addf(json_neighbor, "nbrState", "%s/%s",
ospf6_neighbor_state_str[on->state],
ospf6_neighbor_role_message(on));
json_object_string_add(json_neighbor, "role",
ospf6_neighbor_role_message(on));
if (on->inactivity_timer) {
time_store =
monotime_until(&on->inactivity_timer->u.sands,
Expand Down Expand Up @@ -1230,7 +1224,6 @@ static void ospf6_neighbor_show_detail(struct vty *vty,
} else
json_object_string_add(json_neighbor, "authStatus",
"disabled");

json_object_object_add(json, on->name, json_neighbor);

} else {
Expand Down Expand Up @@ -1387,10 +1380,16 @@ static void ospf6_neighbor_show_detail_common(struct vty *vty,
}

if (uj) {
if (showfunc != ospf6_neighbor_show_detail)
json_object_object_add(json, "neighbors", json_array);
else
if (showfunc != ospf6_neighbor_show_detail) {
json_object_object_add_ex(json, "neighbors",
json_array,
JSON_C_TO_STRING_NOSLASHESCAPE);
} else {
vty_out(vty, "%s\n",
json_object_to_json_string_ext(json,
JSON_C_TO_STRING_NOSLASHESCAPE));
json_object_free(json_array);
}
vty_json(vty, json);
}
}
Expand Down

0 comments on commit c5c41e5

Please sign in to comment.