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"
25 * A MAC forwarding entry in the bridge-domain/L2-FIB
27 class bridge_domain_entry : public object_base
31 * The key for a bridge_domain
33 typedef std::pair<bridge_domain::key_t, mac_address_t> key_t;
36 * Construct a bridge_domain in the given bridge domain
38 bridge_domain_entry(const bridge_domain& bd,
39 const mac_address_t& mac,
40 const interface& tx_itf);
43 * Construct a bridge_domain in the default table
45 bridge_domain_entry(const mac_address_t& mac, const interface& tx_itf);
50 bridge_domain_entry(const bridge_domain_entry& r);
55 ~bridge_domain_entry();
58 * Return the object's key
60 const key_t key() const;
65 bool operator==(const bridge_domain_entry& be) const;
68 * Return the matching 'singular instance'
70 std::shared_ptr<bridge_domain_entry> singular() const;
73 * Find the instnace of the bridge_domain domain in the OM
75 static std::shared_ptr<bridge_domain_entry> find(const key_t& k);
78 * Dump all bridge_domain-doamin into the stream provided
80 static void dump(std::ostream& os);
83 * replay the object to create it in hardware
88 * Convert to string for debugging
90 std::string to_string() const;
94 * Class definition for listeners to OM events
96 class event_handler : public OM::listener, public inspect::command_handler
100 virtual ~event_handler() = default;
103 * Handle a populate event
105 void handle_populate(const client_db::key_t& key);
108 * Handle a replay event
110 void handle_replay();
113 * Show the object in the Singular DB
115 void show(std::ostream& os);
118 * Get the sortable Id of the listener
120 dependency_t order() const;
124 * event_handler to register with OM
126 static event_handler m_evh;
129 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
131 void update(const bridge_domain_entry& obj);
134 * Find or add the instnace of the bridge_domain domain in the OM
136 static std::shared_ptr<bridge_domain_entry> find_or_add(
137 const bridge_domain_entry& temp);
140 * It's the VPPHW class that updates the objects in HW
145 * It's the singular_db class that calls replay()
147 friend class singular_db<key_t, bridge_domain_entry>;
150 * Sweep/reap the object if still stale
155 * HW configuration for the result of creating the bridge_domain
165 * The bridge_domain domain the bridge_domain is in.
167 std::shared_ptr<bridge_domain> m_bd;
172 std::shared_ptr<interface> m_tx_itf;
175 * A map of all bridge_domains
177 static singular_db<key_t, bridge_domain_entry> m_db;
180 std::ostream& operator<<(std::ostream& os,
181 const bridge_domain_entry::key_t& key);
185 * fd.io coding-style-patch-verification: ON
188 * eval: (c-set-style "mozilla")