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>
21 namespace tap_interface_cmds {
22 create_cmd::create_cmd(HW::item<handle_t>& item,
23 const std::string& name,
24 route::prefix_t& prefix,
25 const l2_address_t& l2_address)
26 : interface::create_cmd<vapi::Tap_connect>(item, name)
28 , m_l2_address(l2_address)
33 create_cmd::issue(connection& con)
35 msg_t req(con.ctx(), std::ref(*this));
37 auto& payload = req.get_request().get_payload();
38 memset(payload.tap_name, 0, sizeof(payload.tap_name));
39 memcpy(payload.tap_name, m_name.c_str(),
40 std::min(m_name.length(), sizeof(payload.tap_name)));
41 if (m_prefix != route::prefix_t::ZERO) {
42 if (m_prefix.address().is_v6()) {
43 m_prefix.to_vpp(&payload.ip6_address_set, payload.ip6_address,
44 &payload.ip6_mask_width);
46 m_prefix.to_vpp(&payload.ip4_address_set, payload.ip4_address,
47 &payload.ip4_mask_width);
48 payload.ip4_address_set = 1;
52 if (m_l2_address != l2_address_t::ZERO) {
53 m_l2_address.to_bytes(payload.mac_address, 6);
55 payload.use_random_mac = 1;
58 VAPI_CALL(req.execute());
66 create_cmd::to_string() const
69 s << "tap-intf-create: " << m_hw_item.to_string()
70 << " ip-prefix:" << m_prefix.to_string();
75 delete_cmd::delete_cmd(HW::item<handle_t>& item)
76 : interface::delete_cmd<vapi::Tap_delete>(item)
81 delete_cmd::issue(connection& con)
83 // finally... call VPP
88 delete_cmd::to_string() const
91 s << "tap-itf-delete: " << m_hw_item.to_string();
101 dump_cmd::operator==(const dump_cmd& other) const
107 dump_cmd::issue(connection& con)
109 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
111 VAPI_CALL(m_dump->execute());
115 return rc_t::INPROGRESS;
119 dump_cmd::to_string() const
121 return ("tap-itf-dump");
123 } // namespace tap_interface_cmds
127 * fd.io coding-style-patch-verification: ON
130 * eval: (c-set-style "mozilla")