vom: Add support for BVI interface 18/18518/3
authorMohsin Kazmi <sykazmi@cisco.com>
Mon, 25 Mar 2019 15:41:01 +0000 (16:41 +0100)
committerNeale Ranns <nranns@cisco.com>
Wed, 27 Mar 2019 08:59:56 +0000 (08:59 +0000)
Change-Id: Ie93f3a2107df0452f7a7436b78c337f482904899
Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
extras/vom/vom/interface.cpp
extras/vom/vom/interface_cmds.cpp
extras/vom/vom/interface_cmds.hpp

index ec6204f..40f9607 100644 (file)
@@ -275,13 +275,17 @@ interface::key() const
 std::queue<cmd*>&
 interface::mk_create_cmd(std::queue<cmd*>& q)
 {
-  if ((type_t::LOOPBACK == m_type) || (type_t::BVI == m_type)) {
+  if (type_t::LOOPBACK == m_type) {
     q.push(new interface_cmds::loopback_create_cmd(m_hdl, m_name));
     q.push(new interface_cmds::set_tag(m_hdl, m_name));
     /*
      * set the m_tag for pretty-print
      */
     m_tag = m_name;
+  } else if (type_t::BVI == m_type) {
+    q.push(new interface_cmds::bvi_create_cmd(m_hdl, m_name));
+    q.push(new interface_cmds::set_tag(m_hdl, m_name));
+    m_tag = m_name;
   } else if (type_t::AFPACKET == m_type) {
     q.push(new interface_cmds::af_packet_create_cmd(m_hdl, m_name));
     if (!m_tag.empty())
@@ -301,8 +305,10 @@ interface::mk_create_cmd(std::queue<cmd*>& q)
 std::queue<cmd*>&
 interface::mk_delete_cmd(std::queue<cmd*>& q)
 {
-  if ((type_t::LOOPBACK == m_type) || (type_t::BVI == m_type)) {
+  if (type_t::LOOPBACK == m_type) {
     q.push(new interface_cmds::loopback_delete_cmd(m_hdl));
+  } else if (type_t::BVI == m_type) {
+    q.push(new interface_cmds::bvi_delete_cmd(m_hdl));
   } else if (type_t::AFPACKET == m_type) {
     q.push(new interface_cmds::af_packet_delete_cmd(m_hdl, m_name));
   } else if (type_t::VHOST == m_type) {
index 3a7fb50..b72c2ad 100644 (file)
@@ -23,6 +23,41 @@ DEFINE_VAPI_MSG_IDS_VHOST_USER_API_JSON;
 
 namespace VOM {
 namespace interface_cmds {
+
+bvi_create_cmd::bvi_create_cmd(HW::item<handle_t>& item,
+                               const std::string& name)
+  : create_cmd(item, name)
+{
+}
+
+rc_t
+bvi_create_cmd::issue(connection& con)
+{
+  msg_t req(con.ctx(), std::ref(*this));
+
+  auto& payload = req.get_request().get_payload();
+
+  payload.user_instance = ~0;
+
+  VAPI_CALL(req.execute());
+
+  wait();
+
+  if (m_hw_item.rc() == rc_t::OK) {
+    insert_interface();
+  }
+
+  return rc_t::OK;
+}
+std::string
+bvi_create_cmd::to_string() const
+{
+  std::ostringstream s;
+  s << "bvi-itf-create: " << m_hw_item.to_string() << " name:" << m_name;
+
+  return (s.str());
+}
+
 loopback_create_cmd::loopback_create_cmd(HW::item<handle_t>& item,
                                          const std::string& name)
   : create_cmd(item, name)
@@ -138,6 +173,37 @@ vhost_create_cmd::to_string() const
   return (s.str());
 }
 
+bvi_delete_cmd::bvi_delete_cmd(HW::item<handle_t>& item)
+  : delete_cmd(item)
+{
+}
+
+rc_t
+bvi_delete_cmd::issue(connection& con)
+{
+  msg_t req(con.ctx(), std::ref(*this));
+
+  auto& payload = req.get_request().get_payload();
+  payload.sw_if_index = m_hw_item.data().value();
+
+  VAPI_CALL(req.execute());
+
+  wait();
+  m_hw_item.set(rc_t::NOOP);
+
+  remove_interface();
+  return rc_t::OK;
+}
+
+std::string
+bvi_delete_cmd::to_string() const
+{
+  std::ostringstream s;
+  s << "bvi-itf-delete: " << m_hw_item.to_string();
+
+  return (s.str());
+}
+
 loopback_delete_cmd::loopback_delete_cmd(HW::item<handle_t>& item)
   : delete_cmd(item)
 {
index 218d4b0..2ee892f 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <vapi/af_packet.api.vapi.hpp>
 #include <vapi/interface.api.vapi.hpp>
+#include <vapi/l2.api.vapi.hpp>
 #include <vapi/vhost_user.api.vapi.hpp>
 #include <vapi/vpe.api.vapi.hpp>
 
@@ -37,6 +38,30 @@ namespace interface_cmds {
 std::unique_ptr<interface> new_interface(
   const vapi_payload_sw_interface_details& vd);
 
+/**
+ * A command class to create bvi interfaces in VPP
+ */
+class bvi_create_cmd : public interface::create_cmd<vapi::Bvi_create>
+{
+public:
+  /**
+   * Constructor taking the HW::item to update
+   * and the name of the interface to create
+   */
+  bvi_create_cmd(HW::item<handle_t>& item, const std::string& name);
+  ~bvi_create_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;
+};
+
 /**
  * A command class to create Loopback interfaces in VPP
  */
@@ -108,6 +133,27 @@ private:
   const std::string m_tag;
 };
 
+/**
+ * A command class to delete bvi interfaces in VPP
+ */
+class bvi_delete_cmd : public interface::delete_cmd<vapi::Bvi_delete>
+{
+public:
+  /**
+   * Constructor taking the HW::item to update
+   */
+  bvi_delete_cmd(HW::item<handle_t>& item);
+
+  /**
+   * Issue the command to VPP/HW
+   */
+  rc_t issue(connection& con);
+  /**
+   * convert to string format for debug purposes
+   */
+  std::string to_string() const;
+};
+
 /**
  * A command class to delete loopback interfaces in VPP
  */