NAT: VPP-1531 api cleanup & update
[vpp.git] / extras / vom / vom / nat_binding_cmds.cpp
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 {
20 bind_44_input_cmd::bind_44_input_cmd(HW::item<bool>& item,
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
30 bind_44_input_cmd::operator==(const bind_44_input_cmd& other) const
31 {
32   return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
33 }
34
35 rc_t
36 bind_44_input_cmd::issue(connection& con)
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)(
43     nat_binding::zone_t::INSIDE == m_zone ? NAT_IS_INSIDE : 0);
44   payload.sw_if_index = m_itf.value();
45
46   VAPI_CALL(req.execute());
47
48   return (wait());
49 }
50
51 std::string
52 bind_44_input_cmd::to_string() const
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
61 unbind_44_input_cmd::unbind_44_input_cmd(HW::item<bool>& item,
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
71 unbind_44_input_cmd::operator==(const unbind_44_input_cmd& other) const
72 {
73   return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
74 }
75
76 rc_t
77 unbind_44_input_cmd::issue(connection& con)
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)(
84     nat_binding::zone_t::INSIDE == m_zone ? NAT_IS_INSIDE : 0);
85   payload.sw_if_index = m_itf.value();
86
87   VAPI_CALL(req.execute());
88
89   return (wait());
90 }
91
92 std::string
93 unbind_44_input_cmd::to_string() const
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
102 bind_44_output_cmd::bind_44_output_cmd(HW::item<bool>& item,
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
112 bind_44_output_cmd::operator==(const bind_44_output_cmd& other) const
113 {
114   return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
115 }
116
117 rc_t
118 bind_44_output_cmd::issue(connection& con)
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)(
125     nat_binding::zone_t::INSIDE == m_zone ? NAT_IS_INSIDE : 0);
126   payload.sw_if_index = m_itf.value();
127
128   VAPI_CALL(req.execute());
129
130   return (wait());
131 }
132
133 std::string
134 bind_44_output_cmd::to_string() const
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
143 unbind_44_output_cmd::unbind_44_output_cmd(HW::item<bool>& item,
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
153 unbind_44_output_cmd::operator==(const unbind_44_output_cmd& other) const
154 {
155   return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
156 }
157
158 rc_t
159 unbind_44_output_cmd::issue(connection& con)
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)(
166     nat_binding::zone_t::INSIDE == m_zone ? NAT_IS_INSIDE : 0);
167   payload.sw_if_index = m_itf.value();
168
169   VAPI_CALL(req.execute());
170
171   return (wait());
172 }
173
174 std::string
175 unbind_44_output_cmd::to_string() const
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
184 dump_input_44_cmd::dump_input_44_cmd()
185 {
186 }
187
188 dump_input_44_cmd::dump_input_44_cmd(const dump_input_44_cmd& d)
189 {
190 }
191
192 bool
193 dump_input_44_cmd::operator==(const dump_input_44_cmd& other) const
194 {
195   return (true);
196 }
197
198 rc_t
199 dump_input_44_cmd::issue(connection& con)
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
210 std::string
211 dump_input_44_cmd::to_string() const
212 {
213   return ("nat-44-input-binding-dump");
214 }
215
216 dump_output_44_cmd::dump_output_44_cmd()
217 {
218 }
219
220 dump_output_44_cmd::dump_output_44_cmd(const dump_output_44_cmd& d)
221 {
222 }
223
224 bool
225 dump_output_44_cmd::operator==(const dump_output_44_cmd& other) const
226 {
227   return (true);
228 }
229
230 rc_t
231 dump_output_44_cmd::issue(connection& con)
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
242 std::string
243 dump_output_44_cmd::to_string() const
244 {
245   return ("nat-44-output-binding-dump");
246 }
247
248 bind_66_input_cmd::bind_66_input_cmd(HW::item<bool>& item,
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
258 bind_66_input_cmd::operator==(const bind_66_input_cmd& other) const
259 {
260   return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
261 }
262
263 rc_t
264 bind_66_input_cmd::issue(connection& con)
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)(
271     nat_binding::zone_t::INSIDE == m_zone ? NAT_IS_INSIDE : 0);
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
281 std::string
282 bind_66_input_cmd::to_string() const
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
291 unbind_66_input_cmd::unbind_66_input_cmd(HW::item<bool>& item,
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
301 unbind_66_input_cmd::operator==(const unbind_66_input_cmd& other) const
302 {
303   return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
304 }
305
306 rc_t
307 unbind_66_input_cmd::issue(connection& con)
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)(
314     nat_binding::zone_t::INSIDE == m_zone ? NAT_IS_INSIDE : 0);
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
324 std::string
325 unbind_66_input_cmd::to_string() const
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
334 dump_input_66_cmd::dump_input_66_cmd()
335 {
336 }
337
338 dump_input_66_cmd::dump_input_66_cmd(const dump_input_66_cmd& d)
339 {
340 }
341
342 bool
343 dump_input_66_cmd::operator==(const dump_input_66_cmd& other) const
344 {
345   return (true);
346 }
347
348 rc_t
349 dump_input_66_cmd::issue(connection& con)
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
360 std::string
361 dump_input_66_cmd::to_string() const
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: ON
371  *
372  * Local Variables:
373  * eval: (c-set-style "mozilla")
374  * End:
375  */