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/tap_interface_cmds.hpp"
18 #include <vapi/tap.api.vapi.hpp>
19 #include <vapi/tapv2.api.vapi.hpp>
21 DEFINE_VAPI_MSG_IDS_TAP_API_JSON;
22 DEFINE_VAPI_MSG_IDS_TAPV2_API_JSON;
25 namespace tap_interface_cmds {
29 tapv2_create_cmd::tapv2_create_cmd(HW::item<handle_t>& item,
30 const std::string& name,
31 const route::prefix_t& prefix,
32 const l2_address_t& l2_address)
33 : interface::create_cmd<vapi::Tap_create_v2>(item, name)
35 , m_l2_address(l2_address)
40 tapv2_create_cmd::issue(connection& con)
42 msg_t req(con.ctx(), std::ref(*this));
44 auto& payload = req.get_request().get_payload();
45 memset(payload.host_if_name, 0, sizeof(payload.host_if_name));
46 memcpy(payload.host_if_name, m_name.c_str(),
47 std::min(m_name.length(), sizeof(payload.host_if_name)));
48 payload.host_if_name_set = 1;
50 if (m_prefix != route::prefix_t::ZERO) {
51 if (m_prefix.address().is_v6()) {
52 m_prefix.to_vpp(&payload.host_ip6_addr_set, payload.host_ip6_addr,
53 &payload.host_ip6_prefix_len);
55 m_prefix.to_vpp(&payload.host_ip4_addr_set, payload.host_ip4_addr,
56 &payload.host_ip4_prefix_len);
57 payload.host_ip4_addr_set = 1;
61 if (m_l2_address != l2_address_t::ZERO) {
62 m_l2_address.to_bytes(payload.host_mac_addr, 6);
63 payload.host_mac_addr_set = 1;
66 payload.id = 0xffffffff;
67 payload.use_random_mac = 1;
68 payload.tx_ring_sz = 1024;
69 payload.rx_ring_sz = 1024;
71 VAPI_CALL(req.execute());
75 if (m_hw_item.rc() == rc_t::OK) {
83 tapv2_create_cmd::to_string() const
86 s << "tapv2-intf-create: " << m_hw_item.to_string()
87 << " ip-prefix:" << m_prefix.to_string();
92 tapv2_delete_cmd::tapv2_delete_cmd(HW::item<handle_t>& item)
93 : interface::delete_cmd<vapi::Tap_delete_v2>(item)
98 tapv2_delete_cmd::issue(connection& con)
101 msg_t req(con.ctx(), std::ref(*this));
103 auto& payload = req.get_request().get_payload();
105 payload.sw_if_index = m_hw_item.data().value();
107 VAPI_CALL(req.execute());
110 m_hw_item.set(rc_t::NOOP);
116 tapv2_delete_cmd::to_string() const
118 std::ostringstream s;
119 s << "tapv2-itf-delete: " << m_hw_item.to_string();
124 tapv2_dump_cmd::tapv2_dump_cmd()
129 tapv2_dump_cmd::operator==(const tapv2_dump_cmd& other) const
135 tapv2_dump_cmd::issue(connection& con)
137 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
139 VAPI_CALL(m_dump->execute());
147 tapv2_dump_cmd::to_string() const
149 return ("tapv2-itf-dump");
152 } // namespace tap_interface_cmds
156 * fd.io coding-style-patch-verification: ON
159 * eval: (c-set-style "mozilla")