FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
acl_l3_list.hpp
Go to the documentation of this file.
1 /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 #ifndef __VOM_ACL_L3_LIST_H__
17 #define __VOM_ACL_L3_LIST_H__
18 
19 #include <set>
20 
21 #include "vom/acl_l3_rule.hpp"
22 #include "vom/acl_types.hpp"
23 #include "vom/hw.hpp"
24 #include "vom/inspect.hpp"
25 #include "vom/om.hpp"
26 #include "vom/singular_db.hpp"
27 
28 namespace VOM {
29 namespace ACL {
30 /**
31  * An L3 ACL list comprises a set of match actions rules to be applied to
32  * packets.
33  * A list is bound to a given interface.
34  */
35 class l3_list : public object_base
36 {
37 public:
38  /**
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
42  */
43  typedef std::string key_t;
44 
45  /**
46  * The rule container type
47  */
48  typedef std::multiset<l3_rule> rules_t;
49 
50  /**
51  * Construct a new object matching the desried state
52  */
53  l3_list(const key_t& key);
54 
55  l3_list(const handle_t& hdl, const key_t& key);
56 
57  l3_list(const key_t& key, const rules_t& rules);
58 
59  /**
60  * Copy Constructor
61  */
62  l3_list(const l3_list& o);
63 
64  /**
65  * Destructor
66  */
67  ~l3_list();
68 
69  /**
70  * Return the 'sigular instance' of the ACL that matches this object
71  */
72  std::shared_ptr<l3_list> singular() const;
73 
74  /**
75  * Dump all ACLs into the stream provided
76  */
77  static void dump(std::ostream& os);
78 
79  /**
80  * convert to string format for debug purposes
81  */
82  std::string to_string() const;
83 
84  /**
85  * Insert priority sorted a rule into the list
86  */
87  void insert(const l3_rule& rule);
88 
89  /**
90  * Remove a rule from the list
91  */
92  void remove(const l3_rule& rule);
93 
94  /**
95  * Return the VPP assign handle
96  */
97  const handle_t& handle() const;
98 
99  static std::shared_ptr<l3_list> find(const handle_t& handle);
100 
101  static std::shared_ptr<l3_list> find(const key_t& key);
102  static void add(const key_t& key, const HW::item<handle_t>& item);
103 
104  static void remove(const HW::item<handle_t>& item);
105 
106  const key_t& key() const;
107 
108  const rules_t& rules() const;
109 
110  /**
111  * Comparison operator - for UT
112  */
113  bool operator==(const l3_list& l) const;
114 
115 private:
116  /**
117  * Class definition for listeners to OM events
118  */
120  {
121  public:
122  event_handler();
123 
124  virtual ~event_handler() = default;
125 
126  /**
127  * Handle a populate event
128  */
129  void handle_populate(const client_db::key_t& key);
130 
131  /**
132  * Handle a replay event
133  */
134  void handle_replay();
135 
136  /**
137  * Show the object in the Singular DB
138  */
139  void show(std::ostream& os);
140 
141  /**
142  * Get the sortable Id of the listener
143  */
144  dependency_t order() const;
145  };
146 
147  /**
148  * event_handler to register with OM
149  */
150  static event_handler m_evh;
151 
152  /**
153  * Enqueue commands to the VPP command Q for the update
154  */
155  void update(const l3_list& obj);
156 
157  /**
158  * HW assigned handle
159  */
160  HW::item<handle_t> m_hdl;
161 
162  /**
163  * Find or add the sigular instance in the DB
164  */
165  static std::shared_ptr<l3_list> find_or_add(const l3_list& temp);
166 
167  /**
168  * return the acl-list's handle in the singular instance
169  */
170  const handle_t& handle_i() const;
171 
172  /*
173  * It's the VOM::OM class that updates call update
174  */
175  friend class VOM::OM;
176 
177  /**
178  * It's the VOM::singular_db class that calls replay()
179  */
180  friend class singular_db<key_t, l3_list>;
181 
182  /**
183  * Sweep/reap the object if still stale
184  */
185  void sweep(void);
186 
187  /**
188  * Replay the objects state to HW
189  */
190  void replay(void);
191 
192  /**
193  * A map of all ACL's against the client's key
194  */
195  static singular_db<key_t, l3_list> m_db;
196 
197  /**
198  * A map of all ACLs keyed against VPP's handle
199  */
200  static std::map<handle_t, std::weak_ptr<l3_list>> m_hdl_db;
201 
202  /**
203  * The Key is a user defined identifer for this ACL
204  */
205  const key_t m_key;
206 
207  /**
208  * A sorted list of the rules
209  */
210  rules_t m_rules;
211 };
212 
213 }; // namesace ACL
214 }; // namespace VOM
215 
216 /*
217  * fd.io coding-style-patch-verification: ON
218  *
219  * Local Variables:
220  * eval: (c-set-style "mozilla")
221  * End:
222  */
223 
224 #endif
An L3 ACL list comprises a set of match actions rules to be applied to packets.
Definition: acl_l3_list.hpp:35
const key_t & key() const
const std::string key_t
In the opflex world each entity is known by a URI which can be converted into a string.
Definition: client_db.hpp:51
const handle_t & handle() const
Return the VPP assign handle.
std::multiset< l3_rule > rules_t
The rule container type.
Definition: acl_l3_list.hpp:48
std::string key_t
The KEY can be used to uniquely identify the ACL.
Definition: acl_l3_list.hpp:43
const rules_t & rules() const
static std::shared_ptr< l3_list > find(const handle_t &handle)
std::shared_ptr< l3_list > singular() const
Return the &#39;sigular instance&#39; of the ACL that matches this object.
Definition: acl_l3_list.cpp:75
static void add(const key_t &key, const HW::item< handle_t > &item)
~l3_list()
Destructor.
Definition: acl_l3_list.cpp:68
A Database to store the unique &#39;singular&#39; instances of a single object type.
Definition: singular_db.hpp:33
Class definition for listeners to OM events.
Definition: om.hpp:284
static void dump(std::ostream &os)
Dump all ACLs into the stream provided.
Definition: acl_l3_list.cpp:84
inspect command handler Handler
Definition: inspect.hpp:54
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
void event_handler(void *tls_async)
Definition: tls_async.c:340
dependency_t
There needs to be a strict order in which object types are read from VPP (at boot time) and replayed ...
Definition: types.hpp:43
bool operator==(const l3_list &l) const
Comparison operator - for UT.
The interface to writing objects into VPP OM.
Definition: om.hpp:140
A base class for all object_base in the VPP object_base-Model.
Definition: object_base.hpp:29
void insert(const l3_rule &rule)
Insert priority sorted a rule into the list.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
l3_list(const key_t &key)
Construct a new object matching the desried state.
Definition: acl_l3_list.cpp:42
An ACL rule is the building block of an ACL.
Definition: acl_l3_rule.hpp:31
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
std::string to_string() const
convert to string format for debug purposes
Definition: acl_l3_list.cpp:93