From 9c1f824366bdde7d2b5aafd31ab788bb2135a859 Mon Sep 17 00:00:00 2001 From: Mohsin Kazmi Date: Mon, 25 Mar 2019 16:41:01 +0100 Subject: vom: Add support for BVI interface Change-Id: Ie93f3a2107df0452f7a7436b78c337f482904899 Signed-off-by: Mohsin Kazmi --- extras/vom/vom/interface.cpp | 10 ++++-- extras/vom/vom/interface_cmds.cpp | 66 +++++++++++++++++++++++++++++++++++++++ extras/vom/vom/interface_cmds.hpp | 46 +++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 2 deletions(-) (limited to 'extras') diff --git a/extras/vom/vom/interface.cpp b/extras/vom/vom/interface.cpp index ec6204f1e0c..40f960730d7 100644 --- a/extras/vom/vom/interface.cpp +++ b/extras/vom/vom/interface.cpp @@ -275,13 +275,17 @@ interface::key() const std::queue& interface::mk_create_cmd(std::queue& 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& q) std::queue& interface::mk_delete_cmd(std::queue& 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) { diff --git a/extras/vom/vom/interface_cmds.cpp b/extras/vom/vom/interface_cmds.cpp index 3a7fb50f64b..b72c2ad69e5 100644 --- a/extras/vom/vom/interface_cmds.cpp +++ b/extras/vom/vom/interface_cmds.cpp @@ -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& 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& 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& 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& item) : delete_cmd(item) { diff --git a/extras/vom/vom/interface_cmds.hpp b/extras/vom/vom/interface_cmds.hpp index 218d4b083d1..2ee892fc0f8 100644 --- a/extras/vom/vom/interface_cmds.hpp +++ b/extras/vom/vom/interface_cmds.hpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -37,6 +38,30 @@ namespace interface_cmds { std::unique_ptr 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 +{ +public: + /** + * Constructor taking the HW::item to update + * and the name of the interface to create + */ + bvi_create_cmd(HW::item& 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 +{ +public: + /** + * Constructor taking the HW::item to update + */ + bvi_delete_cmd(HW::item& 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 */ -- cgit 1.2.3-korg