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