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"
17 #include "vom/bridge_domain_entry_cmds.hpp"
18 #include "vom/singular_db_funcs.hpp"
21 singular_db<bridge_domain_entry::key_t, bridge_domain_entry>
22 bridge_domain_entry::m_db;
24 bridge_domain_entry::event_handler bridge_domain_entry::m_evh;
26 bridge_domain_entry::bridge_domain_entry(const bridge_domain& bd,
27 const mac_address_t& mac,
28 const interface& tx_itf)
32 , m_tx_itf(tx_itf.singular())
36 bridge_domain_entry::bridge_domain_entry(const mac_address_t& mac,
37 const interface& tx_itf)
41 , m_tx_itf(tx_itf.singular())
44 * the entry goes in the default bridge-domain
46 bridge_domain bd(bridge_domain::DEFAULT_TABLE);
51 bridge_domain_entry::bridge_domain_entry(const bridge_domain_entry& bde)
55 , m_tx_itf(bde.m_tx_itf)
59 const bridge_domain_entry::key_t
60 bridge_domain_entry::key() const
62 return (std::make_pair(m_bd->key(), m_mac));
66 bridge_domain_entry::operator==(const bridge_domain_entry& bde) const
68 return ((key() == bde.key()) && (m_tx_itf == bde.m_tx_itf));
71 bridge_domain_entry::~bridge_domain_entry()
75 // not in the DB anymore.
76 m_db.release(key(), this);
80 bridge_domain_entry::sweep()
83 HW::enqueue(new bridge_domain_entry_cmds::delete_cmd(
84 m_hw, m_mac, m_bd->id(), interface::type_t::BVI == m_tx_itf->type()));
90 bridge_domain_entry::replay()
93 HW::enqueue(new bridge_domain_entry_cmds::create_cmd(
94 m_hw, m_mac, m_bd->id(), m_tx_itf->handle(),
95 interface::type_t::BVI == m_tx_itf->type()));
99 bridge_domain_entry::to_string() const
101 std::ostringstream s;
102 s << "bridge-domain-entry:[" << m_bd->to_string() << ", " << m_mac.to_string()
103 << ", tx:" << m_tx_itf->name() << "]";
109 bridge_domain_entry::update(const bridge_domain_entry& r)
112 * create the table if it is not yet created
114 if (rc_t::OK != m_hw.rc()) {
115 HW::enqueue(new bridge_domain_entry_cmds::create_cmd(
116 m_hw, m_mac, m_bd->id(), m_tx_itf->handle(),
117 interface::type_t::BVI == m_tx_itf->type()));
121 std::shared_ptr<bridge_domain_entry>
122 bridge_domain_entry::find_or_add(const bridge_domain_entry& temp)
124 return (m_db.find_or_add(temp.key(), temp));
127 std::shared_ptr<bridge_domain_entry>
128 bridge_domain_entry::find(const key_t& k)
130 return (m_db.find(k));
133 std::shared_ptr<bridge_domain_entry>
134 bridge_domain_entry::singular() const
136 return find_or_add(*this);
140 bridge_domain_entry::dump(std::ostream& os)
145 bridge_domain_entry::event_handler::event_handler()
147 OM::register_listener(this);
148 inspect::register_handler({ "bd-entry" },
149 "bridge domain entry configurations", this);
153 bridge_domain_entry::event_handler::handle_replay()
159 bridge_domain_entry::event_handler::handle_populate(const client_db::key_t& key)
161 std::shared_ptr<bridge_domain_entry_cmds::dump_cmd> cmd =
162 std::make_shared<bridge_domain_entry_cmds::dump_cmd>();
167 for (auto& record : *cmd) {
168 auto& payload = record.get_payload();
170 std::shared_ptr<interface> itf = interface::find(payload.sw_if_index);
171 std::shared_ptr<bridge_domain> bd = bridge_domain::find(payload.bd_id);
174 VOM_LOG(log_level_t::ERROR) << "bridge-domain-entry dump:"
175 << " itf:" << payload.sw_if_index
176 << " bd:" << payload.bd_id;
180 mac_address_t mac(payload.mac);
181 bridge_domain_entry bd_e(*bd, mac, *itf);
183 VOM_LOG(log_level_t::DEBUG) << "bridge-domain-entry dump:"
184 << " " << bd->to_string() << " "
185 << itf->to_string() << " mac:["
186 << mac.to_string() << "]";
189 * Write each of the discovered interfaces into the OM,
190 * but disable the HW Command q whilst we do, so that no
191 * commands are sent to VPP
193 OM::commit(key, bd_e);
198 bridge_domain_entry::event_handler::order() const
200 return (dependency_t::ENTRY);
204 bridge_domain_entry::event_handler::show(std::ostream& os)
210 operator<<(std::ostream& os, const bridge_domain_entry::key_t& key)
212 os << "[" << key.first << ", " << key.second.to_string() << "]";
219 * fd.io coding-style-patch-verification: ON
222 * eval: (c-set-style "mozilla")