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_ENTRY_H__
17 #define __VOM_BRIDGE_DOMAIN_ENTRY_H__
19 #include "vom/bridge_domain.hpp"
20 #include "vom/interface.hpp"
21 #include "vom/singular_db.hpp"
23 #include <vapi/l2.api.vapi.hpp>
27 * A MAC forwarding entry in the bridge-domain/L2-FIB
29 class bridge_domain_entry : public object_base
33 * The key for a bridge_domain
35 typedef std::pair<uint32_t, mac_address_t> key_t;
38 * Construct a bridge_domain in the given bridge domain
40 bridge_domain_entry(const bridge_domain& bd,
41 const mac_address_t& mac,
42 const interface& tx_itf);
45 * Construct a bridge_domain in the default table
47 bridge_domain_entry(const mac_address_t& mac, const interface& tx_itf);
52 bridge_domain_entry(const bridge_domain_entry& r);
57 ~bridge_domain_entry();
60 * Return the matching 'singular instance'
62 std::shared_ptr<bridge_domain_entry> singular() const;
65 * Find the instnace of the bridge_domain domain in the OM
67 static std::shared_ptr<bridge_domain_entry> find(
68 const bridge_domain_entry& temp);
71 * Dump all bridge_domain-doamin into the stream provided
73 static void dump(std::ostream& os);
76 * replay the object to create it in hardware
81 * Convert to string for debugging
83 std::string to_string() const;
86 * A command class that creates or updates the bridge_domain
88 class create_cmd : public rpc_cmd<HW::item<bool>, rc_t, vapi::L2fib_add_del>
94 create_cmd(HW::item<bool>& item,
95 const mac_address_t& mac,
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;
121 * A cmd class that deletes a bridge_domain
123 class delete_cmd : public rpc_cmd<HW::item<bool>, rc_t, vapi::L2fib_add_del>
129 delete_cmd(HW::item<bool>& item, const mac_address_t& mac, uint32_t id);
132 * Issue the command to VPP/HW
134 rc_t issue(connection& con);
137 * convert to string format for debug purposes
139 std::string to_string() const;
142 * Comparison operator - only used for UT
144 bool operator==(const delete_cmd& i) const;
152 * A cmd class that Dumps all the interface spans
154 class dump_cmd : public VOM::dump_cmd<vapi::L2_fib_table_dump>
161 dump_cmd(const dump_cmd& d);
164 * Issue the command to VPP/HW
166 rc_t issue(connection& con);
168 * convert to string format for debug purposes
170 std::string to_string() const;
173 * Comparison operator - only used for UT
175 bool operator==(const dump_cmd& i) const;
186 * Class definition for listeners to OM events
188 class event_handler : public OM::listener, public inspect::command_handler
192 virtual ~event_handler() = default;
195 * Handle a populate event
197 void handle_populate(const client_db::key_t& key);
200 * Handle a replay event
202 void handle_replay();
205 * Show the object in the Singular DB
207 void show(std::ostream& os);
210 * Get the sortable Id of the listener
212 dependency_t order() const;
216 * event_handler to register with OM
218 static event_handler m_evh;
221 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
223 void update(const bridge_domain_entry& obj);
226 * Find or add the instnace of the bridge_domain domain in the OM
228 static std::shared_ptr<bridge_domain_entry> find_or_add(
229 const bridge_domain_entry& temp);
232 * It's the VPPHW class that updates the objects in HW
237 * It's the singular_db class that calls replay()
239 friend class singular_db<key_t, bridge_domain_entry>;
242 * Sweep/reap the object if still stale
247 * HW configuration for the result of creating the bridge_domain
257 * The bridge_domain domain the bridge_domain is in.
259 std::shared_ptr<bridge_domain> m_bd;
264 std::shared_ptr<interface> m_tx_itf;
267 * A map of all bridge_domains
269 static singular_db<key_t, bridge_domain_entry> m_db;
272 std::ostream& operator<<(std::ostream& os,
273 const bridge_domain_entry::key_t& key);
277 * fd.io coding-style-patch-verification: ON
280 * eval: (c-set-style "mozilla")