FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
bridge_domain.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_BRIDGE_DOMAIN_H__
17 #define __VOM_BRIDGE_DOMAIN_H__
18 
19 #include "vom/enum_base.hpp"
20 #include "vom/hw.hpp"
21 #include "vom/inspect.hpp"
22 #include "vom/object_base.hpp"
23 #include "vom/om.hpp"
24 #include "vom/singular_db.hpp"
25 
26 namespace VOM {
27 /**
28  * A base class for all object_base in the VPP object_base-Model.
29  * provides the abstract interface.
30  */
31 class bridge_domain : public object_base
32 {
33 public:
34  /**
35  * Key Type for Bridge Domains in the sigular DB
36  */
37  typedef uint32_t key_t;
38 
39  /**
40  * Bridge Domain Learning mode
41  */
42  struct learning_mode_t : enum_base<learning_mode_t>
43  {
44  const static learning_mode_t ON;
45  const static learning_mode_t OFF;
46 
47  private:
48  /**
49  * Private constructor taking the value and the string name
50  */
51  learning_mode_t(int v, const std::string& s);
52  };
53 
54  /**
55  * Bridge Domain ARP termination mode
56  */
57  struct arp_term_mode_t : enum_base<arp_term_mode_t>
58  {
59  const static arp_term_mode_t ON;
60  const static arp_term_mode_t OFF;
61 
62  private:
63  /**
64  * Private constructor taking the value and the string name
65  */
66  arp_term_mode_t(int v, const std::string& s);
67  };
68 
69  /**
70  * Bridge Domain ARP Unicast Forward mode
71  */
72  struct arp_ufwd_mode_t : enum_base<arp_ufwd_mode_t>
73  {
74  const static arp_ufwd_mode_t ON;
75  const static arp_ufwd_mode_t OFF;
76 
77  private:
78  /**
79  * Private constructor taking the value and the string name
80  */
81  arp_ufwd_mode_t(int v, const std::string& s);
82  };
83 
84  /**
85  * Bridge Domain MAC aging mode
86  */
87  struct mac_age_mode_t : enum_base<mac_age_mode_t>
88  {
89  const static mac_age_mode_t ON;
90  const static mac_age_mode_t OFF;
91 
92  private:
93  /**
94  * Private constructor taking the value and the string name
95  */
96  mac_age_mode_t(int v, const std::string& s);
97  };
98 
99  /**
100  * Bridge Domain flood mode
101  */
102  struct flood_mode_t : enum_base<flood_mode_t>
103  {
104  const static flood_mode_t ON;
105  const static flood_mode_t OFF;
106 
107  private:
108  /**
109  * Private constructor taking the value and the string name
110  */
111  flood_mode_t(int v, const std::string& s);
112  };
113 
114  /**
115  * Bridge Domain Unknown Unicast Flood mode
116  */
117  struct uu_flood_mode_t : enum_base<uu_flood_mode_t>
118  {
119  const static uu_flood_mode_t ON;
120  const static uu_flood_mode_t OFF;
121 
122  private:
123  /**
124  * Private constructor taking the value and the string name
125  */
126  uu_flood_mode_t(int v, const std::string& s);
127  };
128 
129  /**
130  * The value of the defaultbridge domain
131  */
132  const static uint32_t DEFAULT_TABLE = 0;
133 
134  /**
135  * Construct a new object matching the desried state
136  */
137  bridge_domain(uint32_t id,
138  const learning_mode_t& lmode = learning_mode_t::ON,
139  const arp_term_mode_t& amode = arp_term_mode_t::ON,
140  const arp_ufwd_mode_t& aumode = arp_ufwd_mode_t::OFF,
141  const flood_mode_t& fmode = flood_mode_t::ON,
142  const uu_flood_mode_t& uufmode = uu_flood_mode_t::ON,
143  const mac_age_mode_t& mmode = mac_age_mode_t::OFF);
144 
145  /**
146  * Copy Constructor
147  */
148  bridge_domain(const bridge_domain& o);
149 
150  /**
151  * Destructor
152  */
153  ~bridge_domain();
154 
155  /**
156  * Comparison operator - for UT
157  */
158  bool operator==(const bridge_domain& b) const;
159 
160  /**
161  * Return the bridge domain's VPP ID
162  */
163  uint32_t id() const;
164 
165  /**
166  * Return the bridge domain's key
167  */
168  const key_t& key() const;
169 
170  /**
171  * Return the matchin 'singular' instance of the bridge-domain
172  */
173  std::shared_ptr<bridge_domain> singular() const;
174 
175  /**
176  * convert to string format for debug purposes
177  */
178  std::string to_string(void) const;
179 
180  /**
181  * Static function to find the bridge_domain in the model
182  */
183  static std::shared_ptr<bridge_domain> find(const key_t& key);
184 
185  /**
186  * Dump all bridge-doamin into the stream provided
187  */
188  static void dump(std::ostream& os);
189 
190 private:
191  /**
192  * Class definition for listeners to OM events
193  */
195  {
196  public:
197  event_handler();
198  virtual ~event_handler() = default;
199 
200  /**
201  * Handle a populate event
202  */
203  void handle_populate(const client_db::key_t& key);
204 
205  /**
206  * Handle a replay event
207  */
208  void handle_replay();
209 
210  /**
211  * Show the object in the Singular DB
212  */
213  void show(std::ostream& os);
214 
215  /**
216  * Get the sortable Id of the listener
217  */
218  dependency_t order() const;
219  };
220 
221  /**
222  * Instance of the event handler to register with OM
223  */
224  static event_handler m_evh;
225 
226  /**
227  * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
228  */
229  void update(const bridge_domain& obj);
230 
231  /**
232  * Find or add an singular of a Bridge-Domain in the object_base Model
233  */
234  static std::shared_ptr<bridge_domain> find_or_add(const bridge_domain& temp);
235 
236  /*
237  * It's the OM class that calls singular()
238  */
239  friend class OM;
240 
241  /**
242  * It's the singular_db class that calls replay()
243  */
244  friend class singular_db<key_t, bridge_domain>;
245 
246  /**
247  * Sweep/reap the object if still stale
248  */
249  void sweep(void);
250 
251  /**
252  * replay the object to create it in hardware
253  */
254  void replay(void);
255 
256  /**
257  * The ID we assign to this BD and the HW result in VPP
258  */
259  HW::item<uint32_t> m_id;
260 
261  /**
262  * The learning mode of the bridge
263  */
264  learning_mode_t m_learning_mode;
265 
266  /**
267  * The ARP termination mode of the bridge
268  */
269  arp_term_mode_t m_arp_term_mode;
270 
271  /**
272  * The ARP Unicast Forward mode of the bridge
273  */
274  arp_ufwd_mode_t m_arp_ufwd_mode;
275 
276  /**
277  * The flood mode of the bridge
278  */
279  flood_mode_t m_flood_mode;
280 
281  /**
282  * The unknown unicast flood mode of the bridge
283  */
284  uu_flood_mode_t m_uu_flood_mode;
285 
286  /**
287  * The MAC aging mode of the bridge
288  */
289  mac_age_mode_t m_mac_age_mode;
290 
291  /**
292  * A map of all interfaces key against the interface's name
293  */
295 };
296 };
297 
298 /*
299  * fd.io coding-style-patch-verification: ON
300  *
301  * Local Variables:
302  * eval: (c-set-style "mozilla")
303  * End:
304  */
305 
306 #endif
Bridge Domain MAC aging mode.
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
std::shared_ptr< bridge_domain > singular() const
Return the matchin &#39;singular&#39; instance of the bridge-domain.
static const arp_term_mode_t OFF
static const flood_mode_t OFF
static const learning_mode_t ON
static const arp_term_mode_t ON
static const uu_flood_mode_t OFF
static std::shared_ptr< bridge_domain > find(const key_t &key)
Static function to find the bridge_domain in the model.
static void dump(std::ostream &os)
Dump all bridge-doamin into the stream provided.
bool operator==(const enum_base &e) const
Comparison operator.
Definition: enum_base.hpp:41
static const flood_mode_t ON
Bridge Domain Unknown Unicast Flood mode.
bridge_domain(uint32_t id, const learning_mode_t &lmode=learning_mode_t::ON, const arp_term_mode_t &amode=arp_term_mode_t::ON, const arp_ufwd_mode_t &aumode=arp_ufwd_mode_t::OFF, const flood_mode_t &fmode=flood_mode_t::ON, const uu_flood_mode_t &uufmode=uu_flood_mode_t::ON, const mac_age_mode_t &mmode=mac_age_mode_t::OFF)
Construct a new object matching the desried state.
static const learning_mode_t OFF
A Database to store the unique &#39;singular&#39; instances of a single object type.
Definition: singular_db.hpp:33
static const mac_age_mode_t ON
const key_t & key() const
Return the bridge domain&#39;s key.
static const mac_age_mode_t OFF
Bridge Domain ARP termination mode.
Bridge Domain Learning mode.
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
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
void event_handler(void *tls_async)
Definition: tls_async.c:338
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
uint32_t key_t
Key Type for Bridge Domains in the sigular DB.
A base class for all object_base in the VPP object_base-Model.
Definition: object_base.hpp:29
Bridge Domain ARP Unicast Forward mode.
static const arp_ufwd_mode_t OFF
Bridge Domain flood mode.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
uint32_t id() const
Return the bridge domain&#39;s VPP ID.
static const uu_flood_mode_t ON
static const uint32_t DEFAULT_TABLE
The value of the defaultbridge domain.
static const arp_ufwd_mode_t ON
~bridge_domain()
Destructor.