IP unnumbered dump 46/12646/3
authorNeale Ranns <neale.ranns@cisco.com>
Fri, 18 May 2018 09:27:10 +0000 (02:27 -0700)
committerDamjan Marion <dmarion.lists@gmail.com>
Fri, 18 May 2018 13:03:05 +0000 (13:03 +0000)
Change-Id: I4f245fd225bcc563fafee2696cd039477d661c57
Signed-off-by: Neale Ranns <neale.ranns@cisco.com>
extras/vom/vom/bridge_domain_cmds.hpp
extras/vom/vom/ip_unnumbered.cpp
extras/vom/vom/ip_unnumbered_cmds.cpp
extras/vom/vom/ip_unnumbered_cmds.hpp
src/vnet/ip/ip.api
src/vnet/ip/ip_api.c

index 0216236..3257d83 100644 (file)
@@ -101,7 +101,7 @@ public:
 };
 
 /**
- * A cmd class that Dumps all the IPv4 L3 configs
+ * A cmd class that Dumps all the bridge domains
  */
 class dump_cmd : public VOM::dump_cmd<vapi::Bridge_domain_dump>
 {
index caeeb41..74a6ede 100644 (file)
@@ -117,7 +117,27 @@ ip_unnumbered::event_handler::handle_replay()
 void
 ip_unnumbered::event_handler::handle_populate(const client_db::key_t& key)
 {
-  // VPP provides no dump for IP unnumbered
+  std::shared_ptr<ip_unnumbered_cmds::dump_cmd> cmd =
+    std::make_shared<ip_unnumbered_cmds::dump_cmd>();
+
+  HW::enqueue(cmd);
+  HW::write();
+
+  for (auto& ip_record : *cmd) {
+    auto& payload = ip_record.get_payload();
+
+    VOM_LOG(log_level_t::DEBUG) << "ip-unnumbered dump: "
+                                << " itf: " << payload.sw_if_index
+                                << " ip: " << payload.ip_sw_if_index;
+
+    std::shared_ptr<interface> itf = interface::find(payload.sw_if_index);
+    std::shared_ptr<interface> ip_itf = interface::find(payload.ip_sw_if_index);
+
+    if (itf && ip_itf) {
+      ip_unnumbered ipun(*itf, *ip_itf);
+      OM::commit(key, ipun);
+    }
+  }
 }
 
 dependency_t
index 4c1fcf6..fa7a115 100644 (file)
@@ -105,6 +105,33 @@ unconfig_cmd::to_string() const
   return (s.str());
 }
 
+bool
+dump_cmd::operator==(const dump_cmd& other) const
+{
+  return (true);
+}
+
+rc_t
+dump_cmd::issue(connection& con)
+{
+  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
+
+  auto& payload = m_dump->get_request().get_payload();
+  payload.sw_if_index = ~0;
+
+  VAPI_CALL(m_dump->execute());
+
+  wait();
+
+  return rc_t::OK;
+}
+
+std::string
+dump_cmd::to_string() const
+{
+  return ("ip-unnumbered-dump");
+}
+
 }; // namespace ip_unnumbered_cmds
 }; // namespace VOM
 
index 0bb7027..4003013 100644 (file)
@@ -16,6 +16,7 @@
 #ifndef __VOM_IP_UNNUMBERED_CMDS_H__
 #define __VOM_IP_UNNUMBERED_CMDS_H__
 
+#include "vom/dump_cmd.hpp"
 #include "vom/ip_unnumbered.hpp"
 #include "vom/rpc_cmd.hpp"
 
@@ -100,6 +101,37 @@ private:
   const handle_t& m_l3_itf;
 };
 
+/**
+ * A cmd class that Dumps all the IP unnumbered interfaces
+ */
+class dump_cmd : public VOM::dump_cmd<vapi::Ip_unnumbered_dump>
+{
+public:
+  /**
+   * Constructor
+   */
+  dump_cmd() = default;
+
+  /**
+   * Issue the command to VPP/HW
+   */
+  rc_t issue(connection& con);
+  /**
+   * convert to string format for debug purposes
+   */
+  std::string to_string() const;
+
+  /**
+   * Comparison operator - only used for UT
+   */
+  bool operator==(const dump_cmd& i) const;
+
+private:
+  /**
+   * HW reutrn code
+   */
+  HW::item<bool> item;
+};
 }; // namespace ip_unnumbered_cmds
 }; // namespace VOM
 
index d59297b..7f4f030 100644 (file)
@@ -19,7 +19,7 @@
     called through a shared memory interface. 
 */
 
-option version = "1.2.3";
+option version = "1.2.4";
 import "vnet/fib/fib_types.api";
 
 /** \brief Add / del table request
@@ -525,6 +525,28 @@ define ip_address_dump
   u8 is_ipv6;
 };
 
+/** \brief IP unnumbered configurations
+    @param sw_if_index The interface that has unnumbered configuration
+    @param ip_sw_if_index The IP interface that it is unnnumbered to
+*/
+define ip_unnumbered_details
+{
+  u32 client_index;
+  u32 context;
+  u32 sw_if_index;
+  u32 ip_sw_if_index;
+};
+
+/** \brief Dump IP unnumbered configurations
+    @param sw_if_index ~0 for all interfaces, else the interface desired
+*/
+define ip_unnumbered_dump
+{
+  u32 client_index;
+  u32 context;
+  u32 sw_if_index;
+};
+
 define ip_details
 {
   u32 sw_if_index;
index d835773..ce3ff79 100644 (file)
@@ -74,6 +74,7 @@ _(IP_NEIGHBOR_DUMP, ip_neighbor_dump)                                   \
 _(IP_MROUTE_ADD_DEL, ip_mroute_add_del)                                 \
 _(MFIB_SIGNAL_DUMP, mfib_signal_dump)                                   \
 _(IP_ADDRESS_DUMP, ip_address_dump)                                     \
+_(IP_UNNUMBERED_DUMP, ip_unnumbered_dump)                               \
 _(IP_DUMP, ip_dump)                                                     \
 _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del)                             \
 _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit)                      \
@@ -1423,6 +1424,74 @@ vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
   BAD_SW_IF_INDEX_LABEL;
 }
 
+static void
+send_ip_unnumbered_details (vpe_api_main_t * am,
+                           vl_api_registration_t * reg,
+                           u32 sw_if_index, u32 ip_sw_if_index, u32 context)
+{
+  vl_api_ip_unnumbered_details_t *mp;
+
+  mp = vl_msg_api_alloc (sizeof (*mp));
+  memset (mp, 0, sizeof (*mp));
+  mp->_vl_msg_id = ntohs (VL_API_IP_UNNUMBERED_DETAILS);
+
+  mp->context = context;
+  mp->sw_if_index = htonl (sw_if_index);
+  mp->ip_sw_if_index = htonl (ip_sw_if_index);
+
+  vl_api_send_msg (reg, (u8 *) mp);
+}
+
+static void
+vl_api_ip_unnumbered_dump_t_handler (vl_api_ip_unnumbered_dump_t * mp)
+{
+  vnet_main_t *vnm = vnet_get_main ();
+  vnet_interface_main_t *im = &vnm->interface_main;
+  int rv __attribute__ ((unused)) = 0;
+  vpe_api_main_t *am = &vpe_api_main;
+  vl_api_registration_t *reg;
+  vnet_sw_interface_t *si;
+  u32 sw_if_index;
+
+  sw_if_index = ntohl (mp->sw_if_index);
+
+  reg = vl_api_client_index_to_registration (mp->client_index);
+  if (!reg)
+    return;
+
+  if (~0 != sw_if_index)
+    {
+      VALIDATE_SW_IF_INDEX (mp);
+
+      si = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
+
+      if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
+       {
+         send_ip_unnumbered_details (am, reg,
+                                     sw_if_index,
+                                     si->unnumbered_sw_if_index,
+                                     mp->context);
+       }
+    }
+  else
+    {
+      /* *INDENT-OFF* */
+      pool_foreach (si, im->sw_interfaces,
+      ({
+        if ((si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
+          {
+            send_ip_unnumbered_details(am, reg,
+                                       si->sw_if_index,
+                                       si->unnumbered_sw_if_index,
+                                       mp->context);
+          }
+      }));
+      /* *INDENT-ON* */
+    }
+
+  BAD_SW_IF_INDEX_LABEL;
+}
+
 static void
 vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
 {