FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
l2_emulation.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_EMULATION_H__
17 #define __VOM_L2_EMULATION_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_emulation : public object_base
33 {
34 public:
35  /**
36  * Key type for an L2 emulation in the singular DB
37  */
39 
40  /**
41  * Construct a new object matching the desried state
42  */
43  l2_emulation(const interface& itf);
44 
45  /**
46  * Copy Constructor
47  */
48  l2_emulation(const l2_emulation& o);
49 
50  /**
51  * Destructor
52  */
53  ~l2_emulation();
54 
55  /**
56  * Return the binding's key
57  */
58  const key_t& key() const;
59 
60  /**
61  * Comparison operator - for UT
62  */
63  bool operator==(const l2_emulation& l) const;
64 
65  /**
66  * Return the 'singular instance' of the L2 config that matches this
67  * object
68  */
69  std::shared_ptr<l2_emulation> singular() const;
70 
71  /**
72  * convert to string format for debug purposes
73  */
74  std::string to_string() const;
75 
76  /**
77  * Dump all l2_emulations into the stream provided
78  */
79  static void dump(std::ostream& os);
80 
81  /**
82  * Static function to find the bridge_domain in the model
83  */
84  static std::shared_ptr<l2_emulation> find(const key_t& key);
85 
86 private:
87  /**
88  * Class definition for listeners to OM events
89  */
91  {
92  public:
93  event_handler();
94  virtual ~event_handler() = default;
95 
96  /**
97  * Handle a populate event
98  */
99  void handle_populate(const client_db::key_t& key);
100 
101  /**
102  * Handle a replay event
103  */
104  void handle_replay();
105 
106  /**
107  * Show the object in the Singular DB
108  */
109  void show(std::ostream& os);
110 
111  /**
112  * Get the sortable Id of the listener
113  */
114  dependency_t order() const;
115  };
116 
117  /**
118  * event_handler to register with OM
119  */
120  static event_handler m_evh;
121 
122  /**
123  * Enquue commonds to the VPP command Q for the update
124  */
125  void update(const l2_emulation& obj);
126 
127  /**
128  * Find or Add the singular instance in the DB
129  */
130  static std::shared_ptr<l2_emulation> find_or_add(const l2_emulation& temp);
131 
132  /*
133  * It's the OM class that calls singular()
134  */
135  friend class OM;
136 
137  /**
138  * It's the singular_db class that calls replay()
139  */
141 
142  /**
143  * Sweep/reap the object if still stale
144  */
145  void sweep(void);
146 
147  /**
148  * replay the object to create it in hardware
149  */
150  void replay(void);
151 
152  /**
153  * A reference counting pointer the interface that this L2 layer
154  * represents. By holding the reference here, we can guarantee that
155  * this object will outlive the interface
156  */
157  const std::shared_ptr<interface> m_itf;
158 
159  /**
160  * HW configuration for the emulation. The bool representing the
161  * enable/disable.
162  */
163  HW::item<bool> m_emulation;
164 
165  /**
166  * A map of all L2 emulation configurations
167  */
169 };
170 };
171 
172 /*
173  * fd.io coding-style-patch-verification: OFF
174  *
175  * Local Variables:
176  * eval: (c-set-style "mozilla")
177  * End:
178  */
179 
180 #endif
VOM::HW::item< bool >
VOM::l2_emulation::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: l2_emulation.cpp:91
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::dependency_t
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
om.hpp
VOM::OM
The interface to writing objects into VPP OM.
Definition: om.hpp:140
VOM::inspect::command_handler
inspect command handler Handler
Definition: inspect.hpp:54
VOM::l2_emulation::l2_emulation
l2_emulation(const interface &itf)
Construct a new object matching the desried state.
Definition: l2_emulation.cpp:31
VOM::OM::listener
Class definition for listeners to OM events.
Definition: om.hpp:284
VOM::l2_emulation::operator==
bool operator==(const l2_emulation &l) const
Comparison operator - for UT.
Definition: l2_emulation.cpp:50
VOM::l2_emulation::dump
static void dump(std::ostream &os)
Dump all l2_emulations into the stream provided.
Definition: l2_emulation.cpp:124
VOM::interface
A representation of an interface in VPP.
Definition: interface.hpp:41
hw.hpp
VOM::client_db::key_t
const typedef 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
VOM::l2_emulation::~l2_emulation
~l2_emulation()
Destructor.
Definition: l2_emulation.cpp:82
VOM::l2_emulation::singular
std::shared_ptr< l2_emulation > singular() const
Return the 'singular instance' of the L2 config that matches this object.
Definition: l2_emulation.cpp:118
VOM::l2_emulation::key_t
interface::key_t key_t
Key type for an L2 emulation in the singular DB.
Definition: l2_emulation.hpp:38
inspect.hpp
bridge_domain.hpp
singular_db.hpp
interface.hpp
VOM::l2_emulation
A Clas representing the binding of an L2 interface to a bridge-domain and the properties of that bind...
Definition: l2_emulation.hpp:32
VOM::l2_emulation::key
const key_t & key() const
Return the binding's key.
Definition: l2_emulation.cpp:44
VOM::l2_emulation::find
static std::shared_ptr< l2_emulation > find(const key_t &key)
Static function to find the bridge_domain in the model.
Definition: l2_emulation.cpp:56
VOM::singular_db
A Database to store the unique 'singular' instances of a single object type.
Definition: singular_db.hpp:33
VOM::interface::key_t
std::string key_t
The key for interface's key.
Definition: interface.hpp:56
show
void show(char *chroot_path, int verbose)
Definition: svmtool.c:104
event_handler
void event_handler(void *tls_async)
Definition: tls_async.c:334
VOM::object_base
A base class for all object_base in the VPP object_base-Model.
Definition: object_base.hpp:29
object_base.hpp
string
const char *const string
Definition: cJSON.h:172