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"
21 * A DB of all LLDP configs
23 singular_db<interface::key_type, lldp_binding> lldp_binding::m_db;
25 lldp_binding::event_handler lldp_binding::m_evh;
27 lldp_binding::lldp_binding(const interface& itf, const std::string& port_desc)
28 : m_itf(itf.singular())
29 , m_port_desc(port_desc)
34 lldp_binding::lldp_binding(const lldp_binding& o)
36 , m_port_desc(o.m_port_desc)
41 lldp_binding::~lldp_binding()
45 // not in the DB anymore.
46 m_db.release(m_itf->key(), this);
53 HW::enqueue(new lldp_binding_cmds::unbind_cmd(m_binding, m_itf->handle()));
59 lldp_binding::dump(std::ostream& os)
65 lldp_binding::replay()
69 new lldp_binding_cmds::bind_cmd(m_binding, m_itf->handle(), m_port_desc));
74 lldp_binding::to_string() const
77 s << "Lldp-binding: " << m_itf->to_string() << " port_desc:" << m_port_desc
78 << " " << m_binding.to_string();
84 lldp_binding::update(const lldp_binding& desired)
87 * the desired state is always that the interface should be created
91 new lldp_binding_cmds::bind_cmd(m_binding, m_itf->handle(), m_port_desc));
95 std::shared_ptr<lldp_binding>
96 lldp_binding::find_or_add(const lldp_binding& temp)
98 return (m_db.find_or_add(temp.m_itf->key(), temp));
101 std::shared_ptr<lldp_binding>
102 lldp_binding::singular() const
104 return find_or_add(*this);
107 lldp_binding::event_handler::event_handler()
109 OM::register_listener(this);
110 inspect::register_handler({ "lldp" }, "LLDP bindings", this);
114 lldp_binding::event_handler::handle_replay()
120 lldp_binding::event_handler::handle_populate(const client_db::key_t& key)
126 lldp_binding::event_handler::order() const
128 return (dependency_t::BINDING);
132 lldp_binding::event_handler::show(std::ostream& os)
139 * fd.io coding-style-patch-verification: ON
142 * eval: (c-set-style "mozilla")