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/l2_binding.hpp"
17 #include "vom/l2_binding_cmds.hpp"
21 * A DB of all the L2 Configs
23 singular_db<const handle_t, l2_binding> l2_binding::m_db;
25 l2_binding::event_handler l2_binding::m_evh;
28 * Make sure these are in sync with the smae enum in VPP
30 const l2_binding::l2_vtr_op_t l2_binding::l2_vtr_op_t::L2_VTR_DISABLED(
33 const l2_binding::l2_vtr_op_t l2_binding::l2_vtr_op_t::L2_VTR_PUSH_1(1,
35 const l2_binding::l2_vtr_op_t l2_binding::l2_vtr_op_t::L2_VTR_PUSH_2(2,
37 const l2_binding::l2_vtr_op_t l2_binding::l2_vtr_op_t::L2_VTR_POP_1(3, "pop-1");
38 const l2_binding::l2_vtr_op_t l2_binding::l2_vtr_op_t::L2_VTR_POP_2(4, "pop-2");
39 const l2_binding::l2_vtr_op_t l2_binding::l2_vtr_op_t::L2_VTR_TRANSLATE_1_1(
42 const l2_binding::l2_vtr_op_t l2_binding::l2_vtr_op_t::L2_VTR_TRANSLATE_1_2(
45 const l2_binding::l2_vtr_op_t l2_binding::l2_vtr_op_t::L2_VTR_TRANSLATE_2_1(
48 const l2_binding::l2_vtr_op_t l2_binding::l2_vtr_op_t::L2_VTR_TRANSLATE_2_2(
52 l2_binding::l2_vtr_op_t::l2_vtr_op_t(int v, const std::string s)
53 : enum_base<l2_binding::l2_vtr_op_t>(v, s)
58 * Construct a new object matching the desried state
60 l2_binding::l2_binding(const interface& itf, const bridge_domain& bd)
61 : m_itf(itf.singular())
64 , m_vtr_op(l2_vtr_op_t::L2_VTR_DISABLED, rc_t::UNSET)
69 l2_binding::l2_binding(const l2_binding& o)
73 , m_vtr_op(o.m_vtr_op)
74 , m_vtr_op_tag(o.m_vtr_op_tag)
81 if (m_binding && handle_t::INVALID != m_itf->handle()) {
83 new l2_binding_cmds::unbind_cmd(m_binding, m_itf->handle(), m_bd->id(),
84 interface::type_t::BVI == m_itf->type()));
87 // no need to undo the VTR operation.
94 if (m_binding && handle_t::INVALID != m_itf->handle()) {
96 new l2_binding_cmds::bind_cmd(m_binding, m_itf->handle(), m_bd->id(),
97 interface::type_t::BVI == m_itf->type()));
100 if (m_vtr_op && handle_t::INVALID != m_itf->handle()) {
101 HW::enqueue(new l2_binding_cmds::set_vtr_op_cmd(m_vtr_op, m_itf->handle(),
106 l2_binding::~l2_binding()
110 // not in the DB anymore.
111 m_db.release(m_itf->handle(), this);
115 l2_binding::to_string() const
117 std::ostringstream s;
118 s << "L2-config:[" << m_itf->to_string() << " " << m_bd->to_string() << " "
119 << m_binding.to_string() << "]";
125 l2_binding::set(const l2_vtr_op_t& op, uint16_t tag)
127 assert(rc_t::UNSET == m_vtr_op.rc());
128 m_vtr_op.set(rc_t::NOOP);
134 l2_binding::update(const l2_binding& desired)
137 * the desired state is always that the interface should be created
139 if (rc_t::OK != m_binding.rc()) {
141 new l2_binding_cmds::bind_cmd(m_binding, m_itf->handle(), m_bd->id(),
142 interface::type_t::BVI == m_itf->type()));
146 * set the VTR operation is request
148 if (m_vtr_op.update(desired.m_vtr_op)) {
149 HW::enqueue(new l2_binding_cmds::set_vtr_op_cmd(m_vtr_op, m_itf->handle(),
154 std::shared_ptr<l2_binding>
155 l2_binding::find_or_add(const l2_binding& temp)
157 return (m_db.find_or_add(temp.m_itf->handle(), temp));
160 std::shared_ptr<l2_binding>
161 l2_binding::singular() const
163 return find_or_add(*this);
167 l2_binding::dump(std::ostream& os)
172 l2_binding::event_handler::event_handler()
174 OM::register_listener(this);
175 inspect::register_handler({ "l2" }, "L2 bindings", this);
179 l2_binding::event_handler::handle_replay()
185 l2_binding::event_handler::handle_populate(const client_db::key_t& key)
188 * This is done while populating the bridge-domain
193 l2_binding::event_handler::order() const
195 return (dependency_t::BINDING);
199 l2_binding::event_handler::show(std::ostream& os)
206 * fd.io coding-style-patch-verification: ON
209 * eval: (c-set-style "mozilla")