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::retention_t::retention_t()
28 : remote_ep_timeout(0xffffffff)
31 gbp_endpoint_group::retention_t::retention_t(uint32_t remote_ep_timeout_)
32 : remote_ep_timeout(remote_ep_timeout_)
37 gbp_endpoint_group::retention_t::operator==(const retention_t& o) const
39 return (remote_ep_timeout == o.remote_ep_timeout);
43 gbp_endpoint_group::retention_t::to_string() const
45 return std::to_string(remote_ep_timeout);
48 gbp_endpoint_group::gbp_endpoint_group(vnid_t vnid,
51 const gbp_route_domain& rd,
52 const gbp_bridge_domain& bd)
56 , m_itf(itf.singular())
63 gbp_endpoint_group::gbp_endpoint_group(vnid_t vnid,
65 const gbp_route_domain& rd,
66 const gbp_bridge_domain& bd)
77 gbp_endpoint_group::gbp_endpoint_group(sclass_t sclass,
78 const gbp_route_domain& rd,
79 const gbp_bridge_domain& bd)
90 gbp_endpoint_group::gbp_endpoint_group(const gbp_endpoint_group& epg)
93 , m_sclass(epg.m_sclass)
97 , m_retention(epg.m_retention)
101 gbp_endpoint_group::~gbp_endpoint_group()
104 m_db.release(key(), this);
107 const gbp_endpoint_group::key_t
108 gbp_endpoint_group::key() const
114 gbp_endpoint_group::vnid() const
120 gbp_endpoint_group::set(const retention_t& retention)
122 m_retention = retention;
126 gbp_endpoint_group::sclass() const
132 gbp_endpoint_group::operator==(const gbp_endpoint_group& gg) const
134 return (key() == gg.key() && (m_vnid == gg.m_vnid) &&
135 (m_retention == gg.m_retention) && (m_itf == gg.m_itf) &&
136 (m_rd == gg.m_rd) && (m_bd == gg.m_bd));
140 gbp_endpoint_group::sweep()
143 HW::enqueue(new gbp_endpoint_group_cmds::delete_cmd(m_hw, m_vnid));
149 gbp_endpoint_group::replay()
152 HW::enqueue(new gbp_endpoint_group_cmds::create_cmd(
153 m_hw, m_vnid, m_sclass, m_bd->id(), m_rd->id(), m_retention,
154 (m_itf ? m_itf->handle() : handle_t::INVALID)));
159 gbp_endpoint_group::to_string() const
161 std::ostringstream s;
162 s << "gbp-endpoint-group:["
163 << "vnid:" << m_vnid << ", sclass:" << m_sclass << ", "
164 << "retention:[" << m_retention.to_string() << "], "
165 << (m_itf ? m_itf->to_string() : "NULL") << ", " << m_bd->to_string()
166 << ", " << m_rd->to_string() << "]";
172 gbp_endpoint_group::update(const gbp_endpoint_group& r)
174 if (rc_t::OK != m_hw.rc()) {
175 HW::enqueue(new gbp_endpoint_group_cmds::create_cmd(
176 m_hw, m_vnid, m_sclass, m_bd->id(), m_rd->id(), m_retention,
177 (m_itf ? m_itf->handle() : handle_t::INVALID)));
181 std::shared_ptr<gbp_endpoint_group>
182 gbp_endpoint_group::find_or_add(const gbp_endpoint_group& temp)
184 return (m_db.find_or_add(temp.key(), temp));
187 std::shared_ptr<gbp_endpoint_group>
188 gbp_endpoint_group::find(const key_t& k)
190 return (m_db.find(k));
193 std::shared_ptr<gbp_endpoint_group>
194 gbp_endpoint_group::singular() const
196 return find_or_add(*this);
200 gbp_endpoint_group::dump(std::ostream& os)
205 const std::shared_ptr<gbp_route_domain>
206 gbp_endpoint_group::get_route_domain() const
211 const std::shared_ptr<gbp_bridge_domain>
212 gbp_endpoint_group::get_bridge_domain() const
217 gbp_endpoint_group::event_handler::event_handler()
219 OM::register_listener(this);
220 inspect::register_handler({ "gbp-endpoint-group" }, "GBP Endpoint_Groups",
225 gbp_endpoint_group::event_handler::handle_replay()
231 gbp_endpoint_group::event_handler::handle_populate(const client_db::key_t& key)
233 std::shared_ptr<gbp_endpoint_group_cmds::dump_cmd> cmd =
234 std::make_shared<gbp_endpoint_group_cmds::dump_cmd>();
239 for (auto& record : *cmd) {
240 auto& payload = record.get_payload();
242 std::shared_ptr<interface> itf =
243 interface::find(payload.epg.uplink_sw_if_index);
244 std::shared_ptr<gbp_route_domain> rd =
245 gbp_route_domain::find(payload.epg.rd_id);
246 std::shared_ptr<gbp_bridge_domain> bd =
247 gbp_bridge_domain::find(payload.epg.bd_id);
249 VOM_LOG(log_level_t::DEBUG) << "data: [" << payload.epg.uplink_sw_if_index
250 << ", " << payload.epg.rd_id << ", "
251 << payload.epg.bd_id << "]";
253 if (itf && bd && rd) {
254 gbp_endpoint_group gbpe(payload.epg.vnid, payload.epg.sclass, *itf, *rd,
256 OM::commit(key, gbpe);
258 VOM_LOG(log_level_t::DEBUG) << "read: " << gbpe.to_string();
259 } else if (bd && rd) {
260 gbp_endpoint_group gbpe(payload.epg.sclass, *rd, *bd);
261 OM::commit(key, gbpe);
263 VOM_LOG(log_level_t::DEBUG) << "read: " << gbpe.to_string();
265 VOM_LOG(log_level_t::ERROR) << "no itf:" << payload.epg.uplink_sw_if_index
266 << " or BD:" << payload.epg.bd_id
267 << " or RD:" << payload.epg.rd_id;
273 gbp_endpoint_group::event_handler::order() const
275 return (dependency_t::ACL);
279 gbp_endpoint_group::event_handler::show(std::ostream& os)
286 * fd.io coding-style-patch-verification: ON
289 * eval: (c-set-style "mozilla")