blob: ee34dbbce5b4190c78fe67504f554e39970b67ab [file] [log] [blame]
Neale Ranns812ed392017-10-16 04:20:13 -07001/*
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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15
16#include "vom/bridge_domain_arp_entry.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070017#include "vom/bridge_domain_arp_entry_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070018
19namespace VOM {
20
21singular_db<bridge_domain_arp_entry::key_t, bridge_domain_arp_entry>
22 bridge_domain_arp_entry::m_db;
23
24bridge_domain_arp_entry::event_handler bridge_domain_arp_entry::m_evh;
25
26bridge_domain_arp_entry::bridge_domain_arp_entry(
27 const bridge_domain& bd,
28 const mac_address_t& mac,
29 const boost::asio::ip::address& ip_addr)
30 : m_hw(false)
31 , m_bd(bd.singular())
32 , m_mac(mac)
33 , m_ip_addr(ip_addr)
34{
35}
36
37bridge_domain_arp_entry::bridge_domain_arp_entry(
38 const mac_address_t& mac,
39 const boost::asio::ip::address& ip_addr)
40 : m_hw(false)
41 , m_bd(nullptr)
42 , m_mac(mac)
43 , m_ip_addr(ip_addr)
44{
45 /*
46 * the route goes in the default table
47 */
48 bridge_domain bd(bridge_domain::DEFAULT_TABLE);
49
50 m_bd = bd.singular();
51}
52
53bridge_domain_arp_entry::bridge_domain_arp_entry(
54 const bridge_domain_arp_entry& bde)
55 : m_hw(bde.m_hw)
56 , m_bd(bde.m_bd)
57 , m_mac(bde.m_mac)
58 , m_ip_addr(bde.m_ip_addr)
59{
60}
61
62bridge_domain_arp_entry::~bridge_domain_arp_entry()
63{
64 sweep();
65
66 // not in the DB anymore.
67 m_db.release(std::make_tuple(m_bd->id(), m_mac, m_ip_addr), this);
68}
69
70void
71bridge_domain_arp_entry::sweep()
72{
73 if (m_hw) {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070074 HW::enqueue(new bridge_domain_arp_entry_cmds::delete_cmd(m_hw, m_bd->id(),
75 m_mac, m_ip_addr));
Neale Ranns812ed392017-10-16 04:20:13 -070076 }
77 HW::write();
78}
79
80void
81bridge_domain_arp_entry::replay()
82{
83 if (m_hw) {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070084 HW::enqueue(new bridge_domain_arp_entry_cmds::create_cmd(m_hw, m_bd->id(),
85 m_mac, m_ip_addr));
Neale Ranns812ed392017-10-16 04:20:13 -070086 }
87}
88
89std::string
90bridge_domain_arp_entry::to_string() const
91{
92 std::ostringstream s;
93 s << "bridge-domain-arp-entry:[" << m_bd->to_string() << ", "
94 << m_mac.to_string() << ", " << m_ip_addr.to_string() << "]";
95
96 return (s.str());
97}
98
99void
100bridge_domain_arp_entry::update(const bridge_domain_arp_entry& r)
101{
102 /*
103 * create the table if it is not yet created
104 */
105 if (rc_t::OK != m_hw.rc()) {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700106 HW::enqueue(new bridge_domain_arp_entry_cmds::create_cmd(m_hw, m_bd->id(),
107 m_mac, m_ip_addr));
Neale Ranns812ed392017-10-16 04:20:13 -0700108 }
109}
110
111std::shared_ptr<bridge_domain_arp_entry>
112bridge_domain_arp_entry::find_or_add(const bridge_domain_arp_entry& temp)
113{
114 return (m_db.find_or_add(
115 std::make_tuple(temp.m_bd->id(), temp.m_mac, temp.m_ip_addr), temp));
116}
117
118std::shared_ptr<bridge_domain_arp_entry>
119bridge_domain_arp_entry::singular() const
120{
121 return find_or_add(*this);
122}
123
124void
125bridge_domain_arp_entry::dump(std::ostream& os)
126{
127 m_db.dump(os);
128}
129
130std::ostream&
131operator<<(std::ostream& os, const bridge_domain_arp_entry::key_t& key)
132{
133 os << "[" << std::get<0>(key) << ", " << std::get<1>(key) << ", "
134 << std::get<2>(key) << "]";
135
136 return (os);
137}
138
139bridge_domain_arp_entry::event_handler::event_handler()
140{
141 OM::register_listener(this);
142 inspect::register_handler({ "bd-arp" },
143 "bridge domain ARP termination entries", this);
144}
145
146void
147bridge_domain_arp_entry::event_handler::handle_replay()
148{
149 m_db.replay();
150}
151
152void
153bridge_domain_arp_entry::event_handler::handle_populate(
154 const client_db::key_t& key)
155{
156}
157
158dependency_t
159bridge_domain_arp_entry::event_handler::order() const
160{
161 return (dependency_t::ENTRY);
162}
163
164void
165bridge_domain_arp_entry::event_handler::show(std::ostream& os)
166{
167 m_db.dump(os);
168}
169}
170/*
171 * fd.io coding-style-patch-verification: ON
172 *
173 * Local Variables:
174 * eval: (c-set-style "mozilla")
175 * End:
176 */