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_ARP_PROXY_BINDING_H__
17 #define __VOM_ARP_PROXY_BINDING_H__
19 #include "vom/arp_proxy_config.hpp"
20 #include "vom/dump_cmd.hpp"
22 #include "vom/inspect.hpp"
23 #include "vom/interface.hpp"
24 #include "vom/object_base.hpp"
26 #include "vom/rpc_cmd.hpp"
27 #include "vom/singular_db.hpp"
29 #include <vapi/vpe.api.vapi.hpp>
33 * A representation of LLDP client configuration on an interface
35 class arp_proxy_binding : public object_base
39 * Construct a new object matching the desried state
41 arp_proxy_binding(const interface& itf, const arp_proxy_config& proxy_cfg);
46 arp_proxy_binding(const arp_proxy_binding& o);
54 * Return the 'singular' of the LLDP binding that matches this object
56 std::shared_ptr<arp_proxy_binding> singular() const;
59 * convert to string format for debug purposes
61 std::string to_string() const;
64 * Dump all LLDP bindings into the stream provided
66 static void dump(std::ostream& os);
69 * A command class that binds the LLDP config to the interface
72 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Proxy_arp_intfc_enable_disable>
78 bind_cmd(HW::item<bool>& item, const handle_t& itf);
81 * Issue the command to VPP/HW
83 rc_t issue(connection& con);
85 * convert to string format for debug purposes
87 std::string to_string() const;
90 * Comparison operator - only used for UT
92 bool operator==(const bind_cmd& i) const;
96 * Reference to the HW::item of the interface to bind
98 const handle_t& m_itf;
102 * A cmd class that Unbinds ArpProxy Config from an interface
105 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Proxy_arp_intfc_enable_disable>
111 unbind_cmd(HW::item<bool>& item, const handle_t& itf);
114 * Issue the command to VPP/HW
116 rc_t issue(connection& con);
118 * convert to string format for debug purposes
120 std::string to_string() const;
123 * Comparison operator - only used for UT
125 bool operator==(const unbind_cmd& i) const;
129 * Reference to the HW::item of the interface to unbind
131 const handle_t& m_itf;
136 * Class definition for listeners to OM events
138 class event_handler : public OM::listener, public inspect::command_handler
142 virtual ~event_handler() = default;
145 * Handle a populate event
147 void handle_populate(const client_db::key_t& key);
150 * Handle a replay event
152 void handle_replay();
155 * Show the object in the Singular DB
157 void show(std::ostream& os);
160 * Get the sortable Id of the listener
162 dependency_t order() const;
166 * event_handler to register with OM
168 static event_handler m_evh;
171 * Enquue commonds to the VPP command Q for the update
173 void update(const arp_proxy_binding& obj);
176 * Find or add LLDP binding to the OM
178 static std::shared_ptr<arp_proxy_binding> find_or_add(
179 const arp_proxy_binding& temp);
182 * It's the OM class that calls singular()
187 * It's the singular_db class that calls replay()
189 friend class singular_db<interface::key_type, arp_proxy_binding>;
192 * Sweep/reap the object if still stale
197 * replay the object to create it in hardware
202 * A reference counting pointer to the interface on which LLDP config
203 * resides. By holding the reference here, we can guarantee that
204 * this object will outlive the interface
206 const std::shared_ptr<interface> m_itf;
209 * A reference counting pointer to the prxy config.
211 const std::shared_ptr<arp_proxy_config> m_arp_proxy_cfg;
214 * HW configuration for the binding. The bool representing the
217 HW::item<bool> m_binding;
220 * A map of all ArpProxy bindings keyed against the interface.
222 static singular_db<interface::key_type, arp_proxy_binding> m_db;
227 * fd.io coding-style-patch-verification: ON
230 * eval: (c-set-style "mozilla")