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/lldp_binding.hpp"
17 #include "vom/lldp_binding_cmds.hpp"
18 #include "vom/singular_db_funcs.hpp"
22 * A DB of all LLDP configs
24 singular_db<interface::key_t, lldp_binding> lldp_binding::m_db;
26 lldp_binding::event_handler lldp_binding::m_evh;
28 lldp_binding::lldp_binding(const interface& itf, const std::string& port_desc)
29 : m_itf(itf.singular())
30 , m_port_desc(port_desc)
35 lldp_binding::lldp_binding(const lldp_binding& o)
37 , m_port_desc(o.m_port_desc)
42 lldp_binding::~lldp_binding()
46 // not in the DB anymore.
47 m_db.release(m_itf->key(), this);
51 lldp_binding::operator==(const lldp_binding& l) const
53 return ((key() == l.key()) && (m_port_desc == l.m_port_desc));
56 const lldp_binding::key_t&
57 lldp_binding::key() const
59 return (m_itf->key());
66 HW::enqueue(new lldp_binding_cmds::unbind_cmd(m_binding, m_itf->handle()));
72 lldp_binding::dump(std::ostream& os)
78 lldp_binding::replay()
82 new lldp_binding_cmds::bind_cmd(m_binding, m_itf->handle(), m_port_desc));
87 lldp_binding::to_string() const
90 s << "Lldp-binding: " << m_itf->to_string() << " port_desc:" << m_port_desc
91 << " " << m_binding.to_string();
97 lldp_binding::update(const lldp_binding& desired)
100 * the desired state is always that the interface should be created
104 new lldp_binding_cmds::bind_cmd(m_binding, m_itf->handle(), m_port_desc));
108 std::shared_ptr<lldp_binding>
109 lldp_binding::find_or_add(const lldp_binding& temp)
111 return (m_db.find_or_add(temp.m_itf->key(), temp));
114 std::shared_ptr<lldp_binding>
115 lldp_binding::find(const key_t& k)
117 return (m_db.find(k));
120 std::shared_ptr<lldp_binding>
121 lldp_binding::singular() const
123 return find_or_add(*this);
126 lldp_binding::event_handler::event_handler()
128 OM::register_listener(this);
129 inspect::register_handler({ "lldp" }, "LLDP bindings", this);
133 lldp_binding::event_handler::handle_replay()
139 lldp_binding::event_handler::handle_populate(const client_db::key_t& key)
145 lldp_binding::event_handler::order() const
147 return (dependency_t::BINDING);
151 lldp_binding::event_handler::show(std::ostream& os)
158 * fd.io coding-style-patch-verification: ON
161 * eval: (c-set-style "mozilla")