]> git.proxmox.com Git - mirror_frr.git/blobdiff - pimd/pim_mlag.c
Merge pull request #5494 from opensourcerouting/mlag-module
[mirror_frr.git] / pimd / pim_mlag.c
index eaec0c716a1cc0d9592ad6c5b6233cee6b093f3b..f60c18204b6d5179c1886445eb6c6d5869634b3d 100644 (file)
@@ -1,23 +1,25 @@
-/* PIM Mlag Code.
- * Copyright (C) 2018 Cumulus Networks, Inc.
- *                    Donald Sharp
+/*
+ * This is an implementation of PIM MLAG Functionality
  *
- * This file is part of FRR.
+ * Module name: PIM MLAG
  *
- * FRR is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
+ * Author: sathesh Kumar karra <sathk@cumulusnetworks.com>
  *
- * FRR is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * Copyright (C) 2019 Cumulus Networks http://www.cumulusnetworks.com
  *
- * You should have received a copy of the GNU General Public License
- * along with FRR; see the file COPYING.  If not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 #include <zebra.h>
 
 
 extern struct zclient *zclient;
 
+
+/********************API to process PIM MLAG Data ************************/
+
+static void pim_mlag_process_mlagd_state_change(struct mlag_status msg)
+{
+       char buf[MLAG_ROLE_STRSIZE];
+
+       if (PIM_DEBUG_MLAG)
+               zlog_debug("%s: msg dump: my_role: %s, peer_state: %s",
+                          __func__,
+                          mlag_role2str(msg.my_role, buf, sizeof(buf)),
+                          (msg.peer_state == MLAG_STATE_RUNNING ? "RUNNING"
+                                                                : "DOWN"));
+}
+
+static void pim_mlag_process_peer_frr_state_change(struct mlag_frr_status msg)
+{
+       if (PIM_DEBUG_MLAG)
+               zlog_debug(
+                       "%s: msg dump: peer_frr_state: %s", __func__,
+                       (msg.frr_state == MLAG_FRR_STATE_UP ? "UP" : "DOWN"));
+}
+
+static void pim_mlag_process_vxlan_update(struct mlag_vxlan *msg)
+{
+}
+
+static void pim_mlag_process_mroute_add(struct mlag_mroute_add msg)
+{
+       if (PIM_DEBUG_MLAG) {
+               zlog_debug(
+                       "%s: msg dump: vrf_name: %s, s.ip: 0x%x, g.ip: 0x%x cost: %u",
+                       __func__, msg.vrf_name, msg.source_ip, msg.group_ip,
+                       msg.cost_to_rp);
+               zlog_debug(
+                       "owner_id: %d, DR: %d, Dual active: %d, vrf_id: 0x%x intf_name: %s",
+                       msg.owner_id, msg.am_i_dr, msg.am_i_dual_active,
+                       msg.vrf_id, msg.intf_name);
+       }
+}
+
+static void pim_mlag_process_mroute_del(struct mlag_mroute_del msg)
+{
+       if (PIM_DEBUG_MLAG) {
+               zlog_debug(
+                       "%s: msg dump: vrf_name: %s, s.ip: 0x%x, g.ip: 0x%x ",
+                       __func__, msg.vrf_name, msg.source_ip, msg.group_ip);
+               zlog_debug("owner_id: %d, vrf_id: 0x%x intf_name: %s",
+                          msg.owner_id, msg.vrf_id, msg.intf_name);
+       }
+}
+
+
+int pim_zebra_mlag_handle_msg(struct stream *s, int len)
+{
+       struct mlag_msg mlag_msg;
+       char buf[ZLOG_FILTER_LENGTH_MAX];
+       int rc = 0;
+
+       rc = mlag_lib_decode_mlag_hdr(s, &mlag_msg);
+       if (rc)
+               return (rc);
+
+       if (PIM_DEBUG_MLAG)
+               zlog_debug("%s: Received msg type: %s length: %d, bulk_cnt: %d",
+                          __func__,
+                          mlag_lib_msgid_to_str(mlag_msg.msg_type, buf,
+                                                sizeof(buf)),
+                          mlag_msg.data_len, mlag_msg.msg_cnt);
+
+       switch (mlag_msg.msg_type) {
+       case MLAG_STATUS_UPDATE: {
+               struct mlag_status msg;
+
+               rc = mlag_lib_decode_mlag_status(s, &msg);
+               if (rc)
+                       return (rc);
+               pim_mlag_process_mlagd_state_change(msg);
+       } break;
+       case MLAG_PEER_FRR_STATUS: {
+               struct mlag_frr_status msg;
+
+               rc = mlag_lib_decode_frr_status(s, &msg);
+               if (rc)
+                       return (rc);
+               pim_mlag_process_peer_frr_state_change(msg);
+       } break;
+       case MLAG_VXLAN_UPDATE: {
+               struct mlag_vxlan msg;
+
+               rc = mlag_lib_decode_vxlan_update(s, &msg);
+               if (rc)
+                       return rc;
+               pim_mlag_process_vxlan_update(&msg);
+       } break;
+       case MLAG_MROUTE_ADD: {
+               struct mlag_mroute_add msg;
+
+               rc = mlag_lib_decode_mroute_add(s, &msg);
+               if (rc)
+                       return (rc);
+               pim_mlag_process_mroute_add(msg);
+       } break;
+       case MLAG_MROUTE_DEL: {
+               struct mlag_mroute_del msg;
+
+               rc = mlag_lib_decode_mroute_del(s, &msg);
+               if (rc)
+                       return (rc);
+               pim_mlag_process_mroute_del(msg);
+       } break;
+       case MLAG_MROUTE_ADD_BULK: {
+               struct mlag_mroute_add msg;
+               int i;
+
+               for (i = 0; i < mlag_msg.msg_cnt; i++) {
+
+                       rc = mlag_lib_decode_mroute_add(s, &msg);
+                       if (rc)
+                               return (rc);
+                       pim_mlag_process_mroute_add(msg);
+               }
+       } break;
+       case MLAG_MROUTE_DEL_BULK: {
+               struct mlag_mroute_del msg;
+               int i;
+
+               for (i = 0; i < mlag_msg.msg_cnt; i++) {
+
+                       rc = mlag_lib_decode_mroute_del(s, &msg);
+                       if (rc)
+                               return (rc);
+                       pim_mlag_process_mroute_del(msg);
+               }
+       } break;
+       default:
+               break;
+       }
+       return 0;
+}
+
+/****************End of PIM Mesasge processing handler********************/
+
+int pim_zebra_mlag_process_up(void)
+{
+       if (PIM_DEBUG_MLAG)
+               zlog_debug("%s: Received Process-Up from Mlag", __func__);
+
+       return 0;
+}
+
+int pim_zebra_mlag_process_down(void)
+{
+       if (PIM_DEBUG_MLAG)
+               zlog_debug("%s: Received Process-Down from Mlag", __func__);
+
+       return 0;
+}
+
 static int pim_mlag_register_handler(struct thread *thread)
 {
        uint32_t bit_mask = 0;
@@ -44,7 +205,7 @@ static int pim_mlag_register_handler(struct thread *thread)
        SET_FLAG(bit_mask, (1 << MLAG_PEER_FRR_STATUS));
 
        if (PIM_DEBUG_MLAG)
-               zlog_debug("%s: Posting Client Register to MLAG mask:0x%x",
+               zlog_debug("%s: Posting Client Register to MLAG mask: 0x%x",
                           __func__, bit_mask);
 
        zclient_send_mlag_register(zclient, bit_mask);
@@ -107,7 +268,7 @@ void pim_if_configure_mlag_dualactive(struct pim_interface *pim_ifp)
        router->pim_mlag_intf_cnt++;
        if (PIM_DEBUG_MLAG)
                zlog_debug(
-                       "%s: Total MLAG configured Interfaces on router: %d, Inst:%d",
+                       "%s: Total MLAG configured Interfaces on router: %d, Inst: %d",
                        __func__, router->pim_mlag_intf_cnt,
                        pim_ifp->pim->inst_mlag_intf_cnt);
 
@@ -130,13 +291,12 @@ void pim_if_unconfigure_mlag_dualactive(struct pim_interface *pim_ifp)
                           __func__, "NULL");
 
        pim_ifp->activeactive = false;
-       if (pim_ifp->pim)
-               pim_ifp->pim->inst_mlag_intf_cnt--;
+       pim_ifp->pim->inst_mlag_intf_cnt--;
 
        router->pim_mlag_intf_cnt--;
        if (PIM_DEBUG_MLAG)
                zlog_debug(
-                       "%s: Total MLAG configured Interfaces on router: %d, Inst:%d",
+                       "%s: Total MLAG configured Interfaces on router: %d, Inst: %d",
                        __func__, router->pim_mlag_intf_cnt,
                        pim_ifp->pim->inst_mlag_intf_cnt);