2 * Copyright (c) 2018 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/ip_punt_redirect.hpp"
17 #include "vom/ip_punt_redirect_cmds.hpp"
18 #include "vom/singular_db_funcs.hpp"
22 * A DB of all IP Punt configs
24 singular_db<ip_punt_redirect::key_t, ip_punt_redirect> ip_punt_redirect::m_db;
26 ip_punt_redirect::event_handler ip_punt_redirect::m_evh;
28 ip_punt_redirect::ip_punt_redirect(const interface& rx_itf,
29 const interface& tx_itf,
30 const boost::asio::ip::address& addr)
31 : m_rx_itf(rx_itf.singular())
32 , m_tx_itf(tx_itf.singular())
37 ip_punt_redirect::ip_punt_redirect(const ip_punt_redirect& o)
38 : m_rx_itf(o.m_rx_itf)
39 , m_tx_itf(o.m_tx_itf)
41 , m_config(o.m_config)
45 ip_punt_redirect::~ip_punt_redirect()
49 // not in the DB anymore.
50 m_db.release(m_rx_itf->key(), this);
54 ip_punt_redirect::sweep()
57 HW::enqueue(new ip_punt_redirect_cmds::unconfig_cmd(
58 m_config, m_rx_itf->handle(), m_tx_itf->handle(), m_addr));
64 ip_punt_redirect::dump(std::ostream& os)
70 ip_punt_redirect::replay()
73 HW::enqueue(new ip_punt_redirect_cmds::config_cmd(
74 m_config, m_rx_itf->handle(), m_tx_itf->handle(), m_addr));
79 ip_punt_redirect::to_string() const
82 s << "IP-punt-redirect-config:"
83 << " rx-itf:" << m_rx_itf->to_string()
84 << " tx-itf:" << m_tx_itf->to_string() << " next-hop:" << m_addr;
90 ip_punt_redirect::update(const ip_punt_redirect& desired)
93 HW::enqueue(new ip_punt_redirect_cmds::config_cmd(
94 m_config, m_rx_itf->handle(), m_tx_itf->handle(), m_addr));
98 std::shared_ptr<ip_punt_redirect>
99 ip_punt_redirect::find_or_add(const ip_punt_redirect& temp)
101 return (m_db.find_or_add(temp.m_rx_itf->key(), temp));
104 std::shared_ptr<ip_punt_redirect>
105 ip_punt_redirect::singular() const
107 return find_or_add(*this);
110 ip_punt_redirect::event_handler::event_handler()
112 OM::register_listener(this);
113 inspect::register_handler({ "ip-punt-redirect" },
114 "IP punt redirect configurations", this);
118 ip_punt_redirect::event_handler::handle_replay()
124 ip_punt_redirect::event_handler::handle_populate(const client_db::key_t& key)
129 ip_punt_redirect::event_handler::order() const
131 return (dependency_t::BINDING);
135 ip_punt_redirect::event_handler::show(std::ostream& os)
142 * fd.io coding-style-patch-verification: ON
145 * eval: (c-set-style "mozilla")