FD.io VPP  v21.01.1
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  */
137  friend class singular_db<key_t, lldp_binding>;
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
string hostname[64]
Definition: dhcp.api:159
A representation of LLDP client configuration on an interface.
static void dump(std::ostream &os)
Dump all LLDP bindings into the stream provided.
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
const char *const string
Definition: cJSON.h:172
static std::shared_ptr< lldp_binding > find(const key_t &k)
Find or add LLDP binding based on its key.
std::string to_string() const
convert to string format for debug purposes
const cJSON *const b
Definition: cJSON.h:255
std::shared_ptr< lldp_binding > singular() const
Return the &#39;singular&#39; of the LLDP binding that matches this object.
A Database to store the unique &#39;singular&#39; instances of a single object type.
Definition: singular_db.hpp:33
~lldp_binding()
Destructor.
A representation of an interface in VPP.
Definition: interface.hpp:41
Class definition for listeners to OM events.
Definition: om.hpp:284
inspect command handler Handler
Definition: inspect.hpp:54
void event_handler(void *tls_async)
Definition: tls_async.c:334
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
bool operator==(const lldp_binding &b) const
Comparison operator.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
lldp_binding(const interface &itf, const std::string &hostname)
Construct a new object matching the desried state.
void show(char *chroot_path, int verbose)
Definition: svmtool.c:104
const key_t & key() const
Return this object&#39;s key.
interface::key_t key_t
Typedef for the key of a LLDP binding.
std::string key_t
The key for interface&#39;s key.
Definition: interface.hpp:56