FD.io VPP  v21.01.1
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 
20 
21 namespace VOM {
22 namespace nat_static_cmds {
23 
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
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.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 
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 bool
84 {
85  return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
86  (m_outside == other.m_outside));
87 }
88 
89 rc_t
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();
108 
109  return rc_t::OK;
110 }
111 
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
125 {
126  return (true);
127 }
128 
129 rc_t
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 
143 {
144  return ("nat-44-static-dump");
145 }
146 
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
159 {
160  return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
161  (m_outside == other.m_outside));
162 }
163 
164 rc_t
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 
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 
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
203 {
204  return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
205  (m_outside == other.m_outside));
206 }
207 
208 rc_t
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();
223 
224  return rc_t::OK;
225 }
226 
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
240 {
241  return (true);
242 }
243 
244 rc_t
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 
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  */
A cmd class that deletes a NAT 44 static mapping.
uint32_t table_id_t
type def the table-id
Definition: prefix.hpp:121
bool operator==(const create_44_cmd &i) const
Comparison operator - only used for UT.
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
bool operator==(const delete_44_cmd &i) const
Comparison operator - only used for UT.
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.
rc_t issue(connection &con)
Issue the command to VPP/HW.
bool operator==(const dump_66_cmd &i) const
Comparison operator - only used for UT.
const char *const string
Definition: cJSON.h:172
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.
std::string to_string() const
convert to string format for debug purposes
std::string to_string() const
convert to string format for debug purposes
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:89
DEFINE_VAPI_MSG_IDS_NAT66_API_JSON
std::string to_string() const
convert to string format for debug purposes
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
std::string to_string() const
convert to string format for debug purposes
void to_bytes(const boost::asio::ip::address_v6 &addr, uint8_t *array)
Definition: prefix.cpp:249
A representation of the connection to VPP.
Definition: connection.hpp:33
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
bool operator==(const dump_44_cmd &i) const
Comparison operator - only used for UT.
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.
rc_t issue(connection &con)
Issue the command to VPP/HW.
bool operator==(const create_66_cmd &i) const
Comparison operator - only used for UT.
bool operator==(const delete_66_cmd &i) const
Comparison operator - only used for UT.
A cmd class that deletes a NAT 66 static mapping.
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 Dumps all the nat_statics.
cJSON * item
Definition: cJSON.h:222
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:109
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:125
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:134
HW::item< bool > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:66
vapi::Nat44_add_del_static_mapping msg_t
convenient typedef
Definition: rpc_cmd.hpp:46
std::string to_string() const
convert to string format for debug purposes