2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include "vom/interface_cmds.hpp"
17 #include "vom/cmd.hpp"
19 DEFINE_VAPI_MSG_IDS_VPE_API_JSON;
20 DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON;
21 DEFINE_VAPI_MSG_IDS_AF_PACKET_API_JSON;
22 DEFINE_VAPI_MSG_IDS_VHOST_USER_API_JSON;
23 DEFINE_VAPI_MSG_IDS_STATS_API_JSON;
26 namespace interface_cmds {
27 loopback_create_cmd::loopback_create_cmd(HW::item<handle_t>& item,
28 const std::string& name)
29 : create_cmd(item, name)
34 loopback_create_cmd::issue(connection& con)
36 msg_t req(con.ctx(), std::ref(*this));
38 VAPI_CALL(req.execute());
42 if (m_hw_item.rc() == rc_t::OK) {
49 loopback_create_cmd::to_string() const
52 s << "loopback-itf-create: " << m_hw_item.to_string() << " name:" << m_name;
57 af_packet_create_cmd::af_packet_create_cmd(HW::item<handle_t>& item,
58 const std::string& name)
59 : create_cmd(item, name)
64 af_packet_create_cmd::issue(connection& con)
66 msg_t req(con.ctx(), std::ref(*this));
68 auto& payload = req.get_request().get_payload();
70 payload.use_random_hw_addr = 1;
71 memset(payload.host_if_name, 0, sizeof(payload.host_if_name));
72 memcpy(payload.host_if_name, m_name.c_str(),
73 std::min(m_name.length(), sizeof(payload.host_if_name)));
75 VAPI_CALL(req.execute());
79 if (m_hw_item.rc() == rc_t::OK) {
86 af_packet_create_cmd::to_string() const
89 s << "af-packet-itf-create: " << m_hw_item.to_string() << " name:" << m_name;
94 vhost_create_cmd::vhost_create_cmd(HW::item<handle_t>& item,
95 const std::string& name,
96 const std::string& tag)
97 : create_cmd(item, name)
103 vhost_create_cmd::issue(connection& con)
105 msg_t req(con.ctx(), std::ref(*this));
107 auto& payload = req.get_request().get_payload();
108 memset(payload.sock_filename, 0, sizeof(payload.sock_filename));
109 memcpy(payload.sock_filename, m_name.c_str(),
110 std::min(m_name.length(), sizeof(payload.sock_filename)));
111 memset(payload.tag, 0, sizeof(payload.tag));
114 memcpy(payload.tag, m_tag.c_str(),
115 std::min(m_tag.length(), sizeof(payload.tag)));
117 payload.is_server = 0;
118 payload.use_custom_mac = 0;
119 payload.renumber = 0;
121 VAPI_CALL(req.execute());
125 if (m_hw_item.rc() == rc_t::OK) {
133 vhost_create_cmd::to_string() const
135 std::ostringstream s;
136 s << "vhost-intf-create: " << m_hw_item.to_string() << " name:" << m_name
142 loopback_delete_cmd::loopback_delete_cmd(HW::item<handle_t>& item)
148 loopback_delete_cmd::issue(connection& con)
150 msg_t req(con.ctx(), std::ref(*this));
152 auto& payload = req.get_request().get_payload();
153 payload.sw_if_index = m_hw_item.data().value();
155 VAPI_CALL(req.execute());
158 m_hw_item.set(rc_t::NOOP);
165 loopback_delete_cmd::to_string() const
167 std::ostringstream s;
168 s << "loopback-itf-delete: " << m_hw_item.to_string();
173 af_packet_delete_cmd::af_packet_delete_cmd(HW::item<handle_t>& item,
174 const std::string& name)
175 : delete_cmd(item, name)
180 af_packet_delete_cmd::issue(connection& con)
182 msg_t req(con.ctx(), std::ref(*this));
184 auto& payload = req.get_request().get_payload();
185 memset(payload.host_if_name, 0, sizeof(payload.host_if_name));
186 memcpy(payload.host_if_name, m_name.c_str(),
187 std::min(m_name.length(), sizeof(payload.host_if_name)));
189 VAPI_CALL(req.execute());
192 m_hw_item.set(rc_t::NOOP);
198 af_packet_delete_cmd::to_string() const
200 std::ostringstream s;
201 s << "af_packet-itf-delete: " << m_hw_item.to_string();
206 vhost_delete_cmd::vhost_delete_cmd(HW::item<handle_t>& item,
207 const std::string& name)
208 : delete_cmd(item, name)
213 vhost_delete_cmd::issue(connection& con)
215 msg_t req(con.ctx(), std::ref(*this));
217 auto& payload = req.get_request().get_payload();
218 payload.sw_if_index = m_hw_item.data().value();
220 VAPI_CALL(req.execute());
228 vhost_delete_cmd::to_string() const
230 std::ostringstream s;
231 s << "vhost-itf-delete: " << m_hw_item.to_string() << " name:" << m_name;
236 state_change_cmd::state_change_cmd(HW::item<interface::admin_state_t>& state,
237 const HW::item<handle_t>& hdl)
244 state_change_cmd::operator==(const state_change_cmd& other) const
246 return ((m_hdl == other.m_hdl) && (m_hw_item == other.m_hw_item));
250 state_change_cmd::issue(connection& con)
252 msg_t req(con.ctx(), std::ref(*this));
254 auto& payload = req.get_request().get_payload();
255 payload.sw_if_index = m_hdl.data().value();
256 payload.admin_up_down = m_hw_item.data().value();
258 VAPI_CALL(req.execute());
264 state_change_cmd::to_string() const
266 std::ostringstream s;
267 s << "itf-state-change: " << m_hw_item.to_string()
268 << " hdl:" << m_hdl.to_string();
272 set_table_cmd::set_table_cmd(HW::item<route::table_id_t>& table,
273 const l3_proto_t& proto,
274 const HW::item<handle_t>& hdl)
282 set_table_cmd::operator==(const set_table_cmd& other) const
284 return ((m_hdl == other.m_hdl) && (m_proto == other.m_proto) &&
285 (m_hw_item == other.m_hw_item));
289 set_table_cmd::issue(connection& con)
291 msg_t req(con.ctx(), std::ref(*this));
293 auto& payload = req.get_request().get_payload();
294 payload.sw_if_index = m_hdl.data().value();
295 payload.is_ipv6 = m_proto.is_ipv6();
296 payload.vrf_id = m_hw_item.data();
298 VAPI_CALL(req.execute());
304 set_table_cmd::to_string() const
306 std::ostringstream s;
307 s << "itf-set-table: " << m_hw_item.to_string()
308 << " proto:" << m_proto.to_string() << " hdl:" << m_hdl.to_string();
312 set_mac_cmd::set_mac_cmd(HW::item<l2_address_t>& mac,
313 const HW::item<handle_t>& hdl)
320 set_mac_cmd::operator==(const set_mac_cmd& other) const
322 return ((m_hdl == other.m_hdl) && (m_hw_item == other.m_hw_item));
326 set_mac_cmd::issue(connection& con)
328 msg_t req(con.ctx(), std::ref(*this));
330 auto& payload = req.get_request().get_payload();
331 payload.sw_if_index = m_hdl.data().value();
332 m_hw_item.data().to_mac().to_bytes(payload.mac_address,
333 sizeof(payload.mac_address));
335 VAPI_CALL(req.execute());
341 set_mac_cmd::to_string() const
343 std::ostringstream s;
344 s << "itf-set-mac: " << m_hw_item.to_string() << " hdl:" << m_hdl.to_string();
348 collect_detail_stats_change_cmd::collect_detail_stats_change_cmd(
349 HW::item<interface::stats_type_t>& item,
359 collect_detail_stats_change_cmd::operator==(
360 const collect_detail_stats_change_cmd& other) const
362 return ((m_hdl == other.m_hdl) && (m_hw_item == other.m_hw_item) &&
363 (m_enable == other.m_enable));
367 collect_detail_stats_change_cmd::issue(connection& con)
369 msg_t req(con.ctx(), std::ref(*this));
371 auto& payload = req.get_request().get_payload();
372 payload.sw_if_index = m_hdl.value();
373 payload.enable_disable = m_enable;
375 VAPI_CALL(req.execute());
381 collect_detail_stats_change_cmd::to_string() const
383 std::ostringstream s;
384 s << "itf-stats: " << m_hw_item.to_string() << " hdl:" << m_hdl.to_string();
388 events_cmd::events_cmd(interface::event_listener& el)
389 : event_cmd(el.status())
395 events_cmd::operator==(const events_cmd& other) const
401 events_cmd::issue(connection& con)
404 * First set the call back to handle the interface events
406 m_reg.reset(new reg_t(con.ctx(), std::ref(*(static_cast<event_cmd*>(this)))));
409 * then send the request to enable them
411 msg_t req(con.ctx(), std::ref(*(static_cast<rpc_cmd*>(this))));
413 auto& payload = req.get_request().get_payload();
414 payload.enable_disable = 1;
415 payload.pid = getpid();
417 VAPI_CALL(req.execute());
425 events_cmd::retire(connection& con)
428 * disable interface events.
430 msg_t req(con.ctx(), std::ref(*(static_cast<rpc_cmd*>(this))));
432 auto& payload = req.get_request().get_payload();
433 payload.enable_disable = 0;
434 payload.pid = getpid();
436 VAPI_CALL(req.execute());
444 m_listener.handle_interface_event(this);
448 events_cmd::to_string() const
450 return ("itf-events");
454 * Interface statistics
456 stats_enable_cmd::stats_enable_cmd(interface::stat_listener& el,
457 const handle_t& handle)
458 : event_cmd(el.status())
460 , m_swifindex(handle)
465 stats_enable_cmd::operator==(const stats_enable_cmd& other) const
471 stats_enable_cmd::issue(connection& con)
474 * First set the call back to handle the interface stats
476 m_reg.reset(new reg_t(con.ctx(), std::ref(*(static_cast<event_cmd*>(this)))));
479 * then send the request to enable them
481 msg_t req(con.ctx(), 1, std::ref(*(static_cast<rpc_cmd*>(this))));
483 auto& payload = req.get_request().get_payload();
484 payload.enable_disable = 1;
485 payload.pid = getpid();
488 payload.sw_ifs[0] = m_swifindex.value();
490 VAPI_CALL(req.execute());
498 stats_enable_cmd::retire(connection& con)
501 * disable interface stats.
503 msg_t req(con.ctx(), 1, std::ref(*(static_cast<rpc_cmd*>(this))));
505 auto& payload = req.get_request().get_payload();
506 payload.enable_disable = 0;
507 payload.pid = getpid();
509 payload.sw_ifs[0] = m_swifindex.value();
511 VAPI_CALL(req.execute());
516 interface::stat_listener&
517 stats_enable_cmd::listener() const
523 stats_enable_cmd::set(const rc_t& rc)
525 m_listener.status().set(rc);
529 stats_enable_cmd::notify()
531 m_listener.handle_interface_stat(this);
535 stats_enable_cmd::to_string() const
537 std::ostringstream s;
538 s << "itf-stats-enable itf:" << m_swifindex.to_string();
542 stats_disable_cmd::stats_disable_cmd(const handle_t& handle)
544 , m_swifindex(handle)
549 stats_disable_cmd::operator==(const stats_disable_cmd& other) const
555 stats_disable_cmd::issue(connection& con)
558 * then send the request to enable them
560 msg_t req(con.ctx(), 1, std::ref(*this));
562 auto& payload = req.get_request().get_payload();
563 payload.enable_disable = 0;
564 payload.pid = getpid();
567 payload.sw_ifs[0] = m_swifindex.value();
569 VAPI_CALL(req.execute());
577 stats_disable_cmd::to_string() const
579 std::ostringstream s;
580 s << "itf-stats-disable itf:" << m_swifindex.to_string();
589 dump_cmd::operator==(const dump_cmd& other) const
595 dump_cmd::issue(connection& con)
597 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
599 auto& payload = m_dump->get_request().get_payload();
600 payload.name_filter_valid = 0;
602 VAPI_CALL(m_dump->execute());
610 dump_cmd::to_string() const
615 vhost_dump_cmd::vhost_dump_cmd()
620 vhost_dump_cmd::operator==(const vhost_dump_cmd& other) const
626 vhost_dump_cmd::issue(connection& con)
628 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
630 VAPI_CALL(m_dump->execute());
638 vhost_dump_cmd::to_string() const
640 return ("vhost-itf-dump");
644 af_packet_dump_cmd::operator==(const af_packet_dump_cmd& other) const
650 af_packet_dump_cmd::issue(connection& con)
652 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
654 VAPI_CALL(m_dump->execute());
662 af_packet_dump_cmd::to_string() const
664 return ("af-packet-itf-dump");
667 set_tag::set_tag(HW::item<handle_t>& item, const std::string& name)
674 set_tag::issue(connection& con)
676 msg_t req(con.ctx(), std::ref(*this));
678 auto& payload = req.get_request().get_payload();
680 payload.sw_if_index = m_hw_item.data().value();
681 memset(payload.tag, 0, sizeof(payload.tag));
682 memcpy(payload.tag, m_name.c_str(), m_name.length());
684 VAPI_CALL(req.execute());
689 set_tag::to_string() const
691 std::ostringstream s;
692 s << "itf-set-tag: " << m_hw_item.to_string() << " name:" << m_name;
698 set_tag::operator==(const set_tag& o) const
700 return ((m_name == o.m_name) && (m_hw_item.data() == o.m_hw_item.data()));
702 }; // namespace interface_cmds
706 * fd.io coding-style-patch-verification: ON
709 * eval: (c-set-style "mozilla")