FD.io VPP  v20.05.1-6-gf53edbc3b
Vector Packet Processing
acl_ethertype.hpp
Go to the documentation of this file.
1 /*
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:
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_ETHERTYPE_H__
17 #define __VOM_ACL_ETHERTYPE_H__
18 
19 #include <set>
20 
21 #include "vom/hw.hpp"
22 #include "vom/inspect.hpp"
23 #include "vom/interface.hpp"
24 #include "vom/object_base.hpp"
25 #include "vom/om.hpp"
26 #include "vom/singular_db.hpp"
27 
28 namespace VOM {
29 namespace ACL {
30 /**
31  * An ACL ethertype list comprises a set of inbound ether types and out bound
32  * ether types
33  * to be applied to packets.
34  * A list is bound to a given interface.
35  */
36 
38 {
39 public:
40  /**
41  * Constructor
42  */
43  ethertype_rule_t(const ethertype_t& eth, const direction_t& dir);
44 
45  /**
46  * Destructor
47  */
48  ~ethertype_rule_t() = default;
49 
50  /**
51  * convert to string
52  */
53  std::string to_string() const;
54 
55  /**
56  * comparision operator
57  */
58  bool operator<(const ethertype_rule_t& other) const;
59 
60  /**
61  * comparision operator (for testing)
62  */
63  bool operator==(const ethertype_rule_t& other) const;
64 
65  /**
66  * get the ether value
67  */
68  uint16_t getEthertype(void) const;
69 
70  /**
71  * get the direction
72  */
73  const direction_t& getDirection(void) const;
74 
75 private:
76  /**
77  * ethertype for this rule
78  */
79  const ethertype_t m_eth;
80 
81  /**
82  * direction in which ethertype will be applied w.r.t. intf
83  */
84  const direction_t m_dir;
85 };
86 
87 class acl_ethertype : public object_base
88 {
89 public:
90  /**
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
94  */
95  typedef std::string key_t;
96 
97  /**
98  * The ethertype container
99  */
100  typedef std::multiset<ethertype_rule_t> ethertype_rules_t;
101 
102  /**
103  * Construct a new object matching the desried state
104  */
105  acl_ethertype(const interface& itf, const ethertype_rules_t& le);
106 
107  /**
108  * Copy Constructor
109  */
110  acl_ethertype(const acl_ethertype& o);
111 
112  /**
113  * Destructor
114  */
115  ~acl_ethertype();
116 
117  /**
118  * Return the binding's key
119  */
120  const key_t& key() const;
121 
122  /**
123  * comparision operator (for testing)
124  */
125  bool operator==(const acl_ethertype& o) const;
126 
127  /**
128  * Return the 'singular' of the acl ethertype that matches this object
129  */
130  std::shared_ptr<acl_ethertype> singular() const;
131 
132  /**
133  * convert to string format for debug purposes
134  */
135  std::string to_string() const;
136 
137  /**
138  * Dump all acl ethertype into the stream provided
139  */
140  static void dump(std::ostream& os);
141 
142  /**
143  * Static function to find the acl_ethertype in the model
144  */
145  static std::shared_ptr<acl_ethertype> find(const key_t& key);
146 
147 private:
148  /**
149  * Class definition for listeners to OM events
150  */
152  {
153  public:
154  event_handler();
155  virtual ~event_handler() = default;
156 
157  /**
158  * Handle a populate event
159  */
160  void handle_populate(const client_db::key_t& key);
161 
162  /**
163  * Handle a replay event
164  */
165  void handle_replay();
166 
167  /**
168  * Show the object in the Singular DB
169  */
170  void show(std::ostream& os);
171 
172  /**
173  * Get the sortable Id of the listener
174  */
175  dependency_t order() const;
176  };
177 
178  /**
179  * event_handler to register with OM
180  */
181  static event_handler m_evh;
182 
183  /**
184  * Enque commands to the VPP command Q for the update
185  */
186  void update(const acl_ethertype& obj);
187 
188  /**
189  * Find or add acl ethertype to the OM
190  */
191  static std::shared_ptr<acl_ethertype> find_or_add(const acl_ethertype& temp);
192 
193  /*
194  * It's the OM class that calls singular()
195  */
196  friend class VOM::OM;
197 
198  /**
199  * It's the singular_db class that calls replay()
200  */
201  friend class singular_db<interface::key_t, acl_ethertype>;
202 
203  /**
204  * Sweep/reap the object if still stale
205  */
206  void sweep(void);
207 
208  /**
209  * replay the object to create it in hardware
210  */
211  void replay(void);
212 
213  /**
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
217  */
218  const std::shared_ptr<interface> m_itf;
219 
220  /**
221  * Inbound and outbound ethers list applied on given interface
222  */
223  ethertype_rules_t m_le;
224 
225  /**
226  * HW configuration for the binding. The bool representing the
227  * do/don't bind.
228  */
229  HW::item<bool> m_binding;
230 
231  /**
232  * A map of all acl ethertype keyed against the interface.
233  */
234  static singular_db<interface::key_t, acl_ethertype> m_db;
235 };
236 };
237 };
238 
239 /*
240  * fd.io coding-style-patch-verification: ON
241  *
242  * Local Variables:
243  * eval: (c-set-style "mozilla")
244  * End:
245  */
246 
247 #endif
std::string to_string() const
convert to string
ethertype_rule_t(const ethertype_t &eth, const direction_t &dir)
Constructor.
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
A HW::item is data that is either to be written to or read from VPP/HW.
Definition: hw.hpp:44
bool operator<(const ethertype_rule_t &other) const
comparision operator
Feature Ethertype.
Definition: types.hpp:167
const direction_t & getDirection(void) const
get the direction
std::string key_t
The KEY can be used to uniquely identify the ACL ethertype.
Feature Directions.
Definition: types.hpp:136
An ACL ethertype list comprises a set of inbound ether types and out bound ether types to be applied ...
A Database to store the unique &#39;singular&#39; instances of a single object type.
Definition: singular_db.hpp:33
std::multiset< ethertype_rule_t > ethertype_rules_t
The ethertype container.
A representation of an interface in VPP.
Definition: interface.hpp:41
Class definition for listeners to OM events.
Definition: om.hpp:284
inspect command handler Handler
Definition: inspect.hpp:54
bool operator==(const ethertype_rule_t &other) const
comparision operator (for testing)
void event_handler(void *tls_async)
Definition: tls_async.c:334
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
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
uint16_t getEthertype(void) const
get the ether value
typedef key
Definition: ipsec_types.api:85
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
~ethertype_rule_t()=default
Destructor.