FD.io VPP  v18.04-17-g3a0d853
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  bool is_bvi)
24  : rpc_cmd(item)
25  , m_itf(itf)
26  , m_bd(bd)
27  , m_is_bvi(is_bvi)
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_is_bvi == other.m_is_bvi));
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;
47  payload.bvi = m_is_bvi;
48  payload.enable = 1;
49 
50  VAPI_CALL(req.execute());
51 
52  m_hw_item.set(wait());
53 
54  return (rc_t::OK);
55 }
56 
57 std::string
59 {
60  std::ostringstream s;
61  s << "L2-bind: " << m_hw_item.to_string() << " itf:" << m_itf.to_string()
62  << " bd:" << m_bd;
63 
64  return (s.str());
65 }
66 
68  const handle_t& itf,
69  uint32_t bd,
70  bool is_bvi)
71  : rpc_cmd(item)
72  , m_itf(itf)
73  , m_bd(bd)
74  , m_is_bvi(is_bvi)
75 {
76 }
77 
78 bool
80 {
81  return ((m_itf == other.m_itf) && (m_bd == other.m_bd) &&
82  (m_is_bvi == other.m_is_bvi));
83 }
84 
85 rc_t
87 {
88  msg_t req(con.ctx(), std::ref(*this));
89 
90  auto& payload = req.get_request().get_payload();
91  payload.rx_sw_if_index = m_itf.value();
92  payload.bd_id = m_bd;
93  payload.shg = 0;
94  payload.bvi = m_is_bvi;
95  payload.enable = 0;
96 
97  VAPI_CALL(req.execute());
98 
99  wait();
101 
102  return (rc_t::OK);
103 }
104 
105 std::string
107 {
108  std::ostringstream s;
109  s << "L2-unbind: " << m_hw_item.to_string() << " itf:" << m_itf.to_string()
110  << " bd:" << m_bd;
111 
112  return (s.str());
113 }
114 
116  const handle_t& itf,
117  uint16_t tag)
118  : rpc_cmd(item)
119  , m_itf(itf)
120  , m_tag(tag)
121 {
122 }
123 
124 bool
126 {
127  return (
128  (m_hw_item.data() == other.m_hw_item.data() && m_itf == other.m_itf) &&
129  (m_tag == other.m_tag));
130 }
131 
132 rc_t
134 {
135  msg_t req(con.ctx(), std::ref(*this));
136 
137  auto& payload = req.get_request().get_payload();
138  payload.sw_if_index = m_itf.value();
139  payload.vtr_op = m_hw_item.data().value();
140  payload.push_dot1q = 1;
141  payload.tag1 = m_tag;
142 
143  VAPI_CALL(req.execute());
144 
145  wait();
146 
147  return (rc_t::OK);
148 }
149 
150 std::string
152 {
153  std::ostringstream s;
154  s << "L2-set-vtr-op: " << m_hw_item.to_string()
155  << " itf:" << m_itf.to_string() << " tag:" << m_tag;
156 
157  return (s.str());
158 }
159 
160 }; // namespace l2_binding_cmds
161 }; // namespace VOM
162 
163 /*
164  * fd.io coding-style-patch-verification: ON
165  *
166  * Local Variables:
167  * eval: (c-set-style "mozilla")
168  * End:
169  */
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:107
HW::item< bool > & m_hw_item
A reference to an object&#39;s HW::item that the command will update.
Definition: rpc_cmd.hpp:135
std::string to_string() const
convert to string format for debug purposes
int value() const
Return the value of the enum - same as integer conversion.
Definition: enum_base.hpp:67
uint32_t value() const
get the value of the handle
Definition: types.cpp:96
bool operator==(const set_vtr_op_cmd &i) const
Comparison operator - only used for UT.
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
Definition: hw.hpp:160
T & data()
Return the data read/written.
Definition: hw.hpp:108
std::string to_string() const
convert to string format for debug purposes
Definition: types.cpp:72
A functor class that binds L2 configuration to an interface.
rc_t issue(connection &con)
Issue the command to VPP/HW.
A representation of the connection to VPP.
Definition: connection.hpp:33
bind_cmd(HW::item< bool > &item, const handle_t &itf, uint32_t bd, bool is_bvi)
Constructor.
HW::item< bool > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:64
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:38
unbind_cmd(HW::item< bool > &item, const handle_t &itf, uint32_t bd, bool is_bvi)
Constructor.
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
rc_t issue(connection &con)
Issue the command to VPP/HW.
A type declaration of an interface handle in VPP.
Definition: types.hpp:236
bool operator==(const unbind_cmd &i) const
Comparison operator - only used for UT.
A cmd class that Unbinds L2 configuration from an interface.
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:112
std::string to_string() const
convert to string format for debug purposes
bool operator==(const bind_cmd &i) const
Comparison operator - only used for UT.
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
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
vapi::Sw_interface_set_l2_bridge msg_t
convenient typedef
Definition: rpc_cmd.hpp:44
set_vtr_op_cmd(HW::item< l2_binding::l2_vtr_op_t > &item, const handle_t &itf, uint16_t tag)
Constructor.
A cmd class sets the VTR operation.
std::string to_string() const
convert to string format for debug purposes
rc_t issue(connection &con)
Issue the command to VPP/HW.