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__
19 #include "vom/dump_cmd.hpp"
21 #include "vom/inspect.hpp"
22 #include "vom/interface.hpp"
23 #include "vom/object_base.hpp"
25 #include "vom/rpc_cmd.hpp"
26 #include "vom/singular_db.hpp"
27 #include "vom/sub_interface.hpp"
29 #include <vapi/lldp.api.vapi.hpp>
33 * A representation of LLDP client configuration on an interface
35 class lldp_binding : public object_base
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);
53 * Return the 'singular' of the LLDP binding that matches this object
55 std::shared_ptr<lldp_binding> singular() const;
58 * convert to string format for debug purposes
60 std::string to_string() const;
63 * Dump all LLDP bindings into the stream provided
65 static void dump(std::ostream& os);
68 * A command class that binds the LLDP config to the interface
71 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Sw_interface_set_lldp>
77 bind_cmd(HW::item<bool>& item,
79 const std::string& port_desc);
82 * Issue the command to VPP/HW
84 rc_t issue(connection& con);
86 * convert to string format for debug purposes
88 std::string to_string() const;
91 * Comparison operator - only used for UT
93 bool operator==(const bind_cmd& i) const;
97 * Reference to the HW::item of the interface to bind
99 const handle_t& m_itf;
102 * The LLDP client's hostname
104 const std::string m_port_desc;
108 * A cmd class that Unbinds Lldp Config from an interface
111 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Sw_interface_set_lldp>
117 unbind_cmd(HW::item<bool>& item, const handle_t& itf);
120 * Issue the command to VPP/HW
122 rc_t issue(connection& con);
124 * convert to string format for debug purposes
126 std::string to_string() const;
129 * Comparison operator - only used for UT
131 bool operator==(const unbind_cmd& i) const;
135 * Reference to the HW::item of the interface to unbind
137 const handle_t& m_itf;
142 * Class definition for listeners to OM events
144 class event_handler : public OM::listener, public inspect::command_handler
148 virtual ~event_handler() = default;
151 * Handle a populate event
153 void handle_populate(const client_db::key_t& key);
156 * Handle a replay event
158 void handle_replay();
161 * Show the object in the Singular DB
163 void show(std::ostream& os);
166 * Get the sortable Id of the listener
168 dependency_t order() const;
172 * event_handler to register with OM
174 static event_handler m_evh;
177 * Enquue commonds to the VPP command Q for the update
179 void update(const lldp_binding& obj);
182 * Find or add LLDP binding to the OM
184 static std::shared_ptr<lldp_binding> find_or_add(const lldp_binding& temp);
187 * It's the OM class that calls singular()
192 * It's the singular_db class that calls replay()
194 friend class singular_db<interface::key_type, lldp_binding>;
197 * Sweep/reap the object if still stale
202 * replay the object to create it in hardware
207 * A reference counting pointer to the interface on which LLDP config
208 * resides. By holding the reference here, we can guarantee that
209 * this object will outlive the interface
211 const std::shared_ptr<interface> m_itf;
214 * The port-description in the LLDP configuration
216 const std::string m_port_desc;
219 * HW configuration for the binding. The bool representing the
222 HW::item<bool> m_binding;
225 * A map of all Lldp bindings keyed against the interface.
227 static singular_db<interface::key_type, lldp_binding> m_db;
232 * fd.io coding-style-patch-verification: ON
235 * eval: (c-set-style "mozilla")