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());
58 m_hw_item.set(wait());
64 create_44_cmd::to_string() const
67 s << "nat-44-static-create: " << m_hw_item.to_string() << " table:" << m_id
68 << " inside:" << m_inside.to_string()
69 << " outside:" << m_outside.to_string();
74 delete_44_cmd::delete_44_cmd(HW::item<bool>& item,
76 const boost::asio::ip::address_v4& inside,
77 const boost::asio::ip::address_v4& outside)
86 delete_44_cmd::operator==(const delete_44_cmd& other) const
88 return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
89 (m_outside == other.m_outside));
93 delete_44_cmd::issue(connection& con)
95 msg_t req(con.ctx(), std::ref(*this));
97 auto& payload = req.get_request().get_payload();
99 payload.addr_only = 1;
100 payload.local_port = 0;
101 payload.external_port = 0;
102 payload.vrf_id = m_id;
103 payload.external_sw_if_index = ~0;
104 to_bytes(m_inside, payload.local_ip_address);
105 to_bytes(m_outside, payload.external_ip_address);
107 VAPI_CALL(req.execute());
110 m_hw_item.set(rc_t::NOOP);
116 delete_44_cmd::to_string() const
118 std::ostringstream s;
119 s << "nat-44-static-delete: " << m_hw_item.to_string() << " table:" << m_id
120 << " inside:" << m_inside.to_string()
121 << " outside:" << m_outside.to_string();
127 dump_44_cmd::operator==(const dump_44_cmd& other) const
133 dump_44_cmd::issue(connection& con)
135 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
137 VAPI_CALL(m_dump->execute());
145 dump_44_cmd::to_string() const
147 return ("nat-44-static-dump");
150 create_66_cmd::create_66_cmd(HW::item<bool>& item,
151 route::table_id_t id,
152 const boost::asio::ip::address_v6& inside,
153 const boost::asio::ip::address_v6& outside)
162 create_66_cmd::operator==(const create_66_cmd& other) const
164 return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
165 (m_outside == other.m_outside));
169 create_66_cmd::issue(connection& con)
171 msg_t req(con.ctx(), std::ref(*this));
173 auto& payload = req.get_request().get_payload();
175 payload.vrf_id = m_id;
176 to_bytes(m_inside, payload.local_ip_address);
177 to_bytes(m_outside, payload.external_ip_address);
179 VAPI_CALL(req.execute());
181 m_hw_item.set(wait());
187 create_66_cmd::to_string() const
189 std::ostringstream s;
190 s << "nat-66-static-create: " << m_hw_item.to_string() << " table:" << m_id
191 << " inside:" << m_inside.to_string()
192 << " outside:" << m_outside.to_string();
197 delete_66_cmd::delete_66_cmd(HW::item<bool>& item,
198 route::table_id_t id,
199 const boost::asio::ip::address_v6& inside,
200 const boost::asio::ip::address_v6& outside)
209 delete_66_cmd::operator==(const delete_66_cmd& other) const
211 return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
212 (m_outside == other.m_outside));
216 delete_66_cmd::issue(connection& con)
218 msg_t req(con.ctx(), std::ref(*this));
220 auto& payload = req.get_request().get_payload();
222 payload.vrf_id = m_id;
223 to_bytes(m_inside, payload.local_ip_address);
224 to_bytes(m_outside, payload.external_ip_address);
226 VAPI_CALL(req.execute());
229 m_hw_item.set(rc_t::NOOP);
235 delete_66_cmd::to_string() const
237 std::ostringstream s;
238 s << "nat-66-static-delete: " << m_hw_item.to_string() << " table:" << m_id
239 << " inside:" << m_inside.to_string()
240 << " outside:" << m_outside.to_string();
246 dump_66_cmd::operator==(const dump_66_cmd& other) const
252 dump_66_cmd::issue(connection& con)
254 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
256 VAPI_CALL(m_dump->execute());
264 dump_66_cmd::to_string() const
266 return ("nat-static-dump");
269 }; // namespace nat_static_cmds
273 * fd.io coding-style-patch-verification: ON
276 * eval: (c-set-style "mozilla")