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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "vom/arp_proxy_config.hpp"
17 #include "vom/api_types.hpp"
18 #include "vom/arp_proxy_config_cmds.hpp"
19 #include "vom/prefix.hpp"
20 #include "vom/singular_db_funcs.hpp"
23 singular_db<arp_proxy_config::key_t, arp_proxy_config> arp_proxy_config::m_db;
25 arp_proxy_config::event_handler arp_proxy_config::m_evh;
27 arp_proxy_config::arp_proxy_config(const boost::asio::ip::address_v4& low,
28 const boost::asio::ip::address_v4& high)
35 arp_proxy_config::arp_proxy_config(const arp_proxy_config& o)
38 , m_config(o.m_config)
42 arp_proxy_config::~arp_proxy_config()
46 // not in the DB anymore.
47 m_db.release(std::make_pair(m_low, m_high), this);
51 arp_proxy_config::sweep()
55 new arp_proxy_config_cmds::unconfig_cmd(m_config, m_low, m_high));
61 arp_proxy_config::dump(std::ostream& os)
67 arp_proxy_config::replay()
70 HW::enqueue(new arp_proxy_config_cmds::config_cmd(m_config, m_low, m_high));
75 arp_proxy_config::to_string() const
79 << " low:" << m_low.to_string() << " high:" << m_high.to_string();
85 arp_proxy_config::update(const arp_proxy_config& desired)
88 HW::enqueue(new arp_proxy_config_cmds::config_cmd(m_config, m_low, m_high));
92 std::shared_ptr<arp_proxy_config>
93 arp_proxy_config::find_or_add(const arp_proxy_config& temp)
95 return (m_db.find_or_add(std::make_pair(temp.m_low, temp.m_high), temp));
98 std::shared_ptr<arp_proxy_config>
99 arp_proxy_config::singular() const
101 return find_or_add(*this);
104 arp_proxy_config::event_handler::event_handler()
106 OM::register_listener(this);
107 inspect::register_handler({ "arp-proxy-config" }, "ARP Proxy configurations",
112 arp_proxy_config::event_handler::handle_replay()
118 arp_proxy_config::event_handler::handle_populate(const client_db::key_t& key)
120 std::shared_ptr<arp_proxy_config_cmds::dump_cmd> cmd =
121 std::make_shared<arp_proxy_config_cmds::dump_cmd>();
126 for (auto& record : *cmd) {
127 auto& payload = record.get_payload();
129 boost::asio::ip::address lo = from_api(payload.proxy.low);
130 boost::asio::ip::address hi = from_api(payload.proxy.hi);
132 arp_proxy_config ap(lo.to_v4(), hi.to_v4());
138 arp_proxy_config::event_handler::order() const
140 return (dependency_t::GLOBAL);
144 arp_proxy_config::event_handler::show(std::ostream& os)
150 operator<<(std::ostream& os, const arp_proxy_config::key_t& key)
152 os << "[" << key.first << ", " << key.second << "]";
158 * fd.io coding-style-patch-verification: ON
161 * eval: (c-set-style "mozilla")