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_recirc.hpp"
17 #include "vom/gbp_recirc_cmds.hpp"
18 #include "vom/singular_db_funcs.hpp"
22 gbp_recirc::type_t::type_t(int v, const std::string s)
23 : enum_base<gbp_recirc::type_t>(v, s)
27 const gbp_recirc::type_t gbp_recirc::type_t::INTERNAL(0, "internal");
28 const gbp_recirc::type_t gbp_recirc::type_t::EXTERNAL(1, "external");
30 singular_db<gbp_recirc::key_t, gbp_recirc> gbp_recirc::m_db;
32 gbp_recirc::event_handler gbp_recirc::m_evh;
34 gbp_recirc::gbp_recirc(const interface& itf,
36 const gbp_endpoint_group& epg)
38 , m_itf(itf.singular())
40 , m_epg(epg.singular())
44 gbp_recirc::gbp_recirc(const gbp_recirc& gbpe)
52 gbp_recirc::~gbp_recirc()
55 m_db.release(key(), this);
58 const gbp_recirc::key_t
59 gbp_recirc::key() const
61 return (m_itf->key());
65 gbp_recirc::handle() const
67 return m_itf->handle();
71 gbp_recirc::operator==(const gbp_recirc& gbpe) const
73 return ((key() == gbpe.key()) && (m_type == gbpe.m_type) &&
74 (m_itf == gbpe.m_itf) && (m_epg == gbpe.m_epg));
81 HW::enqueue(new gbp_recirc_cmds::delete_cmd(m_hw, m_itf->handle()));
90 HW::enqueue(new gbp_recirc_cmds::create_cmd(
91 m_hw, m_itf->handle(), (m_type == type_t::EXTERNAL), m_epg->sclass()));
96 gbp_recirc::to_string() const
99 s << "gbp-recirc:[" << m_itf->to_string() << ", type:" << m_type.to_string()
100 << ", " << m_epg->to_string() << "]";
106 gbp_recirc::update(const gbp_recirc& r)
108 if (rc_t::OK != m_hw.rc()) {
109 HW::enqueue(new gbp_recirc_cmds::create_cmd(
110 m_hw, m_itf->handle(), (m_type == type_t::EXTERNAL), m_epg->sclass()));
114 std::shared_ptr<gbp_recirc>
115 gbp_recirc::find_or_add(const gbp_recirc& temp)
117 return (m_db.find_or_add(temp.key(), temp));
120 std::shared_ptr<gbp_recirc>
121 gbp_recirc::find(const key_t& k)
123 return (m_db.find(k));
126 std::shared_ptr<gbp_recirc>
127 gbp_recirc::singular() const
129 return find_or_add(*this);
133 gbp_recirc::dump(std::ostream& os)
138 gbp_recirc::event_handler::event_handler()
140 OM::register_listener(this);
141 inspect::register_handler({ "gbp-recirc" }, "GBP Recircs", this);
145 gbp_recirc::event_handler::handle_replay()
151 gbp_recirc::event_handler::handle_populate(const client_db::key_t& key)
153 std::shared_ptr<gbp_recirc_cmds::dump_cmd> cmd =
154 std::make_shared<gbp_recirc_cmds::dump_cmd>();
159 for (auto& record : *cmd) {
160 auto& payload = record.get_payload();
162 std::shared_ptr<interface> itf =
163 interface::find(payload.recirc.sw_if_index);
164 std::shared_ptr<gbp_endpoint_group> epg =
165 gbp_endpoint_group::find(payload.recirc.sclass);
167 VOM_LOG(log_level_t::DEBUG) << "data: [" << payload.recirc.sw_if_index
168 << ", " << payload.recirc.sclass << "]";
172 *itf, (payload.recirc.is_ext ? type_t::EXTERNAL : type_t::INTERNAL),
174 OM::commit(key, recirc);
176 VOM_LOG(log_level_t::DEBUG) << "read: " << recirc.to_string();
182 gbp_recirc::event_handler::order() const
184 return (dependency_t::BINDING);
188 gbp_recirc::event_handler::show(std::ostream& os)
195 * fd.io coding-style-patch-verification: ON
198 * eval: (c-set-style "mozilla")