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/bridge_domain_arp_entry.hpp"
17 #include "vom/bridge_domain_arp_entry_cmds.hpp"
18 #include "vom/singular_db_funcs.hpp"
22 singular_db<bridge_domain_arp_entry::key_t, bridge_domain_arp_entry>
23 bridge_domain_arp_entry::m_db;
25 bridge_domain_arp_entry::event_handler bridge_domain_arp_entry::m_evh;
27 bridge_domain_arp_entry::bridge_domain_arp_entry(
28 const bridge_domain& bd,
29 const boost::asio::ip::address& ip_addr,
30 const mac_address_t& mac)
38 bridge_domain_arp_entry::bridge_domain_arp_entry(
39 const boost::asio::ip::address& ip_addr,
40 const mac_address_t& mac)
47 * the route goes in the default table
49 bridge_domain bd(bridge_domain::DEFAULT_TABLE);
54 bridge_domain_arp_entry::bridge_domain_arp_entry(
55 const bridge_domain_arp_entry& bde)
58 , m_ip_addr(bde.m_ip_addr)
63 bridge_domain_arp_entry::~bridge_domain_arp_entry()
67 // not in the DB anymore.
68 m_db.release(key(), this);
71 const bridge_domain_arp_entry::key_t
72 bridge_domain_arp_entry::key() const
74 return (std::make_pair(m_bd->key(), m_ip_addr));
78 bridge_domain_arp_entry::operator==(const bridge_domain_arp_entry& bdae) const
80 return ((key() == bdae.key()) && (m_mac == bdae.m_mac));
84 bridge_domain_arp_entry::sweep()
87 HW::enqueue(new bridge_domain_arp_entry_cmds::delete_cmd(m_hw, m_bd->id(),
94 bridge_domain_arp_entry::replay()
97 HW::enqueue(new bridge_domain_arp_entry_cmds::create_cmd(m_hw, m_bd->id(),
103 bridge_domain_arp_entry::to_string() const
105 std::ostringstream s;
106 s << "bridge-domain-arp-entry:[" << m_bd->to_string() << ", "
107 << m_mac.to_string() << ", " << m_ip_addr.to_string() << "]";
113 bridge_domain_arp_entry::update(const bridge_domain_arp_entry& r)
116 * create the table if it is not yet created
118 if (rc_t::OK != m_hw.rc()) {
119 HW::enqueue(new bridge_domain_arp_entry_cmds::create_cmd(m_hw, m_bd->id(),
124 std::shared_ptr<bridge_domain_arp_entry>
125 bridge_domain_arp_entry::find_or_add(const bridge_domain_arp_entry& temp)
127 return (m_db.find_or_add(temp.key(), temp));
130 std::shared_ptr<bridge_domain_arp_entry>
131 bridge_domain_arp_entry::find(const key_t& k)
133 return (m_db.find(k));
136 std::shared_ptr<bridge_domain_arp_entry>
137 bridge_domain_arp_entry::singular() const
139 return find_or_add(*this);
143 bridge_domain_arp_entry::dump(std::ostream& os)
148 bridge_domain_arp_entry::event_handler::event_handler()
150 OM::register_listener(this);
151 inspect::register_handler({ "bd-arp" },
152 "bridge domain ARP termination entries", this);
156 bridge_domain_arp_entry::event_handler::handle_replay()
162 bridge_domain_arp_entry::event_handler::handle_populate(
163 const client_db::key_t& key)
166 * dump VPP Bridge domains
168 std::shared_ptr<bridge_domain_arp_entry_cmds::dump_cmd> cmd =
169 std::make_shared<bridge_domain_arp_entry_cmds::dump_cmd>(~0);
174 for (auto& record : *cmd) {
175 auto& payload = record.get_payload();
177 std::shared_ptr<bridge_domain> bd = bridge_domain::find(payload.bd_id);
178 bridge_domain_arp_entry bd_ae(
179 *bd, from_bytes(payload.is_ipv6, payload.ip_address),
180 mac_address_t(payload.mac_address));
182 VOM_LOG(log_level_t::DEBUG) << "dump: " << bd_ae.to_string();
185 * Write each of the discovered bridge-domain arp entry into the OM,
186 * but disable the HW Command q whilst we do, so that no
187 * commands are sent to VPP
189 OM::commit(key, bd_ae);
194 bridge_domain_arp_entry::event_handler::order() const
196 return (dependency_t::ENTRY);
200 bridge_domain_arp_entry::event_handler::show(std::ostream& os)
206 operator<<(std::ostream& os, const bridge_domain_arp_entry::key_t& key)
208 os << "[" << key.first << ", " << key.second << "]";
214 * fd.io coding-style-patch-verification: ON
217 * eval: (c-set-style "mozilla")