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 #include "vom/bridge_domain_entry.hpp"
19 singular_db<bridge_domain_entry::key_t, bridge_domain_entry>
20 bridge_domain_entry::m_db;
22 bridge_domain_entry::event_handler bridge_domain_entry::m_evh;
24 bridge_domain_entry::bridge_domain_entry(const bridge_domain& bd,
25 const mac_address_t& mac,
26 const interface& tx_itf)
30 , m_tx_itf(tx_itf.singular())
34 bridge_domain_entry::bridge_domain_entry(const mac_address_t& mac,
35 const interface& tx_itf)
39 , m_tx_itf(tx_itf.singular())
42 * the route goes in the default table
44 bridge_domain bd(bridge_domain::DEFAULT_TABLE);
49 bridge_domain_entry::bridge_domain_entry(const bridge_domain_entry& bde)
53 , m_tx_itf(bde.m_tx_itf)
57 bridge_domain_entry::~bridge_domain_entry()
61 // not in the DB anymore.
62 m_db.release(std::make_pair(m_bd->id(), m_mac), this);
66 bridge_domain_entry::sweep()
69 HW::enqueue(new delete_cmd(m_hw, m_mac, m_bd->id()));
75 bridge_domain_entry::replay()
78 HW::enqueue(new create_cmd(m_hw, m_mac, m_bd->id(), m_tx_itf->handle()));
82 bridge_domain_entry::to_string() const
85 s << "bridge-domain-entry:[" << m_bd->to_string() << ", " << m_mac.to_string()
86 << ", tx:" << m_tx_itf->name() << "]";
92 bridge_domain_entry::update(const bridge_domain_entry& r)
95 * create the table if it is not yet created
97 if (rc_t::OK != m_hw.rc()) {
98 HW::enqueue(new create_cmd(m_hw, m_mac, m_bd->id(), m_tx_itf->handle()));
102 std::shared_ptr<bridge_domain_entry>
103 bridge_domain_entry::find_or_add(const bridge_domain_entry& temp)
105 return (m_db.find_or_add(std::make_pair(temp.m_bd->id(), temp.m_mac), temp));
108 std::shared_ptr<bridge_domain_entry>
109 bridge_domain_entry::singular() const
111 return find_or_add(*this);
115 bridge_domain_entry::dump(std::ostream& os)
120 bridge_domain_entry::event_handler::event_handler()
122 OM::register_listener(this);
123 inspect::register_handler({ "bd-entry" },
124 "bridge domain entry configurations", this);
128 bridge_domain_entry::event_handler::handle_replay()
134 bridge_domain_entry::event_handler::handle_populate(const client_db::key_t& key)
136 std::shared_ptr<bridge_domain_entry::dump_cmd> cmd(
137 new bridge_domain_entry::dump_cmd());
142 for (auto& record : *cmd) {
143 auto& payload = record.get_payload();
145 std::shared_ptr<interface> itf = interface::find(payload.sw_if_index);
146 std::shared_ptr<bridge_domain> bd = bridge_domain::find(payload.bd_id);
147 mac_address_t mac(payload.mac);
148 bridge_domain_entry bd_e(*bd, mac, *itf);
150 VOM_LOG(log_level_t::DEBUG) << "bd-entry-dump: " << bd->to_string()
151 << mac.to_string() << itf->to_string();
154 * Write each of the discovered interfaces into the OM,
155 * but disable the HW Command q whilst we do, so that no
156 * commands are sent to VPP
158 OM::commit(key, bd_e);
163 bridge_domain_entry::event_handler::order() const
165 return (dependency_t::ENTRY);
169 bridge_domain_entry::event_handler::show(std::ostream& os)
175 operator<<(std::ostream& os, const bridge_domain_entry::key_t& key)
177 os << "[" << key.first << ", " << key.second.to_string() << "]";
184 * fd.io coding-style-patch-verification: ON
187 * eval: (c-set-style "mozilla")