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(epg_id_t epg_id,
40 const gbp_route_domain& rd,
41 const gbp_bridge_domain& bd)
50 gbp_endpoint_group::gbp_endpoint_group(const gbp_endpoint_group& epg)
52 , m_epg_id(epg.m_epg_id)
59 gbp_endpoint_group::~gbp_endpoint_group()
62 m_db.release(key(), this);
65 const gbp_endpoint_group::key_t
66 gbp_endpoint_group::key() const
72 gbp_endpoint_group::id() const
78 gbp_endpoint_group::operator==(const gbp_endpoint_group& gg) const
80 return (key() == gg.key() && (m_itf == gg.m_itf) && (m_rd == gg.m_rd) &&
85 gbp_endpoint_group::sweep()
88 HW::enqueue(new gbp_endpoint_group_cmds::delete_cmd(m_hw, m_epg_id));
94 gbp_endpoint_group::replay()
97 HW::enqueue(new gbp_endpoint_group_cmds::create_cmd(
98 m_hw, m_epg_id, m_bd->id(), m_rd->id(),
99 (m_itf ? m_itf->handle() : handle_t::INVALID)));
104 gbp_endpoint_group::to_string() const
106 std::ostringstream s;
107 s << "gbp-endpoint-group:["
108 << "epg:" << m_epg_id << ", " << (m_itf ? m_itf->to_string() : "NULL")
109 << ", " << m_bd->to_string() << ", " << m_rd->to_string() << "]";
115 gbp_endpoint_group::update(const gbp_endpoint_group& r)
117 if (rc_t::OK != m_hw.rc()) {
118 HW::enqueue(new gbp_endpoint_group_cmds::create_cmd(
119 m_hw, m_epg_id, m_bd->id(), m_rd->id(),
120 (m_itf ? m_itf->handle() : handle_t::INVALID)));
124 std::shared_ptr<gbp_endpoint_group>
125 gbp_endpoint_group::find_or_add(const gbp_endpoint_group& temp)
127 return (m_db.find_or_add(temp.key(), temp));
130 std::shared_ptr<gbp_endpoint_group>
131 gbp_endpoint_group::find(const key_t& k)
133 return (m_db.find(k));
136 std::shared_ptr<gbp_endpoint_group>
137 gbp_endpoint_group::singular() const
139 return find_or_add(*this);
143 gbp_endpoint_group::dump(std::ostream& os)
148 const std::shared_ptr<gbp_route_domain>
149 gbp_endpoint_group::get_route_domain()
154 const std::shared_ptr<gbp_bridge_domain>
155 gbp_endpoint_group::get_bridge_domain()
160 gbp_endpoint_group::event_handler::event_handler()
162 OM::register_listener(this);
163 inspect::register_handler({ "gbp-endpoint-group" }, "GBP Endpoint_Groups",
168 gbp_endpoint_group::event_handler::handle_replay()
174 gbp_endpoint_group::event_handler::handle_populate(const client_db::key_t& key)
176 std::shared_ptr<gbp_endpoint_group_cmds::dump_cmd> cmd =
177 std::make_shared<gbp_endpoint_group_cmds::dump_cmd>();
182 for (auto& record : *cmd) {
183 auto& payload = record.get_payload();
185 std::shared_ptr<interface> itf =
186 interface::find(payload.epg.uplink_sw_if_index);
187 std::shared_ptr<gbp_route_domain> rd =
188 gbp_route_domain::find(payload.epg.rd_id);
189 std::shared_ptr<gbp_bridge_domain> bd =
190 gbp_bridge_domain::find(payload.epg.bd_id);
192 VOM_LOG(log_level_t::DEBUG) << "data: [" << payload.epg.uplink_sw_if_index
193 << ", " << payload.epg.rd_id << ", "
194 << payload.epg.bd_id << "]";
196 if (itf && bd && rd) {
197 gbp_endpoint_group gbpe(payload.epg.epg_id, *itf, *rd, *bd);
198 OM::commit(key, gbpe);
200 VOM_LOG(log_level_t::DEBUG) << "read: " << gbpe.to_string();
206 gbp_endpoint_group::event_handler::order() const
208 return (dependency_t::ACL);
212 gbp_endpoint_group::event_handler::show(std::ostream& os)
219 * fd.io coding-style-patch-verification: ON
222 * eval: (c-set-style "mozilla")