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"
20 #include "vom/singular_db_funcs.hpp"
24 const bridge_domain::learning_mode_t bridge_domain::learning_mode_t::ON(1,
26 const bridge_domain::learning_mode_t bridge_domain::learning_mode_t::OFF(0,
29 bridge_domain::learning_mode_t::learning_mode_t(int v, const std::string& s)
30 : enum_base<bridge_domain::learning_mode_t>(v, s)
35 * A DB of al the interfaces, key on the name
37 singular_db<uint32_t, bridge_domain> bridge_domain::m_db;
39 bridge_domain::event_handler bridge_domain::m_evh;
42 * Construct a new object matching the desried state
44 bridge_domain::bridge_domain(uint32_t id, const learning_mode_t& lmode)
46 , m_learning_mode(lmode)
50 bridge_domain::bridge_domain(const bridge_domain& o)
52 , m_learning_mode(o.m_learning_mode)
56 const bridge_domain::key_t&
57 bridge_domain::key() const
63 bridge_domain::id() const
69 bridge_domain::operator==(const bridge_domain& b) const
71 return ((m_learning_mode == b.m_learning_mode) && id() == b.id());
75 bridge_domain::sweep()
77 if (rc_t::OK == m_id.rc()) {
78 HW::enqueue(new bridge_domain_cmds::delete_cmd(m_id));
84 bridge_domain::replay()
86 if (rc_t::OK == m_id.rc()) {
87 HW::enqueue(new bridge_domain_cmds::create_cmd(m_id, m_learning_mode));
91 bridge_domain::~bridge_domain()
95 // not in the DB anymore.
96 m_db.release(m_id.data(), this);
100 bridge_domain::to_string() const
102 std::ostringstream s;
103 s << "bridge-domain:[" << m_id.to_string()
104 << " learning-mode:" << m_learning_mode.to_string() << "]";
109 std::shared_ptr<bridge_domain>
110 bridge_domain::find(const key_t& key)
112 return (m_db.find(key));
116 bridge_domain::update(const bridge_domain& desired)
119 * the desired state is always that the interface should be created
121 if (rc_t::OK != m_id.rc()) {
122 HW::enqueue(new bridge_domain_cmds::create_cmd(m_id, m_learning_mode));
126 std::shared_ptr<bridge_domain>
127 bridge_domain::find_or_add(const bridge_domain& temp)
129 return (m_db.find_or_add(temp.m_id.data(), temp));
132 std::shared_ptr<bridge_domain>
133 bridge_domain::singular() const
135 return find_or_add(*this);
139 bridge_domain::dump(std::ostream& os)
145 bridge_domain::event_handler::handle_populate(const client_db::key_t& key)
148 * dump VPP Bridge domains
150 std::shared_ptr<bridge_domain_cmds::dump_cmd> cmd =
151 std::make_shared<bridge_domain_cmds::dump_cmd>();
156 for (auto& record : *cmd) {
157 auto& payload = record.get_payload();
159 bridge_domain bd(payload.bd_id);
161 VOM_LOG(log_level_t::DEBUG) << "dump: " << bd.to_string();
164 * Write each of the discovered bridge-domains into the OM,
165 * but disable the HW Command q whilst we do, so that no
166 * commands are sent to VPP
171 * For each interface in the BD construct an l2_binding
173 for (unsigned int ii = 0; ii < payload.n_sw_ifs; ii++) {
174 std::shared_ptr<interface> itf =
175 interface::find(payload.sw_if_details[ii].sw_if_index);
176 l2_binding l2(*itf, bd);
182 bridge_domain::event_handler::event_handler()
184 OM::register_listener(this);
185 inspect::register_handler({ "bd", "bridge" }, "Bridge Domains", this);
189 bridge_domain::event_handler::handle_replay()
195 bridge_domain::event_handler::order() const
197 return (dependency_t::TABLE);
201 bridge_domain::event_handler::show(std::ostream& os)
208 * fd.io coding-style-patch-verification: ON
211 * eval: (c-set-style "mozilla")