18 #include <vapi/tap.api.vapi.hpp> 19 #include <vapi/tapv2.api.vapi.hpp> 25 namespace tap_interface_cmds {
27 const std::string& name,
32 , m_l2_address(l2_address)
39 msg_t req(con.
ctx(), std::ref(*
this));
41 auto& payload = req.get_request().get_payload();
42 memset(payload.tap_name, 0,
sizeof(payload.tap_name));
43 memcpy(payload.tap_name,
m_name.c_str(),
44 std::min(
m_name.length(),
sizeof(payload.tap_name)));
46 if (m_prefix.
address().is_v6()) {
47 m_prefix.
to_vpp(&payload.ip6_address_set, payload.ip6_address,
48 &payload.ip6_mask_width);
50 m_prefix.
to_vpp(&payload.ip4_address_set, payload.ip4_address,
51 &payload.ip4_mask_width);
52 payload.ip4_address_set = 1;
57 m_l2_address.
to_bytes(payload.mac_address, 6);
59 payload.use_random_mac = 1;
90 msg_t req(con.
ctx(), std::ref(*
this));
92 auto& payload = req.get_request().get_payload();
107 std::ostringstream s;
126 m_dump.reset(
new msg_t(con.
ctx(), std::ref(*
this)));
138 return (
"tap-itf-dump");
145 const std::string& name,
150 , m_l2_address(l2_address)
157 msg_t req(con.
ctx(), std::ref(*
this));
159 auto& payload = req.get_request().get_payload();
160 memset(payload.host_if_name, 0,
sizeof(payload.host_if_name));
161 memcpy(payload.host_if_name,
m_name.c_str(),
162 std::min(
m_name.length(),
sizeof(payload.host_if_name)));
163 payload.host_if_name_set = 1;
166 if (m_prefix.
address().is_v6()) {
167 m_prefix.
to_vpp(&payload.host_ip6_addr_set, payload.host_ip6_addr,
168 &payload.host_ip6_prefix_len);
170 m_prefix.
to_vpp(&payload.host_ip4_addr_set, payload.host_ip4_addr,
171 &payload.host_ip4_prefix_len);
172 payload.host_ip4_addr_set = 1;
177 m_l2_address.
to_bytes(payload.host_mac_addr, 6);
178 payload.host_mac_addr_set = 1;
181 payload.id = 0xffffffff;
182 payload.use_random_mac = 1;
183 payload.tx_ring_sz = 1024;
184 payload.rx_ring_sz = 1024;
199 std::ostringstream s;
201 <<
" ip-prefix:" << m_prefix.
to_string();
215 msg_t req(con.
ctx(), std::ref(*
this));
217 auto& payload = req.get_request().get_payload();
232 std::ostringstream s;
251 m_dump.reset(
new msg_t(con.
ctx(), std::ref(*
this)));
263 return (
"tapv2-itf-dump");
static const rc_t NOOP
The HW write/update action was/has not been attempted.
std::string to_string() const
convert to string format for debug purposes
void remove_interface()
remove the deleted interface from the DB
uint32_t value() const
get the value of the handle
void to_bytes(uint8_t *array, uint8_t len) const
Convert to byte array.
rc_t issue(connection &con)
Issue the command to VPP/HW.
Error codes that VPP will return during a HW write.
static const l2_address_t ZERO
An all 0's L2 address.
std::string to_string() const
convert to string format for debug purposes
Type def of a L2 address as read from VPP.
rc_t wait()
Wait on the commands promise.
T & data()
Return the data read/written.
std::string to_string() const
convert to string format for debug purposes
rc_t issue(connection &con)
Issue the command to VPP/HW.
A cmd class that Dumps all the Vpp Interfaces.
tap_create_cmd(HW::item< handle_t > &item, const std::string &name, route::prefix_t &prefix, const l2_address_t &l2_address)
rc_t rc() const
Get the HW return code.
rc_t issue(connection &con)
Issue the command to VPP/HW.
tapv2_create_cmd(HW::item< handle_t > &item, const std::string &name, route::prefix_t &prefix, const l2_address_t &l2_address)
std::string to_string() const
convert to string format for debug purposes
const std::string & m_name
The name of the interface to be created.
A representation of the connection to VPP.
rc_t issue(connection &con)
Issue the command to VPP/HW.
std::string to_string() const
convert to string format for debug purposes
bool operator==(const tapv2_dump_cmd &i) const
Comparison operator - only used for UT.
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
void to_vpp(uint8_t *is_ip6, uint8_t *addr, uint8_t *len) const
Convert the prefix into VPP API parameters.
A representation of an interface in VPP.
DEFINE_VAPI_MSG_IDS_TAP_API_JSON
static const rc_t OK
The HW write was successfull.
tap_dump_cmd()
Default Constructor.
DEFINE_VAPI_MSG_IDS_TAPV2_API_JSON
tapv2_delete_cmd(HW::item< handle_t > &item)
tap_delete_cmd(HW::item< handle_t > &item)
A cmd class that Dumps all the Vpp Interfaces.
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
std::string to_string() const
convert to string format for debug purposes
void insert_interface()
add the created interface to the DB
The VPP Object Model (VOM) library.
tapv2_dump_cmd()
Default Constructor.
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.
rc_t issue(connection &con)
Issue the command to VPP/HW.
static const prefix_t ZERO
The all Zeros prefix.
std::string to_string() const
convert to string format for debug purposes
std::string to_string() const
convert to string format for debug purposes
const boost::asio::ip::address & address() const
Get the address.
HW::item< handle_t > & m_hw_item
A reference to an object's HW::item that the command will update.
bool operator==(const tap_dump_cmd &i) const
Comparison operator - only used for UT.
HW::item< handle_t > & item()
return the HW item the command updates
vapi::Tap_connect msg_t
convenient typedef