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/interface.hpp"
20 #include "vom/singular_db.hpp"
21 #include "vom/types.hpp"
25 * A entry in the neighbour entry (ARP or IPv6 ND)
27 class neighbour : public object_base
30 struct flags_t : public enum_base<flags_t>
35 flags_t(int v, const std::string s);
42 flags_t operator|(const flags_t& e1) const
49 const static flags_t NONE;
50 const static flags_t STATIC;
51 const static flags_t NO_FIB_ENTRY;
55 * The key for a neighbour entry;
56 * the interface and IP address
58 typedef std::pair<interface::key_t, boost::asio::ip::address> key_t;
61 * Construct an ARP entry
63 neighbour(const interface& itf,
64 const boost::asio::ip::address& ip_addr,
65 const mac_address_t& mac,
66 const flags_t flags = flags_t::STATIC);
71 neighbour(const neighbour& r);
79 * Return the object's key
81 const key_t key() const;
86 bool operator==(const neighbour& n) const;
89 * Return the matching 'singular instance'
91 std::shared_ptr<neighbour> singular() const;
94 * Find the neighbour fromits key
96 static std::shared_ptr<neighbour> find(const key_t& k);
99 * Dump all neighbours into the stream provided
101 static void dump(std::ostream& os);
104 * replay the object to create it in hardware
109 * Convert to string for debugging
111 std::string to_string() const;
115 * Class definition for listeners to OM events
117 class event_handler : public OM::listener, public inspect::command_handler
121 virtual ~event_handler() = default;
124 * Handle a populate event
126 void handle_populate(const client_db::key_t& key);
129 * Handle a replay event
131 void handle_replay();
134 * Show the object in the Singular DB
136 void show(std::ostream& os);
139 * Get the sortable Id of the listener
141 dependency_t order() const;
145 * event_handler to register with OM
147 static event_handler m_evh;
150 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
152 void update(const neighbour& obj);
155 * Do the populate work
157 static void populate_i(const client_db::key_t& key,
158 std::shared_ptr<interface> itf,
159 const l3_proto_t& proto);
162 * Find or add the instnace of the neighbour in the OM
164 static std::shared_ptr<neighbour> find_or_add(const neighbour& temp);
167 * It's the VPPHW class that updates the objects in HW
172 * It's the singular_db class that calls replay()
174 friend class singular_db<key_t, neighbour>;
177 * Sweep/reap the object if still stale
182 * HW configuration for the result of creating the bridge_domain
184 HW::item<handle_t> m_hw;
187 * The bridge_domain domain the bridge_domain is in.
189 std::shared_ptr<interface> m_itf;
194 boost::asio::ip::address m_ip_addr;
207 * A map of all bridge_domains
209 static singular_db<key_t, neighbour> m_db;
212 std::ostream& operator<<(std::ostream& os, const neighbour::key_t& key);
216 * fd.io coding-style-patch-verification: ON
219 * eval: (c-set-style "mozilla")