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_BRIDGE_DOMAIN_ARP_ENTRY_H__
17 #define __VOM_BRIDGE_DOMAIN_ARP_ENTRY_H__
19 #include "vom/bridge_domain.hpp"
20 #include "vom/interface.hpp"
21 #include "vom/singular_db.hpp"
22 #include "vom/types.hpp"
24 #include <vapi/l2.api.vapi.hpp>
28 * A entry in the ARP termination table of a Bridge Domain
30 class bridge_domain_arp_entry : public object_base
34 * The key for a bridge_domain ARP entry;
35 * the BD, IP address and MAC address
37 typedef std::tuple<uint32_t, mac_address_t, boost::asio::ip::address> key_t;
40 * Construct a bridge_domain in the given bridge domain
42 bridge_domain_arp_entry(const bridge_domain& bd,
43 const mac_address_t& mac,
44 const boost::asio::ip::address& ip_addr);
47 * Construct a bridge_domain in the default table
49 bridge_domain_arp_entry(const mac_address_t& mac,
50 const boost::asio::ip::address& ip_addr);
55 bridge_domain_arp_entry(const bridge_domain_arp_entry& r);
60 ~bridge_domain_arp_entry();
63 * Return the matching 'singular instance'
65 std::shared_ptr<bridge_domain_arp_entry> singular() const;
68 * Find the instnace of the bridge_domain domain in the OM
70 static std::shared_ptr<bridge_domain_arp_entry> find(
71 const bridge_domain_arp_entry& temp);
74 * Dump all bridge_domain-doamin into the stream provided
76 static void dump(std::ostream& os);
79 * replay the object to create it in hardware
84 * Convert to string for debugging
86 std::string to_string() const;
89 * A command class that creates or updates the bridge domain ARP Entry
92 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Bd_ip_mac_add_del>
98 create_cmd(HW::item<bool>& item,
100 const mac_address_t& mac,
101 const boost::asio::ip::address& ip_addr);
104 * Issue the command to VPP/HW
106 rc_t issue(connection& con);
109 * convert to string format for debug purposes
111 std::string to_string() const;
114 * Comparison operator - only used for UT
116 bool operator==(const create_cmd& i) const;
121 boost::asio::ip::address m_ip_addr;
125 * A cmd class that deletes a bridge domain ARP entry
128 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Bd_ip_mac_add_del>
134 delete_cmd(HW::item<bool>& item,
136 const mac_address_t& mac,
137 const boost::asio::ip::address& ip_addr);
140 * Issue the command to VPP/HW
142 rc_t issue(connection& con);
145 * convert to string format for debug purposes
147 std::string to_string() const;
150 * Comparison operator - only used for UT
152 bool operator==(const delete_cmd& i) const;
157 boost::asio::ip::address m_ip_addr;
162 * Class definition for listeners to OM events
164 class event_handler : public OM::listener, public inspect::command_handler
168 virtual ~event_handler() = default;
171 * Handle a populate event
173 void handle_populate(const client_db::key_t& key);
176 * Handle a replay event
178 void handle_replay();
181 * Show the object in the Singular DB
183 void show(std::ostream& os);
186 * Get the sortable Id of the listener
188 dependency_t order() const;
192 * event_handler to register with OM
194 static event_handler m_evh;
197 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
199 void update(const bridge_domain_arp_entry& obj);
202 * Find or add the instnace of the bridge_domain domain in the OM
204 static std::shared_ptr<bridge_domain_arp_entry> find_or_add(
205 const bridge_domain_arp_entry& temp);
208 * It's the VPPHW class that updates the objects in HW
213 * It's the singular_db class that calls replay()
215 friend class singular_db<key_t, bridge_domain_arp_entry>;
218 * Sweep/reap the object if still stale
223 * HW configuration for the result of creating the bridge_domain
228 * The bridge_domain domain the bridge_domain is in.
230 std::shared_ptr<bridge_domain> m_bd;
240 boost::asio::ip::address m_ip_addr;
243 * A map of all bridge_domains
245 static singular_db<key_t, bridge_domain_arp_entry> m_db;
248 std::ostream& operator<<(std::ostream& os,
249 const bridge_domain_arp_entry::key_t& key);
253 * fd.io coding-style-patch-verification: ON
256 * eval: (c-set-style "mozilla")