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_GLOBAL_H__
17 #define __VOM_LLDP_GLOBAL_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 global configuration
35 class lldp_global : public object_base
39 * Construct a new object matching the desried state
41 lldp_global(const std::string& system_name,
43 uint32_t tx_interval);
48 lldp_global(const lldp_global& o);
56 * Return the 'singular' of the LLDP global that matches this object
58 std::shared_ptr<lldp_global> singular() const;
61 * convert to string format for debug purposes
63 std::string to_string() const;
66 * Dump all LLDP globals into the stream provided
68 static void dump(std::ostream& os);
71 * A command class that binds the LLDP global to the interface
73 class config_cmd : public rpc_cmd<HW::item<bool>, rc_t, vapi::Lldp_config>
79 config_cmd(HW::item<bool>& item,
80 const std::string& system_name,
82 uint32_t tx_interval);
85 * Issue the command to VPP/HW
87 rc_t issue(connection& con);
89 * convert to string format for debug purposes
91 std::string to_string() const;
94 * Comparison operator - only used for UT
96 bool operator==(const config_cmd& i) const;
102 const std::string m_system_name;
108 uint32_t m_tx_interval;
113 * Class definition for listeners to OM events
115 class event_handler : public OM::listener, public inspect::command_handler
119 virtual ~event_handler() = default;
122 * Handle a populate event
124 void handle_populate(const client_db::key_t& key);
127 * Handle a replay event
129 void handle_replay();
132 * Show the object in the Singular DB
134 void show(std::ostream& os);
137 * Get the sortable Id of the listener
139 dependency_t order() const;
143 * event_handler to register with OM
145 static event_handler m_evh;
148 * Enquue commonds to the VPP command Q for the update
150 void update(const lldp_global& obj);
153 * Find or add LLDP global to the OM
155 static std::shared_ptr<lldp_global> find_or_add(const lldp_global& temp);
158 * It's the OM class that calls singular()
163 * It's the singular_db class that calls replay()
165 friend class singular_db<interface::key_type, lldp_global>;
168 * Sweep/reap the object if still stale
173 * replay the object to create it in hardware
180 const std::string m_system_name;
186 uint32_t m_tx_interval;
189 * HW globaluration for the binding. The bool representing the
192 HW::item<bool> m_binding;
195 * A map of all Lldp globals keyed against the system name.
196 * there needs to be some sort of key, that will do.
198 static singular_db<std::string, lldp_global> m_db;
203 * fd.io coding-style-patch-verification: ON
206 * eval: (c-set-style "mozilla")