FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
lldp_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_LLDP_BINDING_H__
17 #define __VOM_LLDP_BINDING_H__
18 
19 #include "vom/hw.hpp"
20 #include "vom/inspect.hpp"
21 #include "vom/interface.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 representation of LLDP client configuration on an interface
29  */
30 class lldp_binding : public object_base
31 {
32 public:
33  /**
34  * Typedef for the key of a LLDP binding
35  */
37 
38  /**
39  * Construct a new object matching the desried state
40  */
41  lldp_binding(const interface& itf, const std::string& hostname);
42 
43  /**
44  * Copy Constructor
45  */
46  lldp_binding(const lldp_binding& o);
47 
48  /**
49  * Destructor
50  */
51  ~lldp_binding();
52 
53  /**
54  * Comparison operator
55  */
56  bool operator==(const lldp_binding& b) const;
57 
58  /**
59  * Return this object's key
60  */
61  const key_t& key() const;
62 
63  /**
64  * Return the 'singular' of the LLDP binding that matches this object
65  */
66  std::shared_ptr<lldp_binding> singular() const;
67 
68  /**
69  * convert to string format for debug purposes
70  */
71  std::string to_string() const;
72 
73  /**
74  * Dump all LLDP bindings into the stream provided
75  */
76  static void dump(std::ostream& os);
77 
78  /**
79  * Find or add LLDP binding based on its key
80  */
81  static std::shared_ptr<lldp_binding> find(const key_t& k);
82 
83 private:
84  /**
85  * Class definition for listeners to OM events
86  */
88  {
89  public:
90  event_handler();
91  virtual ~event_handler() = default;
92 
93  /**
94  * Handle a populate event
95  */
96  void handle_populate(const client_db::key_t& key);
97 
98  /**
99  * Handle a replay event
100  */
101  void handle_replay();
102 
103  /**
104  * Show the object in the Singular DB
105  */
106  void show(std::ostream& os);
107 
108  /**
109  * Get the sortable Id of the listener
110  */
111  dependency_t order() const;
112  };
113 
114  /**
115  * event_handler to register with OM
116  */
117  static event_handler m_evh;
118 
119  /**
120  * Enquue commonds to the VPP command Q for the update
121  */
122  void update(const lldp_binding& obj);
123 
124  /**
125  * Find or add LLDP binding to the OM
126  */
127  static std::shared_ptr<lldp_binding> find_or_add(const lldp_binding& temp);
128 
129  /*
130  * It's the OM class that calls singular()
131  */
132  friend class OM;
133 
134  /**
135  * It's the singular_db class that calls replay()
136  */
138 
139  /**
140  * Sweep/reap the object if still stale
141  */
142  void sweep(void);
143 
144  /**
145  * replay the object to create it in hardware
146  */
147  void replay(void);
148 
149  /**
150  * A reference counting pointer to the interface on which LLDP config
151  * resides. By holding the reference here, we can guarantee that
152  * this object will outlive the interface
153  */
154  const std::shared_ptr<interface> m_itf;
155 
156  /**
157  * The port-description in the LLDP configuration
158  */
159  const std::string m_port_desc;
160 
161  /**
162  * HW configuration for the binding. The bool representing the
163  * do/don't bind.
164  */
165  HW::item<bool> m_binding;
166 
167  /**
168  * A map of all Lldp bindings keyed against the interface.
169  */
171 };
172 };
173 
174 /*
175  * fd.io coding-style-patch-verification: OFF
176  *
177  * Local Variables:
178  * eval: (c-set-style "mozilla")
179  * End:
180  */
181 
182 #endif
VOM::lldp_binding::key
const key_t & key() const
Return this object's key.
Definition: lldp_binding.cpp:57
VOM::HW::item< bool >
VOM::lldp_binding::dump
static void dump(std::ostream &os)
Dump all LLDP bindings into the stream provided.
Definition: lldp_binding.cpp:72
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
VOM::lldp_binding::find
static std::shared_ptr< lldp_binding > find(const key_t &k)
Find or add LLDP binding based on its key.
Definition: lldp_binding.cpp:115
om.hpp
VOM::lldp_binding::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: lldp_binding.cpp:87
VOM::lldp_binding
A representation of LLDP client configuration on an interface.
Definition: lldp_binding.hpp:30
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::lldp_binding::singular
std::shared_ptr< lldp_binding > singular() const
Return the 'singular' of the LLDP binding that matches this object.
Definition: lldp_binding.cpp:121
VOM::OM::listener
Class definition for listeners to OM events.
Definition: om.hpp:284
hostname
string hostname[64]
Definition: dhcp.api:159
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::lldp_binding::~lldp_binding
~lldp_binding()
Destructor.
Definition: lldp_binding.cpp:42
inspect.hpp
singular_db.hpp
VOM::lldp_binding::key_t
interface::key_t key_t
Typedef for the key of a LLDP binding.
Definition: lldp_binding.hpp:36
interface.hpp
VOM::lldp_binding::lldp_binding
lldp_binding(const interface &itf, const std::string &hostname)
Construct a new object matching the desried state.
Definition: lldp_binding.cpp:28
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
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::lldp_binding::operator==
bool operator==(const lldp_binding &b) const
Comparison operator.
Definition: lldp_binding.cpp:51
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