]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: EVPN initialization and cleanup
authorvivek <vivek@cumulusnetworks.com>
Mon, 15 May 2017 21:27:51 +0000 (14:27 -0700)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 12 Jul 2017 16:36:34 +0000 (12:36 -0400)
Define the EVPN (EVI) hash table and related structures and initialize
and cleanup.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by: Donald Sharp <sharpd@cumulusnetworks.com>
bgpd/bgp_evpn.c
bgpd/bgp_evpn.h
bgpd/bgpd.c
bgpd/bgpd.h

index 34a3315c0c64479a9e6ad414d44c738988675266..6e6e696a9a32249c9246c4a39603b671353d291c 100644 (file)
@@ -26,6 +26,9 @@
 #include "log.h"
 #include "memory.h"
 #include "stream.h"
+#include "hash.h"
+#include "jhash.h"
+#include "bitfield.h"
 
 #include "bgpd/bgp_attr_evpn.h"
 #include "bgpd/bgpd.h"
 #include "bgpd/bgp_mplsvpn.h"
 #include "bgpd/bgp_label.h"
 #include "bgpd/bgp_evpn.h"
+#include "bgpd/bgp_evpn_private.h"
+#include "bgpd/bgp_ecommunity.h"
+
+/*
+ * Private functions.
+ */
+
+/*
+ * Make vni hash key.
+ */
+static unsigned int
+vni_hash_key_make(void *p)
+{
+  struct bgpevpn *vpn = p;
+  return (jhash_1word(vpn->vni, 0));
+}
+
+/*
+ * Comparison function for vni hash
+ */
+static int
+vni_hash_cmp (const void *p1, const void *p2)
+{
+  const struct bgpevpn *vpn1 = p1;
+  const struct bgpevpn *vpn2 = p2;
+
+  if (!vpn1 && !vpn2)
+    return 1;
+  if (!vpn1 || !vpn2)
+    return 0;
+  return(vpn1->vni == vpn2->vni);
+}
+
+/*
+ * Make import route target hash key.
+ */
+static unsigned int
+import_rt_hash_key_make (void *p)
+{
+  struct irt_node *irt = p;
+  char *pnt = irt->rt.val;
+  unsigned int key = 0;
+  int c=0;
+
+  key += pnt[c];
+  key += pnt[c + 1];
+  key += pnt[c + 2];
+  key += pnt[c + 3];
+  key += pnt[c + 4];
+  key += pnt[c + 5];
+  key += pnt[c + 6];
+  key += pnt[c + 7];
+
+  return (key);
+}
+
+/*
+ * Comparison function for import rt hash
+ */
+static int
+import_rt_hash_cmp (const void *p1, const void *p2)
+{
+  const struct irt_node *irt1 = p1;
+  const struct irt_node *irt2 = p2;
+
+  if (irt1 == NULL && irt2 == NULL)
+    return 1;
+
+  if (irt1 == NULL || irt2 == NULL)
+    return 0;
+
+  return(memcmp(irt1->rt.val, irt2->rt.val, ECOMMUNITY_SIZE) == 0);
+}
+
+/*
+ * Free a VNI entry; iterator function called during cleanup.
+ */
+static void
+free_vni_entry (struct hash_backet *backet, struct bgp *bgp)
+{
+}
+
+
+/*
+ * Public functions.
+ */
 
 int
 bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
@@ -225,3 +314,41 @@ bgp_packet_mpattr_route_type_5(struct stream *s,
                stream_put3(s, 0);
        return;
 }
+
+/*
+ * Cleanup EVPN information - invoked at the time of bgpd exit or when the
+ * BGP instance (default) is being freed.
+ */
+void
+bgp_evpn_cleanup (struct bgp *bgp)
+{
+  hash_iterate (bgp->vnihash,
+                (void (*) (struct hash_backet *, void *))
+                free_vni_entry, bgp);
+  hash_free (bgp->import_rt_hash);
+  bgp->import_rt_hash = NULL;
+  hash_free (bgp->vnihash);
+  bgp->vnihash = NULL;
+  bf_free (bgp->rd_idspace);
+}
+
+/*
+ * Initialization for EVPN
+ * Create
+ *  VNI hash table
+ *  hash for RT to VNI
+ *  unique rd id space for auto derivation of RD for VNIs
+ */
+void
+bgp_evpn_init (struct bgp *bgp)
+{
+  bgp->vnihash = hash_create (vni_hash_key_make,
+                             vni_hash_cmp,
+                             "BGP VNI Hash");
+  bgp->import_rt_hash = hash_create (import_rt_hash_key_make,
+                                    import_rt_hash_cmp,
+                                    "BGP Import RT Hash");
+  bf_init (bgp->rd_idspace, UINT16_MAX);
+  /*assign 0th index in the bitfield, so that we start with id 1*/
+  bf_assign_zero_index (bgp->rd_idspace);
+}
index feabc9cd276319f974e003b26c4d53f3f81bcf57..8a4e27c0cb0a5a49b7d77770e2f2c5a163d60db3 100644 (file)
@@ -28,6 +28,12 @@ extern void
 bgp_packet_mpattr_route_type_5(struct stream *s,
                               struct prefix *p, struct prefix_rd *prd,
                               mpls_label_t *label, struct attr *attr);
+
+extern void
+bgp_evpn_cleanup (struct bgp *bgp);
+extern void
+bgp_evpn_init (struct bgp *bgp);
+
 /* EVPN route types as per RFC7432 and
  * as per draft-ietf-bess-evpn-prefix-advertisement-02
  */
index d7ddd5db8abeefccbd24e7d043776ad6ac3d7fa3..87912693f2c739b72629e747b05668ed9dc15752 100644 (file)
@@ -241,6 +241,7 @@ bgp_router_id_set (struct bgp *bgp, const struct in_addr *id)
                           BGP_NOTIFY_CEASE_CONFIG_CHANGE);
        }
     }
+
   return 0;
 }
 
@@ -3004,6 +3005,7 @@ bgp_create (as_t *as, const char *name, enum bgp_instance_type inst_type)
   QOBJ_REG (bgp, bgp);
 
   update_bgp_group_init(bgp);
+  bgp_evpn_init(bgp);
   return bgp;
 }
 
@@ -3355,6 +3357,8 @@ bgp_free (struct bgp *bgp)
   bgp_scan_finish (bgp);
   bgp_address_destroy (bgp);
 
+  bgp_evpn_cleanup (bgp);
+
   if (bgp->name)
     XFREE(MTYPE_BGP, bgp->name);
   
index 5dc25d00a997107a8611dcfd307f950de7d3c970..31aa6163b0b2978d4e8f80ea586a6e9f756fe493 100644 (file)
@@ -33,6 +33,7 @@
 #include "linklist.h"
 #include "defaults.h"
 #include "bgp_memory.h"
+#include "bitfield.h"
 
 #define BGP_MAX_HOSTNAME 64    /* Linux max, is larger than most other sys */
 
@@ -367,6 +368,20 @@ struct bgp
   struct rfapi *rfapi;
 #endif
 
+  /* EVPN related information */
+
+  /* EVI hash table */
+  struct hash *vnihash;
+
+  /* EVPN enable - advertise local VNIs and their MACs etc. */
+  int advertise_all_vni;
+
+  /* Hash table of Import RTs to EVIs */
+  struct hash *import_rt_hash;
+
+  /* Id space for automatic RD derivation for an EVI */
+  bitfield_t rd_idspace;
+
   QOBJ_FIELDS
 };
 DECLARE_QOBJ_TYPE(bgp)