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"
18 #include "vom/singular_db_funcs.hpp"
23 * A DB of all bond interface binding
25 singular_db<bond_group_binding::key_t, bond_group_binding>
26 bond_group_binding::m_db;
28 bond_group_binding::event_handler bond_group_binding::m_evh;
30 bond_group_binding::bond_group_binding(const bond_interface& itf,
31 const enslaved_itf_t& itfs)
32 : m_itf(itf.singular())
38 bond_group_binding::bond_group_binding(const bond_group_binding& o)
40 , m_mem_itfs(o.m_mem_itfs)
41 , m_binding(o.m_binding)
45 bond_group_binding::~bond_group_binding()
49 // not in the DB anymore.
50 m_db.release(key(), this);
53 const bond_group_binding::key_t
54 bond_group_binding::key() const
56 return (m_itf->key() + "-binding");
60 bond_group_binding::sweep()
63 auto it = m_mem_itfs.cbegin();
64 while (it != m_mem_itfs.cend()) {
67 new bond_group_binding_cmds::unbind_cmd(m_binding, it->hdl()));
75 bond_group_binding::dump(std::ostream& os)
81 bond_group_binding::replay()
83 auto it = m_mem_itfs.cbegin();
84 while (it != m_mem_itfs.cend()) {
87 new bond_group_binding_cmds::bind_cmd(m_binding, m_itf->handle(), *it));
95 bond_group_binding::to_string() const
97 auto it = m_mem_itfs.cbegin();
99 s << "bond-interface-binding: " << m_itf->to_string() << " slave-itfs: [";
100 while (it != m_mem_itfs.cend()) {
101 s << " " << it->to_string();
109 bond_group_binding::update(const bond_group_binding& desired)
112 * the desired state is always that the interface should be created
114 auto it = m_mem_itfs.cbegin();
115 while (it != m_mem_itfs.cend()) {
118 new bond_group_binding_cmds::bind_cmd(m_binding, m_itf->handle(), *it));
124 std::shared_ptr<bond_group_binding>
125 bond_group_binding::find_or_add(const bond_group_binding& temp)
127 return (m_db.find_or_add(temp.key(), temp));
130 std::shared_ptr<bond_group_binding>
131 bond_group_binding::singular() const
133 return find_or_add(*this);
136 bond_group_binding::event_handler::event_handler()
138 OM::register_listener(this);
139 inspect::register_handler({ "bond-intf-binding" }, "Bond interface binding",
144 bond_group_binding::event_handler::handle_replay()
150 bond_group_binding::event_handler::handle_populate(const client_db::key_t& key)
153 * handle it in interface class
158 bond_group_binding::event_handler::order() const
161 * We want enslaved interfaces bind to bond after interface
162 * but before anything else.
164 return (dependency_t::VIRTUAL_INTERFACE);
168 bond_group_binding::event_handler::show(std::ostream& os)
174 * fd.io coding-style-patch-verification: ON
177 * eval: (c-set-style "mozilla")