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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __VOM_LLDP_BINDING_H__
17 #define __VOM_LLDP_BINDING_H__
20 #include "vom/inspect.hpp"
21 #include "vom/interface.hpp"
22 #include "vom/object_base.hpp"
24 #include "vom/singular_db.hpp"
28 * A representation of LLDP client configuration on an interface
30 class lldp_binding : public object_base
34 * Typedef for the key of a LLDP binding
36 typedef interface::key_t key_t;
39 * Construct a new object matching the desried state
41 lldp_binding(const interface& itf, const std::string& hostname);
46 lldp_binding(const lldp_binding& o);
56 bool operator==(const lldp_binding& b) const;
59 * Return this object's key
61 const key_t& key() const;
64 * Return the 'singular' of the LLDP binding that matches this object
66 std::shared_ptr<lldp_binding> singular() const;
69 * convert to string format for debug purposes
71 std::string to_string() const;
74 * Dump all LLDP bindings into the stream provided
76 static void dump(std::ostream& os);
79 * Find or add LLDP binding based on its key
81 static std::shared_ptr<lldp_binding> find(const key_t& k);
85 * Class definition for listeners to OM events
87 class event_handler : public OM::listener, public inspect::command_handler
91 virtual ~event_handler() = default;
94 * Handle a populate event
96 void handle_populate(const client_db::key_t& key);
99 * Handle a replay event
101 void handle_replay();
104 * Show the object in the Singular DB
106 void show(std::ostream& os);
109 * Get the sortable Id of the listener
111 dependency_t order() const;
115 * event_handler to register with OM
117 static event_handler m_evh;
120 * Enquue commonds to the VPP command Q for the update
122 void update(const lldp_binding& obj);
125 * Find or add LLDP binding to the OM
127 static std::shared_ptr<lldp_binding> find_or_add(const lldp_binding& temp);
130 * It's the OM class that calls singular()
135 * It's the singular_db class that calls replay()
137 friend class singular_db<key_t, lldp_binding>;
140 * Sweep/reap the object if still stale
145 * replay the object to create it in hardware
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
154 const std::shared_ptr<interface> m_itf;
157 * The port-description in the LLDP configuration
159 const std::string m_port_desc;
162 * HW configuration for the binding. The bool representing the
165 HW::item<bool> m_binding;
168 * A map of all Lldp bindings keyed against the interface.
170 static singular_db<key_t, lldp_binding> m_db;
175 * fd.io coding-style-patch-verification: ON
178 * eval: (c-set-style "mozilla")