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 #ifndef __VOM_NAT_STATIC_H__
17 #define __VOM_NAT_STATIC_H__
19 #include "vom/dump_cmd.hpp"
20 #include "vom/route.hpp"
21 #include "vom/singular_db.hpp"
22 #include "vom/types.hpp"
24 #include <vapi/nat.api.vapi.hpp>
28 * A entry in the ARP termination table of a Bridge Domain
30 class nat_static : public object_base
34 * The key for a NAT static mapping.
35 * So far only model the address only case. The address
38 typedef std::pair<route::table_id_t, boost::asio::ip::address> key_t;
41 * Construct an NAT Static binding with the outside address in default
44 nat_static(const boost::asio::ip::address& inside,
45 const boost::asio::ip::address_v4& outside);
48 * Construct an NAT Static binding with the outside address in
49 * route-domain specified
51 nat_static(const route_domain& rd,
52 const boost::asio::ip::address& inside,
53 const boost::asio::ip::address_v4& outside);
58 nat_static(const nat_static& r);
66 * Return the matching 'singular instance'
68 std::shared_ptr<nat_static> singular() const;
71 * Find the instnace of the bridge_domain domain in the OM
73 static std::shared_ptr<nat_static> find(const nat_static& temp);
76 * Dump all bridge_domain-doamin into the stream provided
78 static void dump(std::ostream& os);
81 * replay the object to create it in hardware
86 * Convert to string for debugging
88 std::string to_string() const;
91 * A command class that creates NAT 44 static mapping
94 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Nat44_add_del_static_mapping>
100 create_44_cmd(HW::item<bool>& item,
101 route::table_id_t id,
102 const boost::asio::ip::address_v4& inside,
103 const boost::asio::ip::address_v4& outside);
106 * Issue the command to VPP/HW
108 rc_t issue(connection& con);
111 * convert to string format for debug purposes
113 std::string to_string() const;
116 * Comparison operator - only used for UT
118 bool operator==(const create_44_cmd& i) const;
121 route::table_id_t m_id;
122 const boost::asio::ip::address_v4 m_inside;
123 const boost::asio::ip::address_v4 m_outside;
127 * A cmd class that deletes a NAT 44 static mapping
130 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Nat44_add_del_static_mapping>
136 delete_44_cmd(HW::item<bool>& item,
137 route::table_id_t id,
138 const boost::asio::ip::address_v4& inside,
139 const boost::asio::ip::address_v4& outside);
142 * Issue the command to VPP/HW
144 rc_t issue(connection& con);
147 * convert to string format for debug purposes
149 std::string to_string() const;
152 * Comparison operator - only used for UT
154 bool operator==(const delete_44_cmd& i) const;
157 route::table_id_t m_id;
158 const boost::asio::ip::address_v4 m_inside;
159 const boost::asio::ip::address_v4 m_outside;
163 * A cmd class that Dumps all the nat_statics
165 class dump_44_cmd : public dump_cmd<vapi::Nat44_static_mapping_dump>
172 dump_44_cmd(const dump_44_cmd& d);
175 * Issue the command to VPP/HW
177 rc_t issue(connection& con);
179 * convert to string format for debug purposes
181 std::string to_string() const;
184 * Comparison operator - only used for UT
186 bool operator==(const dump_44_cmd& i) const;
197 * Class definition for listeners to OM events
199 class event_handler : public OM::listener, public inspect::command_handler
203 virtual ~event_handler() = default;
206 * Handle a populate event
208 void handle_populate(const client_db::key_t& key);
211 * Handle a replay event
213 void handle_replay();
216 * Show the object in the Singular DB
218 void show(std::ostream& os);
221 * Get the sortable Id of the listener
223 dependency_t order() const;
227 * event_handler to register with OM
229 static event_handler m_evh;
232 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
234 void update(const nat_static& obj);
237 * Find or add the instnace of the bridge_domain domain in the OM
239 static std::shared_ptr<nat_static> find_or_add(const nat_static& temp);
242 * It's the VPPHW class that updates the objects in HW
247 * It's the singular_db class that calls replay()
249 friend class singular_db<key_t, nat_static>;
252 * Sweep/reap the object if still stale
257 * HW configuration for the result of creating the bridge_domain
262 * The table-ID the outside address resides in
264 std::shared_ptr<route_domain> m_rd;
267 * The 'inside' IP address, could be v4 or v6
269 const boost::asio::ip::address& m_inside;
272 * The 'outside' IP address - always v4
274 const boost::asio::ip::address_v4& m_outside;
277 * A map of all NAT statics
279 static singular_db<key_t, nat_static> m_db;
282 std::ostream& operator<<(std::ostream& os, const nat_static::key_t& key);
286 * fd.io coding-style-patch-verification: ON
289 * eval: (c-set-style "mozilla")