diff options
Diffstat (limited to 'src/vpp-api')
-rw-r--r-- | src/vpp-api/vom/Makefile.am | 3 | ||||
-rw-r--r-- | src/vpp-api/vom/bridge_domain.cpp | 2 | ||||
-rw-r--r-- | src/vpp-api/vom/l2_emulation.cpp | 167 | ||||
-rw-r--r-- | src/vpp-api/vom/l2_emulation.hpp | 180 | ||||
-rw-r--r-- | src/vpp-api/vom/l2_emulation_cmds.cpp | 107 | ||||
-rw-r--r-- | src/vpp-api/vom/l2_emulation_cmds.hpp | 102 |
6 files changed, 560 insertions, 1 deletions
diff --git a/src/vpp-api/vom/Makefile.am b/src/vpp-api/vom/Makefile.am index 8eab140896a..b1fbfeedb35 100644 --- a/src/vpp-api/vom/Makefile.am +++ b/src/vpp-api/vom/Makefile.am @@ -72,6 +72,8 @@ libvom_la_SOURCES = \ ip_unnumbered.cpp \ l2_binding_cmds.cpp \ l2_binding.cpp \ + l2_emulation_cmds.cpp \ + l2_emulation.cpp \ l3_binding_cmds.cpp \ l3_binding.cpp \ lldp_binding_cmds.cpp \ @@ -130,6 +132,7 @@ vominclude_HEADERS = \ interface_span.hpp \ ip_unnumbered.hpp \ l2_binding.hpp \ + l2_emulation.hpp \ l3_binding.hpp \ lldp_binding.hpp \ lldp_global.hpp \ diff --git a/src/vpp-api/vom/bridge_domain.cpp b/src/vpp-api/vom/bridge_domain.cpp index ef737d971bc..17144a67ca9 100644 --- a/src/vpp-api/vom/bridge_domain.cpp +++ b/src/vpp-api/vom/bridge_domain.cpp @@ -67,7 +67,7 @@ bridge_domain::id() const bool bridge_domain::operator==(const bridge_domain& b) const { - return (id() == b.id()); + return ((m_learning_mode == b.m_learning_mode) && id() == b.id()); } void diff --git a/src/vpp-api/vom/l2_emulation.cpp b/src/vpp-api/vom/l2_emulation.cpp new file mode 100644 index 00000000000..2a2757616be --- /dev/null +++ b/src/vpp-api/vom/l2_emulation.cpp @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "vom/l2_emulation.hpp" +#include "vom/l2_emulation_cmds.hpp" + +namespace VOM { +/** + * A DB of all the L2 Configs + */ +singular_db<l2_emulation::key_t, l2_emulation> l2_emulation::m_db; + +l2_emulation::event_handler l2_emulation::m_evh; + +/** + * Construct a new object matching the desried state + */ +l2_emulation::l2_emulation(const interface& itf) + : m_itf(itf.singular()) + , m_emulation(0) +{ +} + +l2_emulation::l2_emulation(const l2_emulation& o) + : m_itf(o.m_itf) + , m_emulation(0) +{ +} + +const l2_emulation::key_t& +l2_emulation::key() const +{ + return (m_itf->key()); +} + +bool +l2_emulation::operator==(const l2_emulation& l) const +{ + return ((*m_itf == *l.m_itf)); +} + +std::shared_ptr<l2_emulation> +l2_emulation::find(const key_t& key) +{ + return (m_db.find(key)); +} + +void +l2_emulation::sweep() +{ + if (m_emulation && handle_t::INVALID != m_itf->handle()) { + HW::enqueue( + new l2_emulation_cmds::enable_cmd(m_emulation, m_itf->handle())); + } + + // no need to undo the VTR operation. + HW::write(); +} + +void +l2_emulation::replay() +{ + if (m_emulation && handle_t::INVALID != m_itf->handle()) { + HW::enqueue( + new l2_emulation_cmds::disable_cmd(m_emulation, m_itf->handle())); + } +} + +l2_emulation::~l2_emulation() +{ + sweep(); + + // not in the DB anymore. + m_db.release(m_itf->key(), this); +} + +std::string +l2_emulation::to_string() const +{ + std::ostringstream s; + s << "L2-emulation:[" << m_itf->to_string() << "]"; + + return (s.str()); +} + +void +l2_emulation::update(const l2_emulation& desired) +{ + /* + * the desired state is always that the interface should be created + */ + if (rc_t::OK != m_emulation.rc()) { + HW::enqueue( + new l2_emulation_cmds::enable_cmd(m_emulation, m_itf->handle())); + } +} + +std::shared_ptr<l2_emulation> +l2_emulation::find_or_add(const l2_emulation& temp) +{ + return (m_db.find_or_add(temp.m_itf->key(), temp)); +} + +std::shared_ptr<l2_emulation> +l2_emulation::singular() const +{ + return find_or_add(*this); +} + +void +l2_emulation::dump(std::ostream& os) +{ + m_db.dump(os); +} + +l2_emulation::event_handler::event_handler() +{ + OM::register_listener(this); + inspect::register_handler({ "l2e" }, "L2 Emulation", this); +} + +void +l2_emulation::event_handler::handle_replay() +{ + m_db.replay(); +} + +void +l2_emulation::event_handler::handle_populate(const client_db::key_t& key) +{ + /** + * This is done while populating the bridge-domain + */ +} + +dependency_t +l2_emulation::event_handler::order() const +{ + return (dependency_t::BINDING); +} + +void +l2_emulation::event_handler::show(std::ostream& os) +{ + m_db.dump(os); +} +} + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "mozilla") + * End: + */ diff --git a/src/vpp-api/vom/l2_emulation.hpp b/src/vpp-api/vom/l2_emulation.hpp new file mode 100644 index 00000000000..faf4df8b0a7 --- /dev/null +++ b/src/vpp-api/vom/l2_emulation.hpp @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __VOM_L2_EMULATION_H__ +#define __VOM_L2_EMULATION_H__ + +#include "vom/bridge_domain.hpp" +#include "vom/hw.hpp" +#include "vom/inspect.hpp" +#include "vom/interface.hpp" +#include "vom/object_base.hpp" +#include "vom/om.hpp" +#include "vom/singular_db.hpp" + +namespace VOM { +/** + * A Clas representing the binding of an L2 interface to a bridge-domain + * and the properties of that binding. + */ +class l2_emulation : public object_base +{ +public: + /** + * Key type for an L2 emulation in the singular DB + */ + typedef interface::key_t key_t; + + /** + * Construct a new object matching the desried state + */ + l2_emulation(const interface& itf); + + /** + * Copy Constructor + */ + l2_emulation(const l2_emulation& o); + + /** + * Destructor + */ + ~l2_emulation(); + + /** + * Return the binding's key + */ + const key_t& key() const; + + /** + * Comparison operator - for UT + */ + bool operator==(const l2_emulation& l) const; + + /** + * Return the 'singular instance' of the L2 config that matches this + * object + */ + std::shared_ptr<l2_emulation> singular() const; + + /** + * convert to string format for debug purposes + */ + std::string to_string() const; + + /** + * Dump all l2_emulations into the stream provided + */ + static void dump(std::ostream& os); + + /** + * Static function to find the bridge_domain in the model + */ + static std::shared_ptr<l2_emulation> find(const key_t& key); + +private: + /** + * Class definition for listeners to OM events + */ + class event_handler : public OM::listener, public inspect::command_handler + { + public: + event_handler(); + virtual ~event_handler() = default; + + /** + * Handle a populate event + */ + void handle_populate(const client_db::key_t& key); + + /** + * Handle a replay event + */ + void handle_replay(); + + /** + * Show the object in the Singular DB + */ + void show(std::ostream& os); + + /** + * Get the sortable Id of the listener + */ + dependency_t order() const; + }; + + /** + * event_handler to register with OM + */ + static event_handler m_evh; + + /** + * Enquue commonds to the VPP command Q for the update + */ + void update(const l2_emulation& obj); + + /** + * Find or Add the singular instance in the DB + */ + static std::shared_ptr<l2_emulation> find_or_add(const l2_emulation& temp); + + /* + * It's the OM class that calls singular() + */ + friend class OM; + + /** + * It's the singular_db class that calls replay() + */ + friend class singular_db<key_t, l2_emulation>; + + /** + * Sweep/reap the object if still stale + */ + void sweep(void); + + /** + * replay the object to create it in hardware + */ + void replay(void); + + /** + * A reference counting pointer the interface that this L2 layer + * represents. By holding the reference here, we can guarantee that + * this object will outlive the interface + */ + const std::shared_ptr<interface> m_itf; + + /** + * HW configuration for the emulation. The bool representing the + * enable/disable. + */ + HW::item<bool> m_emulation; + + /** + * A map of all L2 emulation configurations + */ + static singular_db<key_t, l2_emulation> m_db; +}; +}; + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "mozilla") + * End: + */ + +#endif diff --git a/src/vpp-api/vom/l2_emulation_cmds.cpp b/src/vpp-api/vom/l2_emulation_cmds.cpp new file mode 100644 index 00000000000..07107d6ff58 --- /dev/null +++ b/src/vpp-api/vom/l2_emulation_cmds.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "vom/l2_emulation_cmds.hpp" + +DEFINE_VAPI_MSG_IDS_L2E_API_JSON; + +namespace VOM { +namespace l2_emulation_cmds { +enable_cmd::enable_cmd(HW::item<bool>& item, const handle_t& itf) + : rpc_cmd(item) + , m_itf(itf) +{ +} + +bool +enable_cmd::operator==(const enable_cmd& other) const +{ + return (m_itf == other.m_itf); +} + +rc_t +enable_cmd::issue(connection& con) +{ + msg_t req(con.ctx(), std::ref(*this)); + + auto& payload = req.get_request().get_payload(); + payload.sw_if_index = m_itf.value(); + payload.enable = 1; + + VAPI_CALL(req.execute()); + + m_hw_item.set(wait()); + + return (rc_t::OK); +} + +std::string +enable_cmd::to_string() const +{ + std::ostringstream s; + s << "L2-emulation: " << m_hw_item.to_string() + << " itf:" << m_itf.to_string(); + + return (s.str()); +} + +disable_cmd::disable_cmd(HW::item<bool>& item, const handle_t& itf) + : rpc_cmd(item) + , m_itf(itf) +{ +} + +bool +disable_cmd::operator==(const disable_cmd& other) const +{ + return (m_itf == other.m_itf); +} + +rc_t +disable_cmd::issue(connection& con) +{ + msg_t req(con.ctx(), std::ref(*this)); + + auto& payload = req.get_request().get_payload(); + payload.sw_if_index = m_itf.value(); + payload.enable = 0; + + VAPI_CALL(req.execute()); + + wait(); + + return (rc_t::OK); +} + +std::string +disable_cmd::to_string() const +{ + std::ostringstream s; + s << "L2-emulation: " << m_hw_item.to_string() + << " itf:" << m_itf.to_string(); + + return (s.str()); +} + +}; // namespace l2_emulation_cmds +}; // namespace VOM + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "mozilla") + * End: + */ diff --git a/src/vpp-api/vom/l2_emulation_cmds.hpp b/src/vpp-api/vom/l2_emulation_cmds.hpp new file mode 100644 index 00000000000..aeff3a8ddd7 --- /dev/null +++ b/src/vpp-api/vom/l2_emulation_cmds.hpp @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __VOM_L2_EMULATION_CMDS_H__ +#define __VOM_L2_EMULATION_CMDS_H__ + +#include "vom/l2_emulation.hpp" +#include "vom/rpc_cmd.hpp" + +#include <vapi/l2e.api.vapi.hpp> + +namespace VOM { +namespace l2_emulation_cmds { + +/** + * A functor class that enable L2 emulation to an interface + */ +class enable_cmd : public rpc_cmd<HW::item<bool>, rc_t, vapi::L2_emulation> +{ +public: + /** + * Constructor + */ + enable_cmd(HW::item<bool>& item, const handle_t& itf); + + /** + * Issue the command to VPP/HW + */ + rc_t issue(connection& con); + /** + * convert to string format for debug purposes + */ + std::string to_string() const; + + /** + * Comparison operator - only used for UT + */ + bool operator==(const enable_cmd& i) const; + +private: + /** + * The interface to bind + */ + const handle_t m_itf; +}; + +/** + * A cmd class that Unbinds L2 configuration from an interface + */ +class disable_cmd : public rpc_cmd<HW::item<bool>, rc_t, vapi::L2_emulation> +{ +public: + /** + * Constructor + */ + disable_cmd(HW::item<bool>& item, const handle_t& itf); + + /** + * Issue the command to VPP/HW + */ + rc_t issue(connection& con); + /** + * convert to string format for debug purposes + */ + std::string to_string() const; + + /** + * Comparison operator - only used for UT + */ + bool operator==(const disable_cmd& i) const; + +private: + /** + * The interface to bind + */ + const handle_t m_itf; +}; + +}; // namespace l2_emulation_cmds +}; // namespace VOM + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "mozilla") + * End: + */ + +#endif |