4325f3703f3fc703632e80e6902bf49e83bae4b0
[vpp.git] / src / vpp-api / vom / nat_static_cmds.cpp
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.hpp"
17
18 DEFINE_VAPI_MSG_IDS_NAT_API_JSON;
19
20 namespace VOM {
21 nat_static::create_44_cmd::create_44_cmd(
22   HW::item<bool>& item,
23   route::table_id_t id,
24   const boost::asio::ip::address_v4& inside,
25   const boost::asio::ip::address_v4& outside)
26   : rpc_cmd(item)
27   , m_id(id)
28   , m_inside(inside)
29   , m_outside(outside)
30 {
31 }
32
33 bool
34 nat_static::create_44_cmd::operator==(const create_44_cmd& other) const
35 {
36   return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
37           (m_outside == other.m_outside));
38 }
39
40 rc_t
41 nat_static::create_44_cmd::issue(connection& con)
42 {
43   msg_t req(con.ctx(), std::ref(*this));
44
45   auto& payload = req.get_request().get_payload();
46   payload.is_add = 1;
47   payload.addr_only = 1;
48   payload.local_port = 0;
49   payload.external_port = 0;
50   payload.vrf_id = m_id;
51   payload.external_sw_if_index = ~0;
52   to_bytes(m_inside, payload.local_ip_address);
53   to_bytes(m_outside, payload.external_ip_address);
54
55   VAPI_CALL(req.execute());
56
57   m_hw_item.set(wait());
58
59   return rc_t::OK;
60 }
61
62 std::string
63 nat_static::create_44_cmd::to_string() const
64 {
65   std::ostringstream s;
66   s << "nat-44-static-create: " << m_hw_item.to_string() << " table:" << m_id
67     << " inside:" << m_inside.to_string()
68     << " outside:" << m_outside.to_string();
69
70   return (s.str());
71 }
72
73 nat_static::delete_44_cmd::delete_44_cmd(
74   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)
78   : rpc_cmd(item)
79   , m_id(id)
80   , m_inside(inside)
81   , m_outside(outside)
82 {
83 }
84
85 bool
86 nat_static::delete_44_cmd::operator==(const delete_44_cmd& other) const
87 {
88   return ((m_id == other.m_id) && (m_inside == other.m_inside) &&
89           (m_outside == other.m_outside));
90 }
91
92 rc_t
93 nat_static::delete_44_cmd::issue(connection& con)
94 {
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
115 std::string
116 nat_static::delete_44_cmd::to_string() const
117 {
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
126 nat_static::dump_44_cmd::dump_44_cmd()
127 {
128 }
129
130 nat_static::dump_44_cmd::dump_44_cmd(const dump_44_cmd& d)
131 {
132 }
133
134 bool
135 nat_static::dump_44_cmd::operator==(const dump_44_cmd& other) const
136 {
137   return (true);
138 }
139
140 rc_t
141 nat_static::dump_44_cmd::issue(connection& con)
142 {
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
152 std::string
153 nat_static::dump_44_cmd::to_string() const
154 {
155   return ("nat-static-dump");
156 }
157 }
158
159 /*
160  * fd.io coding-style-patch-verification: ON
161  *
162  * Local Variables:
163  * eval: (c-set-style "mozilla")
164  * End:
165  */