blob: 5130ba8d8500fc3578566a190afc393aa2d832a4 [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);
104 inspect::register_handler({ "arp-proxy" }, "ARP Proxy configurations", this);
105}
106
107void
108arp_proxy_config::event_handler::handle_replay()
109{
110 m_db.replay();
111}
112
113void
114arp_proxy_config::event_handler::handle_populate(const client_db::key_t& key)
115{
116 // VPP provides no dump for ARP proxy.
117}
118
119dependency_t
120arp_proxy_config::event_handler::order() const
121{
122 return (dependency_t::GLOBAL);
123}
124
125void
126arp_proxy_config::event_handler::show(std::ostream& os)
127{
128 m_db.dump(os);
129}
130
131std::ostream&
132operator<<(std::ostream& os, const arp_proxy_config::key_t& key)
133{
134 os << "[" << key.first << ", " << key.second << "]";
135
136 return (os);
137}
138}
139/*
140 * fd.io coding-style-patch-verification: ON
141 *
142 * Local Variables:
143 * eval: (c-set-style "mozilla")
144 * End:
145 */