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_ext_itf.hpp"
17 #include "vom/gbp_ext_itf_cmds.hpp"
18 #include "vom/singular_db_funcs.hpp"
22 singular_db<gbp_ext_itf::key_t, gbp_ext_itf> gbp_ext_itf::m_db;
24 gbp_ext_itf::event_handler gbp_ext_itf::m_evh;
26 gbp_ext_itf::gbp_ext_itf(const interface& itf,
27 const gbp_bridge_domain& gbd,
28 const gbp_route_domain& grd)
30 , m_itf(itf.singular())
31 , m_bd(gbd.singular())
32 , m_rd(grd.singular())
36 gbp_ext_itf::gbp_ext_itf(const gbp_ext_itf& gbpe)
44 gbp_ext_itf::~gbp_ext_itf()
47 m_db.release(key(), this);
50 const gbp_ext_itf::key_t
51 gbp_ext_itf::key() const
53 return (m_itf->key());
57 gbp_ext_itf::handle() const
59 return m_itf->handle();
63 gbp_ext_itf::operator==(const gbp_ext_itf& gei) const
65 return ((key() == gei.key()) && (m_itf == gei.m_itf) && (m_rd == gei.m_rd) &&
73 HW::enqueue(new gbp_ext_itf_cmds::delete_cmd(m_hw, m_itf->handle()));
82 HW::enqueue(new gbp_ext_itf_cmds::create_cmd(m_hw, m_itf->handle(),
83 m_bd->id(), m_rd->id()));
88 gbp_ext_itf::to_string() const
91 s << "gbp-ext_itf:[" << m_itf->to_string() << ", " << m_bd->to_string()
92 << ", " << m_rd->to_string() << "]";
98 gbp_ext_itf::update(const gbp_ext_itf& r)
100 if (rc_t::OK != m_hw.rc()) {
101 HW::enqueue(new gbp_ext_itf_cmds::create_cmd(m_hw, m_itf->handle(),
102 m_bd->id(), m_rd->id()));
106 std::shared_ptr<gbp_ext_itf>
107 gbp_ext_itf::find_or_add(const gbp_ext_itf& temp)
109 return (m_db.find_or_add(temp.key(), temp));
112 std::shared_ptr<gbp_ext_itf>
113 gbp_ext_itf::find(const key_t& k)
115 return (m_db.find(k));
118 std::shared_ptr<gbp_ext_itf>
119 gbp_ext_itf::singular() const
121 return find_or_add(*this);
125 gbp_ext_itf::dump(std::ostream& os)
130 gbp_ext_itf::event_handler::event_handler()
132 OM::register_listener(this);
133 inspect::register_handler({ "gbp-ext-itf" }, "GBP External-Itfs", this);
137 gbp_ext_itf::event_handler::handle_replay()
143 gbp_ext_itf::event_handler::handle_populate(const client_db::key_t& key)
145 std::shared_ptr<gbp_ext_itf_cmds::dump_cmd> cmd =
146 std::make_shared<gbp_ext_itf_cmds::dump_cmd>();
151 for (auto& record : *cmd) {
152 auto& payload = record.get_payload();
154 std::shared_ptr<interface> itf =
155 interface::find(payload.ext_itf.sw_if_index);
156 std::shared_ptr<gbp_bridge_domain> gbd =
157 gbp_bridge_domain::find(payload.ext_itf.bd_id);
158 std::shared_ptr<gbp_route_domain> grd =
159 gbp_route_domain::find(payload.ext_itf.rd_id);
161 VOM_LOG(log_level_t::DEBUG) << "data: [" << payload.ext_itf.sw_if_index
162 << ", " << payload.ext_itf.bd_id << ", "
163 << payload.ext_itf.rd_id << "]";
165 if (itf && gbd && grd) {
166 gbp_ext_itf ext_itf(*itf, *gbd, *grd);
167 OM::commit(key, ext_itf);
169 VOM_LOG(log_level_t::DEBUG) << "read: " << ext_itf.to_string();
171 VOM_LOG(log_level_t::ERROR) << "no itf:" << payload.ext_itf.sw_if_index
172 << " or BD:" << payload.ext_itf.bd_id
173 << " or RD:" << payload.ext_itf.rd_id;
179 gbp_ext_itf::event_handler::order() const
181 return (dependency_t::BINDING);
185 gbp_ext_itf::event_handler::show(std::ostream& os)
192 * fd.io coding-style-patch-verification: ON
195 * eval: (c-set-style "mozilla")