blob: a3bfcddf00eff29f000714f68727a078d77738f3 [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,
Neale Rannsfd920602017-11-23 12:15:00 -080028 const boost::asio::ip::address& ip_addr,
29 const mac_address_t& mac)
Neale Ranns812ed392017-10-16 04:20:13 -070030 : m_hw(false)
31 , m_bd(bd.singular())
Neale Ranns812ed392017-10-16 04:20:13 -070032 , m_ip_addr(ip_addr)
Neale Rannsfd920602017-11-23 12:15:00 -080033 , m_mac(mac)
Neale Ranns812ed392017-10-16 04:20:13 -070034{
35}
36
37bridge_domain_arp_entry::bridge_domain_arp_entry(
Neale Rannsfd920602017-11-23 12:15:00 -080038 const boost::asio::ip::address& ip_addr,
39 const mac_address_t& mac)
Neale Ranns812ed392017-10-16 04:20:13 -070040 : m_hw(false)
41 , m_bd(nullptr)
Neale Ranns812ed392017-10-16 04:20:13 -070042 , m_ip_addr(ip_addr)
Neale Rannsfd920602017-11-23 12:15:00 -080043 , m_mac(mac)
Neale Ranns812ed392017-10-16 04:20:13 -070044{
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)
Neale Ranns812ed392017-10-16 04:20:13 -070057 , m_ip_addr(bde.m_ip_addr)
Neale Rannsfd920602017-11-23 12:15:00 -080058 , m_mac(bde.m_mac)
Neale Ranns812ed392017-10-16 04:20:13 -070059{
60}
61
62bridge_domain_arp_entry::~bridge_domain_arp_entry()
63{
64 sweep();
65
66 // not in the DB anymore.
Neale Rannsfd920602017-11-23 12:15:00 -080067 m_db.release(key(), this);
68}
69
70const bridge_domain_arp_entry::key_t
71bridge_domain_arp_entry::key() const
72{
73 return (std::make_pair(m_bd->key(), m_ip_addr));
74}
75
76bool
77bridge_domain_arp_entry::operator==(const bridge_domain_arp_entry& bdae) const
78{
79 return ((key() == bdae.key()) && (m_mac == bdae.m_mac));
Neale Ranns812ed392017-10-16 04:20:13 -070080}
81
82void
83bridge_domain_arp_entry::sweep()
84{
85 if (m_hw) {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070086 HW::enqueue(new bridge_domain_arp_entry_cmds::delete_cmd(m_hw, m_bd->id(),
87 m_mac, m_ip_addr));
Neale Ranns812ed392017-10-16 04:20:13 -070088 }
89 HW::write();
90}
91
92void
93bridge_domain_arp_entry::replay()
94{
95 if (m_hw) {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070096 HW::enqueue(new bridge_domain_arp_entry_cmds::create_cmd(m_hw, m_bd->id(),
97 m_mac, m_ip_addr));
Neale Ranns812ed392017-10-16 04:20:13 -070098 }
99}
100
101std::string
102bridge_domain_arp_entry::to_string() const
103{
104 std::ostringstream s;
105 s << "bridge-domain-arp-entry:[" << m_bd->to_string() << ", "
106 << m_mac.to_string() << ", " << m_ip_addr.to_string() << "]";
107
108 return (s.str());
109}
110
111void
112bridge_domain_arp_entry::update(const bridge_domain_arp_entry& r)
113{
114 /*
115 * create the table if it is not yet created
116 */
117 if (rc_t::OK != m_hw.rc()) {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700118 HW::enqueue(new bridge_domain_arp_entry_cmds::create_cmd(m_hw, m_bd->id(),
119 m_mac, m_ip_addr));
Neale Ranns812ed392017-10-16 04:20:13 -0700120 }
121}
122
123std::shared_ptr<bridge_domain_arp_entry>
124bridge_domain_arp_entry::find_or_add(const bridge_domain_arp_entry& temp)
125{
Neale Rannsfd920602017-11-23 12:15:00 -0800126 return (m_db.find_or_add(temp.key(), temp));
127}
128
129std::shared_ptr<bridge_domain_arp_entry>
130bridge_domain_arp_entry::find(const key_t& k)
131{
132 return (m_db.find(k));
Neale Ranns812ed392017-10-16 04:20:13 -0700133}
134
135std::shared_ptr<bridge_domain_arp_entry>
136bridge_domain_arp_entry::singular() const
137{
138 return find_or_add(*this);
139}
140
141void
142bridge_domain_arp_entry::dump(std::ostream& os)
143{
144 m_db.dump(os);
145}
146
Neale Ranns812ed392017-10-16 04:20:13 -0700147bridge_domain_arp_entry::event_handler::event_handler()
148{
149 OM::register_listener(this);
150 inspect::register_handler({ "bd-arp" },
151 "bridge domain ARP termination entries", this);
152}
153
154void
155bridge_domain_arp_entry::event_handler::handle_replay()
156{
157 m_db.replay();
158}
159
160void
161bridge_domain_arp_entry::event_handler::handle_populate(
162 const client_db::key_t& key)
163{
164}
165
166dependency_t
167bridge_domain_arp_entry::event_handler::order() const
168{
169 return (dependency_t::ENTRY);
170}
171
172void
173bridge_domain_arp_entry::event_handler::show(std::ostream& os)
174{
175 m_db.dump(os);
176}
Neale Ranns7758bf62018-02-14 06:34:20 -0800177
178std::ostream&
179operator<<(std::ostream& os, const bridge_domain_arp_entry::key_t& key)
180{
181 os << "[" << key.first << ", " << key.second << "]";
182
183 return (os);
184}
Neale Ranns812ed392017-10-16 04:20:13 -0700185}
186/*
187 * fd.io coding-style-patch-verification: ON
188 *
189 * Local Variables:
190 * eval: (c-set-style "mozilla")
191 * End:
192 */