FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
l2_binding_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 
16 #include "vom/l2_binding_cmds.hpp"
17 
18 namespace VOM {
19 namespace l2_binding_cmds {
21  const handle_t& itf,
22  uint32_t bd,
23  const l2_binding::l2_port_type_t& port_type)
24  : rpc_cmd(item)
25  , m_itf(itf)
26  , m_bd(bd)
27  , m_port_type(port_type)
28 {
29 }
30 
31 bool
32 bind_cmd::operator==(const bind_cmd& other) const
33 {
34  return ((m_itf == other.m_itf) && (m_bd == other.m_bd) &&
35  (m_port_type == other.m_port_type));
36 }
37 
38 rc_t
40 {
41  msg_t req(con.ctx(), std::ref(*this));
42 
43  auto& payload = req.get_request().get_payload();
44  payload.rx_sw_if_index = m_itf.value();
45  payload.bd_id = m_bd;
46  payload.shg = 0;
48  payload.port_type = L2_API_PORT_TYPE_BVI;
50  payload.port_type = L2_API_PORT_TYPE_UU_FWD;
51  else
52  payload.port_type = L2_API_PORT_TYPE_NORMAL;
53 
54  payload.enable = 1;
55 
56  VAPI_CALL(req.execute());
57 
58  return (wait());
59 }
60 
63 {
64  std::ostringstream s;
65  s << "L2-bind: " << m_hw_item.to_string() << " itf:" << m_itf.to_string()
66  << " bd:" << m_bd << " port-type:" << m_port_type.to_string();
67 
68  return (s.str());
69 }
70 
72  const handle_t& itf,
73  uint32_t bd,
74  const l2_binding::l2_port_type_t& port_type)
75  : rpc_cmd(item)
76  , m_itf(itf)
77  , m_bd(bd)
78  , m_port_type(port_type)
79 {
80 }
81 
82 bool
84 {
85  return ((m_itf == other.m_itf) && (m_bd == other.m_bd) &&
86  (m_port_type == other.m_port_type));
87 }
88 
89 rc_t
91 {
92  msg_t req(con.ctx(), std::ref(*this));
93 
94  auto& payload = req.get_request().get_payload();
95  payload.rx_sw_if_index = m_itf.value();
96  payload.bd_id = m_bd;
97  payload.shg = 0;
99  payload.port_type = L2_API_PORT_TYPE_BVI;
100  else if (m_port_type == l2_binding::l2_port_type_t::L2_PORT_TYPE_UU_FWD)
101  payload.port_type = L2_API_PORT_TYPE_UU_FWD;
102  else
103  payload.port_type = L2_API_PORT_TYPE_NORMAL;
104 
105  payload.enable = 0;
106 
107  VAPI_CALL(req.execute());
108 
109  wait();
111 
112  return (rc_t::OK);
113 }
114 
117 {
118  std::ostringstream s;
119  s << "L2-unbind: " << m_hw_item.to_string() << " itf:" << m_itf.to_string()
120  << " bd:" << m_bd << " port-type:" << m_port_type;
121 
122  return (s.str());
123 }
124 }; // namespace l2_binding_cmds
125 }; // namespace VOM
126 
127 /*
128  * fd.io coding-style-patch-verification: OFF
129  *
130  * Local Variables:
131  * eval: (c-set-style "mozilla")
132  * End:
133  */
VOM::l2_binding_cmds::unbind_cmd::unbind_cmd
unbind_cmd(HW::item< bool > &item, const handle_t &itf, uint32_t bd, const l2_binding::l2_port_type_t &port_type)
Constructor.
Definition: l2_binding_cmds.cpp:71
VOM::HW::item< bool >
VOM::l2_binding_cmds::unbind_cmd
A cmd class that Unbinds L2 configuration from an interface.
Definition: l2_binding_cmds.hpp:77
VOM::l2_binding_cmds::bind_cmd::operator==
bool operator==(const bind_cmd &i) const
Comparison operator - only used for UT.
Definition: l2_binding_cmds.cpp:32
VOM::rpc_cmd< HW::item< bool >, vapi::Sw_interface_set_l2_bridge >::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::rc_t::OK
const static rc_t OK
The HW write was successfull.
Definition: types.hpp:109
VOM::handle_t::value
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
VOM::rpc_cmd
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
VOM::l2_binding_cmds::bind_cmd::bind_cmd
bind_cmd(HW::item< bool > &item, const handle_t &itf, uint32_t bd, const l2_binding::l2_port_type_t &port_type)
Constructor.
Definition: l2_binding_cmds.cpp:20
con
Connection con
Definition: vapi_cpp_test.cpp:56
VOM::rpc_cmd< HW::item< bool >, vapi::Sw_interface_set_l2_bridge >::m_hw_item
HW::item< bool > & m_hw_item
A reference to an object's HW::item that the command will update.
Definition: rpc_cmd.hpp:134
VOM::l2_binding_cmds::bind_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: l2_binding_cmds.cpp:39
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::l2_binding_cmds::unbind_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: l2_binding_cmds.cpp:90
l2_binding_cmds.hpp
VOM::rc_t::NOOP
const static rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
L2_API_PORT_TYPE_NORMAL
@ L2_API_PORT_TYPE_NORMAL
Definition: l2.api:517
VOM::handle_t
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
VOM::HW::item::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
VOM::l2_binding_cmds::bind_cmd
A functor class that binds L2 configuration to an interface.
Definition: l2_binding_cmds.hpp:31
VOM::rpc_cmd< HW::item< bool >, vapi::Sw_interface_set_l2_bridge >::msg_t
vapi::Sw_interface_set_l2_bridge msg_t
convenient typedef
Definition: rpc_cmd.hpp:46
VOM::enum_base::to_string
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
VOM::handle_t::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: types.cpp:69
VOM::l2_binding_cmds::unbind_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: l2_binding_cmds.cpp:116
L2_API_PORT_TYPE_BVI
@ L2_API_PORT_TYPE_BVI
Definition: l2.api:519
VOM::l2_binding_cmds::bind_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: l2_binding_cmds.cpp:62
item
cJSON * item
Definition: cJSON.h:222
L2_API_PORT_TYPE_UU_FWD
@ L2_API_PORT_TYPE_UU_FWD
Definition: l2.api:522
VOM::l2_binding::l2_port_type_t
Definition: l2_binding.hpp:41
VOM::l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI
const static l2_port_type_t L2_PORT_TYPE_BVI
Definition: l2_binding.hpp:47
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
VOM::l2_binding::l2_port_type_t::L2_PORT_TYPE_UU_FWD
const static l2_port_type_t L2_PORT_TYPE_UU_FWD
Definition: l2_binding.hpp:48
VOM::l2_binding_cmds::unbind_cmd::operator==
bool operator==(const unbind_cmd &i) const
Comparison operator - only used for UT.
Definition: l2_binding_cmds.cpp:83
string
const char *const string
Definition: cJSON.h:172