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