acl: do vlib_buffer_enqueue_to_next in outer function
[vpp.git] / extras / deprecated / vom / vom / nat_static_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_static_cmds.hpp"
17
18 DEFINE_VAPI_MSG_IDS_NAT_API_JSON;
19 DEFINE_VAPI_MSG_IDS_NAT66_API_JSON;
20
21 namespace VOM {
22 namespace nat_static_cmds {
23
24 create_44_cmd::create_44_cmd(HW::item<bool>& item,
25                              route::table_id_t id,
26                              const boost::asio::ip::address_v4& inside,
27                              const boost::asio::ip::address_v4& outside)
28   : rpc_cmd(item)
29   , m_id(id)
30   , m_inside(inside)
31   , m_outside(outside)
32 {}
33
34 bool
35 create_44_cmd::operator==(const create_44_cmd& other) const
36 {
37   return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
38           (m_outside == other.m_outside));
39 }
40
41 rc_t
42 create_44_cmd::issue(connection& con)
43 {
44   msg_t req(con.ctx(), std::ref(*this));
45
46   auto& payload = req.get_request().get_payload();
47   payload.is_add = 1;
48   payload.flags = NAT_IS_ADDR_ONLY;
49   payload.local_port = 0;
50   payload.external_port = 0;
51   payload.vrf_id = m_id;
52   payload.external_sw_if_index = ~0;
53   to_bytes(m_inside, payload.local_ip_address);
54   to_bytes(m_outside, payload.external_ip_address);
55
56   VAPI_CALL(req.execute());
57
58   return (wait());
59 }
60
61 std::string
62 create_44_cmd::to_string() const
63 {
64   std::ostringstream s;
65   s << "nat-44-static-create: " << m_hw_item.to_string() << " table:" << m_id
66     << " inside:" << m_inside.to_string()
67     << " outside:" << m_outside.to_string();
68
69   return (s.str());
70 }
71
72 delete_44_cmd::delete_44_cmd(HW::item<bool>& item,
73                              route::table_id_t id,
74                              const boost::asio::ip::address_v4& inside,
75                              const boost::asio::ip::address_v4& outside)
76   : rpc_cmd(item)
77   , m_id(id)
78   , m_inside(inside)
79   , m_outside(outside)
80 {}
81
82 bool
83 delete_44_cmd::operator==(const delete_44_cmd& other) const
84 {
85   return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
86           (m_outside == other.m_outside));
87 }
88
89 rc_t
90 delete_44_cmd::issue(connection& con)
91 {
92   msg_t req(con.ctx(), std::ref(*this));
93
94   auto& payload = req.get_request().get_payload();
95   payload.is_add = 0;
96   payload.flags = NAT_IS_ADDR_ONLY;
97   payload.local_port = 0;
98   payload.external_port = 0;
99   payload.vrf_id = m_id;
100   payload.external_sw_if_index = ~0;
101   to_bytes(m_inside, payload.local_ip_address);
102   to_bytes(m_outside, payload.external_ip_address);
103
104   VAPI_CALL(req.execute());
105
106   wait();
107   m_hw_item.set(rc_t::NOOP);
108
109   return rc_t::OK;
110 }
111
112 std::string
113 delete_44_cmd::to_string() const
114 {
115   std::ostringstream s;
116   s << "nat-44-static-delete: " << m_hw_item.to_string() << " table:" << m_id
117     << " inside:" << m_inside.to_string()
118     << " outside:" << m_outside.to_string();
119
120   return (s.str());
121 }
122
123 bool
124 dump_44_cmd::operator==(const dump_44_cmd& other) const
125 {
126   return (true);
127 }
128
129 rc_t
130 dump_44_cmd::issue(connection& con)
131 {
132   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
133
134   VAPI_CALL(m_dump->execute());
135
136   wait();
137
138   return rc_t::OK;
139 }
140
141 std::string
142 dump_44_cmd::to_string() const
143 {
144   return ("nat-44-static-dump");
145 }
146
147 create_66_cmd::create_66_cmd(HW::item<bool>& item,
148                              route::table_id_t id,
149                              const boost::asio::ip::address_v6& inside,
150                              const boost::asio::ip::address_v6& outside)
151   : rpc_cmd(item)
152   , m_id(id)
153   , m_inside(inside)
154   , m_outside(outside)
155 {}
156
157 bool
158 create_66_cmd::operator==(const create_66_cmd& other) const
159 {
160   return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
161           (m_outside == other.m_outside));
162 }
163
164 rc_t
165 create_66_cmd::issue(connection& con)
166 {
167   msg_t req(con.ctx(), std::ref(*this));
168
169   auto& payload = req.get_request().get_payload();
170   payload.is_add = 1;
171   payload.vrf_id = m_id;
172   to_bytes(m_inside, payload.local_ip_address);
173   to_bytes(m_outside, payload.external_ip_address);
174
175   VAPI_CALL(req.execute());
176
177   return (wait());
178 }
179
180 std::string
181 create_66_cmd::to_string() const
182 {
183   std::ostringstream s;
184   s << "nat-66-static-create: " << m_hw_item.to_string() << " table:" << m_id
185     << " inside:" << m_inside.to_string()
186     << " outside:" << m_outside.to_string();
187
188   return (s.str());
189 }
190
191 delete_66_cmd::delete_66_cmd(HW::item<bool>& item,
192                              route::table_id_t id,
193                              const boost::asio::ip::address_v6& inside,
194                              const boost::asio::ip::address_v6& outside)
195   : rpc_cmd(item)
196   , m_id(id)
197   , m_inside(inside)
198   , m_outside(outside)
199 {}
200
201 bool
202 delete_66_cmd::operator==(const delete_66_cmd& other) const
203 {
204   return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
205           (m_outside == other.m_outside));
206 }
207
208 rc_t
209 delete_66_cmd::issue(connection& con)
210 {
211   msg_t req(con.ctx(), std::ref(*this));
212
213   auto& payload = req.get_request().get_payload();
214   payload.is_add = 0;
215   payload.vrf_id = m_id;
216   to_bytes(m_inside, payload.local_ip_address);
217   to_bytes(m_outside, payload.external_ip_address);
218
219   VAPI_CALL(req.execute());
220
221   wait();
222   m_hw_item.set(rc_t::NOOP);
223
224   return rc_t::OK;
225 }
226
227 std::string
228 delete_66_cmd::to_string() const
229 {
230   std::ostringstream s;
231   s << "nat-66-static-delete: " << m_hw_item.to_string() << " table:" << m_id
232     << " inside:" << m_inside.to_string()
233     << " outside:" << m_outside.to_string();
234
235   return (s.str());
236 }
237
238 bool
239 dump_66_cmd::operator==(const dump_66_cmd& other) const
240 {
241   return (true);
242 }
243
244 rc_t
245 dump_66_cmd::issue(connection& con)
246 {
247   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
248
249   VAPI_CALL(m_dump->execute());
250
251   wait();
252
253   return rc_t::OK;
254 }
255
256 std::string
257 dump_66_cmd::to_string() const
258 {
259   return ("nat-static-dump");
260 }
261
262 }; // namespace nat_static_cmds
263 }; // namespace VOM
264
265 /*
266  * fd.io coding-style-patch-verification: OFF
267  *
268  * Local Variables:
269  * eval: (c-set-style "mozilla")
270  * End:
271  */