blob: 2abe0d2b65835ef2cbc4f6fc4fec9ff438fea242 [file] [log] [blame]
Neale Ranns812ed392017-10-16 04:20:13 -07001/*
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
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070016#include "vom/nat_static_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070017
18DEFINE_VAPI_MSG_IDS_NAT_API_JSON;
19
20namespace VOM {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070021namespace nat_static_cmds {
22
23create_44_cmd::create_44_cmd(HW::item<bool>& item,
24 route::table_id_t id,
25 const boost::asio::ip::address_v4& inside,
26 const boost::asio::ip::address_v4& outside)
Neale Ranns812ed392017-10-16 04:20:13 -070027 : rpc_cmd(item)
28 , m_id(id)
29 , m_inside(inside)
30 , m_outside(outside)
31{
32}
33
34bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070035create_44_cmd::operator==(const create_44_cmd& other) const
Neale Ranns812ed392017-10-16 04:20:13 -070036{
37 return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
38 (m_outside == other.m_outside));
39}
40
41rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070042create_44_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -070043{
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.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);
55
56 VAPI_CALL(req.execute());
57
58 m_hw_item.set(wait());
59
60 return rc_t::OK;
61}
62
63std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070064create_44_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -070065{
66 std::ostringstream s;
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();
70
71 return (s.str());
72}
73
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070074delete_44_cmd::delete_44_cmd(HW::item<bool>& item,
75 route::table_id_t id,
76 const boost::asio::ip::address_v4& inside,
77 const boost::asio::ip::address_v4& outside)
Neale Ranns812ed392017-10-16 04:20:13 -070078 : rpc_cmd(item)
79 , m_id(id)
80 , m_inside(inside)
81 , m_outside(outside)
82{
83}
84
85bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070086delete_44_cmd::operator==(const delete_44_cmd& other) const
Neale Ranns812ed392017-10-16 04:20:13 -070087{
88 return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
89 (m_outside == other.m_outside));
90}
91
92rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070093delete_44_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -070094{
95 msg_t req(con.ctx(), std::ref(*this));
96
97 auto& payload = req.get_request().get_payload();
98 payload.is_add = 0;
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);
106
107 VAPI_CALL(req.execute());
108
109 wait();
110 m_hw_item.set(rc_t::NOOP);
111
112 return rc_t::OK;
113}
114
115std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700116delete_44_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -0700117{
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();
122
123 return (s.str());
124}
125
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700126dump_44_cmd::dump_44_cmd()
Neale Ranns812ed392017-10-16 04:20:13 -0700127{
128}
129
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700130dump_44_cmd::dump_44_cmd(const dump_44_cmd& d)
Neale Ranns812ed392017-10-16 04:20:13 -0700131{
132}
133
134bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700135dump_44_cmd::operator==(const dump_44_cmd& other) const
Neale Ranns812ed392017-10-16 04:20:13 -0700136{
137 return (true);
138}
139
140rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700141dump_44_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -0700142{
143 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
144
145 VAPI_CALL(m_dump->execute());
146
147 wait();
148
149 return rc_t::OK;
150}
151
152std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700153dump_44_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -0700154{
155 return ("nat-static-dump");
156}
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700157} // namespace nat_static_cmds
158} // namespace VOM
Neale Ranns812ed392017-10-16 04:20:13 -0700159
160/*
161 * fd.io coding-style-patch-verification: ON
162 *
163 * Local Variables:
164 * eval: (c-set-style "mozilla")
165 * End:
166 */