blob: c72b5f2e8b0fa43efdcf7ba71d5500ffa5504c37 [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/arp_proxy_config.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070017#include "vom/arp_proxy_config_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070018
19namespace VOM {
Neale Ranns812ed392017-10-16 04:20:13 -070020singular_db<arp_proxy_config::key_t, arp_proxy_config> arp_proxy_config::m_db;
21
22arp_proxy_config::event_handler arp_proxy_config::m_evh;
23
24arp_proxy_config::arp_proxy_config(const boost::asio::ip::address_v4& low,
25 const boost::asio::ip::address_v4& high)
26 : m_low(low)
27 , m_high(high)
28 , m_config(true)
29{
30}
31
32arp_proxy_config::arp_proxy_config(const arp_proxy_config& o)
33 : m_low(o.m_low)
34 , m_high(o.m_high)
35 , m_config(o.m_config)
36{
37}
38
39arp_proxy_config::~arp_proxy_config()
40{
41 sweep();
42
43 // not in the DB anymore.
44 m_db.release(std::make_pair(m_low, m_high), this);
45}
46
47void
48arp_proxy_config::sweep()
49{
50 if (m_config) {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070051 HW::enqueue(
52 new arp_proxy_config_cmds::unconfig_cmd(m_config, m_low, m_high));
Neale Ranns812ed392017-10-16 04:20:13 -070053 }
54 HW::write();
55}
56
57void
58arp_proxy_config::dump(std::ostream& os)
59{
60 m_db.dump(os);
61}
62
63void
64arp_proxy_config::replay()
65{
66 if (m_config) {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070067 HW::enqueue(new arp_proxy_config_cmds::config_cmd(m_config, m_low, m_high));
Neale Ranns812ed392017-10-16 04:20:13 -070068 }
69}
70
71std::string
72arp_proxy_config::to_string() const
73{
74 std::ostringstream s;
75 s << "ARP-proxy:"
76 << " low:" << m_low.to_string() << " high:" << m_high.to_string();
77
78 return (s.str());
79}
80
81void
82arp_proxy_config::update(const arp_proxy_config& desired)
83{
84 if (!m_config) {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070085 HW::enqueue(new arp_proxy_config_cmds::config_cmd(m_config, m_low, m_high));
Neale Ranns812ed392017-10-16 04:20:13 -070086 }
87}
88
89std::shared_ptr<arp_proxy_config>
90arp_proxy_config::find_or_add(const arp_proxy_config& temp)
91{
92 return (m_db.find_or_add(std::make_pair(temp.m_low, temp.m_high), temp));
93}
94
95std::shared_ptr<arp_proxy_config>
96arp_proxy_config::singular() const
97{
98 return find_or_add(*this);
99}
100
101arp_proxy_config::event_handler::event_handler()
102{
103 OM::register_listener(this);
Mohsin Kazmib5eb3b12018-02-26 18:36:17 +0100104 inspect::register_handler({ "arp-proxy-config" }, "ARP Proxy configurations",
105 this);
Neale Ranns812ed392017-10-16 04:20:13 -0700106}
107
108void
109arp_proxy_config::event_handler::handle_replay()
110{
111 m_db.replay();
112}
113
114void
115arp_proxy_config::event_handler::handle_populate(const client_db::key_t& key)
116{
117 // VPP provides no dump for ARP proxy.
118}
119
120dependency_t
121arp_proxy_config::event_handler::order() const
122{
123 return (dependency_t::GLOBAL);
124}
125
126void
127arp_proxy_config::event_handler::show(std::ostream& os)
128{
129 m_db.dump(os);
130}
131
132std::ostream&
133operator<<(std::ostream& os, const arp_proxy_config::key_t& key)
134{
135 os << "[" << key.first << ", " << key.second << "]";
136
137 return (os);
138}
139}
140/*
141 * fd.io coding-style-patch-verification: ON
142 *
143 * Local Variables:
144 * eval: (c-set-style "mozilla")
145 * End:
146 */