FD.io VPP  v18.07-rc0-415-g6c78436
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,
24  const bond_interface::mode_t& mode,
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 = m_mode.value();
47  if ((m_mode == bond_interface::mode_t::XOR ||
48  m_mode == bond_interface::mode_t::LACP) &&
50  payload.lb = m_lb.value();
51 
52  VAPI_CALL(req.execute());
53 
54  m_hw_item = wait();
55  if (m_hw_item.rc() == rc_t::OK) {
57  }
58 
59  return rc_t::OK;
60 }
61 
62 std::string
64 {
65  std::ostringstream s;
66  s << "bond-intf-create: " << m_hw_item.to_string();
67 
68  return (s.str());
69 }
70 
72  : interface::delete_cmd<vapi::Bond_delete>(item)
73 {
74 }
75 
76 rc_t
78 {
79  msg_t req(con.ctx(), std::ref(*this));
80 
81  auto& payload = req.get_request().get_payload();
82  payload.sw_if_index = m_hw_item.data().value();
83 
84  VAPI_CALL(req.execute());
85 
86  wait();
89 
90  return rc_t::OK;
91 }
92 
93 std::string
95 {
96  std::ostringstream s;
97  s << "bond-itf-delete: " << m_hw_item.to_string();
98 
99  return (s.str());
100 }
101 
103 {
104 }
105 
106 bool
107 dump_cmd::operator==(const dump_cmd& other) const
108 {
109  return (true);
110 }
111 
112 rc_t
114 {
115  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
116 
117  VAPI_CALL(m_dump->execute());
118 
119  wait();
120 
121  return rc_t::OK;
122 }
123 
124 std::string
126 {
127  return ("bond-itf-dump");
128 }
129 } // namespace bond_interface_cmds
130 } // namespace VOM
131 
132 /*
133  * fd.io coding-style-patch-verification: ON
134  *
135  * Local Variables:
136  * eval: (c-set-style "mozilla")
137  * End:
138  */
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:107
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:135
int value() const
Return the value of the enum - same as integer conversion.
Definition: enum_base.hpp:67
void remove_interface()
remove the deleted interface from the DB
Definition: interface.hpp:373
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
A functor class that deletes a Tap interface.
void to_bytes(uint8_t *array, uint8_t len) const
Convert to byte array.
Definition: types.cpp:208
std::string to_string() const
convert to string format for debug purposes
static const mode_t XOR
XOR bond interface mode.
Error codes that VPP will return during a HW write.
Definition: types.hpp:90
std::string to_string() const
convert to string format for debug purposes
static const l2_address_t ZERO
An all 0&#39;s L2 address.
Definition: types.hpp:361
rc_t issue(connection &con)
Issue the command to VPP/HW.
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:160
A bond interface load balance.
Type def of a L2 address as read from VPP.
Definition: types.hpp:342
T & data()
Return the data read/written.
Definition: hw.hpp:108
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
static const mode_t LACP
LACP bond interface mode.
Forward declarations.
Definition: vapi.hpp:44
rc_t issue(connection &con)
Issue the command to VPP/HW.
A representation of the connection to VPP.
Definition: connection.hpp:33
A cmd class that Dumps all the Vpp Interfaces.
HW::item< handle_t > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:64
A functor class that creates an interface.
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
A representation of an interface in VPP.
Definition: interface.hpp:41
std::string to_string() const
convert to string format for debug purposes
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)
A bond interface mode.
delete_cmd(HW::item< handle_t > &item)
static const lb_t UNSPECIFIED
Unspecificed bond interface lb.
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:112
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:303
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:124
DEFINE_VAPI_MSG_IDS_BOND_API_JSON
HW::item< handle_t > wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:89