FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
l2_binding.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_L2_BINDING_H__
17 #define __VOM_L2_BINDING_H__
18 
19 #include "vom/bridge_domain.hpp"
20 #include "vom/hw.hpp"
21 #include "vom/inspect.hpp"
22 #include "vom/interface.hpp"
23 #include "vom/object_base.hpp"
24 #include "vom/om.hpp"
25 #include "vom/singular_db.hpp"
26 
27 namespace VOM {
28 /**
29  * A Clas representing the binding of an L2 interface to a bridge-domain
30  * and the properties of that binding.
31  */
32 class l2_binding : public object_base
33 {
34 public:
35  /**
36  * Key type for an L2 binding in the singular DB
37  */
39 
40  struct l2_vtr_op_t : public enum_base<l2_vtr_op_t>
41  {
42  l2_vtr_op_t(const l2_vtr_op_t& l) = default;
43  ~l2_vtr_op_t() = default;
44 
46  const static l2_vtr_op_t L2_VTR_PUSH_1;
47  const static l2_vtr_op_t L2_VTR_PUSH_2;
48  const static l2_vtr_op_t L2_VTR_POP_1;
49  const static l2_vtr_op_t L2_VTR_POP_2;
54 
55  private:
56  l2_vtr_op_t(int v, const std::string s);
57  };
58 
59  struct l2_port_type_t : public enum_base<l2_port_type_t>
60  {
61  l2_port_type_t(const l2_port_type_t& l) = default;
62  ~l2_port_type_t() = default;
63 
67 
68  private:
69  l2_port_type_t(int v, const std::string s);
70  };
71 
72  /**
73  * Construct a new object matching the desried state
74  */
75  l2_binding(const interface& itf, const bridge_domain& bd);
76  l2_binding(const interface& itf,
77  const bridge_domain& bd,
78  const l2_port_type_t& port_type);
79 
80  /**
81  * Copy Constructor
82  */
83  l2_binding(const l2_binding& o);
84 
85  /**
86  * Destructor
87  */
88  ~l2_binding();
89 
90  /**
91  * Return the binding's key
92  */
93  const key_t& key() const;
94 
95  /**
96  * Comparison operator - for UT
97  */
98  bool operator==(const l2_binding& l) const;
99 
100  /**
101  * Return the 'singular instance' of the L2 config that matches this
102  * object
103  */
104  std::shared_ptr<l2_binding> singular() const;
105 
106  /**
107  * convert to string format for debug purposes
108  */
109  std::string to_string() const;
110 
111  /**
112  * Dump all l2_bindings into the stream provided
113  */
114  static void dump(std::ostream& os);
115 
116  /**
117  * Set the VTR operation on the binding/interface
118  */
119  void set(const l2_vtr_op_t& op, uint16_t tag);
120 
121  /**
122  * Static function to find the bridge_domain in the model
123  */
124  static std::shared_ptr<l2_binding> find(const key_t& key);
125 
126 private:
127  /**
128  * Class definition for listeners to OM events
129  */
131  {
132  public:
133  event_handler();
134  virtual ~event_handler() = default;
135 
136  /**
137  * Handle a populate event
138  */
139  void handle_populate(const client_db::key_t& key);
140 
141  /**
142  * Handle a replay event
143  */
144  void handle_replay();
145 
146  /**
147  * Show the object in the Singular DB
148  */
149  void show(std::ostream& os);
150 
151  /**
152  * Get the sortable Id of the listener
153  */
154  dependency_t order() const;
155  };
156 
157  /**
158  * event_handler to register with OM
159  */
160  static event_handler m_evh;
161 
162  /**
163  * Enquue commonds to the VPP command Q for the update
164  */
165  void update(const l2_binding& obj);
166 
167  /**
168  * Find or Add the singular instance in the DB
169  */
170  static std::shared_ptr<l2_binding> find_or_add(const l2_binding& temp);
171 
172  /*
173  * It's the OM class that calls singular()
174  */
175  friend class OM;
176 
177  /**
178  * It's the singular_db class that calls replay()
179  */
180  friend class singular_db<key_t, l2_binding>;
181 
182  /**
183  * Sweep/reap the object if still stale
184  */
185  void sweep(void);
186 
187  /**
188  * replay the object to create it in hardware
189  */
190  void replay(void);
191 
192  /**
193  * A reference counting pointer the interface that this L2 layer
194  * represents. By holding the reference here, we can guarantee that
195  * this object will outlive the interface
196  */
197  const std::shared_ptr<interface> m_itf;
198 
199  /**
200  * A reference counting pointer the Bridge-Domain that this L2
201  * interface is bound to. By holding the reference here, we can
202  * guarantee that this object will outlive the BD.
203  */
204  std::shared_ptr<bridge_domain> m_bd;
205 
206  /**
207  * l2 port type i.e. normal, bvi or unknown unicast
208  */
209  l2_port_type_t m_port_type;
210 
211  /**
212  * HW configuration for the binding. The bool representing the
213  * do/don't bind.
214  */
215  HW::item<bool> m_binding;
216 
217  /**
218  * HW configuration for the VTR option
219  */
220  HW::item<l2_vtr_op_t> m_vtr_op;
221 
222  /**
223  * The Dot1q tag for the VTR operation
224  */
225  uint16_t m_vtr_op_tag;
226 
227  /**
228  * A map of all L2 interfaces key against the interface's handle_t
229  */
230  static singular_db<key_t, l2_binding> m_db;
231 };
232 };
233 
234 /*
235  * fd.io coding-style-patch-verification: ON
236  *
237  * Local Variables:
238  * eval: (c-set-style "mozilla")
239  * End:
240  */
241 
242 #endif
A Clas representing the binding of an L2 interface to a bridge-domain and the properties of that bind...
Definition: l2_binding.hpp:32
A template base class for all enum types.
Definition: enum_base.hpp:30
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
static const l2_vtr_op_t L2_VTR_PUSH_1
Definition: l2_binding.hpp:46
static const l2_vtr_op_t L2_VTR_POP_1
Definition: l2_binding.hpp:48
std::shared_ptr< l2_binding > singular() const
Return the &#39;singular instance&#39; of the L2 config that matches this object.
Definition: l2_binding.cpp:219
static const l2_vtr_op_t L2_VTR_DISABLED
Definition: l2_binding.hpp:45
static const l2_vtr_op_t L2_VTR_TRANSLATE_1_2
Definition: l2_binding.hpp:51
static std::shared_ptr< l2_binding > find(const key_t &key)
Static function to find the bridge_domain in the model.
Definition: l2_binding.cpp:125
static const l2_port_type_t L2_PORT_TYPE_NORMAL
Definition: l2_binding.hpp:64
bool operator==(const enum_base &e) const
Comparison operator.
Definition: enum_base.hpp:41
static const l2_vtr_op_t L2_VTR_PUSH_2
Definition: l2_binding.hpp:47
const key_t & key() const
Return the binding&#39;s key.
Definition: l2_binding.cpp:112
A Database to store the unique &#39;singular&#39; instances of a single object type.
Definition: singular_db.hpp:33
static const l2_vtr_op_t L2_VTR_TRANSLATE_2_1
Definition: l2_binding.hpp:52
interface::key_t key_t
Key type for an L2 binding in the singular DB.
Definition: l2_binding.hpp:38
static const l2_port_type_t L2_PORT_TYPE_UU_FWD
Definition: l2_binding.hpp:66
A representation of an interface in VPP.
Definition: interface.hpp:41
A base class for all object_base in the VPP object_base-Model.
Class definition for listeners to OM events.
Definition: om.hpp:284
inspect command handler Handler
Definition: inspect.hpp:54
~l2_binding()
Destructor.
Definition: l2_binding.cpp:156
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
static const l2_port_type_t L2_PORT_TYPE_BVI
Definition: l2_binding.hpp:65
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
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
static const l2_vtr_op_t L2_VTR_TRANSLATE_2_2
Definition: l2_binding.hpp:53
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
l2_binding(const interface &itf, const bridge_domain &bd)
Construct a new object matching the desried state.
Definition: l2_binding.cpp:74
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
l2_vtr_op_t(const l2_vtr_op_t &l)=default
static const l2_vtr_op_t L2_VTR_TRANSLATE_1_1
Definition: l2_binding.hpp:50
static void dump(std::ostream &os)
Dump all l2_bindings into the stream provided.
Definition: l2_binding.cpp:225
std::string key_t
The key for interface&#39;s key.
Definition: interface.hpp:56
static const l2_vtr_op_t L2_VTR_POP_2
Definition: l2_binding.hpp:49