FD.io VPP  v21.10.1-2-g0a485f517
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.flags = (vapi_enum_nat_config_flags)(
44  payload.sw_if_index = m_itf.value();
45 
46  VAPI_CALL(req.execute());
47 
48  return (wait());
49 }
50 
53 {
54  std::ostringstream s;
55  s << "nat-44-input-binding-create: " << m_hw_item.to_string()
56  << " itf:" << m_itf << " " << m_zone.to_string();
57 
58  return (s.str());
59 }
60 
62  const handle_t& itf,
63  const nat_binding::zone_t& zone)
64  : rpc_cmd(item)
65  , m_itf(itf)
66  , m_zone(zone)
67 {
68 }
69 
70 bool
72 {
73  return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
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.is_add = 0;
83  payload.flags = (vapi_enum_nat_config_flags)(
85  payload.sw_if_index = m_itf.value();
86 
87  VAPI_CALL(req.execute());
88 
89  return (wait());
90 }
91 
94 {
95  std::ostringstream s;
96  s << "nat-44-input-binding-create: " << m_hw_item.to_string()
97  << " itf:" << m_itf << " " << m_zone.to_string();
98 
99  return (s.str());
100 }
101 
103  const handle_t& itf,
104  const nat_binding::zone_t& zone)
105  : rpc_cmd(item)
106  , m_itf(itf)
107  , m_zone(zone)
108 {
109 }
110 
111 bool
113 {
114  return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
115 }
116 
117 rc_t
119 {
120  msg_t req(con.ctx(), std::ref(*this));
121 
122  auto& payload = req.get_request().get_payload();
123  payload.is_add = 1;
124  payload.flags = (vapi_enum_nat_config_flags)(
126  payload.sw_if_index = m_itf.value();
127 
128  VAPI_CALL(req.execute());
129 
130  return (wait());
131 }
132 
135 {
136  std::ostringstream s;
137  s << "nat-44-output-binding-create: " << m_hw_item.to_string()
138  << " itf:" << m_itf << " " << m_zone.to_string();
139 
140  return (s.str());
141 }
142 
144  const handle_t& itf,
145  const nat_binding::zone_t& zone)
146  : rpc_cmd(item)
147  , m_itf(itf)
148  , m_zone(zone)
149 {
150 }
151 
152 bool
154 {
155  return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
156 }
157 
158 rc_t
160 {
161  msg_t req(con.ctx(), std::ref(*this));
162 
163  auto& payload = req.get_request().get_payload();
164  payload.is_add = 0;
165  payload.flags = (vapi_enum_nat_config_flags)(
167  payload.sw_if_index = m_itf.value();
168 
169  VAPI_CALL(req.execute());
170 
171  return (wait());
172 }
173 
176 {
177  std::ostringstream s;
178  s << "nat-44-output-binding-create: " << m_hw_item.to_string()
179  << " itf:" << m_itf << " " << m_zone.to_string();
180 
181  return (s.str());
182 }
183 
185 {
186 }
187 
189 {
190 }
191 
192 bool
194 {
195  return (true);
196 }
197 
198 rc_t
200 {
201  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
202 
203  VAPI_CALL(m_dump->execute());
204 
205  wait();
206 
207  return rc_t::OK;
208 }
209 
212 {
213  return ("nat-44-input-binding-dump");
214 }
215 
217 {
218 }
219 
221 {
222 }
223 
224 bool
226 {
227  return (true);
228 }
229 
230 rc_t
232 {
233  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
234 
235  VAPI_CALL(m_dump->execute());
236 
237  wait();
238 
239  return rc_t::OK;
240 }
241 
244 {
245  return ("nat-44-output-binding-dump");
246 }
247 
249  const handle_t& itf,
250  const nat_binding::zone_t& zone)
251  : rpc_cmd(item)
252  , m_itf(itf)
253  , m_zone(zone)
254 {
255 }
256 
257 bool
259 {
260  return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
261 }
262 
263 rc_t
265 {
266  msg_t req(con.ctx(), std::ref(*this));
267 
268  auto& payload = req.get_request().get_payload();
269  payload.is_add = 1;
270  payload.flags = (vapi_enum_nat_config_flags)(
272  payload.sw_if_index = m_itf.value();
273 
274  VAPI_CALL(req.execute());
275 
276  wait();
277 
278  return rc_t::OK;
279 }
280 
283 {
284  std::ostringstream s;
285  s << "nat-66-input-binding-create: " << m_hw_item.to_string()
286  << " itf:" << m_itf << " " << m_zone.to_string();
287 
288  return (s.str());
289 }
290 
292  const handle_t& itf,
293  const nat_binding::zone_t& zone)
294  : rpc_cmd(item)
295  , m_itf(itf)
296  , m_zone(zone)
297 {
298 }
299 
300 bool
302 {
303  return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
304 }
305 
306 rc_t
308 {
309  msg_t req(con.ctx(), std::ref(*this));
310 
311  auto& payload = req.get_request().get_payload();
312  payload.is_add = 0;
313  payload.flags = (vapi_enum_nat_config_flags)(
315  payload.sw_if_index = m_itf.value();
316 
317  VAPI_CALL(req.execute());
318 
319  wait();
320 
321  return rc_t::OK;
322 }
323 
326 {
327  std::ostringstream s;
328  s << "nat-66-input-binding-create: " << m_hw_item.to_string()
329  << " itf:" << m_itf << " " << m_zone.to_string();
330 
331  return (s.str());
332 }
333 
335 {
336 }
337 
339 {
340 }
341 
342 bool
344 {
345  return (true);
346 }
347 
348 rc_t
350 {
351  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
352 
353  VAPI_CALL(m_dump->execute());
354 
355  wait();
356 
357  return rc_t::OK;
358 }
359 
362 {
363  return ("nat-66-input-binding-dump");
364 }
365 
366 }; // namespace nat_binding_cmds
367 }; // namespace VOM
368 
369 /*
370  * fd.io coding-style-patch-verification: OFF
371  *
372  * Local Variables:
373  * eval: (c-set-style "mozilla")
374  * End:
375  */
VOM::HW::item< bool >
VOM::dump_cmd< vapi::Nat44_interface_dump >::msg_t
vapi::Nat44_interface_dump msg_t
Definition: dump_cmd.hpp:46
VOM::nat_binding_cmds::dump_input_44_cmd
A cmd class that Dumps all the nat_statics.
Definition: nat_binding_cmds.hpp:191
VOM::rpc_cmd< HW::item< bool >, vapi::Nat44_interface_add_del_feature >::wait
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
VOM::nat_binding_cmds::unbind_66_input_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: nat_binding_cmds.cpp:307
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::nat_binding_cmds::dump_output_44_cmd::operator==
bool operator==(const dump_output_44_cmd &i) const
Comparison operator - only used for UT.
Definition: nat_binding_cmds.cpp:225
VOM::nat_binding_cmds::unbind_44_input_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: nat_binding_cmds.cpp:93
VOM::nat_binding_cmds::bind_44_input_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: nat_binding_cmds.cpp:36
VOM::nat_binding_cmds::bind_44_output_cmd::bind_44_output_cmd
bind_44_output_cmd(HW::item< bool > &item, const handle_t &itf, const nat_binding::zone_t &zone)
Constructor.
Definition: nat_binding_cmds.cpp:102
VOM::nat_binding_cmds::unbind_44_output_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: nat_binding_cmds.cpp:175
VOM::nat_binding_cmds::bind_66_input_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: nat_binding_cmds.cpp:264
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::nat_binding::zone_t::INSIDE
const static zone_t INSIDE
Permit Zone.
Definition: nat_binding.hpp:51
VOM::nat_binding_cmds::bind_44_input_cmd::operator==
bool operator==(const bind_44_input_cmd &i) const
Comparison operator - only used for UT.
Definition: nat_binding_cmds.cpp:30
VOM::nat_binding_cmds::dump_input_44_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: nat_binding_cmds.cpp:199
VOM::nat_binding_cmds::unbind_44_output_cmd
A cmd class that unbinds a NAT configuration from an output interface.
Definition: nat_binding_cmds.hpp:151
VOM::nat_binding::zone_t
NAT Zoness.
Definition: nat_binding.hpp:36
VOM::nat_binding_cmds::unbind_44_input_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: nat_binding_cmds.cpp:77
con
Connection con
Definition: vapi_cpp_test.cpp:56
VOM::nat_binding_cmds::bind_66_input_cmd::bind_66_input_cmd
bind_66_input_cmd(HW::item< bool > &item, const handle_t &itf, const nat_binding::zone_t &zone)
Constructor.
Definition: nat_binding_cmds.cpp:248
VOM::nat_binding_cmds::bind_44_input_cmd::bind_44_input_cmd
bind_44_input_cmd(HW::item< bool > &item, const handle_t &itf, const nat_binding::zone_t &zone)
Constructor.
Definition: nat_binding_cmds.cpp:20
VOM::rpc_cmd< HW::item< bool >, vapi::Nat44_interface_add_del_feature >::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::dump_cmd< vapi::Nat44_interface_dump >::m_dump
std::unique_ptr< vapi::Nat44_interface_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
VOM::nat_binding_cmds::bind_44_output_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: nat_binding_cmds.cpp:118
VAPI_CALL
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
VOM::nat_binding_cmds::unbind_66_input_cmd::operator==
bool operator==(const unbind_66_input_cmd &i) const
Comparison operator - only used for UT.
Definition: nat_binding_cmds.cpp:301
VOM::nat_binding_cmds::dump_output_44_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: nat_binding_cmds.cpp:231
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
VOM::dump_cmd< vapi::Nat44_interface_dump >::wait
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
VOM::nat_binding_cmds::dump_output_44_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: nat_binding_cmds.cpp:243
VOM::nat_binding_cmds::unbind_66_input_cmd
A cmd class that unbinds a NAT configuration from an input interface.
Definition: nat_binding_cmds.hpp:299
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::nat_binding_cmds::bind_44_output_cmd
A functor class that binds a NAT configuration to an output interface.
Definition: nat_binding_cmds.hpp:111
VOM::nat_binding_cmds::dump_input_44_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: nat_binding_cmds.cpp:211
VOM::rpc_cmd< HW::item< bool >, vapi::Nat44_interface_add_del_feature >::msg_t
vapi::Nat44_interface_add_del_feature 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::nat_binding_cmds::unbind_66_input_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: nat_binding_cmds.cpp:325
VOM::nat_binding_cmds::bind_44_output_cmd::operator==
bool operator==(const bind_44_output_cmd &i) const
Comparison operator - only used for UT.
Definition: nat_binding_cmds.cpp:112
VOM::nat_binding_cmds::dump_input_44_cmd::operator==
bool operator==(const dump_input_44_cmd &i) const
Comparison operator - only used for UT.
Definition: nat_binding_cmds.cpp:193
VOM::nat_binding_cmds::unbind_44_input_cmd
A cmd class that unbinds a NAT configuration from an input interface.
Definition: nat_binding_cmds.hpp:71
VOM::nat_binding_cmds::unbind_44_input_cmd::unbind_44_input_cmd
unbind_44_input_cmd(HW::item< bool > &item, const handle_t &itf, const nat_binding::zone_t &zone)
Constructor.
Definition: nat_binding_cmds.cpp:61
nat_binding_cmds.hpp
VOM::nat_binding_cmds::dump_input_66_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: nat_binding_cmds.cpp:361
VOM::nat_binding_cmds::unbind_44_output_cmd::unbind_44_output_cmd
unbind_44_output_cmd(HW::item< bool > &item, const handle_t &itf, const nat_binding::zone_t &zone)
Constructor.
Definition: nat_binding_cmds.cpp:143
VOM::nat_binding_cmds::bind_44_input_cmd
A functor class that binds a NAT configuration to an input interface.
Definition: nat_binding_cmds.hpp:31
VOM::nat_binding_cmds::bind_66_input_cmd
A functor class that binds a NAT configuration to an input interface.
Definition: nat_binding_cmds.hpp:259
item
cJSON * item
Definition: cJSON.h:222
VOM::nat_binding_cmds::dump_input_66_cmd
A cmd class that Dumps all the nat_statics.
Definition: nat_binding_cmds.hpp:339
VOM::nat_binding_cmds::unbind_44_input_cmd::operator==
bool operator==(const unbind_44_input_cmd &i) const
Comparison operator - only used for UT.
Definition: nat_binding_cmds.cpp:71
VOM::nat_binding_cmds::dump_input_66_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: nat_binding_cmds.cpp:349
VOM::nat_binding_cmds::dump_input_66_cmd::operator==
bool operator==(const dump_input_66_cmd &i) const
Comparison operator - only used for UT.
Definition: nat_binding_cmds.cpp:343
VOM::nat_binding_cmds::unbind_44_output_cmd::operator==
bool operator==(const unbind_44_output_cmd &i) const
Comparison operator - only used for UT.
Definition: nat_binding_cmds.cpp:153
VOM::nat_binding_cmds::dump_input_44_cmd::dump_input_44_cmd
dump_input_44_cmd()
Constructor.
Definition: nat_binding_cmds.cpp:184
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
VOM::nat_binding_cmds::bind_44_input_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: nat_binding_cmds.cpp:52
NAT_IS_INSIDE
@ NAT_IS_INSIDE
Definition: nat_types.api:44
VOM::nat_binding_cmds::unbind_66_input_cmd::unbind_66_input_cmd
unbind_66_input_cmd(HW::item< bool > &item, const handle_t &itf, const nat_binding::zone_t &zone)
Constructor.
Definition: nat_binding_cmds.cpp:291
VOM::nat_binding_cmds::bind_66_input_cmd::operator==
bool operator==(const bind_66_input_cmd &i) const
Comparison operator - only used for UT.
Definition: nat_binding_cmds.cpp:258
VOM::nat_binding_cmds::bind_66_input_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: nat_binding_cmds.cpp:282
VOM::nat_binding_cmds::dump_output_44_cmd
A cmd class that Dumps all the nat_statics.
Definition: nat_binding_cmds.hpp:224
VOM::nat_binding_cmds::dump_output_44_cmd::dump_output_44_cmd
dump_output_44_cmd()
Constructor.
Definition: nat_binding_cmds.cpp:216
VOM::nat_binding_cmds::bind_44_output_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: nat_binding_cmds.cpp:134
VOM::nat_binding_cmds::dump_input_66_cmd::dump_input_66_cmd
dump_input_66_cmd()
Constructor.
Definition: nat_binding_cmds.cpp:334
VOM::nat_binding_cmds::unbind_44_output_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: nat_binding_cmds.cpp:159
string
const char *const string
Definition: cJSON.h:172