[ospfd] record timestamp and event of last NSM state change for neighbour
2006-07-10 Paul Jakma <paul.jakma@sun.com>
* ospf_nsm.c: (ospf_nsm_event) Record state change timestamp
and event in nbr struct.
* ospf_neighbor.h: (struct ospf_neighbor) Add fields to record
timestamp of last NSM change and event.
* ospf_vty.c: (show_ip_ospf_neighbor_detail_sub) Print
last state change timestamp and event, if available.
diff --git a/ospfd/ChangeLog b/ospfd/ChangeLog
index 79bb2bd..1564bdb 100644
--- a/ospfd/ChangeLog
+++ b/ospfd/ChangeLog
@@ -22,6 +22,11 @@
(ospf_nsm_event) call nsm_notice_state_changes from here.
Move the debug message to entry of function, so it gets out
even if something goes wrong.
+ Record state change timestamp and event in nbr struct.
+ * ospf_neighbor.h: (struct ospf_neighbor) Add fields to record
+ timestamp of last NSM change and event.
+ * ospf_vty.c: (show_ip_ospf_neighbor_detail_sub) Print
+ last state change timestamp and event, if available.
2006-07-10 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
diff --git a/ospfd/ospf_neighbor.h b/ospfd/ospf_neighbor.h
index cbfbc2d..9b7ff36 100644
--- a/ospfd/ospf_neighbor.h
+++ b/ospfd/ospf_neighbor.h
@@ -82,6 +82,8 @@
/* Statistics Field */
u_int32_t state_change;
+ struct timeval ts_last_change;
+ const char *last_event_str;
struct ospf_nbr_nbma *nbr_nbma;
};
diff --git a/ospfd/ospf_nsm.c b/ospfd/ospf_nsm.c
index 1b4116d..ff0a52d 100644
--- a/ospfd/ospf_nsm.c
+++ b/ospfd/ospf_nsm.c
@@ -615,6 +615,9 @@
LOOKUP (ospf_nsm_state_msg, next_state),
ospf_nsm_event_str [event]);
+ nbr->ts_last_change = recent_time;
+ nbr->last_event_str = ospf_nsm_event_str [event];
+
#ifdef HAVE_SNMP
/* Terminal state or regression */
if ((next_state == NSM_Full)
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index ec00201..44049d8 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -3155,7 +3155,14 @@
nbr->priority, LOOKUP (ospf_nsm_state_msg, nbr->state));
/* Show state changes. */
vty_out (vty, " %d state changes%s", nbr->state_change, VTY_NEWLINE);
-
+ if (nbr->ts_last_change.tv_sec || nbr->ts_last_change.tv_usec)
+ {
+ struct timeval res = tv_sub (recent_time, nbr->ts_last_change);
+ vty_out (vty, " Last state change %s ago, due to %s%s",
+ ospf_timeval_dump (&res, timebuf, sizeof(timebuf)),
+ (nbr->last_event_str ? nbr->last_event_str : "??"),
+ VTY_NEWLINE);
+ }
/* Show Designated Rotuer ID. */
vty_out (vty, " DR is %s,", inet_ntoa (nbr->d_router));
/* Show Backup Designated Rotuer ID. */