FD.io VPP  v18.07-rc0-415-g6c78436
Vector Packet Processing
nat_static_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_static_cmds.hpp"
17 
19 
20 namespace VOM {
21 namespace nat_static_cmds {
22 
25  const boost::asio::ip::address_v4& inside,
26  const boost::asio::ip::address_v4& outside)
27  : rpc_cmd(item)
28  , m_id(id)
29  , m_inside(inside)
30  , m_outside(outside)
31 {
32 }
33 
34 bool
36 {
37  return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
38  (m_outside == other.m_outside));
39 }
40 
41 rc_t
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.addr_only = 1;
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  m_hw_item.set(wait());
59 
60  return rc_t::OK;
61 }
62 
63 std::string
65 {
66  std::ostringstream s;
67  s << "nat-44-static-create: " << m_hw_item.to_string() << " table:" << m_id
68  << " inside:" << m_inside.to_string()
69  << " outside:" << m_outside.to_string();
70 
71  return (s.str());
72 }
73 
76  const boost::asio::ip::address_v4& inside,
77  const boost::asio::ip::address_v4& outside)
78  : rpc_cmd(item)
79  , m_id(id)
80  , m_inside(inside)
81  , m_outside(outside)
82 {
83 }
84 
85 bool
87 {
88  return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
89  (m_outside == other.m_outside));
90 }
91 
92 rc_t
94 {
95  msg_t req(con.ctx(), std::ref(*this));
96 
97  auto& payload = req.get_request().get_payload();
98  payload.is_add = 0;
99  payload.addr_only = 1;
100  payload.local_port = 0;
101  payload.external_port = 0;
102  payload.vrf_id = m_id;
103  payload.external_sw_if_index = ~0;
104  to_bytes(m_inside, payload.local_ip_address);
105  to_bytes(m_outside, payload.external_ip_address);
106 
107  VAPI_CALL(req.execute());
108 
109  wait();
111 
112  return rc_t::OK;
113 }
114 
115 std::string
117 {
118  std::ostringstream s;
119  s << "nat-44-static-delete: " << m_hw_item.to_string() << " table:" << m_id
120  << " inside:" << m_inside.to_string()
121  << " outside:" << m_outside.to_string();
122 
123  return (s.str());
124 }
125 
126 bool
128 {
129  return (true);
130 }
131 
132 rc_t
134 {
135  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
136 
137  VAPI_CALL(m_dump->execute());
138 
139  wait();
140 
141  return rc_t::OK;
142 }
143 
144 std::string
146 {
147  return ("nat-44-static-dump");
148 }
149 
152  const boost::asio::ip::address_v6& inside,
153  const boost::asio::ip::address_v6& outside)
154  : rpc_cmd(item)
155  , m_id(id)
156  , m_inside(inside)
157  , m_outside(outside)
158 {
159 }
160 
161 bool
163 {
164  return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
165  (m_outside == other.m_outside));
166 }
167 
168 rc_t
170 {
171  msg_t req(con.ctx(), std::ref(*this));
172 
173  auto& payload = req.get_request().get_payload();
174  payload.is_add = 1;
175  payload.vrf_id = m_id;
176  to_bytes(m_inside, payload.local_ip_address);
177  to_bytes(m_outside, payload.external_ip_address);
178 
179  VAPI_CALL(req.execute());
180 
181  m_hw_item.set(wait());
182 
183  return rc_t::OK;
184 }
185 
186 std::string
188 {
189  std::ostringstream s;
190  s << "nat-66-static-create: " << m_hw_item.to_string() << " table:" << m_id
191  << " inside:" << m_inside.to_string()
192  << " outside:" << m_outside.to_string();
193 
194  return (s.str());
195 }
196 
199  const boost::asio::ip::address_v6& inside,
200  const boost::asio::ip::address_v6& outside)
201  : rpc_cmd(item)
202  , m_id(id)
203  , m_inside(inside)
204  , m_outside(outside)
205 {
206 }
207 
208 bool
210 {
211  return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
212  (m_outside == other.m_outside));
213 }
214 
215 rc_t
217 {
218  msg_t req(con.ctx(), std::ref(*this));
219 
220  auto& payload = req.get_request().get_payload();
221  payload.is_add = 0;
222  payload.vrf_id = m_id;
223  to_bytes(m_inside, payload.local_ip_address);
224  to_bytes(m_outside, payload.external_ip_address);
225 
226  VAPI_CALL(req.execute());
227 
228  wait();
230 
231  return rc_t::OK;
232 }
233 
234 std::string
236 {
237  std::ostringstream s;
238  s << "nat-66-static-delete: " << m_hw_item.to_string() << " table:" << m_id
239  << " inside:" << m_inside.to_string()
240  << " outside:" << m_outside.to_string();
241 
242  return (s.str());
243 }
244 
245 bool
247 {
248  return (true);
249 }
250 
251 rc_t
253 {
254  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
255 
256  VAPI_CALL(m_dump->execute());
257 
258  wait();
259 
260  return rc_t::OK;
261 }
262 
263 std::string
265 {
266  return ("nat-static-dump");
267 }
268 
269 }; // namespace nat_static_cmds
270 }; // namespace VOM
271 
272 /*
273  * fd.io coding-style-patch-verification: ON
274  *
275  * Local Variables:
276  * eval: (c-set-style "mozilla")
277  * End:
278  */
std::string to_string() const
convert to string format for debug purposes
A cmd class that deletes a NAT 44 static mapping.
uint32_t table_id_t
type def the table-id
Definition: prefix.hpp:83
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:107
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
rc_t issue(connection &con)
Issue the command to VPP/HW.
A command class that creates NAT 44 static mapping.
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.
create_44_cmd(HW::item< bool > &item, route::table_id_t id, const boost::asio::ip::address_v4 &inside, const boost::asio::ip::address_v4 &outside)
Constructor.
create_66_cmd(HW::item< bool > &item, route::table_id_t id, const boost::asio::ip::address_v6 &inside, const boost::asio::ip::address_v6 &outside)
Constructor.
Error codes that VPP will return during a HW write.
Definition: types.hpp:90
std::string to_string() const
convert to string format for debug purposes
bool operator==(const dump_44_cmd &i) const
Comparison operator - only used for UT.
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:160
bool operator==(const delete_44_cmd &i) const
Comparison operator - only used for UT.
void to_bytes(const boost::asio::ip::address_v6 &addr, uint8_t *array)
Definition: prefix.cpp:218
A representation of the connection to VPP.
Definition: connection.hpp:33
bool operator==(const delete_66_cmd &i) const
Comparison operator - only used for UT.
std::string to_string() const
convert to string format for debug purposes
bool operator==(const dump_66_cmd &i) const
Comparison operator - only used for UT.
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
delete_44_cmd(HW::item< bool > &item, route::table_id_t id, const boost::asio::ip::address_v4 &inside, const boost::asio::ip::address_v4 &outside)
Constructor.
std::string to_string() const
convert to string format for debug purposes
rc_t issue(connection &con)
Issue the command to VPP/HW.
A cmd class that deletes a NAT 66 static mapping.
rc_t issue(connection &con)
Issue the command to VPP/HW.
A cmd class that Dumps all the nat_statics.
std::string to_string() const
convert to string format for debug purposes
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:112
bool operator==(const create_44_cmd &i) const
Comparison operator - only used for UT.
A cmd class that Dumps all the nat_statics.
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
rc_t issue(connection &con)
Issue the command to VPP/HW.
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
vapi::Nat44_add_del_static_mapping msg_t
convenient typedef
Definition: rpc_cmd.hpp:44
DEFINE_VAPI_MSG_IDS_NAT_API_JSON
delete_66_cmd(HW::item< bool > &item, route::table_id_t id, const boost::asio::ip::address_v6 &inside, const boost::asio::ip::address_v6 &outside)
Constructor.
A command class that creates NAT 66 static mapping.
bool operator==(const create_66_cmd &i) const
Comparison operator - only used for UT.