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/gbp_bridge_domain.hpp"
17 #include "vom/gbp_bridge_domain_cmds.hpp"
18 #include "vom/interface.hpp"
19 #include "vom/l2_binding.hpp"
20 #include "vom/singular_db_funcs.hpp"
25 * A DB of al the interfaces, key on the name
27 singular_db<uint32_t, gbp_bridge_domain> gbp_bridge_domain::m_db;
29 gbp_bridge_domain::event_handler gbp_bridge_domain::m_evh;
32 * Construct a new object matching the desried state
34 gbp_bridge_domain::gbp_bridge_domain(const bridge_domain& bd,
38 , m_bvi(bvi.singular())
42 gbp_bridge_domain::gbp_bridge_domain(const bridge_domain& bd)
48 gbp_bridge_domain::gbp_bridge_domain(const bridge_domain& bd,
50 const interface& uu_fwd)
53 , m_bvi(bvi.singular())
54 , m_uu_fwd(uu_fwd.singular())
58 gbp_bridge_domain::gbp_bridge_domain(const bridge_domain& bd,
59 const std::shared_ptr<interface> bvi,
60 const std::shared_ptr<interface> uu_fwd)
63 , m_bvi(bvi->singular())
64 , m_uu_fwd(uu_fwd->singular())
68 gbp_bridge_domain::gbp_bridge_domain(const bridge_domain& bd,
70 const std::shared_ptr<interface> uu_fwd)
73 , m_bvi(bvi.singular())
74 , m_uu_fwd(uu_fwd->singular())
78 gbp_bridge_domain::gbp_bridge_domain(const gbp_bridge_domain& bd)
82 , m_uu_fwd(bd.m_uu_fwd)
86 const gbp_bridge_domain::key_t
87 gbp_bridge_domain::key() const
93 gbp_bridge_domain::id() const
98 const std::shared_ptr<bridge_domain>
99 gbp_bridge_domain::get_bridge_domain()
104 const std::shared_ptr<interface>
105 gbp_bridge_domain::get_bvi()
111 gbp_bridge_domain::operator==(const gbp_bridge_domain& b) const
115 if (m_bvi && b.m_bvi)
116 equal &= (m_bvi->key() == b.m_bvi->key());
117 else if (!m_bvi && !b.m_bvi)
122 if (m_uu_fwd && b.m_uu_fwd)
123 equal &= (m_uu_fwd->key() == b.m_uu_fwd->key());
124 else if (!m_uu_fwd && !b.m_uu_fwd)
129 return ((m_bd->key() == b.m_bd->key()) && equal);
133 gbp_bridge_domain::sweep()
135 if (rc_t::OK == m_id.rc()) {
136 HW::enqueue(new gbp_bridge_domain_cmds::delete_cmd(m_id));
142 gbp_bridge_domain::replay()
144 if (rc_t::OK == m_id.rc()) {
145 if (m_bvi && m_uu_fwd)
146 HW::enqueue(new gbp_bridge_domain_cmds::create_cmd(m_id, m_bvi->handle(),
147 m_uu_fwd->handle()));
149 HW::enqueue(new gbp_bridge_domain_cmds::create_cmd(
150 m_id, handle_t::INVALID, handle_t::INVALID));
154 gbp_bridge_domain::~gbp_bridge_domain()
158 // not in the DB anymore.
159 m_db.release(m_id.data(), this);
163 gbp_bridge_domain::to_string() const
165 std::ostringstream s;
166 s << "gbp-bridge-domain:[" << m_bd->to_string();
169 s << " bvi:" << m_bvi->to_string();
171 s << " uu-fwd:" << m_uu_fwd->to_string();
178 std::shared_ptr<gbp_bridge_domain>
179 gbp_bridge_domain::find(const key_t& key)
181 return (m_db.find(key));
185 gbp_bridge_domain::update(const gbp_bridge_domain& desired)
188 * the desired state is always that the interface should be created
190 if (rc_t::OK != m_id.rc()) {
191 if (m_bvi && m_uu_fwd)
192 HW::enqueue(new gbp_bridge_domain_cmds::create_cmd(m_id, m_bvi->handle(),
193 m_uu_fwd->handle()));
195 HW::enqueue(new gbp_bridge_domain_cmds::create_cmd(
196 m_id, handle_t::INVALID, handle_t::INVALID));
200 std::shared_ptr<gbp_bridge_domain>
201 gbp_bridge_domain::find_or_add(const gbp_bridge_domain& temp)
203 return (m_db.find_or_add(temp.m_id.data(), temp));
206 std::shared_ptr<gbp_bridge_domain>
207 gbp_bridge_domain::singular() const
209 return find_or_add(*this);
213 gbp_bridge_domain::dump(std::ostream& os)
219 gbp_bridge_domain::event_handler::handle_populate(const client_db::key_t& key)
222 * dump VPP Bridge domains
224 std::shared_ptr<gbp_bridge_domain_cmds::dump_cmd> cmd =
225 std::make_shared<gbp_bridge_domain_cmds::dump_cmd>();
230 for (auto& record : *cmd) {
231 auto& payload = record.get_payload();
233 std::shared_ptr<interface> uu_fwd =
234 interface::find(payload.bd.uu_fwd_sw_if_index);
235 std::shared_ptr<interface> bvi =
236 interface::find(payload.bd.bvi_sw_if_index);
239 gbp_bridge_domain bd(payload.bd.bd_id, bvi, uu_fwd);
241 VOM_LOG(log_level_t::DEBUG) << "dump: " << bd.to_string();
243 gbp_bridge_domain bd(payload.bd.bd_id, *bvi);
245 VOM_LOG(log_level_t::DEBUG) << "dump: " << bd.to_string();
250 gbp_bridge_domain::event_handler::event_handler()
252 OM::register_listener(this);
253 inspect::register_handler({ "gbd", "gbridge" }, "GBP Bridge Domains", this);
257 gbp_bridge_domain::event_handler::handle_replay()
263 gbp_bridge_domain::event_handler::order() const
265 return (dependency_t::TABLE);
269 gbp_bridge_domain::event_handler::show(std::ostream& os)
276 * fd.io coding-style-patch-verification: ON
279 * eval: (c-set-style "mozilla")