vapi: handle more magic
[vpp.git] / src / vpp-api / vom / interface_cmds.cpp
index 750ad1f..df34154 100644 (file)
@@ -20,6 +20,7 @@ DEFINE_VAPI_MSG_IDS_VPE_API_JSON;
 DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON;
 DEFINE_VAPI_MSG_IDS_AF_PACKET_API_JSON;
 DEFINE_VAPI_MSG_IDS_TAP_API_JSON;
+DEFINE_VAPI_MSG_IDS_VHOST_USER_API_JSON;
 DEFINE_VAPI_MSG_IDS_STATS_API_JSON;
 
 namespace VOM {
@@ -129,6 +130,50 @@ tap_create_cmd::to_string() const
   return (s.str());
 }
 
+vhost_create_cmd::vhost_create_cmd(HW::item<handle_t>& item,
+                                   const std::string& name,
+                                   const std::string& tag)
+  : create_cmd(item, name)
+  , m_tag(tag)
+{
+}
+
+rc_t
+vhost_create_cmd::issue(connection& con)
+{
+  msg_t req(con.ctx(), std::ref(*this));
+
+  auto& payload = req.get_request().get_payload();
+  memset(payload.sock_filename, 0, sizeof(payload.sock_filename));
+  memcpy(payload.sock_filename, m_name.c_str(),
+         std::min(m_name.length(), sizeof(payload.sock_filename)));
+  memset(payload.tag, 0, sizeof(payload.tag));
+
+  if (!m_tag.empty())
+    memcpy(payload.tag, m_tag.c_str(),
+           std::min(m_tag.length(), sizeof(payload.tag)));
+
+  payload.is_server = 1;
+  payload.use_custom_mac = 0;
+  payload.renumber = 0;
+
+  VAPI_CALL(req.execute());
+
+  m_hw_item = wait();
+
+  return rc_t::OK;
+}
+
+std::string
+vhost_create_cmd::to_string() const
+{
+  std::ostringstream s;
+  s << "vhost-intf-create: " << m_hw_item.to_string() << " name:" << m_name
+    << " tag:" << m_tag;
+
+  return (s.str());
+}
+
 loopback_delete_cmd::loopback_delete_cmd(HW::item<handle_t>& item)
   : delete_cmd(item)
 {
@@ -215,6 +260,35 @@ tap_delete_cmd::to_string() const
   return (s.str());
 }
 
+vhost_delete_cmd::vhost_delete_cmd(HW::item<handle_t>& item,
+                                   const std::string& name)
+  : delete_cmd(item, name)
+{
+}
+
+rc_t
+vhost_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();
+
+  return rc_t::OK;
+}
+std::string
+vhost_delete_cmd::to_string() const
+{
+  std::ostringstream s;
+  s << "vhost-itf-delete: " << m_hw_item.to_string() << " name:" << m_name;
+
+  return (s.str());
+}
+
 state_change_cmd::state_change_cmd(HW::item<interface::admin_state_t>& state,
                                    const HW::item<handle_t>& hdl)
   : rpc_cmd(state)
@@ -366,7 +440,7 @@ events_cmd::issue(connection& con)
 
   wait();
 
-  return (rc_t::INPROGRESS);
+  return (rc_t::OK);
 }
 
 void
@@ -401,7 +475,8 @@ events_cmd::to_string() const
 /**
  * Interface statistics
  */
-stats_cmd::stats_cmd(interface::stat_listener& el, const handle_t& handle)
+stats_enable_cmd::stats_enable_cmd(interface::stat_listener& el,
+                                   const handle_t& handle)
   : event_cmd(el.status())
   , m_listener(el)
   , m_swifindex(handle)
@@ -409,13 +484,13 @@ stats_cmd::stats_cmd(interface::stat_listener& el, const handle_t& handle)
 }
 
 bool
-stats_cmd::operator==(const stats_cmd& other) const
+stats_enable_cmd::operator==(const stats_enable_cmd& other) const
 {
   return (true);
 }
 
 rc_t
-stats_cmd::issue(connection& con)
+stats_enable_cmd::issue(connection& con)
 {
   /*
    * First set the call back to handle the interface stats
@@ -438,11 +513,11 @@ stats_cmd::issue(connection& con)
 
   wait();
 
-  return (rc_t::INPROGRESS);
+  return (rc_t::OK);
 }
 
 void
-stats_cmd::retire(connection& con)
+stats_enable_cmd::retire(connection& con)
 {
   /*
    * disable interface stats.
@@ -461,15 +536,59 @@ stats_cmd::retire(connection& con)
 }
 
 void
-stats_cmd::notify()
+stats_enable_cmd::notify()
 {
   m_listener.handle_interface_stat(this);
 }
 
 std::string
-stats_cmd::to_string() const
+stats_enable_cmd::to_string() const
+{
+  std::ostringstream s;
+  s << "itf-stats-enable itf:" << m_swifindex.to_string();
+  return (s.str());
+}
+
+stats_disable_cmd::stats_disable_cmd(const handle_t& handle)
+  : rpc_cmd(m_res)
+  , m_swifindex(handle)
+{
+}
+
+bool
+stats_disable_cmd::operator==(const stats_disable_cmd& other) const
+{
+  return (true);
+}
+
+rc_t
+stats_disable_cmd::issue(connection& con)
+{
+  /*
+   * then send the request to enable them
+   */
+  msg_t req(con.ctx(), 1, std::ref(*this));
+
+  auto& payload = req.get_request().get_payload();
+  payload.enable_disable = 0;
+  payload.pid = getpid();
+  payload.num = 1;
+
+  payload.sw_ifs[0] = m_swifindex.value();
+
+  VAPI_CALL(req.execute());
+
+  wait();
+
+  return (rc_t::OK);
+}
+
+std::string
+stats_disable_cmd::to_string() const
 {
-  return ("itf-stats");
+  std::ostringstream s;
+  s << "itf-stats-disable itf:" << m_swifindex.to_string();
+  return (s.str());
 }
 
 dump_cmd::dump_cmd()
@@ -503,6 +622,34 @@ dump_cmd::to_string() const
   return ("itf-dump");
 }
 
+vhost_dump_cmd::vhost_dump_cmd()
+{
+}
+
+bool
+vhost_dump_cmd::operator==(const vhost_dump_cmd& other) const
+{
+  return (true);
+}
+
+rc_t
+vhost_dump_cmd::issue(connection& con)
+{
+  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
+
+  VAPI_CALL(m_dump->execute());
+
+  wait();
+
+  return rc_t::OK;
+}
+
+std::string
+vhost_dump_cmd::to_string() const
+{
+  return ("vhost-itf-dump");
+}
+
 set_tag::set_tag(HW::item<handle_t>& item, const std::string& name)
   : rpc_cmd(item)
   , m_name(name)