Browse Source

Run DR election when hello packet is received.

Everton Marques 7 years ago
parent
commit
777fe1f2b6
5 changed files with 23 additions and 12 deletions
  1. 3 2
      pimd/pim_cmd.c
  2. 1 1
      pimd/pim_iface.c
  3. 1 0
      pimd/pim_iface.h
  4. 5 4
      pimd/pim_neighbor.c
  5. 13 5
      pimd/pim_pim.c

+ 3 - 2
pimd/pim_cmd.c

@@ -563,7 +563,7 @@ static void pim_show_dr(struct vty *vty)
 	  "NonPri: Number of neighbors missing DR Priority hello option%s%s",
 	  VTY_NEWLINE, VTY_NEWLINE);
   
-  vty_out(vty, "Interface Address         DR              Uptime   Elections NonPri%s", VTY_NEWLINE);
+  vty_out(vty, "Interface Address         DR              Uptime   Elections Changes NonPri%s", VTY_NEWLINE);
 
   for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
     struct pim_interface *pim_ifp;
@@ -587,12 +587,13 @@ static void pim_show_dr(struct vty *vty)
     pim_inet4_dump("<dr?>", pim_ifp->pim_dr_addr,
 		   dr_str, sizeof(dr_str));
 
-    vty_out(vty, "%-9s %-15s %-15s %8s %9d %6d%s",
+    vty_out(vty, "%-9s %-15s %-15s %8s %9d %7d %6d%s",
 	    ifp->name,
 	    inet_ntoa(ifaddr),
 	    dr_str,
 	    dr_uptime,
 	    pim_ifp->pim_dr_election_count,
+	    pim_ifp->pim_dr_election_changes,
 	    pim_ifp->pim_dr_num_nondrpri_neighbors,
 	    VTY_NEWLINE);
   }

+ 1 - 1
pimd/pim_iface.c

@@ -226,7 +226,7 @@ static void pim_addr_change(struct interface *ifp)
   pim_ifp = ifp->info;
   zassert(pim_ifp);
 
-  pim_if_dr_election(ifp); /* Done TODO T30 */
+  pim_if_dr_election(ifp); /* router's own DR Priority (addr) changes -- Done TODO T30 */
   pim_if_update_join_desired(pim_ifp); /* depends on DR */
   pim_if_update_could_assert(ifp); /* depends on DR */
   pim_if_update_my_assert_metric(ifp); /* depends on could_assert */

+ 1 - 0
pimd/pim_iface.h

@@ -87,6 +87,7 @@ struct pim_interface {
   /* DR Election */
   int64_t        pim_dr_election_last; /* timestamp */
   int            pim_dr_election_count;
+  int            pim_dr_election_changes;
   struct in_addr pim_dr_addr;
   uint32_t       pim_dr_priority;            /* config */
   int            pim_dr_num_nondrpri_neighbors; /* neighbors without dr_pri */

+ 5 - 4
pimd/pim_neighbor.c

@@ -132,7 +132,8 @@ void pim_if_dr_election(struct interface *ifp)
     zlog_info("%s: DR was %s now is %s on interface %s",
 	      __PRETTY_FUNCTION__,
 	      dr_old_str, dr_new_str, ifp->name);
-    
+
+    ++pim_ifp->pim_dr_election_changes; 
     pim_if_update_join_desired(pim_ifp);
     pim_if_update_could_assert(ifp);
     pim_if_update_assert_tracking_desired(ifp);
@@ -191,7 +192,7 @@ static void update_dr_priority(struct pim_neighbor *neigh,
       PIM Hello message is received, when a neighbor times out, or when a
       router's own DR Priority changes.
     */
-    pim_if_dr_election(neigh->interface);
+    pim_if_dr_election(neigh->interface); // router's own DR Priority changes
   }
 }
 
@@ -226,7 +227,7 @@ static int on_neighbor_timer(struct thread *t)
     PIM Hello message is received, when a neighbor times out, or when a
     router's own DR Priority changes.
   */
-  pim_if_dr_election(ifp);
+  pim_if_dr_election(ifp); // neighbor times out
 
   return 0;
 }
@@ -347,7 +348,7 @@ static struct pim_neighbor *pim_neighbor_new(struct interface *ifp,
     PIM Hello message is received, when a neighbor times out, or when a
     router's own DR Priority changes.
   */
-  pim_if_dr_election(neigh->interface);
+  pim_if_dr_election(neigh->interface); // new neighbor -- should not trigger dr election...
 
   /*
     RFC 4601: 4.3.1.  Sending Hello Messages

+ 13 - 5
pimd/pim_pim.c

@@ -208,10 +208,14 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len)
   }
 
   if (pim_type == PIM_MSG_TYPE_HELLO) {
-    return pim_hello_recv(ifp,
-			  ip_hdr->ip_src,
-			  pim_msg + PIM_MSG_HEADER_LEN,
-			  pim_msg_len - PIM_MSG_HEADER_LEN);
+    int result = pim_hello_recv(ifp,
+                 ip_hdr->ip_src,
+                 pim_msg + PIM_MSG_HEADER_LEN,
+                 pim_msg_len - PIM_MSG_HEADER_LEN);
+    if (!result) {
+      pim_if_dr_election(ifp); /* PIM Hello message is received */
+    }
+    return result;
   }
 
   neigh = pim_neighbor_find(ifp, ip_hdr->ip_src);
@@ -324,7 +328,10 @@ static int pim_sock_read(struct thread *t)
   }
 #endif
 
-  if (pim_pim_packet(ifp, buf, len)) {
+  int fail = pim_pim_packet(ifp, buf, len);
+  if (fail) {
+    zlog_warn("%s: pim_pim_packet() return=%d",
+              __PRETTY_FUNCTION__, fail);
     goto done;
   }
 
@@ -429,6 +436,7 @@ void pim_sock_reset(struct interface *ifp)
   /* DR Election */
   pim_ifp->pim_dr_election_last          = 0; /* timestamp */
   pim_ifp->pim_dr_election_count         = 0;
+  pim_ifp->pim_dr_election_changes       = 0;
   pim_ifp->pim_dr_num_nondrpri_neighbors = 0; /* neighbors without dr_pri */
   pim_ifp->pim_dr_addr                   = pim_ifp->primary_address;