FD.io VPP  v18.07-rc0-415-g6c78436
Vector Packet Processing
nat_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/nat_binding_cmds.hpp"
17 
18 namespace VOM {
19 namespace nat_binding_cmds {
21  const handle_t& itf,
22  const nat_binding::zone_t& zone)
23  : rpc_cmd(item)
24  , m_itf(itf)
25  , m_zone(zone)
26 {
27 }
28 
29 bool
31 {
32  return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
33 }
34 
35 rc_t
37 {
38  msg_t req(con.ctx(), std::ref(*this));
39 
40  auto& payload = req.get_request().get_payload();
41  payload.is_add = 1;
42  payload.is_inside = (nat_binding::zone_t::INSIDE == m_zone ? 1 : 0);
43  payload.sw_if_index = m_itf.value();
44 
45  VAPI_CALL(req.execute());
46 
47  m_hw_item.set(wait());
48 
49  return rc_t::OK;
50 }
51 
52 std::string
54 {
55  std::ostringstream s;
56  s << "nat-44-input-binding-create: " << m_hw_item.to_string()
57  << " itf:" << m_itf << " " << m_zone.to_string();
58 
59  return (s.str());
60 }
61 
63  const handle_t& itf,
64  const nat_binding::zone_t& zone)
65  : rpc_cmd(item)
66  , m_itf(itf)
67  , m_zone(zone)
68 {
69 }
70 
71 bool
73 {
74  return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
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.is_add = 0;
84  payload.is_inside = (nat_binding::zone_t::INSIDE == m_zone ? 1 : 0);
85  payload.sw_if_index = m_itf.value();
86 
87  VAPI_CALL(req.execute());
88 
89  m_hw_item.set(wait());
90 
91  return rc_t::OK;
92 }
93 
94 std::string
96 {
97  std::ostringstream s;
98  s << "nat-44-input-binding-create: " << m_hw_item.to_string()
99  << " itf:" << m_itf << " " << m_zone.to_string();
100 
101  return (s.str());
102 }
103 
105  const handle_t& itf,
106  const nat_binding::zone_t& zone)
107  : rpc_cmd(item)
108  , m_itf(itf)
109  , m_zone(zone)
110 {
111 }
112 
113 bool
115 {
116  return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
117 }
118 
119 rc_t
121 {
122  msg_t req(con.ctx(), std::ref(*this));
123 
124  auto& payload = req.get_request().get_payload();
125  payload.is_add = 1;
126  payload.is_inside = (nat_binding::zone_t::INSIDE == m_zone ? 1 : 0);
127  payload.sw_if_index = m_itf.value();
128 
129  VAPI_CALL(req.execute());
130 
131  m_hw_item.set(wait());
132 
133  return rc_t::OK;
134 }
135 
136 std::string
138 {
139  std::ostringstream s;
140  s << "nat-44-output-binding-create: " << m_hw_item.to_string()
141  << " itf:" << m_itf << " " << m_zone.to_string();
142 
143  return (s.str());
144 }
145 
147  const handle_t& itf,
148  const nat_binding::zone_t& zone)
149  : rpc_cmd(item)
150  , m_itf(itf)
151  , m_zone(zone)
152 {
153 }
154 
155 bool
157 {
158  return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
159 }
160 
161 rc_t
163 {
164  msg_t req(con.ctx(), std::ref(*this));
165 
166  auto& payload = req.get_request().get_payload();
167  payload.is_add = 0;
168  payload.is_inside = (nat_binding::zone_t::INSIDE == m_zone ? 1 : 0);
169  payload.sw_if_index = m_itf.value();
170 
171  VAPI_CALL(req.execute());
172 
173  m_hw_item.set(wait());
174 
175  return rc_t::OK;
176 }
177 
178 std::string
180 {
181  std::ostringstream s;
182  s << "nat-44-output-binding-create: " << m_hw_item.to_string()
183  << " itf:" << m_itf << " " << m_zone.to_string();
184 
185  return (s.str());
186 }
187 
189 {
190 }
191 
193 {
194 }
195 
196 bool
198 {
199  return (true);
200 }
201 
202 rc_t
204 {
205  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
206 
207  VAPI_CALL(m_dump->execute());
208 
209  wait();
210 
211  return rc_t::OK;
212 }
213 
214 std::string
216 {
217  return ("nat-44-input-binding-dump");
218 }
219 
221 {
222 }
223 
225 {
226 }
227 
228 bool
230 {
231  return (true);
232 }
233 
234 rc_t
236 {
237  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
238 
239  VAPI_CALL(m_dump->execute());
240 
241  wait();
242 
243  return rc_t::OK;
244 }
245 
246 std::string
248 {
249  return ("nat-44-output-binding-dump");
250 }
251 
253  const handle_t& itf,
254  const nat_binding::zone_t& zone)
255  : rpc_cmd(item)
256  , m_itf(itf)
257  , m_zone(zone)
258 {
259 }
260 
261 bool
263 {
264  return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
265 }
266 
267 rc_t
269 {
270  msg_t req(con.ctx(), std::ref(*this));
271 
272  auto& payload = req.get_request().get_payload();
273  payload.is_add = 1;
274  payload.is_inside = (nat_binding::zone_t::INSIDE == m_zone ? 1 : 0);
275  payload.sw_if_index = m_itf.value();
276 
277  VAPI_CALL(req.execute());
278 
279  m_hw_item.set(wait());
280 
281  return rc_t::OK;
282 }
283 
284 std::string
286 {
287  std::ostringstream s;
288  s << "nat-66-input-binding-create: " << m_hw_item.to_string()
289  << " itf:" << m_itf << " " << m_zone.to_string();
290 
291  return (s.str());
292 }
293 
295  const handle_t& itf,
296  const nat_binding::zone_t& zone)
297  : rpc_cmd(item)
298  , m_itf(itf)
299  , m_zone(zone)
300 {
301 }
302 
303 bool
305 {
306  return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
307 }
308 
309 rc_t
311 {
312  msg_t req(con.ctx(), std::ref(*this));
313 
314  auto& payload = req.get_request().get_payload();
315  payload.is_add = 0;
316  payload.is_inside = (nat_binding::zone_t::INSIDE == m_zone ? 1 : 0);
317  payload.sw_if_index = m_itf.value();
318 
319  VAPI_CALL(req.execute());
320 
321  m_hw_item.set(wait());
322 
323  return rc_t::OK;
324 }
325 
326 std::string
328 {
329  std::ostringstream s;
330  s << "nat-66-input-binding-create: " << m_hw_item.to_string()
331  << " itf:" << m_itf << " " << m_zone.to_string();
332 
333  return (s.str());
334 }
335 
337 {
338 }
339 
341 {
342 }
343 
344 bool
346 {
347  return (true);
348 }
349 
350 rc_t
352 {
353  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
354 
355  VAPI_CALL(m_dump->execute());
356 
357  wait();
358 
359  return rc_t::OK;
360 }
361 
362 std::string
364 {
365  return ("nat-66-input-binding-dump");
366 }
367 
368 }; // namespace nat_binding_cmds
369 }; // namespace VOM
370 
371 /*
372  * fd.io coding-style-patch-verification: ON
373  *
374  * Local Variables:
375  * eval: (c-set-style "mozilla")
376  * End:
377  */
bool operator==(const dump_input_44_cmd &i) const
Comparison operator - only used for UT.
A cmd class that Dumps all the nat_statics.
rc_t issue(connection &con)
Issue the command to VPP/HW.
std::string to_string() const
convert to string format for debug purposes
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
rc_t issue(connection &con)
Issue the command to VPP/HW.
bind_44_output_cmd(HW::item< bool > &item, const handle_t &itf, const nat_binding::zone_t &zone)
Constructor.
std::string to_string() const
convert to string format for debug purposes
A cmd class that unbinds a NAT configuration from an input interface.
bool operator==(const unbind_44_output_cmd &i) const
Comparison operator - only used for UT.
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
std::string to_string() const
convert to string format for debug purposes
A functor class that binds a NAT configuration to an output interface.
rc_t issue(connection &con)
Issue the command to VPP/HW.
A cmd class that unbinds a NAT configuration from an input interface.
Error codes that VPP will return during a HW write.
Definition: types.hpp:90
rc_t issue(connection &con)
Issue the command to VPP/HW.
unbind_66_input_cmd(HW::item< bool > &item, const handle_t &itf, const nat_binding::zone_t &zone)
Constructor.
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:160
std::string to_string() const
convert to string format for debug purposes
rc_t issue(connection &con)
Issue the command to VPP/HW.
std::string to_string() const
convert to string format for debug purposes
rc_t issue(connection &con)
Issue the command to VPP/HW.
bool operator==(const unbind_66_input_cmd &i) const
Comparison operator - only used for UT.
static const zone_t INSIDE
Permit Zone.
Definition: nat_binding.hpp:51
A representation of the connection to VPP.
Definition: connection.hpp:33
A cmd class that Dumps all the nat_statics.
rc_t issue(connection &con)
Issue the command to VPP/HW.
unbind_44_input_cmd(HW::item< bool > &item, const handle_t &itf, const nat_binding::zone_t &zone)
Constructor.
std::string to_string() const
convert to string format for debug purposes
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
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
A functor class that binds a NAT configuration to an input interface.
std::string to_string() const
convert to string format for debug purposes
A functor class that binds a NAT configuration to an input interface.
A type declaration of an interface handle in VPP.
Definition: types.hpp:236
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:112
unbind_44_output_cmd(HW::item< bool > &item, const handle_t &itf, const nat_binding::zone_t &zone)
Constructor.
bind_44_input_cmd(HW::item< bool > &item, const handle_t &itf, const nat_binding::zone_t &zone)
Constructor.
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
A cmd class that Dumps all the nat_statics.
bool operator==(const dump_output_44_cmd &i) const
Comparison operator - only used for UT.
bool operator==(const bind_44_input_cmd &i) const
Comparison operator - only used for UT.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
rc_t issue(connection &con)
Issue the command to VPP/HW.
bool operator==(const unbind_44_input_cmd &i) const
Comparison operator - only used for UT.
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
bind_66_input_cmd(HW::item< bool > &item, const handle_t &itf, const nat_binding::zone_t &zone)
Constructor.
vapi::Nat44_interface_add_del_feature msg_t
convenient typedef
Definition: rpc_cmd.hpp:44
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
bool operator==(const bind_66_input_cmd &i) const
Comparison operator - only used for UT.
A cmd class that unbinds a NAT configuration from an output interface.
bool operator==(const dump_input_66_cmd &i) const
Comparison operator - only used for UT.
bool operator==(const bind_44_output_cmd &i) const
Comparison operator - only used for UT.
rc_t issue(connection &con)
Issue the command to VPP/HW.
std::string to_string() const
convert to string format for debug purposes