Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ospf6d: rework ospf6 neighbor state display #14912

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 73 additions & 22 deletions ospf6d/ospf6_neighbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -848,16 +848,34 @@ DEFPY(ipv6_ospf6_p2xp_neigh_poll_interval,
return CMD_SUCCESS;
}

static const char *ospf6_neighbor_role_message(struct ospf6_neighbor *on)
{
/* Neighbor State */
if (on->router_id == on->drouter)
return "DR";
if (on->router_id == on->bdrouter)
return "BR";
return "DROther";
}

ton31337 marked this conversation as resolved.
Show resolved Hide resolved
static const char *ospf6_neighbor_state_message(struct ospf6_neighbor *on)
{
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 */
static void ospf6_neighbor_show(struct vty *vty, struct ospf6_neighbor *on,
json_object *json_array, bool use_json)
{
char router_id[16];
char duration[64];
struct timeval res;
char nstate[16];
char deadtime[64];
long h, m, s;
long h, m, s, time_store;
json_object *json_route;

/* Router-ID (Name) */
Expand All @@ -879,20 +897,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");
}

/* Duration */
monotime_since(&on->last_changed, &res);
timerstring(&res, duration, sizeof(duration));
Expand All @@ -906,11 +910,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",
ton31337 marked this conversation as resolved.
Show resolved Hide resolved
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 All @@ -922,7 +949,8 @@ static void ospf6_neighbor_show(struct vty *vty, struct ospf6_neighbor *on,
} else
vty_out(vty, "%-15s %3d %11s %8s/%-12s %11s %s[%s]\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this enough/aligned with the new output?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact only json part is modified

router_id, on->priority, deadtime,
ospf6_neighbor_state_str[on->state], nstate, duration,
ospf6_neighbor_state_str[on->state],
ospf6_neighbor_state_message(on), duration,
on->ospf6_if->interface->name,
ospf6_interface_state_str[on->ospf6_if->state]);
}
Expand Down Expand Up @@ -984,6 +1012,7 @@ static void ospf6_neighbor_show_detail(struct vty *vty,
json_object *json_neighbor;
json_object *json_array;
char db_desc_str[20];
long time_store;

inet_ntop(AF_INET6, &on->linklocal_addr, linklocal_addr,
sizeof(linklocal_addr));
Expand All @@ -1008,8 +1037,30 @@ static void ospf6_neighbor_show_detail(struct vty *vty,
"%pI6", on->ospf6_if->linklocal_addr);
json_object_string_add(json_neighbor, "linkLocalAddress",
linklocal_addr);
#if CONFDATE > 20241129
CPP_NOTICE(
"Remove %s() JSON keys: neighborState", __func__)
#endif
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_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,
NULL)
/ 1000LL;
json_object_int_add(json_neighbor,
"routerDeadIntervalTimerDueMsec",
time_store);
} else
json_object_string_add(json_neighbor,
"routerDeadIntervalTimerDueMsec",
"inactive");
json_object_string_add(json_neighbor, "neighborStateDuration",
duration);
json_object_string_add(json_neighbor, "neighborDRouter",
Expand Down Expand Up @@ -1175,7 +1226,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 @@ -1332,9 +1382,10 @@ 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(json, "neighbors",
json_array);
} else
json_object_free(json_array);
vty_json(vty, json);
}
Expand Down
11 changes: 3 additions & 8 deletions ospfd/ospf_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -5089,14 +5089,9 @@ DEFUN (show_ip_ospf_neighbor_all,
if (ospf) {
ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj,
use_vrf);
if (uj) {
vty_out(vty, "%s\n",
json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
}
}

if (uj)
if (uj)
vty_json(vty, json);
} else if (uj)
json_object_free(json);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should call and print an empty JSON in such a case, right? vty_json_empty()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i use vty_json since it manage "/" caracter


return ret;
Expand Down
6 changes: 3 additions & 3 deletions tests/topotests/lib/ospf.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,15 +780,15 @@ def verify_ospf6_neighbor(tgen, topo=None, dut=None, input_dict=None, lan=False)
"neighbors": {
"r1": {
"state": "Full",
"role": "DR"
"nbrState": "Full/DR"
},
"r2": {
"state": "Full",
"role": "DROther"
"nbrState": "Full/DROther"
},
"r3": {
"state": "Full",
"role": "DROther"
"nbrState": "Full/DROther"
}
}
}
Expand Down
Loading