Hi.

I cleaned my patch little bit more.  Sending as attached file.

2015-06-16 18:27 GMT+02:00 Patrik Brigant <[email protected]>:

> Dear Quagga Team
>
> I am sending you my work of BGP Best External feature in below attached
> patch. Please be informed that I am more networking guy than programmer :-)
> and this was my first 'big' attempt to make something like that. I was
> testing this with feature in Lab with Cisco devices. Feel free to edit, I
> hope that it will be at least a little usefull, and also hope that patch is
> OK. If more files are required or the format of the patch is not OK, just
> ping me, I will try to correct.
>
> Best.... Patrik
>
> 2015-05-01 21:06 GMT+02:00 Patrik Brigant <[email protected]>:
>
>> Dear Quagga Team
>>
>> My name is Patrik Brigant and I am student of University of Zilina. As I
>> am finishing my Engineer studies, my master thesis was about Current trends
>> of BGP Routing Protocol.  One of many parts was also implementation of BGP
>> Best External feature to Quagga routing software.
>>
>> I want to provide you this feature, if you have interest. Is in your team
>> someone who is responsible or familiar with bgpd deamon, and will be able
>> to check my work. What additional steps i need to take, and in which format
>> I need to give you my work. I heard about some patch. But currently I do
>> not have any additional informations.
>>
>> thanks for now, and waiting to your reply.
>> Patrik Brigant
>>
>> --
>> Bc. Patrik Brigant
>> Hviezdoslavova 43/33
>> 965 01  Žiar nad Hronom
>> Mobil : +421 915 808 794
>> e-mail : [email protected]
>>
>>
>
>
> --
> Ing. Patrik Brigant
> Mobil : +421 915 808 794
> e-mail : [email protected]
>
>


-- 
Ing. Patrik Brigant
Mobil : +421 915 808 794
e-mail : [email protected]
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index e7357e5..4f01916 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -1304,6 +1304,8 @@
 {
   struct bgp_info *old;
   struct bgp_info *new;
+  struct bgp_info *new_best_external;
+  struct bgp_info *old_best_external;
 };
 
 static void
@@ -1319,6 +1322,9 @@
   struct bgp_info *nextri = NULL;
   int paths_eq, do_mpath;
   struct list mp_list;
+
+  struct bgp_info *new_best_external;
+  struct bgp_info *old_best_external;
 
   bgp_mp_list_init (&mp_list);
   do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
@@ -1376,11 +1382,16 @@
        bgp_mp_list_clear (&mp_list);
       }
 
   /* Check old selected route and new selected route. */
   old_select = NULL;
   new_select = NULL;
+  new_best_external = NULL;
+  old_best_external = NULL;
   for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
     {
@@ -1423,6 +1436,25 @@
 
       if (do_mpath && paths_eq)
        bgp_mp_list_add (&mp_list, ri);
+
+      /*BGP BEST EXTERNAL Feature*/
+
+
+         if (CHECK_FLAG (ri->flags, BGP_INFO_BEST_EXTERNAL))
+                 old_best_external = ri;
+
+                         if ((ri) && ((ri->peer->as) && (ri->peer->as != 
ri->peer->local_as)))
+                         {
+                                 if (bgp_info_cmp (bgp, ri, new_best_external, 
&paths_eq))
+                                 {
+                                         new_best_external = ri;
+
+                                 }
+
+                         }
+
+      /*BGP BEST EXTERNAL Feature*/
+
     }
     
 
@@ -1434,6 +1466,8 @@
 
   result->old = old_select;
   result->new = new_select;
+  result->new_best_external = new_best_external;
+  result->old_best_external = old_best_external;
 
   return;
 }
@@ -1571,12 +1610,67 @@
   struct bgp_info *old_select;
   struct bgp_info_pair old_and_new;
   struct listnode *node, *nnode;
-  struct peer *peer;
-  
+  struct bgp_info *new_best_external;
+  struct bgp_info *old_best_external;
+
   /* Best path selection. */
   bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
   old_select = old_and_new.old;
   new_select = old_and_new.new;
+  new_best_external = old_and_new.new_best_external;
+  old_best_external = old_and_new.old_best_external;
+
+  /*BEST EXTERNAL */
+  if((bgp_flag_check (bgp, BGP_FLAG_ADVERTISE_BEST_EXTERNAL )) && 
(new_best_external))
+        {
+                 if( old_best_external != new_best_external)
+                 {
+
+                                  for (ALL_LIST_ELEMENTS (bgp->peer, node, 
nnode, peer))
+                                  {
+                                                 if(bgp->as == peer->as)
+                                                 {
+                                                         
bgp_process_announce_selected (peer, new_best_external, rn, afi, safi);
+                                                         bgp_info_set_flag 
(rn, new_best_external, BGP_INFO_BEST_EXTERNAL);
+                                                 }
+                                   }
+
+                 }
+                 else { /*zlog_info("Bgp MAIN BEST EXTERNAL NOTHING TO DO 
.");*/ }
+
+         }
+  else
+  {
+       if(!(bgp_flag_check (bgp, BGP_FLAG_ADVERTISE_BEST_EXTERNAL )))
+       {
+                if ( (new_best_external) && (CHECK_FLAG 
(new_best_external->flags, BGP_INFO_BEST_EXTERNAL)))
+
+                {
+                        if (CHECK_FLAG (new_best_external->flags, 
BGP_INFO_SELECTED))
+                        {
+                                bgp_info_unset_flag (rn, new_best_external, 
BGP_INFO_BEST_EXTERNAL);
+                        }
+                        else
+                        {
+                        for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
+                                           {
+                                                if(bgp->as == peer->as)
+                                                  {
+                                                       bgp_adj_out_unset(rn, 
peer, &rn->p, afi, safi);
+                                                   }
+                                                }
+                        bgp_info_unset_flag (rn, new_best_external, 
BGP_INFO_BEST_EXTERNAL);
+                        }
+
+                }
+       }
+
+  }
+
+
+  /*BEST EXTERNAL END*/
 
   /* Nothing to do. */
   if (old_select && old_select == new_select)
@@ -2597,7 +2696,7 @@
 
   for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
     for (ri = rn->info; ri; ri = ri->next)
-      if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
+      if (((CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) || (CHECK_FLAG 
(ri->flags, BGP_INFO_BEST_EXTERNAL))) && (ri->peer != peer))
        {
          if ( (rsclient) ?
               (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, 
safi))
@@ -5637,6 +5737,10 @@
   else
     vty_out (vty, " ");
 
+  /* Best External route. */
+  if (CHECK_FLAG (binfo->flags, BGP_INFO_BEST_EXTERNAL))
+        vty_out (vty, "x");
+
   /* Internal route. */
     if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
       vty_out (vty, "i");
@@ -6121,7 +6225,8 @@
 
 #define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
                              "h history, * valid, > best, = multipath,%s"\
-               "              i internal, r RIB-failure, S Stale, R Removed%s"
+               "              i internal, r RIB-failure, S Stale, R Removed%s" 
\
+               "                               b backup path, x 
best-external%s"
 #define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - 
incomplete%s%s"
 #define BGP_SHOW_HEADER "   Network          Next Hop            Metric LocPrf 
Weight Path%s"
 #define BGP_SHOW_DAMP_HEADER "   Network          From             Reuse    
Path%s"
diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h
index 3d2eea5..a3142bd 100644
--- a/bgpd/bgp_route.h
+++ b/bgpd/bgp_route.h
@@ -79,9 +79,10 @@
 #define BGP_INFO_DMED_SELECTED  (1 << 7)
 #define BGP_INFO_STALE          (1 << 8)
 #define BGP_INFO_REMOVED        (1 << 9)
-#define BGP_INFO_COUNTED       (1 << 10)
+#define BGP_INFO_COUNTED               (1 << 10)
 #define BGP_INFO_MULTIPATH      (1 << 11)
 #define BGP_INFO_MULTIPATH_CHG  (1 << 12)
+#define BGP_INFO_BEST_EXTERNAL  (1 << 13)
 
   /* BGP route type.  This can be static, RIP, OSPF, BGP etc.  */
   u_char type;
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index ca44774..6da297f 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -9020,6 +9020,37 @@
        "Pointer to route-map entries\n")
 #endif /* HAVE_IPV6 */
 
+DEFUN (bgp_advertise_best_external,
+       bgp_advertise_best_external_cmd,
+       "bgp advertise-best-external",
+       "BGP specific commands\n"
+       "Advertise best external path to internal peers\n")
+{
+  struct bgp *bgp;
+
+  bgp = vty->index;
+  bgp_flag_set (bgp, BGP_FLAG_ADVERTISE_BEST_EXTERNAL);
+
+
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (no_bgp_advertise_best_external,
+       no_bgp_advertise_best_external_cmd,
+       "no bgp advertise-best-external",
+       NO_STR
+       "BGP specific commands\n"
+       "Advertise best external path to internal peers\n")
+{
+       struct bgp *bgp;
+
+       bgp = vty->index;
+       bgp_flag_unset (bgp, BGP_FLAG_ADVERTISE_BEST_EXTERNAL);
+       return CMD_SUCCESS;
+}
+
+
 int
 bgp_config_write_redistribute (struct vty *vty, struct bgp *bgp, afi_t afi,
                               safi_t safi, int *write)
@@ -10235,6 +10266,16 @@
   
   /* Community-list. */
   community_list_vty ();
+
+  /* "bgp advertise-best-external" commands*/
+  install_element (BGP_NODE, &bgp_advertise_best_external_cmd);
+  install_element (BGP_NODE, &no_bgp_advertise_best_external_cmd);
+  install_element (BGP_IPV4_NODE, &bgp_advertise_best_external_cmd);
+  install_element (BGP_IPV4_NODE, &no_bgp_advertise_best_external_cmd);
+  install_element (BGP_IPV6_NODE, &bgp_advertise_best_external_cmd);
+  install_element (BGP_IPV6_NODE, &no_bgp_advertise_best_external_cmd);
+  install_element (BGP_VPNV4_NODE, &bgp_advertise_best_external_cmd);
+  install_element (BGP_VPNV4_NODE, &no_bgp_advertise_best_external_cmd);
 }
 
 #include "memory.h"
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index d72708e..11c91ad 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -5265,6 +5265,9 @@
       if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED))
        vty_out (vty, " bgp always-compare-med%s", VTY_NEWLINE);
 
+      if (bgp_flag_check (bgp, BGP_FLAG_ADVERTISE_BEST_EXTERNAL))
+    vty_out (vty, " bgp advertise-best-external%s", VTY_NEWLINE);
+
       /* BGP default ipv4-unicast. */
       if (bgp_flag_check (bgp, BGP_FLAG_NO_DEFAULT_IPV4))
        vty_out (vty, " no bgp default ipv4-unicast%s", VTY_NEWLINE);
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index 40c381c..bf44160 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -123,6 +123,7 @@
 #define BGP_FLAG_GRACEFUL_RESTART         (1 << 12)
 #define BGP_FLAG_ASPATH_CONFED            (1 << 13)
 #define BGP_FLAG_ASPATH_MULTIPATH_RELAX   (1 << 14)
+#define BGP_FLAG_ADVERTISE_BEST_EXTERNAL  (1 << 15)
 
   /* BGP Per AF flags */
   u_int16_t af_flags[AFI_MAX][SAFI_MAX];
_______________________________________________
Quagga-dev mailing list
[email protected]
https://lists.quagga.net/mailman/listinfo/quagga-dev

Reply via email to