FD.io VPP  v18.01.2-1-g9b554f3
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  /**
60  * Construct a new object matching the desried state
61  */
62  l2_binding(const interface& itf, const bridge_domain& bd);
63 
64  /**
65  * Copy Constructor
66  */
67  l2_binding(const l2_binding& o);
68 
69  /**
70  * Destructor
71  */
72  ~l2_binding();
73 
74  /**
75  * Return the binding's key
76  */
77  const key_t& key() const;
78 
79  /**
80  * Comparison operator - for UT
81  */
82  bool operator==(const l2_binding& l) const;
83 
84  /**
85  * Return the 'singular instance' of the L2 config that matches this
86  * object
87  */
88  std::shared_ptr<l2_binding> singular() const;
89 
90  /**
91  * convert to string format for debug purposes
92  */
93  std::string to_string() const;
94 
95  /**
96  * Dump all l2_bindings into the stream provided
97  */
98  static void dump(std::ostream& os);
99 
100  /**
101  * Set the VTR operation on the binding/interface
102  */
103  void set(const l2_vtr_op_t& op, uint16_t tag);
104 
105  /**
106  * Static function to find the bridge_domain in the model
107  */
108  static std::shared_ptr<l2_binding> find(const key_t& key);
109 
110 private:
111  /**
112  * Class definition for listeners to OM events
113  */
114  class event_handler : public OM::listener, public inspect::command_handler
115  {
116  public:
117  event_handler();
118  virtual ~event_handler() = default;
119 
120  /**
121  * Handle a populate event
122  */
123  void handle_populate(const client_db::key_t& key);
124 
125  /**
126  * Handle a replay event
127  */
128  void handle_replay();
129 
130  /**
131  * Show the object in the Singular DB
132  */
133  void show(std::ostream& os);
134 
135  /**
136  * Get the sortable Id of the listener
137  */
138  dependency_t order() const;
139  };
140 
141  /**
142  * event_handler to register with OM
143  */
144  static event_handler m_evh;
145 
146  /**
147  * Enquue commonds to the VPP command Q for the update
148  */
149  void update(const l2_binding& obj);
150 
151  /**
152  * Find or Add the singular instance in the DB
153  */
154  static std::shared_ptr<l2_binding> find_or_add(const l2_binding& temp);
155 
156  /*
157  * It's the OM class that calls singular()
158  */
159  friend class OM;
160 
161  /**
162  * It's the singular_db class that calls replay()
163  */
164  friend class singular_db<key_t, l2_binding>;
165 
166  /**
167  * Sweep/reap the object if still stale
168  */
169  void sweep(void);
170 
171  /**
172  * replay the object to create it in hardware
173  */
174  void replay(void);
175 
176  /**
177  * A reference counting pointer the interface that this L2 layer
178  * represents. By holding the reference here, we can guarantee that
179  * this object will outlive the interface
180  */
181  const std::shared_ptr<interface> m_itf;
182 
183  /**
184  * A reference counting pointer the Bridge-Domain that this L2
185  * interface is bound to. By holding the reference here, we can
186  * guarantee that this object will outlive the BD.
187  */
188  std::shared_ptr<bridge_domain> m_bd;
189 
190  /**
191  * HW configuration for the binding. The bool representing the
192  * do/don't bind.
193  */
194  HW::item<bool> m_binding;
195 
196  /**
197  * HW configuration for the VTR option
198  */
199  HW::item<l2_vtr_op_t> m_vtr_op;
200 
201  /**
202  * The Dot1q tag for the VTR operation
203  */
204  uint16_t m_vtr_op_tag;
205 
206  /**
207  * A map of all L2 interfaces key against the interface's handle_t
208  */
209  static singular_db<key_t, l2_binding> m_db;
210 };
211 };
212 
213 /*
214  * fd.io coding-style-patch-verification: ON
215  *
216  * Local Variables:
217  * eval: (c-set-style "mozilla")
218  * End:
219  */
220 
221 #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
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:91
static const l2_vtr_op_t L2_VTR_PUSH_2
Definition: l2_binding.hpp:47
#define v
Definition: acl.c:341
const key_t & key() const
Return the binding&#39;s key.
Definition: l2_binding.cpp:79
A Database to store the unique &#39;singular&#39; instances of a single object type.
Definition: singular_db.hpp:32
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
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:124
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:60
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
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:47
static const l2_vtr_op_t L2_VTR_POP_2
Definition: l2_binding.hpp:49