FD.io VPP  v21.10.1-2-g0a485f517
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  */
VOM::HW::item< bool >
VOM::dump_cmd< vapi::Nat44_static_mapping_dump >::msg_t
vapi::Nat44_static_mapping_dump msg_t
Definition: dump_cmd.hpp:46
VOM::rpc_cmd< HW::item< bool >, vapi::Nat44_add_del_static_mapping >::wait
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
VOM::HW::item::set
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
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::rc_t::OK
const static rc_t OK
The HW write was successfull.
Definition: types.hpp:109
VOM::to_bytes
void to_bytes(const boost::asio::ip::address_v6 &addr, uint8_t *array)
Definition: prefix.cpp:249
VOM::nat_static_cmds::dump_44_cmd::operator==
bool operator==(const dump_44_cmd &i) const
Comparison operator - only used for UT.
Definition: nat_static_cmds.cpp:124
VOM::nat_static_cmds::delete_44_cmd::delete_44_cmd
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.
Definition: nat_static_cmds.cpp:72
VOM::nat_static_cmds::create_66_cmd
A command class that creates NAT 66 static mapping.
Definition: nat_static_cmds.hpp:136
VOM::nat_static_cmds::dump_66_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: nat_static_cmds.cpp:245
VOM::nat_static_cmds::dump_66_cmd
A cmd class that Dumps all the nat_statics.
Definition: nat_static_cmds.hpp:208
VOM::rpc_cmd
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
con
Connection con
Definition: vapi_cpp_test.cpp:56
VOM::nat_static_cmds::dump_44_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: nat_static_cmds.cpp:130
VOM::nat_static_cmds::dump_44_cmd
A cmd class that Dumps all the nat_statics.
Definition: nat_static_cmds.hpp:103
VOM::nat_static_cmds::delete_44_cmd
A cmd class that deletes a NAT 44 static mapping.
Definition: nat_static_cmds.hpp:67
VOM::rpc_cmd< HW::item< bool >, vapi::Nat44_add_del_static_mapping >::m_hw_item
HW::item< bool > & m_hw_item
A reference to an object's HW::item that the command will update.
Definition: rpc_cmd.hpp:134
VOM::dump_cmd< vapi::Nat44_static_mapping_dump >::m_dump
std::unique_ptr< vapi::Nat44_static_mapping_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
VOM::nat_static_cmds::delete_66_cmd::delete_66_cmd
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.
Definition: nat_static_cmds.cpp:191
VOM::nat_static_cmds::delete_66_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: nat_static_cmds.cpp:209
VOM::nat_static_cmds::create_44_cmd
A command class that creates NAT 44 static mapping.
Definition: nat_static_cmds.hpp:31
VAPI_CALL
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
VOM::nat_static_cmds::delete_66_cmd::operator==
bool operator==(const delete_66_cmd &i) const
Comparison operator - only used for UT.
Definition: nat_static_cmds.cpp:202
VOM::nat_static_cmds::create_44_cmd::create_44_cmd
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.
Definition: nat_static_cmds.cpp:24
VOM::nat_static_cmds::dump_44_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: nat_static_cmds.cpp:142
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
VOM::nat_static_cmds::delete_44_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: nat_static_cmds.cpp:113
VOM::nat_static_cmds::create_44_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: nat_static_cmds.cpp:62
VOM::dump_cmd< vapi::Nat44_static_mapping_dump >::wait
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
nat_static_cmds.hpp
VOM::nat_static_cmds::create_44_cmd::operator==
bool operator==(const create_44_cmd &i) const
Comparison operator - only used for UT.
Definition: nat_static_cmds.cpp:35
DEFINE_VAPI_MSG_IDS_NAT66_API_JSON
DEFINE_VAPI_MSG_IDS_NAT66_API_JSON
Definition: nat_static_cmds.cpp:19
VOM::rc_t::NOOP
const static rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
VOM::HW::item::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
DEFINE_VAPI_MSG_IDS_NAT_API_JSON
DEFINE_VAPI_MSG_IDS_NAT_API_JSON
Definition: nat_static_cmds.cpp:18
VOM::nat_static_cmds::delete_44_cmd::operator==
bool operator==(const delete_44_cmd &i) const
Comparison operator - only used for UT.
Definition: nat_static_cmds.cpp:83
VOM::nat_static_cmds::create_66_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: nat_static_cmds.cpp:165
id
u8 id[64]
Definition: dhcp.api:160
VOM::rpc_cmd< HW::item< bool >, vapi::Nat44_add_del_static_mapping >::msg_t
vapi::Nat44_add_del_static_mapping msg_t
convenient typedef
Definition: rpc_cmd.hpp:46
VOM::nat_static_cmds::delete_44_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: nat_static_cmds.cpp:90
VOM::nat_static_cmds::create_66_cmd::create_66_cmd
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.
Definition: nat_static_cmds.cpp:147
VOM::nat_static_cmds::create_66_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: nat_static_cmds.cpp:181
VOM::nat_static_cmds::create_44_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: nat_static_cmds.cpp:42
VOM::nat_static_cmds::dump_66_cmd::operator==
bool operator==(const dump_66_cmd &i) const
Comparison operator - only used for UT.
Definition: nat_static_cmds.cpp:239
NAT_IS_ADDR_ONLY
@ NAT_IS_ADDR_ONLY
Definition: nat_types.api:42
VOM::nat_static_cmds::dump_66_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: nat_static_cmds.cpp:257
item
cJSON * item
Definition: cJSON.h:222
VOM::route::table_id_t
uint32_t table_id_t
type def the table-id
Definition: prefix.hpp:121
VOM::nat_static_cmds::delete_66_cmd
A cmd class that deletes a NAT 66 static mapping.
Definition: nat_static_cmds.hpp:172
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
VOM::nat_static_cmds::delete_66_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: nat_static_cmds.cpp:228
VOM::nat_static_cmds::create_66_cmd::operator==
bool operator==(const create_66_cmd &i) const
Comparison operator - only used for UT.
Definition: nat_static_cmds.cpp:158
string
const char *const string
Definition: cJSON.h:172