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_ACL_BINDING_H__
17 #define __VOM_ACL_BINDING_H__
21 #include "vom/acl_l2_list.hpp"
22 #include "vom/acl_l3_list.hpp"
23 #include "vom/acl_types.hpp"
25 #include "vom/inspect.hpp"
26 #include "vom/interface.hpp"
27 #include "vom/object_base.hpp"
29 #include "vom/singular_db.hpp"
30 #include "vom/singular_db_funcs.hpp"
35 * A binding between an ACL and an interface.
36 * A representation of the application of the ACL to the interface.
38 template <typename LIST>
39 class binding : public object_base
43 * The key for a binding is the direction and the interface
45 typedef std::pair<direction_t, interface::key_t> key_t;
48 * Construct a new object matching the desried state
50 binding(const direction_t& direction, const interface& itf, const LIST& acl)
51 : m_direction(direction)
52 , m_itf(itf.singular())
53 , m_acl(acl.singular())
62 binding(const binding& o)
63 : m_direction(o.m_direction)
66 , m_binding(o.m_binding)
76 m_db.release(std::make_pair(m_direction, m_itf->key()), this);
80 * Return the 'singular instance' of the L2 config that matches this
83 std::shared_ptr<binding> singular() const { return find_or_add(*this); }
86 * convert to string format for debug purposes
88 std::string to_string() const
91 s << "acl-binding:[" << m_direction.to_string() << " " << m_itf->to_string()
92 << " " << m_acl->to_string() << " " << m_binding.to_string() << "]";
98 * Dump all bindings into the stream provided
100 static void dump(std::ostream& os) { m_db.dump(os); }
102 static dependency_t order() { return m_evh.order(); }
106 * Class definition for listeners to OM events
108 class event_handler : public OM::listener, public inspect::command_handler
113 virtual ~event_handler() = default;
116 * Handle a populate event
118 void handle_populate(const client_db::key_t& key);
121 * Handle a replay event
123 void handle_replay() { m_db.replay(); }
126 * Show the object in the Singular DB
128 void show(std::ostream& os) { db_dump(m_db, os); }
131 * Get the sortable Id of the listener
133 dependency_t order() const;
137 * event_handler to register with OM
139 static event_handler m_evh;
142 * Enquue commonds to the VPP command Q for the update
144 void update(const binding& obj);
147 * Find or Add the instance in the DB
149 static std::shared_ptr<binding> find_or_add(const binding& temp)
151 return (m_db.find_or_add(
152 std::make_pair(temp.m_direction, temp.m_itf->key()), temp));
156 * It's the OM class that calls singular()
158 friend class VOM::OM;
161 * It's the singular_db class that calls replay()
163 friend class singular_db<key_t, binding>;
166 * Sweep/reap the object if still stale
171 * Replay the objects state to HW
176 * The direction the of the packets on which to apply the ACL
179 const direction_t m_direction;
182 * A reference counting pointer the interface that this L3 layer
183 * represents. By holding the reference here, we can guarantee that
184 * this object will outlive the interface
186 const std::shared_ptr<interface> m_itf;
189 * A reference counting pointer the ACL that this
190 * interface is bound to. By holding the reference here, we can
191 * guarantee that this object will outlive the BD.
193 const std::shared_ptr<LIST> m_acl;
196 * HW configuration for the binding. The bool representing the
199 HW::item<bool> m_binding;
202 * A map of all L2 interfaces key against the interface's handle_t
204 static singular_db<key_t, binding> m_db;
208 * Typedef the L3 binding type
210 typedef binding<l3_list> l3_binding;
213 * Typedef the L2 binding type
215 typedef binding<l2_list> l2_binding;
218 * Definition of the static Singular DB for ACL bindings
220 template <typename LIST>
221 singular_db<typename ACL::binding<LIST>::key_t, ACL::binding<LIST>>
224 template <typename LIST>
225 typename ACL::binding<LIST>::event_handler binding<LIST>::m_evh;
228 const static dependency_t __attribute__((unused)) l2o = l2_binding::order();
229 const static dependency_t __attribute__((unused)) l3o = l3_binding::order();
233 std::ostream& operator<<(std::ostream& os,
234 const std::pair<direction_t, interface::key_t>& key);
238 * fd.io coding-style-patch-verification: ON
241 * eval: (c-set-style "mozilla")