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/api_types.hpp"
18 #include "vom/bridge_domain_arp_entry_cmds.hpp"
19 #include "vom/singular_db_funcs.hpp"
23 singular_db<bridge_domain_arp_entry::key_t, bridge_domain_arp_entry>
24 bridge_domain_arp_entry::m_db;
26 bridge_domain_arp_entry::event_handler bridge_domain_arp_entry::m_evh;
28 bridge_domain_arp_entry::bridge_domain_arp_entry(
29 const bridge_domain& bd,
30 const boost::asio::ip::address& ip_addr,
31 const mac_address_t& mac)
39 bridge_domain_arp_entry::bridge_domain_arp_entry(
40 const boost::asio::ip::address& ip_addr,
41 const mac_address_t& mac)
48 * the route goes in the default table
50 bridge_domain bd(bridge_domain::DEFAULT_TABLE);
55 bridge_domain_arp_entry::bridge_domain_arp_entry(
56 const bridge_domain_arp_entry& bde)
59 , m_ip_addr(bde.m_ip_addr)
64 bridge_domain_arp_entry::~bridge_domain_arp_entry()
68 // not in the DB anymore.
69 m_db.release(key(), this);
72 const bridge_domain_arp_entry::key_t
73 bridge_domain_arp_entry::key() const
75 return (std::make_pair(m_bd->key(), m_ip_addr));
79 bridge_domain_arp_entry::operator==(const bridge_domain_arp_entry& bdae) const
81 return ((key() == bdae.key()) && (m_mac == bdae.m_mac));
85 bridge_domain_arp_entry::sweep()
88 HW::enqueue(new bridge_domain_arp_entry_cmds::delete_cmd(m_hw, m_bd->id(),
95 bridge_domain_arp_entry::replay()
98 HW::enqueue(new bridge_domain_arp_entry_cmds::create_cmd(m_hw, m_bd->id(),
104 bridge_domain_arp_entry::to_string() const
106 std::ostringstream s;
107 s << "bridge-domain-arp-entry:[" << m_bd->to_string() << ", "
108 << m_mac.to_string() << ", " << m_ip_addr.to_string() << "]";
114 bridge_domain_arp_entry::update(const bridge_domain_arp_entry& r)
117 * create the table if it is not yet created
119 if (rc_t::OK != m_hw.rc()) {
120 HW::enqueue(new bridge_domain_arp_entry_cmds::create_cmd(m_hw, m_bd->id(),
125 std::shared_ptr<bridge_domain_arp_entry>
126 bridge_domain_arp_entry::find_or_add(const bridge_domain_arp_entry& temp)
128 return (m_db.find_or_add(temp.key(), temp));
131 std::shared_ptr<bridge_domain_arp_entry>
132 bridge_domain_arp_entry::find(const key_t& k)
134 return (m_db.find(k));
137 std::shared_ptr<bridge_domain_arp_entry>
138 bridge_domain_arp_entry::singular() const
140 return find_or_add(*this);
144 bridge_domain_arp_entry::dump(std::ostream& os)
149 bridge_domain_arp_entry::event_handler::event_handler()
151 OM::register_listener(this);
152 inspect::register_handler({ "bd-arp" },
153 "bridge domain ARP termination entries", this);
157 bridge_domain_arp_entry::event_handler::handle_replay()
163 bridge_domain_arp_entry::event_handler::handle_populate(
164 const client_db::key_t& key)
167 * dump VPP Bridge domains
169 std::shared_ptr<bridge_domain_arp_entry_cmds::dump_cmd> cmd =
170 std::make_shared<bridge_domain_arp_entry_cmds::dump_cmd>(~0);
175 for (auto& record : *cmd) {
176 auto& payload = record.get_payload();
178 std::shared_ptr<bridge_domain> bd =
179 bridge_domain::find(payload.entry.bd_id);
180 bridge_domain_arp_entry bd_ae(*bd, from_api(payload.entry.ip),
181 from_api(payload.entry.mac));
183 VOM_LOG(log_level_t::DEBUG) << "dump: " << bd_ae.to_string();
186 * Write each of the discovered bridge-domain arp entry into the OM,
187 * but disable the HW Command q whilst we do, so that no
188 * commands are sent to VPP
190 OM::commit(key, bd_ae);
195 bridge_domain_arp_entry::event_handler::order() const
197 return (dependency_t::ENTRY);
201 bridge_domain_arp_entry::event_handler::show(std::ostream& os)
207 operator<<(std::ostream& os, const bridge_domain_arp_entry::key_t& key)
209 os << "[" << key.first << ", " << key.second << "]";
215 * fd.io coding-style-patch-verification: ON
218 * eval: (c-set-style "mozilla")