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_emulation.hpp"
17 #include "vom/l2_emulation_cmds.hpp"
18 #include "vom/singular_db_funcs.hpp"
22 * A DB of all the L2 Configs
24 singular_db<l2_emulation::key_t, l2_emulation> l2_emulation::m_db;
26 l2_emulation::event_handler l2_emulation::m_evh;
29 * Construct a new object matching the desried state
31 l2_emulation::l2_emulation(const interface& itf)
32 : m_itf(itf.singular())
37 l2_emulation::l2_emulation(const l2_emulation& o)
43 const l2_emulation::key_t&
44 l2_emulation::key() const
46 return (m_itf->key());
50 l2_emulation::operator==(const l2_emulation& l) const
52 return ((*m_itf == *l.m_itf));
55 std::shared_ptr<l2_emulation>
56 l2_emulation::find(const key_t& key)
58 return (m_db.find(key));
64 if (m_emulation && handle_t::INVALID != m_itf->handle()) {
66 new l2_emulation_cmds::disable_cmd(m_emulation, m_itf->handle()));
69 // no need to undo the VTR operation.
74 l2_emulation::replay()
76 if (m_emulation && handle_t::INVALID != m_itf->handle()) {
78 new l2_emulation_cmds::enable_cmd(m_emulation, m_itf->handle()));
82 l2_emulation::~l2_emulation()
86 // not in the DB anymore.
87 m_db.release(m_itf->key(), this);
91 l2_emulation::to_string() const
94 s << "L2-emulation:[" << m_itf->to_string() << "]";
100 l2_emulation::update(const l2_emulation& desired)
103 * the desired state is always that the interface should be created
105 if (rc_t::OK != m_emulation.rc()) {
107 new l2_emulation_cmds::enable_cmd(m_emulation, m_itf->handle()));
111 std::shared_ptr<l2_emulation>
112 l2_emulation::find_or_add(const l2_emulation& temp)
114 return (m_db.find_or_add(temp.m_itf->key(), temp));
117 std::shared_ptr<l2_emulation>
118 l2_emulation::singular() const
120 return find_or_add(*this);
124 l2_emulation::dump(std::ostream& os)
129 l2_emulation::event_handler::event_handler()
131 OM::register_listener(this);
132 inspect::register_handler({ "l2e" }, "L2 Emulation", this);
136 l2_emulation::event_handler::handle_replay()
142 l2_emulation::event_handler::handle_populate(const client_db::key_t& key)
145 * This is done while populating the bridge-domain
150 l2_emulation::event_handler::order() const
152 return (dependency_t::BINDING);
156 l2_emulation::event_handler::show(std::ostream& os)
163 * fd.io coding-style-patch-verification: ON
166 * eval: (c-set-style "mozilla")