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_BINDING_H__
17 #define __VOM_NAT_BINDING_H__
20 #include "vom/interface.hpp"
21 #include "vom/object_base.hpp"
23 #include "vom/singular_db.hpp"
27 * A Class representing the binding of an L2 interface to a bridge-domain
28 * and the properties of that binding.
30 class nat_binding : public object_base
36 struct zone_t : public enum_base<zone_t>
41 zone_t(int v, const std::string s);
51 const static zone_t INSIDE;
56 const static zone_t OUTSIDE;
58 const static zone_t& from_vpp(u8 is_inside);
62 * The key for a NAT Binding.
63 * The zoe is not included, since the same interface is never inside
66 typedef std::tuple<interface::key_t, direction_t, l3_proto_t> key_t;
69 * Construct a new object matching the desried state
70 * @param itf The interface onto which we bind/apply the feature
71 * @param dir The direction (input/output)
72 * @param proto The L3 proto used inside.
73 * @param zone The NAT zone for the link
75 nat_binding(const interface& itf,
76 const direction_t& dir,
77 const l3_proto_t& proto,
83 nat_binding(const nat_binding& o);
91 * Comparison operator - for UT
93 bool operator==(const nat_binding& n) const;
96 * Return the binding's key
98 const key_t key() const;
101 * Return the 'singular instance' of the L2 config that matches this
104 std::shared_ptr<nat_binding> singular() const;
107 * convert to string format for debug purposes
109 std::string to_string() const;
112 * Static function to find the bridge_domain in the model
114 static std::shared_ptr<nat_binding> find(const key_t& key);
117 * Dump all nat_bindings into the stream provided
119 static void dump(std::ostream& os);
123 * Class definition for listeners to OM events
125 class event_handler : public OM::listener, public inspect::command_handler
129 virtual ~event_handler() = default;
132 * Handle a populate event
134 void handle_populate(const client_db::key_t& key);
137 * Handle a replay event
139 void handle_replay();
142 * Show the object in the Singular DB
144 void show(std::ostream& os);
147 * Get the sortable Id of the listener
149 dependency_t order() const;
153 * event_handler to register with OM
155 static event_handler m_evh;
158 * Enquue commonds to the VPP command Q for the update
160 void update(const nat_binding& obj);
163 * Find or Add the singular instance in the DB
165 static std::shared_ptr<nat_binding> find_or_add(const nat_binding& temp);
168 * It's the OM class that calls singular()
173 * It's the singular_db class that calls replay()
175 friend class singular_db<const key_t, nat_binding>;
178 * Sweep/reap the object if still stale
183 * replay the object to create it in hardware
188 * HW configuration for the binding. The bool representing the
191 HW::item<bool> m_binding;
194 * A reference counting pointer the interface that this NAT binding
195 * represents. By holding the reference here, we can guarantee that
196 * this object will outlive the interface
198 const std::shared_ptr<interface> m_itf;
201 * The direction in which the feature applies
206 * The L3 protocol used on the inside
211 * The NAT zone the interface is in
216 * A map of all L2 interfaces key against the interface's handle_t
218 static singular_db<const key_t, nat_binding> m_db;
221 std::ostream& operator<<(std::ostream& os, const nat_binding::key_t& key);
225 * fd.io coding-style-patch-verification: ON
228 * eval: (c-set-style "mozilla")