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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "vom/nat_static_cmds.hpp"
18 DEFINE_VAPI_MSG_IDS_NAT_API_JSON;
19 DEFINE_VAPI_MSG_IDS_NAT66_API_JSON;
22 namespace nat_static_cmds {
24 create_44_cmd::create_44_cmd(HW::item<bool>& item,
26 const boost::asio::ip::address_v4& inside,
27 const boost::asio::ip::address_v4& outside)
35 create_44_cmd::operator==(const create_44_cmd& other) const
37 return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
38 (m_outside == other.m_outside));
42 create_44_cmd::issue(connection& con)
44 msg_t req(con.ctx(), std::ref(*this));
46 auto& payload = req.get_request().get_payload();
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);
56 VAPI_CALL(req.execute());
62 create_44_cmd::to_string() const
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();
72 delete_44_cmd::delete_44_cmd(HW::item<bool>& item,
74 const boost::asio::ip::address_v4& inside,
75 const boost::asio::ip::address_v4& outside)
83 delete_44_cmd::operator==(const delete_44_cmd& other) const
85 return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
86 (m_outside == other.m_outside));
90 delete_44_cmd::issue(connection& con)
92 msg_t req(con.ctx(), std::ref(*this));
94 auto& payload = req.get_request().get_payload();
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);
104 VAPI_CALL(req.execute());
107 m_hw_item.set(rc_t::NOOP);
113 delete_44_cmd::to_string() const
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();
124 dump_44_cmd::operator==(const dump_44_cmd& other) const
130 dump_44_cmd::issue(connection& con)
132 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
134 VAPI_CALL(m_dump->execute());
142 dump_44_cmd::to_string() const
144 return ("nat-44-static-dump");
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)
158 create_66_cmd::operator==(const create_66_cmd& other) const
160 return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
161 (m_outside == other.m_outside));
165 create_66_cmd::issue(connection& con)
167 msg_t req(con.ctx(), std::ref(*this));
169 auto& payload = req.get_request().get_payload();
171 payload.vrf_id = m_id;
172 to_bytes(m_inside, payload.local_ip_address);
173 to_bytes(m_outside, payload.external_ip_address);
175 VAPI_CALL(req.execute());
181 create_66_cmd::to_string() const
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();
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)
202 delete_66_cmd::operator==(const delete_66_cmd& other) const
204 return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
205 (m_outside == other.m_outside));
209 delete_66_cmd::issue(connection& con)
211 msg_t req(con.ctx(), std::ref(*this));
213 auto& payload = req.get_request().get_payload();
215 payload.vrf_id = m_id;
216 to_bytes(m_inside, payload.local_ip_address);
217 to_bytes(m_outside, payload.external_ip_address);
219 VAPI_CALL(req.execute());
222 m_hw_item.set(rc_t::NOOP);
228 delete_66_cmd::to_string() const
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();
239 dump_66_cmd::operator==(const dump_66_cmd& other) const
245 dump_66_cmd::issue(connection& con)
247 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
249 VAPI_CALL(m_dump->execute());
257 dump_66_cmd::to_string() const
259 return ("nat-static-dump");
262 }; // namespace nat_static_cmds
266 * fd.io coding-style-patch-verification: ON
269 * eval: (c-set-style "mozilla")