]> git.puffer.fish Git - mirror/frr.git/commitdiff
ospf6d: add 'log-adjacency-changes [detail]'
authorDinesh Dutt <ddutt@cumulusnetworks.com>
Mon, 26 Aug 2013 03:40:16 +0000 (03:40 +0000)
committerDavid Lamparter <equinox@opensourcerouting.org>
Fri, 8 Nov 2013 02:15:43 +0000 (18:15 -0800)
Similar to OSPFv2, add support for 'log-adjacency-changes [detail]' to log
changes in adjacency state of ospfv3 neighbors.

Signed-off-by: Pradosh Mohapatra <pmohapat at cumulusnetworks.com>
Reviewed-by: Dinesh G Dutt <ddutt at cumulusnetworks.com>
Reviewed-by: Scott Feldman <sfeldma at cumulusnetworks.com>
Reviewed-by: Shrijeet Mukherjee <shm at cumulusnetworks.com>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
ospf6d/ospf6_neighbor.c
ospf6d/ospf6_neighbor.h
ospf6d/ospf6_top.c
ospf6d/ospf6_top.h

index b7d2e40dbd7a160b278dcbb84dfca988eecda0ff..fb209fdfab44b0857a4efc177279a871908ec12f 100644 (file)
@@ -142,7 +142,7 @@ ospf6_neighbor_delete (struct ospf6_neighbor *on)
 }
 
 static void
-ospf6_neighbor_state_change (u_char next_state, struct ospf6_neighbor *on)
+ospf6_neighbor_state_change (u_char next_state, struct ospf6_neighbor *on, int event)
 {
   u_char prev_state;
 
@@ -158,11 +158,23 @@ ospf6_neighbor_state_change (u_char next_state, struct ospf6_neighbor *on)
   /* log */
   if (IS_OSPF6_DEBUG_NEIGHBOR (STATE))
     {
-      zlog_debug ("Neighbor state change %s: [%s]->[%s]", on->name,
+      zlog_debug ("Neighbor state change %s: [%s]->[%s] (%s)", on->name,
                  ospf6_neighbor_state_str[prev_state],
-                 ospf6_neighbor_state_str[next_state]);
+                 ospf6_neighbor_state_str[next_state],
+                 ospf6_neighbor_event_string(event));
     }
 
+  /* Optionally notify about adjacency changes */
+  if (CHECK_FLAG(on->ospf6_if->area->ospf6->config_flags,
+                OSPF6_LOG_ADJACENCY_CHANGES) &&
+      (CHECK_FLAG(on->ospf6_if->area->ospf6->config_flags,
+                 OSPF6_LOG_ADJACENCY_DETAIL) ||
+       (next_state == OSPF6_NEIGHBOR_FULL) || (next_state < prev_state)))
+    zlog_notice("AdjChg: Nbr %s: %s -> %s (%s)", on->name,
+               ospf6_neighbor_state_str[prev_state],
+               ospf6_neighbor_state_str[next_state],
+               ospf6_neighbor_event_string(event));
+
   if (prev_state == OSPF6_NEIGHBOR_FULL || next_state == OSPF6_NEIGHBOR_FULL)
     {
       OSPF6_ROUTER_LSA_SCHEDULE (on->ospf6_if->area);
@@ -223,7 +235,8 @@ hello_received (struct thread *thread)
                                            on->ospf6_if->dead_interval);
 
   if (on->state <= OSPF6_NEIGHBOR_DOWN)
-    ospf6_neighbor_state_change (OSPF6_NEIGHBOR_INIT, on);
+    ospf6_neighbor_state_change (OSPF6_NEIGHBOR_INIT, on,
+                                OSPF6_NEIGHBOR_EVENT_HELLO_RCVD);
 
   return 0;
 }
@@ -246,11 +259,13 @@ twoway_received (struct thread *thread)
 
   if (! need_adjacency (on))
     {
-      ospf6_neighbor_state_change (OSPF6_NEIGHBOR_TWOWAY, on);
+      ospf6_neighbor_state_change (OSPF6_NEIGHBOR_TWOWAY, on,
+                                  OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD);
       return 0;
     }
 
-  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on);
+  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on,
+                              OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD);
   SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
   SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
   SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
@@ -327,7 +342,8 @@ negotiation_done (struct thread *thread)
     }
 
   UNSET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
-  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXCHANGE, on);
+  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXCHANGE, on,
+                              OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE);
 
   return 0;
 }
@@ -355,10 +371,12 @@ exchange_done (struct thread *thread)
 */
 
   if (on->request_list->count == 0)
-    ospf6_neighbor_state_change (OSPF6_NEIGHBOR_FULL, on);
+    ospf6_neighbor_state_change (OSPF6_NEIGHBOR_FULL, on,
+                                OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE);
   else
     {
-      ospf6_neighbor_state_change (OSPF6_NEIGHBOR_LOADING, on);
+      ospf6_neighbor_state_change (OSPF6_NEIGHBOR_LOADING, on,
+                                  OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE);
 
       if (on->thread_send_lsreq == NULL)
        on->thread_send_lsreq =
@@ -408,7 +426,8 @@ loading_done (struct thread *thread)
 
   assert (on->request_list->count == 0);
 
-  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_FULL, on);
+  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_FULL, on,
+                              OSPF6_NEIGHBOR_EVENT_LOADING_DONE);
 
   return 0;
 }
@@ -427,7 +446,8 @@ adj_ok (struct thread *thread)
 
   if (on->state == OSPF6_NEIGHBOR_TWOWAY && need_adjacency (on))
     {
-      ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on);
+      ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on,
+                                  OSPF6_NEIGHBOR_EVENT_ADJ_OK);
       SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
       SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
       SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
@@ -440,7 +460,8 @@ adj_ok (struct thread *thread)
   else if (on->state >= OSPF6_NEIGHBOR_EXSTART &&
            ! need_adjacency (on))
     {
-      ospf6_neighbor_state_change (OSPF6_NEIGHBOR_TWOWAY, on);
+      ospf6_neighbor_state_change (OSPF6_NEIGHBOR_TWOWAY, on,
+                                  OSPF6_NEIGHBOR_EVENT_ADJ_OK);
       ospf6_lsdb_remove_all (on->summary_list);
       ospf6_lsdb_remove_all (on->request_list);
       for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
@@ -469,7 +490,8 @@ seqnumber_mismatch (struct thread *thread)
   if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
     zlog_debug ("Neighbor Event %s: *SeqNumberMismatch*", on->name);
 
-  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on);
+  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on,
+                              OSPF6_NEIGHBOR_EVENT_SEQNUMBER_MISMATCH);
   SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
   SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
   SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
@@ -507,7 +529,8 @@ bad_lsreq (struct thread *thread)
   if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
     zlog_debug ("Neighbor Event %s: *BadLSReq*", on->name);
 
-  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on);
+  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on,
+                              OSPF6_NEIGHBOR_EVENT_BAD_LSREQ);
   SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
   SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
   SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
@@ -545,7 +568,8 @@ oneway_received (struct thread *thread)
   if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
     zlog_debug ("Neighbor Event %s: *1Way-Received*", on->name);
 
-  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_INIT, on);
+  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_INIT, on,
+                              OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD);
   thread_add_event (master, neighbor_change, on->ospf6_if, 0);
 
   ospf6_lsdb_remove_all (on->summary_list);
@@ -580,7 +604,8 @@ inactivity_timer (struct thread *thread)
   on->drouter = on->prev_drouter = 0;
   on->bdrouter = on->prev_bdrouter = 0;
 
-  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_DOWN, on);
+  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_DOWN, on,
+                              OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER);
   thread_add_event (master, neighbor_change, on->ospf6_if, 0);
 
   listnode_delete (on->ospf6_if->neighbor_list, on);
index 750e1b24289f1b3306a216c877ee2742be2b954e..888218980ab14d0e6ce76440c18c68808788ca47 100644 (file)
@@ -108,6 +108,44 @@ struct ospf6_neighbor
 #define OSPF6_NEIGHBOR_LOADING  7
 #define OSPF6_NEIGHBOR_FULL     8
 
+/* Neighbor Events */
+#define OSPF6_NEIGHBOR_EVENT_NO_EVENT             0
+#define OSPF6_NEIGHBOR_EVENT_HELLO_RCVD           1
+#define OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD          2
+#define OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE     3
+#define OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE        4
+#define OSPF6_NEIGHBOR_EVENT_LOADING_DONE         5
+#define OSPF6_NEIGHBOR_EVENT_ADJ_OK               6
+#define OSPF6_NEIGHBOR_EVENT_SEQNUMBER_MISMATCH   7
+#define OSPF6_NEIGHBOR_EVENT_BAD_LSREQ            8
+#define OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD          9
+#define OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER    10
+#define OSPF6_NEIGHBOR_EVENT_MAX_EVENT           11
+
+static const char *ospf6_neighbor_event_str[] =
+  {
+    "NoEvent",
+    "HelloReceived",
+    "2-WayReceived",
+    "NegotiationDone",
+    "ExchangeDone",
+    "LoadingDone",
+    "AdjOK?",
+    "SeqNumberMismatch",
+    "BadLSReq",
+    "1-WayReceived",
+    "InactivityTimer",
+  };
+
+static const char *ospf6_neighbor_event_string (int event)
+{
+  #define OSPF6_NEIGHBOR_UNKNOWN_EVENT_STRING "UnknownEvent"
+
+  if (event < OSPF6_NEIGHBOR_EVENT_MAX_EVENT)
+      return ospf6_neighbor_event_str[event];
+  return OSPF6_NEIGHBOR_UNKNOWN_EVENT_STRING;
+}
+
 extern const char *ospf6_neighbor_state_str[];
 
 \f
index dec7096cf0006dfbdb65d303bd09979dca5c1ca7..1f7cdc8542f70775992d360275e4ff4b47f73bda 100644 (file)
@@ -338,6 +338,56 @@ DEFUN (ospf6_router_id,
   return CMD_SUCCESS;
 }
 
+DEFUN (ospf6_log_adjacency_changes,
+       ospf6_log_adjacency_changes_cmd,
+       "log-adjacency-changes",
+       "Log changes in adjacency state\n")
+{
+  struct ospf6 *ospf6 = vty->index;
+
+  SET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_CHANGES);
+  return CMD_SUCCESS;
+}
+
+DEFUN (ospf6_log_adjacency_changes_detail,
+       ospf6_log_adjacency_changes_detail_cmd,
+       "log-adjacency-changes detail",
+              "Log changes in adjacency state\n"
+       "Log all state changes\n")
+{
+  struct ospf6 *ospf6 = vty->index;
+
+  SET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_CHANGES);
+  SET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_DETAIL);
+  return CMD_SUCCESS;
+}
+
+DEFUN (no_ospf6_log_adjacency_changes,
+       no_ospf6_log_adjacency_changes_cmd,
+       "no log-adjacency-changes",
+              NO_STR
+       "Log changes in adjacency state\n")
+{
+  struct ospf6 *ospf6 = vty->index;
+
+  UNSET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_DETAIL);
+  UNSET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_CHANGES);
+  return CMD_SUCCESS;
+}
+
+DEFUN (no_ospf6_log_adjacency_changes_detail,
+       no_ospf6_log_adjacency_changes_detail_cmd,
+       "no log-adjacency-changes detail",
+              NO_STR
+              "Log changes in adjacency state\n"
+       "Log all state changes\n")
+{
+  struct ospf6 *ospf6 = vty->index;
+
+  UNSET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_DETAIL);
+  return CMD_SUCCESS;
+}
+
 DEFUN (ospf6_interface_area,
        ospf6_interface_area_cmd,
        "interface IFNAME area A.B.C.D",
@@ -592,6 +642,16 @@ ospf6_show (struct vty *vty, struct ospf6 *o)
   vty_out (vty, " Number of areas in this router is %u%s",
            listcount (o->area_list), VNL);
 
+  if (CHECK_FLAG(o->config_flags, OSPF6_LOG_ADJACENCY_CHANGES))
+    {
+      if (CHECK_FLAG(o->config_flags, OSPF6_LOG_ADJACENCY_DETAIL))
+       vty_out(vty, " All adjacency changes are logged%s",VTY_NEWLINE);
+      else
+       vty_out(vty, " Adjacency changes are logged%s",VTY_NEWLINE);
+    }
+
+  vty_out (vty, "%s",VTY_NEWLINE);
+
   for (ALL_LIST_ELEMENTS_RO (o->area_list, n, oa))
     ospf6_area_show (vty, oa);
 }
@@ -782,6 +842,15 @@ config_write_ospf6 (struct vty *vty)
   if (ospf6->router_id_static != 0)
     vty_out (vty, " router-id %s%s", router_id, VNL);
 
+  /* log-adjacency-changes flag print. */
+  if (CHECK_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_CHANGES))
+    {
+      vty_out(vty, " log-adjacency-changes");
+      if (CHECK_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_DETAIL))
+       vty_out(vty, " detail");
+      vty_out(vty, "%s", VTY_NEWLINE);
+    }
+
   ospf6_stub_router_config_write (vty);
   ospf6_redistribute_config_write (vty);
   ospf6_area_config_write (vty);
@@ -836,6 +905,10 @@ ospf6_top_init (void)
 
   install_default (OSPF6_NODE);
   install_element (OSPF6_NODE, &ospf6_router_id_cmd);
+  install_element (OSPF6_NODE, &ospf6_log_adjacency_changes_cmd);
+  install_element (OSPF6_NODE, &ospf6_log_adjacency_changes_detail_cmd);
+  install_element (OSPF6_NODE, &no_ospf6_log_adjacency_changes_cmd);
+  install_element (OSPF6_NODE, &no_ospf6_log_adjacency_changes_detail_cmd);
   install_element (OSPF6_NODE, &ospf6_interface_area_cmd);
   install_element (OSPF6_NODE, &no_ospf6_interface_area_cmd);
   install_element (OSPF6_NODE, &ospf6_stub_router_admin_cmd);
index 02eb9154735ceb68aa40fa81bad16cd2fd311b19..9d7cfd9199c76bb081e0377b8bb8e5bd12eb7227 100644 (file)
@@ -60,6 +60,11 @@ struct ospf6
 
   u_char flag;
 
+  /* Configured flags */
+  u_char config_flags;
+#define OSPF6_LOG_ADJACENCY_CHANGES      (1 << 0)
+#define OSPF6_LOG_ADJACENCY_DETAIL       (1 << 1)
+
   /* SPF parameters */
   unsigned int spf_delay;              /* SPF delay time. */
   unsigned int spf_holdtime;           /* SPF hold time. */