VOM: support for pipes
[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.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   return (wait());
48 }
49
50 std::string
51 bind_44_input_cmd::to_string() const
52 {
53   std::ostringstream s;
54   s << "nat-44-input-binding-create: " << m_hw_item.to_string()
55     << " itf:" << m_itf << " " << m_zone.to_string();
56
57   return (s.str());
58 }
59
60 unbind_44_input_cmd::unbind_44_input_cmd(HW::item<bool>& item,
61                                          const handle_t& itf,
62                                          const nat_binding::zone_t& zone)
63   : rpc_cmd(item)
64   , m_itf(itf)
65   , m_zone(zone)
66 {
67 }
68
69 bool
70 unbind_44_input_cmd::operator==(const unbind_44_input_cmd& other) const
71 {
72   return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
73 }
74
75 rc_t
76 unbind_44_input_cmd::issue(connection& con)
77 {
78   msg_t req(con.ctx(), std::ref(*this));
79
80   auto& payload = req.get_request().get_payload();
81   payload.is_add = 0;
82   payload.is_inside = (nat_binding::zone_t::INSIDE == m_zone ? 1 : 0);
83   payload.sw_if_index = m_itf.value();
84
85   VAPI_CALL(req.execute());
86
87   return (wait());
88 }
89
90 std::string
91 unbind_44_input_cmd::to_string() const
92 {
93   std::ostringstream s;
94   s << "nat-44-input-binding-create: " << m_hw_item.to_string()
95     << " itf:" << m_itf << " " << m_zone.to_string();
96
97   return (s.str());
98 }
99
100 bind_44_output_cmd::bind_44_output_cmd(HW::item<bool>& item,
101                                        const handle_t& itf,
102                                        const nat_binding::zone_t& zone)
103   : rpc_cmd(item)
104   , m_itf(itf)
105   , m_zone(zone)
106 {
107 }
108
109 bool
110 bind_44_output_cmd::operator==(const bind_44_output_cmd& other) const
111 {
112   return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
113 }
114
115 rc_t
116 bind_44_output_cmd::issue(connection& con)
117 {
118   msg_t req(con.ctx(), std::ref(*this));
119
120   auto& payload = req.get_request().get_payload();
121   payload.is_add = 1;
122   payload.is_inside = (nat_binding::zone_t::INSIDE == m_zone ? 1 : 0);
123   payload.sw_if_index = m_itf.value();
124
125   VAPI_CALL(req.execute());
126
127   return (wait());
128 }
129
130 std::string
131 bind_44_output_cmd::to_string() const
132 {
133   std::ostringstream s;
134   s << "nat-44-output-binding-create: " << m_hw_item.to_string()
135     << " itf:" << m_itf << " " << m_zone.to_string();
136
137   return (s.str());
138 }
139
140 unbind_44_output_cmd::unbind_44_output_cmd(HW::item<bool>& item,
141                                            const handle_t& itf,
142                                            const nat_binding::zone_t& zone)
143   : rpc_cmd(item)
144   , m_itf(itf)
145   , m_zone(zone)
146 {
147 }
148
149 bool
150 unbind_44_output_cmd::operator==(const unbind_44_output_cmd& other) const
151 {
152   return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
153 }
154
155 rc_t
156 unbind_44_output_cmd::issue(connection& con)
157 {
158   msg_t req(con.ctx(), std::ref(*this));
159
160   auto& payload = req.get_request().get_payload();
161   payload.is_add = 0;
162   payload.is_inside = (nat_binding::zone_t::INSIDE == m_zone ? 1 : 0);
163   payload.sw_if_index = m_itf.value();
164
165   VAPI_CALL(req.execute());
166
167   return (wait());
168 }
169
170 std::string
171 unbind_44_output_cmd::to_string() const
172 {
173   std::ostringstream s;
174   s << "nat-44-output-binding-create: " << m_hw_item.to_string()
175     << " itf:" << m_itf << " " << m_zone.to_string();
176
177   return (s.str());
178 }
179
180 dump_input_44_cmd::dump_input_44_cmd()
181 {
182 }
183
184 dump_input_44_cmd::dump_input_44_cmd(const dump_input_44_cmd& d)
185 {
186 }
187
188 bool
189 dump_input_44_cmd::operator==(const dump_input_44_cmd& other) const
190 {
191   return (true);
192 }
193
194 rc_t
195 dump_input_44_cmd::issue(connection& con)
196 {
197   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
198
199   VAPI_CALL(m_dump->execute());
200
201   wait();
202
203   return rc_t::OK;
204 }
205
206 std::string
207 dump_input_44_cmd::to_string() const
208 {
209   return ("nat-44-input-binding-dump");
210 }
211
212 dump_output_44_cmd::dump_output_44_cmd()
213 {
214 }
215
216 dump_output_44_cmd::dump_output_44_cmd(const dump_output_44_cmd& d)
217 {
218 }
219
220 bool
221 dump_output_44_cmd::operator==(const dump_output_44_cmd& other) const
222 {
223   return (true);
224 }
225
226 rc_t
227 dump_output_44_cmd::issue(connection& con)
228 {
229   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
230
231   VAPI_CALL(m_dump->execute());
232
233   wait();
234
235   return rc_t::OK;
236 }
237
238 std::string
239 dump_output_44_cmd::to_string() const
240 {
241   return ("nat-44-output-binding-dump");
242 }
243
244 bind_66_input_cmd::bind_66_input_cmd(HW::item<bool>& item,
245                                      const handle_t& itf,
246                                      const nat_binding::zone_t& zone)
247   : rpc_cmd(item)
248   , m_itf(itf)
249   , m_zone(zone)
250 {
251 }
252
253 bool
254 bind_66_input_cmd::operator==(const bind_66_input_cmd& other) const
255 {
256   return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
257 }
258
259 rc_t
260 bind_66_input_cmd::issue(connection& con)
261 {
262   msg_t req(con.ctx(), std::ref(*this));
263
264   auto& payload = req.get_request().get_payload();
265   payload.is_add = 1;
266   payload.is_inside = (nat_binding::zone_t::INSIDE == m_zone ? 1 : 0);
267   payload.sw_if_index = m_itf.value();
268
269   VAPI_CALL(req.execute());
270
271   wait();
272
273   return rc_t::OK;
274 }
275
276 std::string
277 bind_66_input_cmd::to_string() const
278 {
279   std::ostringstream s;
280   s << "nat-66-input-binding-create: " << m_hw_item.to_string()
281     << " itf:" << m_itf << " " << m_zone.to_string();
282
283   return (s.str());
284 }
285
286 unbind_66_input_cmd::unbind_66_input_cmd(HW::item<bool>& item,
287                                          const handle_t& itf,
288                                          const nat_binding::zone_t& zone)
289   : rpc_cmd(item)
290   , m_itf(itf)
291   , m_zone(zone)
292 {
293 }
294
295 bool
296 unbind_66_input_cmd::operator==(const unbind_66_input_cmd& other) const
297 {
298   return ((m_itf == other.m_itf) && (m_zone == other.m_zone));
299 }
300
301 rc_t
302 unbind_66_input_cmd::issue(connection& con)
303 {
304   msg_t req(con.ctx(), std::ref(*this));
305
306   auto& payload = req.get_request().get_payload();
307   payload.is_add = 0;
308   payload.is_inside = (nat_binding::zone_t::INSIDE == m_zone ? 1 : 0);
309   payload.sw_if_index = m_itf.value();
310
311   VAPI_CALL(req.execute());
312
313   wait();
314
315   return rc_t::OK;
316 }
317
318 std::string
319 unbind_66_input_cmd::to_string() const
320 {
321   std::ostringstream s;
322   s << "nat-66-input-binding-create: " << m_hw_item.to_string()
323     << " itf:" << m_itf << " " << m_zone.to_string();
324
325   return (s.str());
326 }
327
328 dump_input_66_cmd::dump_input_66_cmd()
329 {
330 }
331
332 dump_input_66_cmd::dump_input_66_cmd(const dump_input_66_cmd& d)
333 {
334 }
335
336 bool
337 dump_input_66_cmd::operator==(const dump_input_66_cmd& other) const
338 {
339   return (true);
340 }
341
342 rc_t
343 dump_input_66_cmd::issue(connection& con)
344 {
345   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
346
347   VAPI_CALL(m_dump->execute());
348
349   wait();
350
351   return rc_t::OK;
352 }
353
354 std::string
355 dump_input_66_cmd::to_string() const
356 {
357   return ("nat-66-input-binding-dump");
358 }
359
360 }; // namespace nat_binding_cmds
361 }; // namespace VOM
362
363 /*
364  * fd.io coding-style-patch-verification: ON
365  *
366  * Local Variables:
367  * eval: (c-set-style "mozilla")
368  * End:
369  */