FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
bond_interface_cmds.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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 
19 
20 namespace VOM {
21 namespace bond_interface_cmds {
23  const std::string& name,
25  const bond_interface::lb_t& lb,
26  const l2_address_t& l2_address)
27  : interface::create_cmd<vapi::Bond_create>(item, name)
28  , m_mode(mode)
29  , m_lb(lb)
30  , m_l2_address(l2_address)
31 {
32 }
33 
34 rc_t
36 {
37  msg_t req(con.ctx(), std::ref(*this));
38 
39  auto& payload = req.get_request().get_payload();
40 
41  if (m_l2_address != l2_address_t::ZERO) {
42  m_l2_address.to_bytes(payload.mac_address, 6);
43  payload.use_custom_mac = 1;
44  }
45 
46  payload.mode = (vapi_enum_bond_mode)m_mode.value();
47  if ((m_mode == bond_interface::mode_t::XOR ||
48  m_mode == bond_interface::mode_t::LACP) &&
50  payload.lb = (vapi_enum_bond_lb_algo)m_lb.value();
51 
52  VAPI_CALL(req.execute());
53 
54  wait();
55 
56  if (m_hw_item.rc() == rc_t::OK) {
58  }
59 
60  return rc_t::OK;
61 }
62 
65 {
66  std::ostringstream s;
67  s << "bond-intf-create: " << m_hw_item.to_string();
68 
69  return (s.str());
70 }
71 
73  : interface::delete_cmd<vapi::Bond_delete>(item)
74 {
75 }
76 
77 rc_t
79 {
80  msg_t req(con.ctx(), std::ref(*this));
81 
82  auto& payload = req.get_request().get_payload();
83  payload.sw_if_index = m_hw_item.data().value();
84 
85  VAPI_CALL(req.execute());
86 
87  wait();
90 
91  return rc_t::OK;
92 }
93 
96 {
97  std::ostringstream s;
98  s << "bond-itf-delete: " << m_hw_item.to_string();
99 
100  return (s.str());
101 }
102 
104 {
105 }
106 
107 bool
108 dump_cmd::operator==(const dump_cmd& other) const
109 {
110  return (true);
111 }
112 
113 rc_t
115 {
116  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
117 
118  VAPI_CALL(m_dump->execute());
119 
120  wait();
121 
122  return rc_t::OK;
123 }
124 
127 {
128  return ("bond-itf-dump");
129 }
130 } // namespace bond_interface_cmds
131 } // namespace VOM
132 
133 /*
134  * fd.io coding-style-patch-verification: OFF
135  *
136  * Local Variables:
137  * eval: (c-set-style "mozilla")
138  * End:
139  */
VOM::HW::item< handle_t >
VOM::dump_cmd< vapi::Sw_interface_bond_dump >::msg_t
vapi::Sw_interface_bond_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::Bond_create >::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::bond_interface_cmds::delete_cmd::delete_cmd
delete_cmd(HW::item< handle_t > &item)
Definition: bond_interface_cmds.cpp:72
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
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
bond_interface_cmds.hpp
mode
vl_api_tunnel_mode_t mode
Definition: gre.api:48
VOM::bond_interface_cmds::delete_cmd
A functor class that deletes a Tap interface.
Definition: bond_interface_cmds.hpp:60
VOM::bond_interface::mode_t::LACP
const static mode_t LACP
LACP bond interface mode.
Definition: bond_interface.hpp:52
con
Connection con
Definition: vapi_cpp_test.cpp:56
VOM::bond_interface_cmds::dump_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: bond_interface_cmds.cpp:114
VOM::bond_interface::lb_t
A bond interface load balance.
Definition: bond_interface.hpp:73
VOM::rpc_cmd< HW::item< handle_t >, vapi::Bond_create >::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_bond_dump >::m_dump
std::unique_ptr< vapi::Sw_interface_bond_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
VOM::interface::create_cmd< vapi::Bond_create >::insert_interface
void insert_interface()
add the created interface to the DB
Definition: interface.hpp:343
DEFINE_VAPI_MSG_IDS_BOND_API_JSON
DEFINE_VAPI_MSG_IDS_BOND_API_JSON
Definition: bond_interface_cmds.cpp:18
VOM::bond_interface::lb_t::UNSPECIFIED
const static lb_t UNSPECIFIED
Unspecified bond interface lb.
Definition: bond_interface.hpp:90
VOM::enum_base::value
int value() const
Return the value of the enum - same as integer conversion.
Definition: enum_base.hpp:88
VOM::bond_interface::mode_t::XOR
const static mode_t XOR
XOR bond interface mode.
Definition: bond_interface.hpp:44
VAPI_CALL
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
VOM::bond_interface_cmds::create_cmd
A functor class that creates an interface.
Definition: bond_interface_cmds.hpp:33
VOM::dump_cmd< vapi::Sw_interface_bond_dump >::wait
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
VOM::bond_interface_cmds::dump_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: bond_interface_cmds.cpp:126
VOM::bond_interface_cmds::create_cmd::create_cmd
create_cmd(HW::item< handle_t > &item, const std::string &name, const bond_interface::mode_t &mode, const bond_interface::lb_t &lb, const l2_address_t &l2_address)
Definition: bond_interface_cmds.cpp:22
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::bond_interface_cmds::delete_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: bond_interface_cmds.cpp:95
VOM::bond_interface_cmds::delete_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: bond_interface_cmds.cpp:78
VOM::HW::item::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
VOM::bond_interface_cmds::dump_cmd
A cmd class that Dumps all the Vpp Interfaces.
Definition: bond_interface_cmds.hpp:78
VOM::bond_interface_cmds::create_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: bond_interface_cmds.cpp:64
VOM::bond_interface_cmds::create_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: bond_interface_cmds.cpp:35
VOM::rpc_cmd< HW::item< handle_t >, vapi::Bond_create >::msg_t
vapi::Bond_create 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::Bond_delete >::remove_interface
void remove_interface()
remove the deleted interface from the DB
Definition: interface.hpp:412
VOM::bond_interface_cmds::dump_cmd::dump_cmd
dump_cmd()
Default Constructor.
Definition: bond_interface_cmds.cpp:103
VOM::bond_interface::mode_t
A bond interface mode.
Definition: bond_interface.hpp:31
item
cJSON * item
Definition: cJSON.h:222
vapi
Forward declarations.
Definition: vapi.hpp:44
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
VOM::bond_interface_cmds::dump_cmd::operator==
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
Definition: bond_interface_cmds.cpp:108
string
const char *const string
Definition: cJSON.h:172