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__
20 #include "vom/inspect.hpp"
21 #include "vom/interface.hpp"
22 #include "vom/object_base.hpp"
24 #include "vom/singular_db.hpp"
25 #include "vom/sub_interface.hpp"
27 #include <vapi/lldp.api.vapi.hpp>
31 * A representation of LLDP global configuration
33 class lldp_global : public object_base
37 * Construct a new object matching the desried state
39 lldp_global(const std::string& system_name,
41 uint32_t tx_interval);
46 lldp_global(const lldp_global& o);
54 * Return the 'singular' of the LLDP global that matches this object
56 std::shared_ptr<lldp_global> singular() const;
59 * convert to string format for debug purposes
61 std::string to_string() const;
64 * Dump all LLDP globals into the stream provided
66 static void dump(std::ostream& os);
69 * A command class that binds the LLDP global to the interface
71 class config_cmd : public rpc_cmd<HW::item<bool>, rc_t, vapi::Lldp_config>
77 config_cmd(HW::item<bool>& item,
78 const std::string& system_name,
80 uint32_t tx_interval);
83 * Issue the command to VPP/HW
85 rc_t issue(connection& con);
87 * convert to string format for debug purposes
89 std::string to_string() const;
92 * Comparison operator - only used for UT
94 bool operator==(const config_cmd& i) const;
100 const std::string m_system_name;
106 uint32_t m_tx_interval;
111 * Class definition for listeners to OM events
113 class event_handler : public OM::listener, public inspect::command_handler
117 virtual ~event_handler() = default;
120 * Handle a populate event
122 void handle_populate(const client_db::key_t& key);
125 * Handle a replay event
127 void handle_replay();
130 * Show the object in the Singular DB
132 void show(std::ostream& os);
135 * Get the sortable Id of the listener
137 dependency_t order() const;
141 * event_handler to register with OM
143 static event_handler m_evh;
146 * Enquue commonds to the VPP command Q for the update
148 void update(const lldp_global& obj);
151 * Find or add LLDP global to the OM
153 static std::shared_ptr<lldp_global> find_or_add(const lldp_global& temp);
156 * It's the OM class that calls singular()
161 * It's the singular_db class that calls replay()
163 friend class singular_db<interface::key_type, lldp_global>;
166 * Sweep/reap the object if still stale
171 * replay the object to create it in hardware
178 const std::string m_system_name;
184 uint32_t m_tx_interval;
187 * HW globaluration for the binding. The bool representing the
190 HW::item<bool> m_binding;
193 * A map of all Lldp globals keyed against the system name.
194 * there needs to be some sort of key, that will do.
196 static singular_db<std::string, lldp_global> m_db;
201 * fd.io coding-style-patch-verification: ON
204 * eval: (c-set-style "mozilla")