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_NEIGHBOUR_H__
17 #define __VOM_NEIGHBOUR_H__
19 #include "vom/dump_cmd.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 neighbour : public object_base
34 * The key for a bridge_domain ARP entry;
35 * the BD, IP address and MAC address
37 typedef std::tuple<interface::key_type,
39 boost::asio::ip::address>
43 * Construct an ARP entry
45 neighbour(const interface& itf,
46 const mac_address_t& mac,
47 const boost::asio::ip::address& ip_addr);
52 neighbour(const neighbour& r);
60 * Return the matching 'singular instance'
62 std::shared_ptr<neighbour> singular() const;
65 * Find the instnace of the bridge_domain domain in the OM
67 static std::shared_ptr<neighbour> find(const neighbour& temp);
70 * Dump all bridge_domain-doamin into the stream provided
72 static void dump(std::ostream& os);
75 * replay the object to create it in hardware
80 * Convert to string for debugging
82 std::string to_string() const;
85 * A command class that creates or updates the bridge domain ARP Entry
88 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Ip_neighbor_add_del>
94 create_cmd(HW::item<bool>& item,
96 const mac_address_t& mac,
97 const boost::asio::ip::address& ip_addr);
100 * Issue the command to VPP/HW
102 rc_t issue(connection& con);
105 * convert to string format for debug purposes
107 std::string to_string() const;
110 * Comparison operator - only used for UT
112 bool operator==(const create_cmd& i) const;
117 boost::asio::ip::address m_ip_addr;
121 * A cmd class that deletes a bridge domain ARP entry
124 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Ip_neighbor_add_del>
130 delete_cmd(HW::item<bool>& item,
132 const mac_address_t& mac,
133 const boost::asio::ip::address& ip_addr);
136 * Issue the command to VPP/HW
138 rc_t issue(connection& con);
141 * convert to string format for debug purposes
143 std::string to_string() const;
146 * Comparison operator - only used for UT
148 bool operator==(const delete_cmd& i) const;
153 boost::asio::ip::address m_ip_addr;
157 * A cmd class that Dumps all the neighbours
159 class dump_cmd : public VOM::dump_cmd<vapi::Ip_neighbor_dump>
165 dump_cmd(const handle_t& itf, const l3_proto_t& proto);
166 dump_cmd(const dump_cmd& d);
169 * Issue the command to VPP/HW
171 rc_t issue(connection& con);
173 * convert to string format for debug purposes
175 std::string to_string() const;
178 * Comparison operator - only used for UT
180 bool operator==(const dump_cmd& i) const;
189 * The interface to dump
201 * Class definition for listeners to OM events
203 class event_handler : public OM::listener, public inspect::command_handler
207 virtual ~event_handler() = default;
210 * Handle a populate event
212 void handle_populate(const client_db::key_t& key);
215 * Handle a replay event
217 void handle_replay();
220 * Show the object in the Singular DB
222 void show(std::ostream& os);
225 * Get the sortable Id of the listener
227 dependency_t order() const;
231 * event_handler to register with OM
233 static event_handler m_evh;
236 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
238 void update(const neighbour& obj);
241 * Do the populate work
243 static void populate_i(const client_db::key_t& key,
244 std::shared_ptr<interface> itf,
245 const l3_proto_t& proto);
248 * Find or add the instnace of the bridge_domain domain in the OM
250 static std::shared_ptr<neighbour> find_or_add(const neighbour& temp);
253 * It's the VPPHW class that updates the objects in HW
258 * It's the singular_db class that calls replay()
260 friend class singular_db<key_t, neighbour>;
263 * Sweep/reap the object if still stale
268 * HW configuration for the result of creating the bridge_domain
273 * The bridge_domain domain the bridge_domain is in.
275 std::shared_ptr<interface> m_itf;
285 boost::asio::ip::address m_ip_addr;
288 * A map of all bridge_domains
290 static singular_db<key_t, neighbour> m_db;
293 std::ostream& operator<<(std::ostream& os, const neighbour::key_t& key);
297 * fd.io coding-style-patch-verification: ON
300 * eval: (c-set-style "mozilla")