2 * Copyright (c) 2018 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_ETHERTYPE_H__
17 #define __VOM_ACL_ETHERTYPE_H__
22 #include "vom/inspect.hpp"
23 #include "vom/interface.hpp"
24 #include "vom/object_base.hpp"
26 #include "vom/singular_db.hpp"
31 * An ACL ethertype list comprises a set of inbound ether types and out bound
33 * to be applied to packets.
34 * A list is bound to a given interface.
37 struct ethertype_rule_t
43 ethertype_rule_t(const ethertype_t& eth, const direction_t& dir);
48 ~ethertype_rule_t() = default;
53 std::string to_string() const;
56 * comparision operator
58 bool operator<(const ethertype_rule_t& other) const;
61 * comparision operator (for testing)
63 bool operator==(const ethertype_rule_t& other) const;
68 uint16_t getEthertype(void) const;
73 const direction_t& getDirection(void) const;
77 * ethertype for this rule
79 const ethertype_t m_eth;
82 * direction in which ethertype will be applied w.r.t. intf
84 const direction_t m_dir;
87 class acl_ethertype : public object_base
91 * The KEY can be used to uniquely identify the ACL ethertype.
92 * (other choices for keys, like the summation of the properties
93 * of the rules, are rather too cumbersome to use
95 typedef std::string key_t;
98 * The ethertype container
100 typedef std::multiset<ethertype_rule_t> ethertype_rules_t;
103 * Construct a new object matching the desried state
105 acl_ethertype(const interface& itf, const ethertype_rules_t& le);
110 acl_ethertype(const acl_ethertype& o);
118 * Return the binding's key
120 const key_t& key() const;
123 * comparision operator (for testing)
125 bool operator==(const acl_ethertype& o) const;
128 * Return the 'singular' of the acl ethertype that matches this object
130 std::shared_ptr<acl_ethertype> singular() const;
133 * convert to string format for debug purposes
135 std::string to_string() const;
138 * Dump all acl ethertype into the stream provided
140 static void dump(std::ostream& os);
143 * Static function to find the acl_ethertype in the model
145 static std::shared_ptr<acl_ethertype> find(const key_t& key);
149 * Class definition for listeners to OM events
151 class event_handler : public OM::listener, public inspect::command_handler
155 virtual ~event_handler() = default;
158 * Handle a populate event
160 void handle_populate(const client_db::key_t& key);
163 * Handle a replay event
165 void handle_replay();
168 * Show the object in the Singular DB
170 void show(std::ostream& os);
173 * Get the sortable Id of the listener
175 dependency_t order() const;
179 * event_handler to register with OM
181 static event_handler m_evh;
184 * Enque commands to the VPP command Q for the update
186 void update(const acl_ethertype& obj);
189 * Find or add acl ethertype to the OM
191 static std::shared_ptr<acl_ethertype> find_or_add(const acl_ethertype& temp);
194 * It's the OM class that calls singular()
196 friend class VOM::OM;
199 * It's the singular_db class that calls replay()
201 friend class singular_db<interface::key_t, acl_ethertype>;
204 * Sweep/reap the object if still stale
209 * replay the object to create it in hardware
214 * A reference counting pointer to the interface on which acl ethertype
215 * resides. By holding the reference here, we can guarantee that
216 * this object will outlive the interface
218 const std::shared_ptr<interface> m_itf;
221 * Inbound and outbound ethers list applied on given interface
223 ethertype_rules_t m_le;
226 * HW configuration for the binding. The bool representing the
229 HW::item<bool> m_binding;
232 * A map of all acl ethertype keyed against the interface.
234 static singular_db<interface::key_t, acl_ethertype> m_db;
240 * fd.io coding-style-patch-verification: ON
243 * eval: (c-set-style "mozilla")