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;
21 namespace nat_static_cmds {
23 create_44_cmd::create_44_cmd(HW::item<bool>& item,
25 const boost::asio::ip::address_v4& inside,
26 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.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);
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)
84 delete_44_cmd::operator==(const delete_44_cmd& other) const
86 return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
87 (m_outside == other.m_outside));
91 delete_44_cmd::issue(connection& con)
93 msg_t req(con.ctx(), std::ref(*this));
95 auto& payload = req.get_request().get_payload();
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);
105 VAPI_CALL(req.execute());
108 m_hw_item.set(rc_t::NOOP);
114 delete_44_cmd::to_string() const
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();
125 dump_44_cmd::operator==(const dump_44_cmd& other) const
131 dump_44_cmd::issue(connection& con)
133 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
135 VAPI_CALL(m_dump->execute());
143 dump_44_cmd::to_string() const
145 return ("nat-44-static-dump");
148 create_66_cmd::create_66_cmd(HW::item<bool>& item,
149 route::table_id_t id,
150 const boost::asio::ip::address_v6& inside,
151 const boost::asio::ip::address_v6& outside)
160 create_66_cmd::operator==(const create_66_cmd& other) const
162 return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
163 (m_outside == other.m_outside));
167 create_66_cmd::issue(connection& con)
169 msg_t req(con.ctx(), std::ref(*this));
171 auto& payload = req.get_request().get_payload();
173 payload.vrf_id = m_id;
174 to_bytes(m_inside, payload.local_ip_address);
175 to_bytes(m_outside, payload.external_ip_address);
177 VAPI_CALL(req.execute());
183 create_66_cmd::to_string() const
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();
193 delete_66_cmd::delete_66_cmd(HW::item<bool>& item,
194 route::table_id_t id,
195 const boost::asio::ip::address_v6& inside,
196 const boost::asio::ip::address_v6& outside)
205 delete_66_cmd::operator==(const delete_66_cmd& other) const
207 return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
208 (m_outside == other.m_outside));
212 delete_66_cmd::issue(connection& con)
214 msg_t req(con.ctx(), std::ref(*this));
216 auto& payload = req.get_request().get_payload();
218 payload.vrf_id = m_id;
219 to_bytes(m_inside, payload.local_ip_address);
220 to_bytes(m_outside, payload.external_ip_address);
222 VAPI_CALL(req.execute());
225 m_hw_item.set(rc_t::NOOP);
231 delete_66_cmd::to_string() const
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();
242 dump_66_cmd::operator==(const dump_66_cmd& other) const
248 dump_66_cmd::issue(connection& con)
250 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
252 VAPI_CALL(m_dump->execute());
260 dump_66_cmd::to_string() const
262 return ("nat-static-dump");
265 }; // namespace nat_static_cmds
269 * fd.io coding-style-patch-verification: ON
272 * eval: (c-set-style "mozilla")