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)
33 , m_itf(itf.singular())
39 gbp_endpoint_group::gbp_endpoint_group(const gbp_endpoint_group& epg)
41 , m_epg_id(epg.m_epg_id)
48 gbp_endpoint_group::~gbp_endpoint_group()
51 m_db.release(key(), this);
54 const gbp_endpoint_group::key_t
55 gbp_endpoint_group::key() const
61 gbp_endpoint_group::id() const
67 gbp_endpoint_group::operator==(const gbp_endpoint_group& gg) const
69 return (key() == gg.key() && (m_itf == gg.m_itf) && (m_rd == gg.m_rd) &&
74 gbp_endpoint_group::sweep()
77 HW::enqueue(new gbp_endpoint_group_cmds::delete_cmd(m_hw, m_epg_id));
83 gbp_endpoint_group::replay()
86 HW::enqueue(new gbp_endpoint_group_cmds::create_cmd(
87 m_hw, m_epg_id, m_bd->id(), m_rd->id(), m_itf->handle()));
92 gbp_endpoint_group::to_string() const
95 s << "gbp-endpoint-group:["
96 << "epg:" << m_epg_id << ", " << m_itf->to_string() << ", "
97 << m_bd->to_string() << ", " << m_rd->to_string() << "]";
103 gbp_endpoint_group::update(const gbp_endpoint_group& r)
105 if (rc_t::OK != m_hw.rc()) {
106 HW::enqueue(new gbp_endpoint_group_cmds::create_cmd(
107 m_hw, m_epg_id, m_bd->id(), m_rd->id(), m_itf->handle()));
111 std::shared_ptr<gbp_endpoint_group>
112 gbp_endpoint_group::find_or_add(const gbp_endpoint_group& temp)
114 return (m_db.find_or_add(temp.key(), temp));
117 std::shared_ptr<gbp_endpoint_group>
118 gbp_endpoint_group::find(const key_t& k)
120 return (m_db.find(k));
123 std::shared_ptr<gbp_endpoint_group>
124 gbp_endpoint_group::singular() const
126 return find_or_add(*this);
130 gbp_endpoint_group::dump(std::ostream& os)
135 gbp_endpoint_group::event_handler::event_handler()
137 OM::register_listener(this);
138 inspect::register_handler({ "gbp-endpoint-group" }, "GBP Endpoint_Groups",
143 gbp_endpoint_group::event_handler::handle_replay()
149 gbp_endpoint_group::event_handler::handle_populate(const client_db::key_t& key)
151 std::shared_ptr<gbp_endpoint_group_cmds::dump_cmd> cmd =
152 std::make_shared<gbp_endpoint_group_cmds::dump_cmd>();
157 for (auto& record : *cmd) {
158 auto& payload = record.get_payload();
160 std::shared_ptr<interface> itf =
161 interface::find(payload.epg.uplink_sw_if_index);
162 std::shared_ptr<gbp_route_domain> rd =
163 gbp_route_domain::find(payload.epg.rd_id);
164 std::shared_ptr<gbp_bridge_domain> bd =
165 gbp_bridge_domain::find(payload.epg.bd_id);
167 VOM_LOG(log_level_t::DEBUG) << "data: [" << payload.epg.uplink_sw_if_index
168 << ", " << payload.epg.rd_id << ", "
169 << payload.epg.bd_id << "]";
171 if (itf && bd && rd) {
172 gbp_endpoint_group gbpe(payload.epg.epg_id, *itf, *rd, *bd);
173 OM::commit(key, gbpe);
175 VOM_LOG(log_level_t::DEBUG) << "read: " << gbpe.to_string();
181 gbp_endpoint_group::event_handler::order() const
183 return (dependency_t::ACL);
187 gbp_endpoint_group::event_handler::show(std::ostream& os)
194 * fd.io coding-style-patch-verification: ON
197 * eval: (c-set-style "mozilla")