2 * Copyright (c) 2017 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.hpp"
17 #include "vom/gbp_endpoint_cmds.hpp"
18 #include "vom/singular_db_funcs.hpp"
22 singular_db<gbp_endpoint::key_t, gbp_endpoint> gbp_endpoint::m_db;
24 gbp_endpoint::event_handler gbp_endpoint::m_evh;
26 gbp_endpoint::gbp_endpoint(const interface& itf,
27 const boost::asio::ip::address& ip_addr,
28 const mac_address_t& mac,
29 const gbp_endpoint_group& epg)
31 , m_itf(itf.singular())
34 , m_epg(epg.singular())
38 gbp_endpoint::gbp_endpoint(const gbp_endpoint& gbpe)
47 gbp_endpoint::~gbp_endpoint()
50 m_db.release(key(), this);
53 const gbp_endpoint::key_t
54 gbp_endpoint::key() const
56 return (std::make_pair(m_itf->key(), m_ip));
60 gbp_endpoint::operator==(const gbp_endpoint& gbpe) const
62 return ((key() == gbpe.key()) && (m_epg == gbpe.m_epg));
69 HW::enqueue(new gbp_endpoint_cmds::delete_cmd(m_hw, m_itf->handle(), m_ip));
75 gbp_endpoint::replay()
78 HW::enqueue(new gbp_endpoint_cmds::create_cmd(m_hw, m_itf->handle(), m_ip,
84 gbp_endpoint::to_string() const
87 s << "gbp-endpoint:[" << m_itf->to_string() << ", " << m_ip.to_string()
88 << ", " << m_mac.to_string() << ", epg:" << m_epg->to_string() << "]";
94 gbp_endpoint::update(const gbp_endpoint& r)
96 if (rc_t::OK != m_hw.rc()) {
97 HW::enqueue(new gbp_endpoint_cmds::create_cmd(m_hw, m_itf->handle(), m_ip,
102 std::shared_ptr<gbp_endpoint>
103 gbp_endpoint::find_or_add(const gbp_endpoint& temp)
105 return (m_db.find_or_add(temp.key(), temp));
108 std::shared_ptr<gbp_endpoint>
109 gbp_endpoint::find(const key_t& k)
111 return (m_db.find(k));
114 std::shared_ptr<gbp_endpoint>
115 gbp_endpoint::singular() const
117 return find_or_add(*this);
121 gbp_endpoint::dump(std::ostream& os)
126 gbp_endpoint::event_handler::event_handler()
128 OM::register_listener(this);
129 inspect::register_handler({ "gbp-endpoint" }, "GBP Endpoints", this);
133 gbp_endpoint::event_handler::handle_replay()
139 gbp_endpoint::event_handler::handle_populate(const client_db::key_t& key)
141 std::shared_ptr<gbp_endpoint_cmds::dump_cmd> cmd =
142 std::make_shared<gbp_endpoint_cmds::dump_cmd>();
147 for (auto& record : *cmd) {
148 auto& payload = record.get_payload();
150 boost::asio::ip::address address =
151 from_bytes(payload.endpoint.is_ip6, payload.endpoint.address);
152 std::shared_ptr<interface> itf =
153 interface::find(payload.endpoint.sw_if_index);
154 std::shared_ptr<gbp_endpoint_group> epg =
155 gbp_endpoint_group::find(payload.endpoint.epg_id);
156 mac_address_t mac(payload.endpoint.mac);
158 VOM_LOG(log_level_t::DEBUG) << "data: " << payload.endpoint.sw_if_index;
161 gbp_endpoint gbpe(*itf, address, mac, *epg);
162 OM::commit(key, gbpe);
164 VOM_LOG(log_level_t::DEBUG) << "read: " << gbpe.to_string();
170 gbp_endpoint::event_handler::order() const
172 return (dependency_t::ENTRY);
176 gbp_endpoint::event_handler::show(std::ostream& os)
183 * fd.io coding-style-patch-verification: ON
186 * eval: (c-set-style "mozilla")