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"
20 singular_db<bridge_domain_entry::key_t, bridge_domain_entry>
21 bridge_domain_entry::m_db;
23 bridge_domain_entry::event_handler bridge_domain_entry::m_evh;
25 bridge_domain_entry::bridge_domain_entry(const bridge_domain& bd,
26 const mac_address_t& mac,
27 const interface& tx_itf)
31 , m_tx_itf(tx_itf.singular())
35 bridge_domain_entry::bridge_domain_entry(const mac_address_t& mac,
36 const interface& tx_itf)
40 , m_tx_itf(tx_itf.singular())
43 * the entry goes in the default bridge-domain
45 bridge_domain bd(bridge_domain::DEFAULT_TABLE);
50 bridge_domain_entry::bridge_domain_entry(const bridge_domain_entry& bde)
54 , m_tx_itf(bde.m_tx_itf)
58 const bridge_domain_entry::key_t
59 bridge_domain_entry::key() const
61 return (std::make_pair(m_bd->key(), m_mac));
65 bridge_domain_entry::operator==(const bridge_domain_entry& bde) const
67 return ((key() == bde.key()) && (m_tx_itf == bde.m_tx_itf));
70 bridge_domain_entry::~bridge_domain_entry()
74 // not in the DB anymore.
75 m_db.release(key(), this);
79 bridge_domain_entry::sweep()
82 HW::enqueue(new bridge_domain_entry_cmds::delete_cmd(
83 m_hw, m_mac, m_bd->id(), interface::type_t::BVI == m_tx_itf->type()));
89 bridge_domain_entry::replay()
92 HW::enqueue(new bridge_domain_entry_cmds::create_cmd(
93 m_hw, m_mac, m_bd->id(), m_tx_itf->handle(),
94 interface::type_t::BVI == m_tx_itf->type()));
98 bridge_domain_entry::to_string() const
100 std::ostringstream s;
101 s << "bridge-domain-entry:[" << m_bd->to_string() << ", " << m_mac.to_string()
102 << ", tx:" << m_tx_itf->name() << "]";
108 bridge_domain_entry::update(const bridge_domain_entry& r)
111 * create the table if it is not yet created
113 if (rc_t::OK != m_hw.rc()) {
114 HW::enqueue(new bridge_domain_entry_cmds::create_cmd(
115 m_hw, m_mac, m_bd->id(), m_tx_itf->handle(),
116 interface::type_t::BVI == m_tx_itf->type()));
120 std::shared_ptr<bridge_domain_entry>
121 bridge_domain_entry::find_or_add(const bridge_domain_entry& temp)
123 return (m_db.find_or_add(temp.key(), temp));
126 std::shared_ptr<bridge_domain_entry>
127 bridge_domain_entry::find(const key_t& k)
129 return (m_db.find(k));
132 std::shared_ptr<bridge_domain_entry>
133 bridge_domain_entry::singular() const
135 return find_or_add(*this);
139 bridge_domain_entry::dump(std::ostream& os)
144 bridge_domain_entry::event_handler::event_handler()
146 OM::register_listener(this);
147 inspect::register_handler({ "bd-entry" },
148 "bridge domain entry configurations", this);
152 bridge_domain_entry::event_handler::handle_replay()
158 bridge_domain_entry::event_handler::handle_populate(const client_db::key_t& key)
160 std::shared_ptr<bridge_domain_entry_cmds::dump_cmd> cmd =
161 std::make_shared<bridge_domain_entry_cmds::dump_cmd>();
166 for (auto& record : *cmd) {
167 auto& payload = record.get_payload();
169 std::shared_ptr<interface> itf = interface::find(payload.sw_if_index);
170 std::shared_ptr<bridge_domain> bd = bridge_domain::find(payload.bd_id);
173 VOM_LOG(log_level_t::ERROR) << "bridge-domain-entry dump:"
174 << " itf:" << payload.sw_if_index
175 << " bd:" << payload.bd_id;
179 mac_address_t mac(payload.mac);
180 bridge_domain_entry bd_e(*bd, mac, *itf);
182 VOM_LOG(log_level_t::DEBUG) << "bridge-domain-entry dump:"
183 << " " << bd->to_string() << " "
184 << itf->to_string() << " mac:["
185 << mac.to_string() << "]";
188 * Write each of the discovered interfaces into the OM,
189 * but disable the HW Command q whilst we do, so that no
190 * commands are sent to VPP
192 OM::commit(key, bd_e);
197 bridge_domain_entry::event_handler::order() const
199 return (dependency_t::ENTRY);
203 bridge_domain_entry::event_handler::show(std::ostream& os)
209 operator<<(std::ostream& os, const bridge_domain_entry::key_t& key)
211 os << "[" << key.first << ", " << key.second.to_string() << "]";
218 * fd.io coding-style-patch-verification: ON
221 * eval: (c-set-style "mozilla")