2 * Copyright (c) 2018 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_endpoint_group.hpp"
17 #include "vom/gbp_endpoint_group_cmds.hpp"
18 #include "vom/singular_db_funcs.hpp"
22 singular_db<gbp_endpoint_group::key_t, gbp_endpoint_group>
23 gbp_endpoint_group::m_db;
25 gbp_endpoint_group::event_handler gbp_endpoint_group::m_evh;
27 gbp_endpoint_group::gbp_endpoint_group(epg_id_t epg_id,
29 const gbp_route_domain& rd,
30 const gbp_bridge_domain& bd)
34 , m_itf(itf.singular())
40 gbp_endpoint_group::gbp_endpoint_group(epg_id_t epg_id,
41 const gbp_route_domain& rd,
42 const gbp_bridge_domain& bd)
52 gbp_endpoint_group::gbp_endpoint_group(epg_id_t epg_id,
55 const gbp_route_domain& rd,
56 const gbp_bridge_domain& bd)
60 , m_itf(itf.singular())
66 gbp_endpoint_group::gbp_endpoint_group(epg_id_t epg_id,
68 const gbp_route_domain& rd,
69 const gbp_bridge_domain& bd)
79 gbp_endpoint_group::gbp_endpoint_group(const gbp_endpoint_group& epg)
81 , m_epg_id(epg.m_epg_id)
82 , m_sclass(epg.m_sclass)
89 gbp_endpoint_group::~gbp_endpoint_group()
92 m_db.release(key(), this);
95 const gbp_endpoint_group::key_t
96 gbp_endpoint_group::key() const
102 gbp_endpoint_group::id() const
108 gbp_endpoint_group::operator==(const gbp_endpoint_group& gg) const
110 return (key() == gg.key() && (m_sclass == gg.m_sclass) &&
111 (m_itf == gg.m_itf) && (m_rd == gg.m_rd) && (m_bd == gg.m_bd));
115 gbp_endpoint_group::sweep()
118 HW::enqueue(new gbp_endpoint_group_cmds::delete_cmd(m_hw, m_epg_id));
124 gbp_endpoint_group::replay()
127 HW::enqueue(new gbp_endpoint_group_cmds::create_cmd(
128 m_hw, m_epg_id, m_sclass, m_bd->id(), m_rd->id(),
129 (m_itf ? m_itf->handle() : handle_t::INVALID)));
134 gbp_endpoint_group::to_string() const
136 std::ostringstream s;
137 s << "gbp-endpoint-group:["
138 << "epg:" << m_epg_id << ", sclass:" << m_sclass << ", "
139 << (m_itf ? m_itf->to_string() : "NULL") << ", " << m_bd->to_string()
140 << ", " << m_rd->to_string() << "]";
146 gbp_endpoint_group::update(const gbp_endpoint_group& r)
148 if (rc_t::OK != m_hw.rc()) {
149 HW::enqueue(new gbp_endpoint_group_cmds::create_cmd(
150 m_hw, m_epg_id, m_sclass, m_bd->id(), m_rd->id(),
151 (m_itf ? m_itf->handle() : handle_t::INVALID)));
155 std::shared_ptr<gbp_endpoint_group>
156 gbp_endpoint_group::find_or_add(const gbp_endpoint_group& temp)
158 return (m_db.find_or_add(temp.key(), temp));
161 std::shared_ptr<gbp_endpoint_group>
162 gbp_endpoint_group::find(const key_t& k)
164 return (m_db.find(k));
167 std::shared_ptr<gbp_endpoint_group>
168 gbp_endpoint_group::singular() const
170 return find_or_add(*this);
174 gbp_endpoint_group::dump(std::ostream& os)
179 const std::shared_ptr<gbp_route_domain>
180 gbp_endpoint_group::get_route_domain() const
185 const std::shared_ptr<gbp_bridge_domain>
186 gbp_endpoint_group::get_bridge_domain() const
191 gbp_endpoint_group::event_handler::event_handler()
193 OM::register_listener(this);
194 inspect::register_handler({ "gbp-endpoint-group" }, "GBP Endpoint_Groups",
199 gbp_endpoint_group::event_handler::handle_replay()
205 gbp_endpoint_group::event_handler::handle_populate(const client_db::key_t& key)
207 std::shared_ptr<gbp_endpoint_group_cmds::dump_cmd> cmd =
208 std::make_shared<gbp_endpoint_group_cmds::dump_cmd>();
213 for (auto& record : *cmd) {
214 auto& payload = record.get_payload();
216 std::shared_ptr<interface> itf =
217 interface::find(payload.epg.uplink_sw_if_index);
218 std::shared_ptr<gbp_route_domain> rd =
219 gbp_route_domain::find(payload.epg.rd_id);
220 std::shared_ptr<gbp_bridge_domain> bd =
221 gbp_bridge_domain::find(payload.epg.bd_id);
223 VOM_LOG(log_level_t::DEBUG) << "data: [" << payload.epg.uplink_sw_if_index
224 << ", " << payload.epg.rd_id << ", "
225 << payload.epg.bd_id << "]";
227 if (itf && bd && rd) {
228 gbp_endpoint_group gbpe(payload.epg.epg_id, payload.epg.sclass, *itf, *rd,
230 OM::commit(key, gbpe);
232 VOM_LOG(log_level_t::DEBUG) << "read: " << gbpe.to_string();
233 } else if (bd && rd) {
234 gbp_endpoint_group gbpe(payload.epg.epg_id, payload.epg.sclass, *rd, *bd);
235 OM::commit(key, gbpe);
237 VOM_LOG(log_level_t::DEBUG) << "read: " << gbpe.to_string();
239 VOM_LOG(log_level_t::ERROR) << "no itf:" << payload.epg.uplink_sw_if_index
240 << " or BD:" << payload.epg.bd_id
241 << " or RD:" << payload.epg.rd_id;
247 gbp_endpoint_group::event_handler::order() const
249 return (dependency_t::ACL);
253 gbp_endpoint_group::event_handler::show(std::ostream& os)
260 * fd.io coding-style-patch-verification: ON
263 * eval: (c-set-style "mozilla")