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/route.hpp"
20 #include "vom/singular_db.hpp"
21 #include "vom/types.hpp"
25 * A entry in the ARP termination table of a Bridge Domain
27 class nat_static : public object_base
31 * The key for a NAT static mapping.
32 * So far only model the address only case. The address
35 typedef std::pair<route::table_id_t, boost::asio::ip::address> key_t;
38 * Construct an NAT Static binding with the outside address in default
41 nat_static(const boost::asio::ip::address& inside,
42 const boost::asio::ip::address_v4& outside);
45 * Construct an NAT Static binding with the outside address in
46 * route-domain specified
48 nat_static(const route_domain& rd,
49 const boost::asio::ip::address& inside,
50 const boost::asio::ip::address_v4& outside);
55 nat_static(const nat_static& r);
63 * Return the matching 'singular instance'
65 std::shared_ptr<nat_static> singular() const;
68 * Find the instnace of the bridge_domain domain in the OM
70 static std::shared_ptr<nat_static> find(const nat_static& temp);
73 * Dump all bridge_domain-doamin into the stream provided
75 static void dump(std::ostream& os);
78 * replay the object to create it in hardware
83 * Convert to string for debugging
85 std::string to_string() const;
89 * Class definition for listeners to OM events
91 class event_handler : public OM::listener, public inspect::command_handler
95 virtual ~event_handler() = default;
98 * Handle a populate event
100 void handle_populate(const client_db::key_t& key);
103 * Handle a replay event
105 void handle_replay();
108 * Show the object in the Singular DB
110 void show(std::ostream& os);
113 * Get the sortable Id of the listener
115 dependency_t order() const;
119 * event_handler to register with OM
121 static event_handler m_evh;
124 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
126 void update(const nat_static& obj);
129 * Find or add the instnace of the bridge_domain domain in the OM
131 static std::shared_ptr<nat_static> find_or_add(const nat_static& temp);
134 * It's the VPPHW class that updates the objects in HW
139 * It's the singular_db class that calls replay()
141 friend class singular_db<key_t, nat_static>;
144 * Sweep/reap the object if still stale
149 * HW configuration for the result of creating the bridge_domain
154 * The table-ID the outside address resides in
156 std::shared_ptr<route_domain> m_rd;
159 * The 'inside' IP address, could be v4 or v6
161 const boost::asio::ip::address& m_inside;
164 * The 'outside' IP address - always v4
166 const boost::asio::ip::address_v4& m_outside;
169 * A map of all NAT statics
171 static singular_db<key_t, nat_static> m_db;
174 std::ostream& operator<<(std::ostream& os, const nat_static::key_t& key);
178 * fd.io coding-style-patch-verification: ON
181 * eval: (c-set-style "mozilla")