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/bridge_domain.hpp"
17 #include "vom/bridge_domain_cmds.hpp"
18 #include "vom/interface.hpp"
19 #include "vom/l2_binding.hpp"
23 * A DB of al the interfaces, key on the name
25 singular_db<uint32_t, bridge_domain> bridge_domain::m_db;
27 bridge_domain::event_handler bridge_domain::m_evh;
30 * Construct a new object matching the desried state
32 bridge_domain::bridge_domain(uint32_t id)
37 bridge_domain::bridge_domain(const bridge_domain& o)
43 bridge_domain::id() const
49 bridge_domain::sweep()
51 if (rc_t::OK == m_id.rc()) {
52 HW::enqueue(new bridge_domain_cmds::delete_cmd(m_id));
58 bridge_domain::replay()
60 if (rc_t::OK == m_id.rc()) {
61 HW::enqueue(new bridge_domain_cmds::create_cmd(m_id));
65 bridge_domain::~bridge_domain()
69 // not in the DB anymore.
70 m_db.release(m_id.data(), this);
74 bridge_domain::to_string() const
77 s << "bridge-domain:[" << m_id.to_string() << "]";
82 std::shared_ptr<bridge_domain>
83 bridge_domain::find(uint32_t id)
86 * Loop throught the entire map looking for matching interface.
87 * not the most efficient algorithm, but it will do for now. The
88 * number of L3 configs is low and this is only called during bootup
90 std::shared_ptr<bridge_domain> bd;
92 auto it = m_db.cbegin();
94 while (it != m_db.cend()) {
96 * The key in the DB is a pair of the interface's name and prefix.
97 * If the keys match, save the L3-config
102 bd = it->second.lock();
113 bridge_domain::update(const bridge_domain& desired)
116 * the desired state is always that the interface should be created
118 if (rc_t::OK != m_id.rc()) {
119 HW::enqueue(new bridge_domain_cmds::create_cmd(m_id));
123 std::shared_ptr<bridge_domain>
124 bridge_domain::find_or_add(const bridge_domain& temp)
126 return (m_db.find_or_add(temp.m_id.data(), temp));
129 std::shared_ptr<bridge_domain>
130 bridge_domain::singular() const
132 return find_or_add(*this);
136 bridge_domain::dump(std::ostream& os)
142 bridge_domain::event_handler::handle_populate(const client_db::key_t& key)
145 * dump VPP Bridge domains
147 std::shared_ptr<bridge_domain_cmds::dump_cmd> cmd(
148 new bridge_domain_cmds::dump_cmd());
153 for (auto& record : *cmd) {
154 auto& payload = record.get_payload();
156 bridge_domain bd(payload.bd_id);
158 VOM_LOG(log_level_t::DEBUG) << "dump: " << bd.to_string();
161 * Write each of the discovered interfaces into the OM,
162 * but disable the HW Command q whilst we do, so that no
163 * commands are sent to VPP
168 * For each interface in the BD construct an l2_binding
170 for (unsigned int ii = 0; ii < payload.n_sw_ifs; ii++) {
171 std::shared_ptr<interface> itf =
172 interface::find(payload.sw_if_details[ii].sw_if_index);
173 l2_binding l2(*itf, bd);
179 bridge_domain::event_handler::event_handler()
181 OM::register_listener(this);
182 inspect::register_handler({ "bd", "bridge" }, "Bridge Domains", this);
186 bridge_domain::event_handler::handle_replay()
192 bridge_domain::event_handler::order() const
194 return (dependency_t::TABLE);
198 bridge_domain::event_handler::show(std::ostream& os)
205 * fd.io coding-style-patch-verification: ON
208 * eval: (c-set-style "mozilla")