FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
tap_interface_cmds.cpp
Go to the documentation of this file.
1 /*
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 
17 
18 #include <vapi/tap.api.vapi.hpp>
19 #include <vapi/tapv2.api.vapi.hpp>
20 
23 
24 namespace VOM {
25 namespace tap_interface_cmds {
26 /*
27  * TAPV2
28  */
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)
34  , m_prefix(prefix)
35  , m_l2_address(l2_address)
36 {
37 }
38 
39 rc_t
41 {
42  msg_t req(con.ctx(), std::ref(*this));
43 
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;
49 
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);
54  } else {
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;
58  }
59  }
60 
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;
64  }
65 
66  payload.id = 0xffffffff;
67  payload.use_random_mac = 1;
68  payload.tx_ring_sz = 1024;
69  payload.rx_ring_sz = 1024;
70 
71  VAPI_CALL(req.execute());
72 
73  wait();
74 
75  if (m_hw_item.rc() == rc_t::OK) {
77  }
78 
79  return rc_t::OK;
80 }
81 
82 std::string
84 {
85  std::ostringstream s;
86  s << "tapv2-intf-create: " << m_hw_item.to_string()
87  << " ip-prefix:" << m_prefix.to_string();
88 
89  return (s.str());
90 }
91 
93  : interface::delete_cmd<vapi::Tap_delete_v2>(item)
94 {
95 }
96 
97 rc_t
99 {
100 
101  msg_t req(con.ctx(), std::ref(*this));
102 
103  auto& payload = req.get_request().get_payload();
104 
105  payload.sw_if_index = m_hw_item.data().value();
106 
107  VAPI_CALL(req.execute());
108 
109  wait();
111 
113  return rc_t::OK;
114 }
115 std::string
117 {
118  std::ostringstream s;
119  s << "tapv2-itf-delete: " << m_hw_item.to_string();
120 
121  return (s.str());
122 }
123 
125 {
126 }
127 
128 bool
130 {
131  return (true);
132 }
133 
134 rc_t
136 {
137  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
138 
139  VAPI_CALL(m_dump->execute());
140 
141  wait();
142 
143  return rc_t::OK;
144 }
145 
146 std::string
148 {
149  return ("tapv2-itf-dump");
150 }
151 
152 } // namespace tap_interface_cmds
153 } // namespace VOM
154 
155 /*
156  * fd.io coding-style-patch-verification: ON
157  *
158  * Local Variables:
159  * eval: (c-set-style "mozilla")
160  * End:
161  */
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
bool operator==(const tapv2_dump_cmd &i) const
Comparison operator - only used for UT.
const boost::asio::ip::address & address() const
Get the address.
Definition: prefix.cpp:149
std::string to_string() const
convert to string format for debug purposes
Definition: prefix.cpp:183
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
void remove_interface()
remove the deleted interface from the DB
Definition: interface.hpp:404
std::string to_string() const
convert to string format for debug purposes
rc_t issue(connection &con)
Issue the command to VPP/HW.
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
static const l2_address_t ZERO
An all 0&#39;s L2 address.
Definition: types.hpp:358
Type def of a L2 address as read from VPP.
Definition: types.hpp:339
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
T & data()
Return the data read/written.
Definition: hw.hpp:109
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
Forward declarations.
Definition: vapi.hpp:44
std::string to_string() const
convert to string format for debug purposes
A cmd class that Dumps all the Vpp Interfaces.
const std::string & m_name
The name of the interface to be created.
Definition: interface.hpp:361
std::string to_string() const
convert to string format for debug purposes
A representation of the connection to VPP.
Definition: connection.hpp:33
void to_vpp(uint8_t *is_ip6, uint8_t *addr, uint8_t *len) const
Convert the prefix into VPP API parameters.
Definition: prefix.cpp:251
rc_t issue(connection &con)
Issue the command to VPP/HW.
u8 name[64]
Definition: memclnt.api:152
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
void to_bytes(uint8_t *array, uint8_t len) const
Convert to byte array.
Definition: types.cpp:208
A representation of an interface in VPP.
Definition: interface.hpp:41
DEFINE_VAPI_MSG_IDS_TAP_API_JSON
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:109
DEFINE_VAPI_MSG_IDS_TAPV2_API_JSON
tapv2_delete_cmd(HW::item< handle_t > &item)
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
void insert_interface()
add the created interface to the DB
Definition: interface.hpp:335
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
rc_t issue(connection &con)
Issue the command to VPP/HW.
void set(const rc_t &rc)
Set the HW return code - should only be called from the family of Command objects.
Definition: hw.hpp:125
static const prefix_t ZERO
The all Zeros prefix.
Definition: prefix.hpp:166
typedef prefix
Definition: ip_types.api:35
tapv2_create_cmd(HW::item< handle_t > &item, const std::string &name, const route::prefix_t &prefix, const l2_address_t &l2_address)
A prefix defintion.
Definition: prefix.hpp:92
HW::item< handle_t > & m_hw_item
A reference to an object&#39;s HW::item that the command will update.
Definition: rpc_cmd.hpp:134
HW::item< handle_t > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:66
vapi::Tap_create_v2 msg_t
convenient typedef
Definition: rpc_cmd.hpp:46