blob: 799b9afd58ac8d45dabf7bd92952fea4900d8400 [file] [log] [blame]
Neale Ranns812ed392017-10-16 04:20:13 -07001/*
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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070016#include "vom/tap_interface_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070017
18#include <vapi/tap.api.vapi.hpp>
19
20namespace VOM {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070021namespace tap_interface_cmds {
22create_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)
Neale Ranns812ed392017-10-16 04:20:13 -070026 : interface::create_cmd<vapi::Tap_connect>(item, name)
27 , m_prefix(prefix)
28 , m_l2_address(l2_address)
29{
30}
31
32rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070033create_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -070034{
35 msg_t req(con.ctx(), std::ref(*this));
36
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);
45 } else {
46 m_prefix.to_vpp(&payload.ip4_address_set, payload.ip4_address,
47 &payload.ip4_mask_width);
48 payload.ip4_address_set = 1;
49 }
50 }
51
52 if (m_l2_address != l2_address_t::ZERO) {
53 m_l2_address.to_bytes(payload.mac_address, 6);
54 } else {
55 payload.use_random_mac = 1;
56 }
57
58 VAPI_CALL(req.execute());
59
60 m_hw_item = wait();
61
62 return rc_t::OK;
63}
64
65std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070066create_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -070067{
68 std::ostringstream s;
69 s << "tap-intf-create: " << m_hw_item.to_string()
70 << " ip-prefix:" << m_prefix.to_string();
71
72 return (s.str());
73}
74
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070075delete_cmd::delete_cmd(HW::item<handle_t>& item)
Neale Ranns812ed392017-10-16 04:20:13 -070076 : interface::delete_cmd<vapi::Tap_delete>(item)
77{
78}
79
80rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070081delete_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -070082{
83 // finally... call VPP
84
85 return rc_t::OK;
86}
87std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070088delete_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -070089{
90 std::ostringstream s;
91 s << "tap-itf-delete: " << m_hw_item.to_string();
92
93 return (s.str());
94}
95
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070096dump_cmd::dump_cmd()
Neale Ranns812ed392017-10-16 04:20:13 -070097{
98}
99
100bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700101dump_cmd::operator==(const dump_cmd& other) const
Neale Ranns812ed392017-10-16 04:20:13 -0700102{
103 return (true);
104}
105
106rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700107dump_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -0700108{
109 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
110
111 VAPI_CALL(m_dump->execute());
112
113 wait();
114
115 return rc_t::INPROGRESS;
116}
117
118std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700119dump_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -0700120{
121 return ("tap-itf-dump");
122}
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700123} // namespace tap_interface_cmds
124} // namespace VOM
Neale Ranns812ed392017-10-16 04:20:13 -0700125
126/*
127 * fd.io coding-style-patch-verification: ON
128 *
129 * Local Variables:
130 * eval: (c-set-style "mozilla")
131 * End:
132 */