FD.io VPP  v21.06-3-gbb25fbf28
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/tapv2.api.vapi.hpp>
19 
21 
22 namespace VOM {
23 namespace tap_interface_cmds {
24 /*
25  * TAPV2
26  */
28  const std::string& name,
29  const route::prefix_t& prefix,
30  const l2_address_t& l2_address)
31  : interface::create_cmd<vapi::Tap_create_v2>(item, name)
32  , m_prefix(prefix)
33  , m_l2_address(l2_address)
34 {}
35 
36 rc_t
38 {
39  msg_t req(con.ctx(), std::ref(*this));
40 
41  auto& payload = req.get_request().get_payload();
42  memset(payload.host_if_name, 0, sizeof(payload.host_if_name));
43  memcpy(payload.host_if_name,
44  m_name.c_str(),
45  std::min(m_name.length(), sizeof(payload.host_if_name)));
46  payload.host_if_name_set = 1;
47 
48  if (m_prefix != route::prefix_t::ZERO) {
49  if (m_prefix.address().is_v6()) {
50  m_prefix.to_vpp((uint8_t*)&payload.host_ip6_prefix_set,
51  payload.host_ip6_prefix.address,
52  &payload.host_ip6_prefix.len);
53  } else {
54  m_prefix.to_vpp((uint8_t*)&payload.host_ip4_prefix_set,
55  payload.host_ip4_prefix.address,
56  &payload.host_ip4_prefix.len);
57  payload.host_ip4_prefix_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 
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 rc_t
98 {
99 
100  msg_t req(con.ctx(), std::ref(*this));
101 
102  auto& payload = req.get_request().get_payload();
103 
104  payload.sw_if_index = m_hw_item.data().value();
105 
106  VAPI_CALL(req.execute());
107 
108  wait();
110 
112  return rc_t::OK;
113 }
116 {
117  std::ostringstream s;
118  s << "tapv2-itf-delete: " << m_hw_item.to_string();
119 
120  return (s.str());
121 }
122 
124 
125 bool
127 {
128  return (true);
129 }
130 
131 rc_t
133 {
134  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
135 
136  VAPI_CALL(m_dump->execute());
137 
138  wait();
139 
140  return rc_t::OK;
141 }
142 
145 {
146  return ("tapv2-itf-dump");
147 }
148 
149 } // namespace tap_interface_cmds
150 } // namespace VOM
151 
152 /*
153  * fd.io coding-style-patch-verification: OFF
154  *
155  * Local Variables:
156  * eval: (c-set-style "mozilla")
157  * End:
158  */
VOM::route::prefix_t
A prefix defintion.
Definition: prefix.hpp:131
VOM::HW::item< handle_t >
VOM::dump_cmd< vapi::Sw_interface_tap_v2_dump >::msg_t
vapi::Sw_interface_tap_v2_dump msg_t
Definition: dump_cmd.hpp:46
VOM::l2_address_t::ZERO
const static l2_address_t ZERO
An all 0's L2 address.
Definition: types.hpp:358
VOM::rpc_cmd< HW::item< handle_t >, vapi::Tap_create_v2 >::wait
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
VOM::HW::item::set
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
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::route::prefix_t::ZERO
const static prefix_t ZERO
The all Zeros prefix.
Definition: prefix.hpp:205
tap_interface_cmds.hpp
VOM::rc_t::OK
const static rc_t OK
The HW write was successfull.
Definition: types.hpp:109
name
string name[64]
Definition: fib.api:25
VOM::l2_address_t::to_bytes
void to_bytes(uint8_t *array, uint8_t len) const
Convert to byte array.
Definition: types.cpp:208
VOM::handle_t::value
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
VOM::tap_interface_cmds::tapv2_create_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: tap_interface_cmds.cpp:83
VOM::tap_interface_cmds::tapv2_delete_cmd::tapv2_delete_cmd
tapv2_delete_cmd(HW::item< handle_t > &item)
Definition: tap_interface_cmds.cpp:92
con
Connection con
Definition: vapi_cpp_test.cpp:56
VOM::tap_interface_cmds::tapv2_dump_cmd
A cmd class that Dumps all the Vpp Interfaces.
Definition: tap_interface_cmds.hpp:76
VOM::rpc_cmd< HW::item< handle_t >, vapi::Tap_create_v2 >::m_hw_item
HW::item< handle_t > & m_hw_item
A reference to an object's HW::item that the command will update.
Definition: rpc_cmd.hpp:134
VOM::dump_cmd< vapi::Sw_interface_tap_v2_dump >::m_dump
std::unique_ptr< vapi::Sw_interface_tap_v2_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
VOM::interface::create_cmd< vapi::Tap_create_v2 >::insert_interface
void insert_interface()
add the created interface to the DB
Definition: interface.hpp:343
VOM::route::prefix_t::address
const boost::asio::ip::address & address() const
Get the address.
Definition: prefix.cpp:180
VOM::route::prefix_t::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: prefix.cpp:214
VOM::tap_interface_cmds::tapv2_create_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: tap_interface_cmds.cpp:37
VAPI_CALL
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
VOM::tap_interface_cmds::tapv2_dump_cmd::tapv2_dump_cmd
tapv2_dump_cmd()
Default Constructor.
Definition: tap_interface_cmds.cpp:123
DEFINE_VAPI_MSG_IDS_TAPV2_API_JSON
DEFINE_VAPI_MSG_IDS_TAPV2_API_JSON
Definition: tap_interface_cmds.cpp:20
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
VOM::tap_interface_cmds::tapv2_dump_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: tap_interface_cmds.cpp:144
VOM::dump_cmd< vapi::Sw_interface_tap_v2_dump >::wait
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
VOM::interface
A representation of an interface in VPP.
Definition: interface.hpp:41
VOM::rc_t::NOOP
const static rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
VOM::HW::item::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
VOM::rpc_cmd< HW::item< handle_t >, vapi::Tap_create_v2 >::msg_t
vapi::Tap_create_v2 msg_t
convenient typedef
Definition: rpc_cmd.hpp:46
VOM::HW::item::rc
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
VOM::l2_address_t
Type def of a L2 address as read from VPP.
Definition: types.hpp:339
VOM::HW::item::data
T & data()
Return the data read/written.
Definition: hw.hpp:109
VOM::interface::delete_cmd< vapi::Tap_delete_v2 >::remove_interface
void remove_interface()
remove the deleted interface from the DB
Definition: interface.hpp:412
VOM::tap_interface_cmds::tapv2_dump_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: tap_interface_cmds.cpp:132
VOM::tap_interface_cmds::tapv2_create_cmd::tapv2_create_cmd
tapv2_create_cmd(HW::item< handle_t > &item, const std::string &name, const route::prefix_t &prefix, const l2_address_t &l2_address)
Definition: tap_interface_cmds.cpp:27
VOM::tap_interface_cmds::tapv2_delete_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: tap_interface_cmds.cpp:97
VOM::route::prefix_t::to_vpp
void to_vpp(uint8_t *is_ip6, uint8_t *addr, uint8_t *len) const
Convert the prefix into VPP API parameters.
Definition: prefix.cpp:282
item
cJSON * item
Definition: cJSON.h:222
VOM::interface::create_cmd< vapi::Tap_create_v2 >::m_name
const std::string & m_name
The name of the interface to be created.
Definition: interface.hpp:369
vapi
Forward declarations.
Definition: vapi.hpp:44
VOM::tap_interface_cmds::tapv2_delete_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: tap_interface_cmds.cpp:115
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
VOM::tap_interface_cmds::tapv2_dump_cmd::operator==
bool operator==(const tapv2_dump_cmd &i) const
Comparison operator - only used for UT.
Definition: tap_interface_cmds.cpp:126
prefix
vl_api_prefix_t prefix
Definition: ip.api:146
string
const char *const string
Definition: cJSON.h:172