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/bond_group_binding.hpp"
17 #include "vom/bond_group_binding_cmds.hpp"
22 * A DB of all bond interface binding
24 singular_db<bond_group_binding::key_t, bond_group_binding>
25 bond_group_binding::m_db;
27 bond_group_binding::event_handler bond_group_binding::m_evh;
29 bond_group_binding::bond_group_binding(const bond_interface& itf,
30 const enslaved_itf_t& itfs)
31 : m_itf(itf.singular())
37 bond_group_binding::bond_group_binding(const bond_group_binding& o)
39 , m_mem_itfs(o.m_mem_itfs)
40 , m_binding(o.m_binding)
44 bond_group_binding::~bond_group_binding()
48 // not in the DB anymore.
49 m_db.release(key(), this);
52 const bond_group_binding::key_t
53 bond_group_binding::key() const
55 return (m_itf->key() + "-binding");
59 bond_group_binding::sweep()
62 auto it = m_mem_itfs.cbegin();
63 while (it != m_mem_itfs.cend()) {
66 new bond_group_binding_cmds::unbind_cmd(m_binding, it->hdl()));
74 bond_group_binding::dump(std::ostream& os)
80 bond_group_binding::replay()
82 auto it = m_mem_itfs.cbegin();
83 while (it != m_mem_itfs.cend()) {
86 new bond_group_binding_cmds::bind_cmd(m_binding, m_itf->handle(), *it));
94 bond_group_binding::to_string() const
96 auto it = m_mem_itfs.cbegin();
98 s << "bond-interface-binding: " << m_itf->to_string() << " slave-itfs: [";
99 while (it != m_mem_itfs.cend()) {
100 s << " " << it->to_string();
108 bond_group_binding::update(const bond_group_binding& desired)
111 * the desired state is always that the interface should be created
113 auto it = m_mem_itfs.cbegin();
114 while (it != m_mem_itfs.cend()) {
117 new bond_group_binding_cmds::bind_cmd(m_binding, m_itf->handle(), *it));
123 std::shared_ptr<bond_group_binding>
124 bond_group_binding::find_or_add(const bond_group_binding& temp)
126 return (m_db.find_or_add(temp.key(), temp));
129 std::shared_ptr<bond_group_binding>
130 bond_group_binding::singular() const
132 return find_or_add(*this);
135 bond_group_binding::event_handler::event_handler()
137 OM::register_listener(this);
138 inspect::register_handler({ "bond-intf-binding" }, "Bond interface binding",
143 bond_group_binding::event_handler::handle_replay()
149 bond_group_binding::event_handler::handle_populate(const client_db::key_t& key)
152 * handle it in interface class
157 bond_group_binding::event_handler::order() const
160 * We want enslaved interfaces bind to bond after interface
161 * but before anything else.
163 return (dependency_t::BOND_BINDING);
167 bond_group_binding::event_handler::show(std::ostream& os)
173 * fd.io coding-style-patch-verification: ON
176 * eval: (c-set-style "mozilla")