FD.io VPP  v18.10-34-gcce845e
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  return (wait());
59 }
60 
61 std::string
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 
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 
83 bool
85 {
86  return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
87  (m_outside == other.m_outside));
88 }
89 
90 rc_t
92 {
93  msg_t req(con.ctx(), std::ref(*this));
94 
95  auto& payload = req.get_request().get_payload();
96  payload.is_add = 0;
97  payload.addr_only = 1;
98  payload.local_port = 0;
99  payload.external_port = 0;
100  payload.vrf_id = m_id;
101  payload.external_sw_if_index = ~0;
102  to_bytes(m_inside, payload.local_ip_address);
103  to_bytes(m_outside, payload.external_ip_address);
104 
105  VAPI_CALL(req.execute());
106 
107  wait();
109 
110  return rc_t::OK;
111 }
112 
113 std::string
115 {
116  std::ostringstream s;
117  s << "nat-44-static-delete: " << m_hw_item.to_string() << " table:" << m_id
118  << " inside:" << m_inside.to_string()
119  << " outside:" << m_outside.to_string();
120 
121  return (s.str());
122 }
123 
124 bool
126 {
127  return (true);
128 }
129 
130 rc_t
132 {
133  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
134 
135  VAPI_CALL(m_dump->execute());
136 
137  wait();
138 
139  return rc_t::OK;
140 }
141 
142 std::string
144 {
145  return ("nat-44-static-dump");
146 }
147 
150  const boost::asio::ip::address_v6& inside,
151  const boost::asio::ip::address_v6& outside)
152  : rpc_cmd(item)
153  , m_id(id)
154  , m_inside(inside)
155  , m_outside(outside)
156 {
157 }
158 
159 bool
161 {
162  return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
163  (m_outside == other.m_outside));
164 }
165 
166 rc_t
168 {
169  msg_t req(con.ctx(), std::ref(*this));
170 
171  auto& payload = req.get_request().get_payload();
172  payload.is_add = 1;
173  payload.vrf_id = m_id;
174  to_bytes(m_inside, payload.local_ip_address);
175  to_bytes(m_outside, payload.external_ip_address);
176 
177  VAPI_CALL(req.execute());
178 
179  return (wait());
180 }
181 
182 std::string
184 {
185  std::ostringstream s;
186  s << "nat-66-static-create: " << m_hw_item.to_string() << " table:" << m_id
187  << " inside:" << m_inside.to_string()
188  << " outside:" << m_outside.to_string();
189 
190  return (s.str());
191 }
192 
195  const boost::asio::ip::address_v6& inside,
196  const boost::asio::ip::address_v6& outside)
197  : rpc_cmd(item)
198  , m_id(id)
199  , m_inside(inside)
200  , m_outside(outside)
201 {
202 }
203 
204 bool
206 {
207  return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
208  (m_outside == other.m_outside));
209 }
210 
211 rc_t
213 {
214  msg_t req(con.ctx(), std::ref(*this));
215 
216  auto& payload = req.get_request().get_payload();
217  payload.is_add = 0;
218  payload.vrf_id = m_id;
219  to_bytes(m_inside, payload.local_ip_address);
220  to_bytes(m_outside, payload.external_ip_address);
221 
222  VAPI_CALL(req.execute());
223 
224  wait();
226 
227  return rc_t::OK;
228 }
229 
230 std::string
232 {
233  std::ostringstream s;
234  s << "nat-66-static-delete: " << m_hw_item.to_string() << " table:" << m_id
235  << " inside:" << m_inside.to_string()
236  << " outside:" << m_outside.to_string();
237 
238  return (s.str());
239 }
240 
241 bool
243 {
244  return (true);
245 }
246 
247 rc_t
249 {
250  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
251 
252  VAPI_CALL(m_dump->execute());
253 
254  wait();
255 
256  return rc_t::OK;
257 }
258 
259 std::string
261 {
262  return ("nat-static-dump");
263 }
264 
265 }; // namespace nat_static_cmds
266 }; // namespace VOM
267 
268 /*
269  * fd.io coding-style-patch-verification: ON
270  *
271  * Local Variables:
272  * eval: (c-set-style "mozilla")
273  * End:
274  */
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:82
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:99
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:84
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.
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:104
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
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.
HW::item< bool > & m_hw_item
A reference to an object&#39;s HW::item that the command will update.
Definition: rpc_cmd.hpp:132
HW::item< bool > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:64
bool operator==(const create_66_cmd &i) const
Comparison operator - only used for UT.
vapi::Nat44_add_del_static_mapping msg_t
convenient typedef
Definition: rpc_cmd.hpp:44