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_L2_LIST_H__
17 #define __VOM_ACL_L2_LIST_H__
21 #include "vom/acl_l2_rule.hpp"
22 #include "vom/acl_types.hpp"
24 #include "vom/inspect.hpp"
26 #include "vom/singular_db.hpp"
31 * An L2 ACL list comprises a set of match actions rules to be applied to
33 * A list is bound to a given interface.
35 class l2_list : public object_base
39 * The KEY can be used to uniquely identify the ACL.
40 * (other choices for keys, like the summation of the properties
41 * of the rules, are rather too cumbersome to use
43 typedef std::string key_t;
46 * The rule container type
48 typedef std::multiset<l2_rule> rules_t;
51 * Construct a new object matching the desried state
53 l2_list(const key_t& key);
55 l2_list(const handle_t& hdl, const key_t& key);
57 l2_list(const key_t& key, const rules_t& rules);
62 l2_list(const l2_list& o);
70 * Return the 'sigular instance' of the ACL that matches this object
72 std::shared_ptr<l2_list> singular() const;
75 * Dump all ACLs into the stream provided
77 static void dump(std::ostream& os);
80 * convert to string format for debug purposes
82 std::string to_string() const;
85 * Insert priority sorted a rule into the list
87 void insert(const l2_rule& rule);
90 * Remove a rule from the list
92 void remove(const l2_rule& rule);
95 * Return the VPP assign handle
97 const handle_t& handle() const;
99 static std::shared_ptr<l2_list> find(const handle_t& handle);
101 static std::shared_ptr<l2_list> find(const key_t& key);
102 static void add(const key_t& key, const HW::item<handle_t>& item);
104 static void remove(const HW::item<handle_t>& item);
106 const key_t& key() const;
108 const rules_t& rules() const;
111 * Comparison operator - for UT
113 bool operator==(const l2_list& l) const;
117 * Class definition for listeners to OM events
119 class event_handler : public OM::listener, public inspect::command_handler
124 virtual ~event_handler() = default;
127 * Handle a populate event
129 void handle_populate(const client_db::key_t& key);
132 * Handle a replay event
134 void handle_replay();
137 * Show the object in the Singular DB
139 void show(std::ostream& os);
142 * Get the sortable Id of the listener
144 dependency_t order() const;
148 * event_handler to register with OM
150 static event_handler m_evh;
153 * Enqueue commands to the VPP command Q for the update
155 void update(const l2_list& obj);
160 HW::item<handle_t> m_hdl;
163 * Find or add the sigular instance in the DB
165 static std::shared_ptr<l2_list> find_or_add(const l2_list& temp);
168 * return the acl-list's handle in the singular instance
170 const handle_t& handle_i() const;
173 * It's the VOM::OM class that updates call update
175 friend class VOM::OM;
178 * It's the VOM::singular_db class that calls replay()
180 friend class singular_db<key_t, l2_list>;
183 * Sweep/reap the object if still stale
188 * Replay the objects state to HW
193 * A map of all ACL's against the client's key
195 static singular_db<key_t, l2_list> m_db;
198 * A map of all ACLs keyed against VPP's handle
200 static std::map<handle_t, std::weak_ptr<l2_list>> m_hdl_db;
203 * The Key is a user defined identifer for this ACL
208 * A sorted list of the rules
217 * fd.io coding-style-patch-verification: ON
220 * eval: (c-set-style "mozilla")