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 * Comparison operator - for UT
65 bool operator==(const nat_static& n) const;
68 * Return the object's key
70 const key_t key() const;
73 * Return the matching 'singular instance'
75 std::shared_ptr<nat_static> singular() const;
78 * Find the instnace of the bridge_domain domain in the OM
80 static std::shared_ptr<nat_static> find(const key_t& key);
83 * Dump all bridge_domain-doamin into the stream provided
85 static void dump(std::ostream& os);
88 * replay the object to create it in hardware
93 * Convert to string for debugging
95 std::string to_string() const;
99 * Class definition for listeners to OM events
101 class event_handler : public OM::listener, public inspect::command_handler
105 virtual ~event_handler() = default;
108 * Handle a populate event
110 void handle_populate(const client_db::key_t& key);
113 * Handle a replay event
115 void handle_replay();
118 * Show the object in the Singular DB
120 void show(std::ostream& os);
123 * Get the sortable Id of the listener
125 dependency_t order() const;
129 * event_handler to register with OM
131 static event_handler m_evh;
134 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
136 void update(const nat_static& obj);
139 * Find or add the instnace of the bridge_domain domain in the OM
141 static std::shared_ptr<nat_static> find_or_add(const nat_static& temp);
144 * It's the VPPHW class that updates the objects in HW
149 * It's the singular_db class that calls replay()
151 friend class singular_db<key_t, nat_static>;
154 * Sweep/reap the object if still stale
159 * HW configuration for the result of creating the bridge_domain
164 * The table-ID the outside address resides in
166 std::shared_ptr<route_domain> m_rd;
169 * The 'inside' IP address, could be v4 or v6
171 const boost::asio::ip::address m_inside;
174 * The 'outside' IP address - always v4
176 const boost::asio::ip::address_v4 m_outside;
179 * A map of all NAT statics
181 static singular_db<key_t, nat_static> m_db;
184 std::ostream& operator<<(std::ostream& os, const nat_static::key_t& key);
188 * fd.io coding-style-patch-verification: ON
191 * eval: (c-set-style "mozilla")