From 32f6d8e0ca39483f706dc3a1c28223e9fe028f06 Mon Sep 17 00:00:00 2001 From: Neale Ranns Date: Tue, 5 Mar 2019 04:22:08 -0800 Subject: [PATCH] GBP: per-group EP retention policy Change-Id: I3ed4e2e92f74f15b07fcd3e7fbc3fa8718d5249d Signed-off-by: Neale Ranns --- extras/vom/vom/CMakeLists.txt | 3 - extras/vom/vom/gbp_endpoint_group.cpp | 40 ++++++- extras/vom/vom/gbp_endpoint_group.hpp | 27 +++++ extras/vom/vom/gbp_endpoint_group_cmds.cpp | 6 +- extras/vom/vom/gbp_endpoint_group_cmds.hpp | 2 + extras/vom/vom/gbp_global.cpp | 155 ------------------------- extras/vom/vom/gbp_global.hpp | 180 ----------------------------- extras/vom/vom/gbp_global_cmds.cpp | 64 ---------- extras/vom/vom/gbp_global_cmds.hpp | 73 ------------ src/plugins/gbp/gbp.api | 18 +-- src/plugins/gbp/gbp_api.c | 31 +++-- src/plugins/gbp/gbp_endpoint.c | 35 ++---- src/plugins/gbp/gbp_endpoint.h | 1 - src/plugins/gbp/gbp_endpoint_group.c | 9 +- src/plugins/gbp/gbp_endpoint_group.h | 18 ++- src/plugins/gbp/gbp_learn.h | 2 - src/plugins/gbp/gbp_scanner.c | 7 +- test/test_gbp.py | 72 ++++++------ test/vpp_papi_provider.py | 11 +- 19 files changed, 164 insertions(+), 590 deletions(-) delete mode 100644 extras/vom/vom/gbp_global.cpp delete mode 100644 extras/vom/vom/gbp_global.hpp delete mode 100644 extras/vom/vom/gbp_global_cmds.cpp delete mode 100644 extras/vom/vom/gbp_global_cmds.hpp diff --git a/extras/vom/vom/CMakeLists.txt b/extras/vom/vom/CMakeLists.txt index b2f8ec6415d..26dd3e46574 100644 --- a/extras/vom/vom/CMakeLists.txt +++ b/extras/vom/vom/CMakeLists.txt @@ -87,8 +87,6 @@ if(GBP_FILE) gbp_endpoint_group.cpp gbp_ext_itf.cpp gbp_ext_itf_cmds.cpp - gbp_global.cpp - gbp_global_cmds.cpp gbp_recirc_cmds.cpp gbp_recirc.cpp gbp_route_domain_cmds.cpp @@ -218,7 +216,6 @@ if(GBP_FILE) gbp_endpoint.hpp gbp_endpoint_group.hpp gbp_ext_itf.hpp - gbp_global.hpp gbp_recirc.hpp gbp_route_domain.hpp gbp_rule.hpp diff --git a/extras/vom/vom/gbp_endpoint_group.cpp b/extras/vom/vom/gbp_endpoint_group.cpp index 44bdcdb3524..d549a067e67 100644 --- a/extras/vom/vom/gbp_endpoint_group.cpp +++ b/extras/vom/vom/gbp_endpoint_group.cpp @@ -24,6 +24,27 @@ singular_db gbp_endpoint_group::event_handler gbp_endpoint_group::m_evh; +gbp_endpoint_group::retention_t::retention_t() + : remote_ep_timeout(0xffffffff) +{ +} +gbp_endpoint_group::retention_t::retention_t(uint32_t remote_ep_timeout_) + : remote_ep_timeout(remote_ep_timeout_) +{ +} + +bool +gbp_endpoint_group::retention_t::operator==(const retention_t& o) const +{ + return (remote_ep_timeout == o.remote_ep_timeout); +} + +std::string +gbp_endpoint_group::retention_t::to_string() const +{ + return std::to_string(remote_ep_timeout); +} + gbp_endpoint_group::gbp_endpoint_group(epg_id_t epg_id, const interface& itf, const gbp_route_domain& rd, @@ -34,6 +55,7 @@ gbp_endpoint_group::gbp_endpoint_group(epg_id_t epg_id, , m_itf(itf.singular()) , m_rd(rd.singular()) , m_bd(bd.singular()) + , m_retention() { } @@ -46,6 +68,7 @@ gbp_endpoint_group::gbp_endpoint_group(epg_id_t epg_id, , m_itf() , m_rd(rd.singular()) , m_bd(bd.singular()) + , m_retention() { } @@ -60,6 +83,7 @@ gbp_endpoint_group::gbp_endpoint_group(epg_id_t epg_id, , m_itf(itf.singular()) , m_rd(rd.singular()) , m_bd(bd.singular()) + , m_retention() { } @@ -73,6 +97,7 @@ gbp_endpoint_group::gbp_endpoint_group(epg_id_t epg_id, , m_itf() , m_rd(rd.singular()) , m_bd(bd.singular()) + , m_retention() { } @@ -83,6 +108,7 @@ gbp_endpoint_group::gbp_endpoint_group(const gbp_endpoint_group& epg) , m_itf(epg.m_itf) , m_rd(epg.m_rd) , m_bd(epg.m_bd) + , m_retention(epg.m_retention) { } @@ -104,11 +130,18 @@ gbp_endpoint_group::id() const return (m_epg_id); } +void +gbp_endpoint_group::set(const retention_t& retention) +{ + m_retention = retention; +} + bool gbp_endpoint_group::operator==(const gbp_endpoint_group& gg) const { return (key() == gg.key() && (m_sclass == gg.m_sclass) && - (m_itf == gg.m_itf) && (m_rd == gg.m_rd) && (m_bd == gg.m_bd)); + (m_retention == gg.m_retention) && (m_itf == gg.m_itf) && + (m_rd == gg.m_rd) && (m_bd == gg.m_bd)); } void @@ -125,7 +158,7 @@ gbp_endpoint_group::replay() { if (m_hw) { HW::enqueue(new gbp_endpoint_group_cmds::create_cmd( - m_hw, m_epg_id, m_sclass, m_bd->id(), m_rd->id(), + m_hw, m_epg_id, m_sclass, m_bd->id(), m_rd->id(), m_retention, (m_itf ? m_itf->handle() : handle_t::INVALID))); } } @@ -136,6 +169,7 @@ gbp_endpoint_group::to_string() const std::ostringstream s; s << "gbp-endpoint-group:[" << "epg:" << m_epg_id << ", sclass:" << m_sclass << ", " + << "retention:[" << m_retention.to_string() << "], " << (m_itf ? m_itf->to_string() : "NULL") << ", " << m_bd->to_string() << ", " << m_rd->to_string() << "]"; @@ -147,7 +181,7 @@ gbp_endpoint_group::update(const gbp_endpoint_group& r) { if (rc_t::OK != m_hw.rc()) { HW::enqueue(new gbp_endpoint_group_cmds::create_cmd( - m_hw, m_epg_id, m_sclass, m_bd->id(), m_rd->id(), + m_hw, m_epg_id, m_sclass, m_bd->id(), m_rd->id(), m_retention, (m_itf ? m_itf->handle() : handle_t::INVALID))); } } diff --git a/extras/vom/vom/gbp_endpoint_group.hpp b/extras/vom/vom/gbp_endpoint_group.hpp index b60b1553e3f..d6af570b7a9 100644 --- a/extras/vom/vom/gbp_endpoint_group.hpp +++ b/extras/vom/vom/gbp_endpoint_group.hpp @@ -36,6 +36,26 @@ typedef uint32_t epg_id_t; class gbp_endpoint_group : public object_base { public: + /** + * Endpoint Retention Policy Settings + */ + struct retention_t + { + retention_t(); + retention_t(uint32_t remote_ep_timeout); + + retention_t(const retention_t&) = default; + retention_t& operator=(const retention_t&) = default; + + bool operator==(const retention_t& o) const; + std::string to_string() const; + + /** + * Remote Endpoint timeout/ageing + */ + uint32_t remote_ep_timeout; + }; + /** * The key for a GBP endpoint group is its ID */ @@ -114,6 +134,8 @@ public: const std::shared_ptr get_route_domain() const; const std::shared_ptr get_bridge_domain() const; + void set(const retention_t& retention); + private: /** * Class definition for listeners to OM events @@ -206,6 +228,11 @@ private: */ std::shared_ptr m_bd; + /** + * The Group's EP retention Policy + */ + retention_t m_retention; + /** * A map of all bridge_domains */ diff --git a/extras/vom/vom/gbp_endpoint_group_cmds.cpp b/extras/vom/vom/gbp_endpoint_group_cmds.cpp index 8d0e48e5c2f..a4f86603cb8 100644 --- a/extras/vom/vom/gbp_endpoint_group_cmds.cpp +++ b/extras/vom/vom/gbp_endpoint_group_cmds.cpp @@ -23,6 +23,7 @@ create_cmd::create_cmd(HW::item& item, uint16_t sclass, uint32_t bd_id, route::table_id_t rd_id, + const gbp_endpoint_group::retention_t& retention, const handle_t& itf) : rpc_cmd(item) , m_epg_id(epg_id) @@ -30,6 +31,7 @@ create_cmd::create_cmd(HW::item& item, , m_bd_id(bd_id) , m_rd_id(rd_id) , m_itf(itf) + , m_retention(retention) { } @@ -37,7 +39,8 @@ bool create_cmd::operator==(const create_cmd& other) const { return ((m_itf == other.m_itf) && (m_bd_id == other.m_bd_id) && - (m_rd_id == other.m_rd_id) && (m_epg_id == other.m_epg_id)); + (m_rd_id == other.m_rd_id) && (m_epg_id == other.m_epg_id) && + (m_retention == other.m_retention)); } rc_t @@ -51,6 +54,7 @@ create_cmd::issue(connection& con) payload.epg.sclass = m_sclass; payload.epg.bd_id = m_bd_id; payload.epg.rd_id = m_rd_id; + payload.epg.retention.remote_ep_timeout = m_retention.remote_ep_timeout; VAPI_CALL(req.execute()); diff --git a/extras/vom/vom/gbp_endpoint_group_cmds.hpp b/extras/vom/vom/gbp_endpoint_group_cmds.hpp index 2294629ee16..b735b5c132d 100644 --- a/extras/vom/vom/gbp_endpoint_group_cmds.hpp +++ b/extras/vom/vom/gbp_endpoint_group_cmds.hpp @@ -38,6 +38,7 @@ public: uint16_t sclass, uint32_t bd_id, route::table_id_t rd_id, + const gbp_endpoint_group::retention_t& retention, const handle_t& itf); /** @@ -61,6 +62,7 @@ private: const uint32_t m_bd_id; const route::table_id_t m_rd_id; const handle_t m_itf; + const gbp_endpoint_group::retention_t m_retention; }; /** diff --git a/extras/vom/vom/gbp_global.cpp b/extras/vom/vom/gbp_global.cpp deleted file mode 100644 index a6cbdd7512c..00000000000 --- a/extras/vom/vom/gbp_global.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* - * 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/gbp_global.hpp" -#include "vom/gbp_global_cmds.hpp" -#include "vom/singular_db_funcs.hpp" - -namespace VOM { -/** - * A DB of all GBP configs - */ -singular_db gbp_global::m_db; - -gbp_global::event_handler gbp_global::m_evh; - -gbp_global::gbp_global(const std::string& system_name, - uint32_t remote_ep_retention) - : m_system_name(system_name) - , m_remote_ep_retention(remote_ep_retention) -{ -} - -gbp_global::gbp_global(const gbp_global& o) - : m_system_name(o.m_system_name) - , m_remote_ep_retention(o.m_remote_ep_retention) -{ -} - -gbp_global::~gbp_global() -{ - sweep(); - m_db.release(m_system_name, this); -} - -const gbp_global::key_t& -gbp_global::key() const -{ - return (m_system_name); -} - -bool -gbp_global::operator==(const gbp_global& l) const -{ - return ((key() == l.key()) && - (m_remote_ep_retention == l.m_remote_ep_retention)); -} - -void -gbp_global::sweep() -{ - // no means to remove this in VPP -} - -void -gbp_global::dump(std::ostream& os) -{ - db_dump(m_db, os); -} - -void -gbp_global::replay() -{ - if (m_binding) { - HW::enqueue( - new gbp_global_cmds::config_cmd(m_binding, m_remote_ep_retention)); - } -} - -std::string -gbp_global::to_string() const -{ - std::ostringstream s; - s << "GBP-global:" - << " remote-EP-retention:" << m_remote_ep_retention; - - return (s.str()); -} - -void -gbp_global::update(const gbp_global& desired) -{ - if (!m_binding) { - HW::enqueue( - new gbp_global_cmds::config_cmd(m_binding, m_remote_ep_retention)); - } -} - -std::shared_ptr -gbp_global::find_or_add(const gbp_global& temp) -{ - return (m_db.find_or_add(temp.key(), temp)); -} - -std::shared_ptr -gbp_global::find(const key_t& k) -{ - return (m_db.find(k)); -} - -std::shared_ptr -gbp_global::singular() const -{ - return find_or_add(*this); -} - -gbp_global::event_handler::event_handler() -{ - OM::register_listener(this); - inspect::register_handler({ "gbp-global" }, "GBP global configurations", - this); -} - -void -gbp_global::event_handler::handle_replay() -{ - m_db.replay(); -} - -void -gbp_global::event_handler::handle_populate(const client_db::key_t& key) -{ -} - -dependency_t -gbp_global::event_handler::order() const -{ - return (dependency_t::GLOBAL); -} - -void -gbp_global::event_handler::show(std::ostream& os) -{ - db_dump(m_db, os); -} -} - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "mozilla") - * End: - */ diff --git a/extras/vom/vom/gbp_global.hpp b/extras/vom/vom/gbp_global.hpp deleted file mode 100644 index 7c451cc6270..00000000000 --- a/extras/vom/vom/gbp_global.hpp +++ /dev/null @@ -1,180 +0,0 @@ -/* - * 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_GBP_GLOBAL_H__ -#define __VOM_GBP_GLOBAL_H__ - -#include "vom/hw.hpp" -#include "vom/inspect.hpp" -#include "vom/object_base.hpp" -#include "vom/om.hpp" -#include "vom/singular_db.hpp" - -namespace VOM { -/** - * A representation of GBP global configuration - */ -class gbp_global : public object_base -{ -public: - /** - * The key for the global conifugration is the 'system' namse - */ - typedef std::string key_t; - - /** - * Construct a new object matching the desried state - */ - gbp_global(const std::string& system_name, uint32_t remote_ep_retention); - - /** - * Copy Constructor - */ - gbp_global(const gbp_global& o); - - /** - * Destructor - */ - ~gbp_global(); - - /** - * Get this objects key - */ - const key_t& key() const; - - /** - * Comparison operator - */ - bool operator==(const gbp_global& l) const; - - /** - * Return the 'singular' of the GBP global that matches this object - */ - std::shared_ptr singular() const; - - /** - * convert to string format for debug purposes - */ - std::string to_string() const; - - /** - * Dump all GBP globals into the stream provided - */ - static void dump(std::ostream& os); - - /** - * Find GBP global config from its key - */ - static std::shared_ptr find(const key_t& k); - -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 gbp_global& obj); - - /** - * Find or add GBP global to the OM - */ - static std::shared_ptr find_or_add(const gbp_global& 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; - - /** - * Sweep/reap the object if still stale - */ - void sweep(void); - - /** - * replay the object to create it in hardware - */ - void replay(void); - - /** - * The system name - */ - const std::string m_system_name; - - /** - * TX timer configs - */ - uint32_t m_remote_ep_retention; - - /** - * HW globaluration for the binding. The bool representing the - * do/don't bind. - */ - HW::item m_binding; - - /** - * A map of all Gbp globals keyed against the system name. - * there needs to be some sort of key, that will do. - */ - static singular_db m_db; -}; -}; - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "mozilla") - * End: - */ - -#endif diff --git a/extras/vom/vom/gbp_global_cmds.cpp b/extras/vom/vom/gbp_global_cmds.cpp deleted file mode 100644 index 3ad651b68a3..00000000000 --- a/extras/vom/vom/gbp_global_cmds.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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/gbp_global_cmds.hpp" - -namespace VOM { -namespace gbp_global_cmds { -config_cmd::config_cmd(HW::item& item, uint32_t remote_ep_retention) - : rpc_cmd(item) - , m_remote_ep_retention(remote_ep_retention) -{ -} - -bool -config_cmd::operator==(const config_cmd& other) const -{ - return (m_remote_ep_retention == other.m_remote_ep_retention); -} - -rc_t -config_cmd::issue(connection& con) -{ - msg_t req(con.ctx(), std::ref(*this)); - - auto& payload = req.get_request().get_payload(); - payload.threshold = m_remote_ep_retention; - - VAPI_CALL(req.execute()); - - return (wait()); -} - -std::string -config_cmd::to_string() const -{ - std::ostringstream s; - s << "Gbp-global-config: " << m_hw_item.to_string() - << " remote_ep_retention:" << m_remote_ep_retention; - - return (s.str()); -} - -}; // namespace gbp_global_cmds -}; // namespace VOM - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "mozilla") - * End: - */ diff --git a/extras/vom/vom/gbp_global_cmds.hpp b/extras/vom/vom/gbp_global_cmds.hpp deleted file mode 100644 index 377b607c013..00000000000 --- a/extras/vom/vom/gbp_global_cmds.hpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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_GBP_GLOBAL_CMDS_H__ -#define __VOM_GBP_GLOBAL_CMDS_H__ - -#include "vom/dump_cmd.hpp" -#include "vom/gbp_global.hpp" -#include "vom/rpc_cmd.hpp" - -#include - -namespace VOM { -namespace gbp_global_cmds { - -/** - * A command class that binds the GBP global to the interface - */ -class config_cmd - : public rpc_cmd, - vapi::Gbp_endpoint_learn_set_inactive_threshold> -{ -public: - /** - * Constructor - */ - config_cmd(HW::item& item, uint32_t remote_ep_retention); - - /** - * 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 config_cmd& i) const; - -private: - /** - * TX timer configs - */ - uint32_t m_remote_ep_retention; -}; - -}; // namespace gbp_global_cmds -}; // namespace VOM - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "mozilla") - * End: - */ - -#endif diff --git a/src/plugins/gbp/gbp.api b/src/plugins/gbp/gbp.api index a7a9a7e8dc8..347855197d7 100644 --- a/src/plugins/gbp/gbp.api +++ b/src/plugins/gbp/gbp.api @@ -157,6 +157,11 @@ define gbp_endpoint_details vl_api_gbp_endpoint_t endpoint; }; +typedef gbp_endpoint_retention +{ + u32 remote_ep_timeout; +}; + typeonly define gbp_endpoint_group { u16 epg_id; @@ -164,6 +169,7 @@ typeonly define gbp_endpoint_group u32 bd_id; u32 rd_id; u32 uplink_sw_if_index; + vl_api_gbp_endpoint_retention_t retention; }; autoreply define gbp_endpoint_group_add @@ -321,18 +327,6 @@ define gbp_contract_details vl_api_gbp_contract_t contract; }; -/** - * @brief Set the time throeshold after which an endpoint is - considered inative and is aged/reaped by the scanner - * @param threshold In seconds - */ -autoreply define gbp_endpoint_learn_set_inactive_threshold -{ - u32 client_index; - u32 context; - u32 threshold; -}; - /** * @brief Configure a 'base' tunnel from which learned tunnels * are permitted to derive diff --git a/src/plugins/gbp/gbp_api.c b/src/plugins/gbp/gbp_api.c index 665d97ea0b1..7c36da6829a 100644 --- a/src/plugins/gbp/gbp_api.c +++ b/src/plugins/gbp/gbp_api.c @@ -80,9 +80,8 @@ _(GBP_EXT_ITF_DUMP, gbp_ext_itf_dump) \ _(GBP_CONTRACT_ADD_DEL, gbp_contract_add_del) \ _(GBP_CONTRACT_DUMP, gbp_contract_dump) \ - _(GBP_ENDPOINT_LEARN_SET_INACTIVE_THRESHOLD, gbp_endpoint_learn_set_inactive_threshold) \ - _(GBP_VXLAN_TUNNEL_ADD, gbp_vxlan_tunnel_add) \ - _(GBP_VXLAN_TUNNEL_DEL, gbp_vxlan_tunnel_del) \ + _(GBP_VXLAN_TUNNEL_ADD, gbp_vxlan_tunnel_add) \ + _(GBP_VXLAN_TUNNEL_DEL, gbp_vxlan_tunnel_del) \ _(GBP_VXLAN_TUNNEL_DUMP, gbp_vxlan_tunnel_dump) gbp_main_t gbp_main; @@ -199,19 +198,6 @@ vl_api_gbp_endpoint_del_t_handler (vl_api_gbp_endpoint_del_t * mp) REPLY_MACRO (VL_API_GBP_ENDPOINT_DEL_REPLY + GBP_MSG_BASE); } -static void - vl_api_gbp_endpoint_learn_set_inactive_threshold_t_handler - (vl_api_gbp_endpoint_learn_set_inactive_threshold_t * mp) -{ - vl_api_gbp_endpoint_learn_set_inactive_threshold_reply_t *rmp; - int rv = 0; - - gbp_learn_set_inactive_threshold (ntohl (mp->threshold)); - - REPLY_MACRO (VL_API_GBP_ENDPOINT_LEARN_SET_INACTIVE_THRESHOLD_REPLY + - GBP_MSG_BASE); -} - typedef struct gbp_walk_ctx_t_ { vl_api_registration_t *reg; @@ -290,18 +276,29 @@ vl_api_gbp_endpoint_dump_t_handler (vl_api_gbp_endpoint_dump_t * mp) gbp_endpoint_walk (gbp_endpoint_send_details, &ctx); } +static void +gbp_retention_decode (const vl_api_gbp_endpoint_retention_t * in, + gbp_endpoint_retention_t * out) +{ + out->remote_ep_timeout = ntohl (in->remote_ep_timeout); +} + static void vl_api_gbp_endpoint_group_add_t_handler (vl_api_gbp_endpoint_group_add_t * mp) { vl_api_gbp_endpoint_group_add_reply_t *rmp; + gbp_endpoint_retention_t retention; int rv = 0; + gbp_retention_decode (&mp->epg.retention, &retention); + rv = gbp_endpoint_group_add_and_lock (ntohs (mp->epg.epg_id), ntohs (mp->epg.sclass), ntohl (mp->epg.bd_id), ntohl (mp->epg.rd_id), - ntohl (mp->epg.uplink_sw_if_index)); + ntohl (mp->epg.uplink_sw_if_index), + &retention); REPLY_MACRO (VL_API_GBP_ENDPOINT_GROUP_ADD_REPLY + GBP_MSG_BASE); } diff --git a/src/plugins/gbp/gbp_endpoint.c b/src/plugins/gbp/gbp_endpoint.c index f32a8820238..9cae2ab9421 100644 --- a/src/plugins/gbp/gbp_endpoint.c +++ b/src/plugins/gbp/gbp_endpoint.c @@ -50,13 +50,6 @@ vlib_log_class_t gbp_ep_logger; #define GBP_ENDPOINT_INFO(...) \ vlib_log_notice (gbp_ep_logger, __VA_ARGS__); -/** - * GBP Endpoint inactive timeout (in seconds) - * If a dynamically learned Endpoint has not been heard from in this - * amount of time it is considered inactive and discarded - */ -static u32 GBP_ENDPOINT_INACTIVE_TIME = 30; - /** * Pool of GBP endpoints */ @@ -1340,16 +1333,22 @@ VLIB_CLI_COMMAND (gbp_endpoint_show_node, static) = { static void gbp_endpoint_check (index_t gei, f64 start_time) { + gbp_endpoint_group_t *gg; gbp_endpoint_loc_t *gel; gbp_endpoint_t *ge; ge = gbp_endpoint_get (gei); gel = gbp_endpoint_loc_find (ge, GBP_ENDPOINT_SRC_DP); - if ((NULL != gel) && - ((start_time - ge->ge_last_time) > GBP_ENDPOINT_INACTIVE_TIME)) + if (NULL != gel) { - gbp_endpoint_unlock (GBP_ENDPOINT_SRC_DP, gei); + gg = gbp_endpoint_group_get (gel->gel_epg); + + if ((start_time - ge->ge_last_time) > + gg->gg_retention.remote_ep_timeout) + { + gbp_endpoint_unlock (GBP_ENDPOINT_SRC_DP, gei); + } } } @@ -1464,22 +1463,6 @@ gbp_endpoint_scan (vlib_main_t * vm) gbp_endpoint_scan_l3 (vm); } -void -gbp_learn_set_inactive_threshold (u32 threshold) -{ - GBP_ENDPOINT_INACTIVE_TIME = threshold; - - vlib_process_signal_event (vlib_get_main (), - gbp_scanner_node.index, - GBP_ENDPOINT_SCAN_SET_TIME, 0); -} - -f64 -gbp_endpoint_scan_threshold (void) -{ - return (GBP_ENDPOINT_INACTIVE_TIME); -} - static fib_node_t * gbp_endpoint_get_node (fib_node_index_t index) { diff --git a/src/plugins/gbp/gbp_endpoint.h b/src/plugins/gbp/gbp_endpoint.h index 4b4c2e0b627..e399ff4f671 100644 --- a/src/plugins/gbp/gbp_endpoint.h +++ b/src/plugins/gbp/gbp_endpoint.h @@ -236,7 +236,6 @@ extern void gbp_endpoint_child_remove (index_t gei, u32 sibling); typedef walk_rc_t (*gbp_endpoint_cb_t) (index_t gbpei, void *ctx); extern void gbp_endpoint_walk (gbp_endpoint_cb_t cb, void *ctx); extern void gbp_endpoint_scan (vlib_main_t * vm); -extern f64 gbp_endpoint_scan_threshold (void); extern int gbp_endpoint_is_remote (const gbp_endpoint_t * ge); extern int gbp_endpoint_is_local (const gbp_endpoint_t * ge); extern int gbp_endpoint_is_external (const gbp_endpoint_t * ge); diff --git a/src/plugins/gbp/gbp_endpoint_group.c b/src/plugins/gbp/gbp_endpoint_group.c index a2922716e42..dc4440743c7 100644 --- a/src/plugins/gbp/gbp_endpoint_group.c +++ b/src/plugins/gbp/gbp_endpoint_group.c @@ -75,7 +75,10 @@ gbp_endpoint_group_find (epg_id_t epg_id) int gbp_endpoint_group_add_and_lock (epg_id_t epg_id, u16 sclass, - u32 bd_id, u32 rd_id, u32 uplink_sw_if_index) + u32 bd_id, + u32 rd_id, + u32 uplink_sw_if_index, + const gbp_endpoint_retention_t * retention) { gbp_endpoint_group_t *gg; index_t ggi; @@ -113,6 +116,7 @@ gbp_endpoint_group_add_and_lock (epg_id_t epg_id, gg->gg_uplink_sw_if_index = uplink_sw_if_index; gg->gg_locks = 1; gg->gg_sclass = sclass; + gg->gg_retention = *retention; if (SCLASS_INVALID != gg->gg_sclass) hash_set (gbp_epg_sclass_db, gg->gg_sclass, gg->gg_id); @@ -256,6 +260,7 @@ static clib_error_t * gbp_endpoint_group_cli (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { + gbp_endpoint_retention_t retention = { 0 }; epg_id_t epg_id = EPG_INVALID, sclass; vnet_main_t *vnm = vnet_get_main (); u32 uplink_sw_if_index = ~0; @@ -297,7 +302,7 @@ gbp_endpoint_group_cli (vlib_main_t * vm, return clib_error_return (0, "route-domain must be specified"); gbp_endpoint_group_add_and_lock (epg_id, sclass, bd_id, rd_id, - uplink_sw_if_index); + uplink_sw_if_index, &retention); } else gbp_endpoint_group_delete (epg_id); diff --git a/src/plugins/gbp/gbp_endpoint_group.h b/src/plugins/gbp/gbp_endpoint_group.h index 123954f63ea..08e3a5c874c 100644 --- a/src/plugins/gbp/gbp_endpoint_group.h +++ b/src/plugins/gbp/gbp_endpoint_group.h @@ -20,6 +20,15 @@ #include +/** + * Endpoint Retnetion Policy + */ +typedef struct gbp_endpoint_retention_t_ +{ + /** Aging timeout for remote endpoints */ + u32 remote_ep_timeout; +} gbp_endpoint_retention_t; + /** * An Endpoint Group representation */ @@ -65,6 +74,11 @@ typedef struct gpb_endpoint_group_t_ * Locks/references to this EPG */ u32 gg_locks; + + /** + * EP retention policy + */ + gbp_endpoint_retention_t gg_retention; } gbp_endpoint_group_t; /** @@ -79,7 +93,9 @@ extern int gbp_endpoint_group_add_and_lock (epg_id_t epg_id, u16 sclass, u32 bd_id, u32 rd_id, - u32 uplink_sw_if_index); + u32 uplink_sw_if_index, + const gbp_endpoint_retention_t * + retention); extern index_t gbp_endpoint_group_find (epg_id_t epg_id); extern int gbp_endpoint_group_delete (epg_id_t epg_id); extern void gbp_endpoint_group_unlock (index_t index); diff --git a/src/plugins/gbp/gbp_learn.h b/src/plugins/gbp/gbp_learn.h index c40196ef259..15a9fecaddd 100644 --- a/src/plugins/gbp/gbp_learn.h +++ b/src/plugins/gbp/gbp_learn.h @@ -56,8 +56,6 @@ extern gbp_learn_main_t gbp_learn_main; extern void gbp_learn_enable (u32 sw_if_index, gbb_learn_mode_t mode); extern void gbp_learn_disable (u32 sw_if_index, gbb_learn_mode_t mode); -extern void gbp_learn_set_inactive_threshold (u32 max_age); - #endif /* diff --git a/src/plugins/gbp/gbp_scanner.c b/src/plugins/gbp/gbp_scanner.c index 90507a60568..9ae962b7449 100644 --- a/src/plugins/gbp/gbp_scanner.c +++ b/src/plugins/gbp/gbp_scanner.c @@ -45,9 +45,7 @@ gbp_scanner (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) if (gs_enabled) { /* scan every 'inactive threshold' seconds */ - vlib_process_wait_for_event_or_clock (vm, - gbp_endpoint_scan_threshold - ()); + vlib_process_wait_for_event_or_clock (vm, 2); } else vlib_process_wait_for_event (vm); @@ -99,8 +97,7 @@ static clib_error_t * gbp_scanner_cli (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { - vlib_cli_output (vm, "GBP-scanner: enabled:%d interval:%f", - gs_enabled, gbp_endpoint_scan_threshold ()); + vlib_cli_output (vm, "GBP-scanner: enabled:%d interval:2", gs_enabled); return (NULL); } diff --git a/test/test_gbp.py b/test/test_gbp.py index ec72981df16..d716ab2668b 100644 --- a/test/test_gbp.py +++ b/test/test_gbp.py @@ -275,13 +275,22 @@ class VppGbpSubnet(VppObject): return False +class VppGbpEndpointRetention(object): + def __init__(self, remote_ep_timeout=0xffffffff): + self.remote_ep_timeout = remote_ep_timeout + + def encode(self): + return {'remote_ep_timeout': self.remote_ep_timeout} + + class VppGbpEndpointGroup(VppObject): """ GBP Endpoint Group """ def __init__(self, test, epg, sclass, rd, bd, uplink, - bvi, bvi_ip4, bvi_ip6=None): + bvi, bvi_ip4, bvi_ip6=None, + retention=VppGbpEndpointRetention()): self._test = test self.uplink = uplink self.bvi = bvi @@ -293,6 +302,7 @@ class VppGbpEndpointGroup(VppObject): self.sclass = sclass if 0 == self.sclass: self.sclass = 0xffff + self.retention = retention def add_vpp_config(self): self._test.vapi.gbp_endpoint_group_add( @@ -300,12 +310,12 @@ class VppGbpEndpointGroup(VppObject): self.sclass, self.bd.bd.bd_id, self.rd.rd_id, - self.uplink.sw_if_index if self.uplink else INDEX_INVALID) + self.uplink.sw_if_index if self.uplink else INDEX_INVALID, + self.retention.encode()) self._test.registry.register(self, self._test.logger) def remove_vpp_config(self): - self._test.vapi.gbp_endpoint_group_del( - self.epg) + self._test.vapi.gbp_endpoint_group_del(self.epg) def __str__(self): return self.object_id() @@ -1458,12 +1468,6 @@ class TestGBP(VppTestCase): 'ip': '10.0.0.2', 'ip6': '2001:10::3'}] - # - # lower the inactive threshold so these tests pass in a - # reasonable amount of time - # - self.vapi.gbp_endpoint_learn_set_inactive_threshold(2) - # # IP tables # @@ -1518,12 +1522,14 @@ class TestGBP(VppTestCase): epg_220 = VppGbpEndpointGroup(self, 220, 112, rd1, gbd1, None, self.loop0, "10.0.0.128", - "2001:10::128") + "2001:10::128", + VppGbpEndpointRetention(2)) epg_220.add_vpp_config() epg_330 = VppGbpEndpointGroup(self, 330, 113, rd1, gbd1, None, self.loop1, "10.0.1.128", - "2001:11::128") + "2001:11::128", + VppGbpEndpointRetention(2)) epg_330.add_vpp_config() # @@ -1860,12 +1866,6 @@ class TestGBP(VppTestCase): 'ip': '10.0.0.2', 'ip6': '2001:10::3'}] - # - # lower the inactive threshold so these tests pass in a - # reasonable amount of time - # - self.vapi.gbp_endpoint_learn_set_inactive_threshold(2) - # # IP tables # @@ -1924,7 +1924,8 @@ class TestGBP(VppTestCase): epg_220 = VppGbpEndpointGroup(self, 220, 441, rd1, gbd1, None, self.loop0, "10.0.0.128", - "2001:10::128") + "2001:10::128", + VppGbpEndpointRetention(2)) epg_220.add_vpp_config() # @@ -2033,12 +2034,6 @@ class TestGBP(VppTestCase): 'ip': '10.0.1.3', 'ip6': '2001:10::3'}] - # - # lower the inactive threshold so these tests pass in a - # reasonable amount of time - # - self.vapi.gbp_endpoint_learn_set_inactive_threshold(2) - # # IP tables # @@ -2104,7 +2099,8 @@ class TestGBP(VppTestCase): epg_220 = VppGbpEndpointGroup(self, 220, 441, rd1, gbd1, None, self.loop0, "10.0.0.128", - "2001:10::128") + "2001:10::128", + VppGbpEndpointRetention(2)) epg_220.add_vpp_config() # @@ -2476,12 +2472,6 @@ class TestGBP(VppTestCase): 'ip': '10.0.1.3', 'ip6': '2001:10::3'}] - # - # lower the inactive threshold so these tests pass in a - # reasonable amount of time - # - self.vapi.gbp_endpoint_learn_set_inactive_threshold(2) - # # IP tables # @@ -2536,17 +2526,20 @@ class TestGBP(VppTestCase): epg_220 = VppGbpEndpointGroup(self, 220, 440, rd1, gbd1, None, gbd1.bvi, "10.0.0.128", - "2001:10::128") + "2001:10::128", + VppGbpEndpointRetention(2)) epg_220.add_vpp_config() epg_221 = VppGbpEndpointGroup(self, 221, 441, rd1, gbd2, None, gbd2.bvi, "10.0.1.128", - "2001:11::128") + "2001:11::128", + VppGbpEndpointRetention(2)) epg_221.add_vpp_config() epg_222 = VppGbpEndpointGroup(self, 222, 442, rd1, gbd1, None, gbd1.bvi, "10.0.2.128", - "2001:12::128") + "2001:12::128", + VppGbpEndpointRetention(2)) epg_222.add_vpp_config() # @@ -2574,12 +2567,14 @@ class TestGBP(VppTestCase): epg_320 = VppGbpEndpointGroup(self, 320, 550, rd1, gbd3, None, gbd1.bvi, "12.0.0.128", - "4001:10::128") + "4001:10::128", + VppGbpEndpointRetention(2)) epg_320.add_vpp_config() epg_321 = VppGbpEndpointGroup(self, 321, 551, rd1, gbd4, None, gbd2.bvi, "12.0.1.128", - "4001:11::128") + "4001:11::128", + VppGbpEndpointRetention(2)) epg_321.add_vpp_config() # @@ -3088,7 +3083,8 @@ class TestGBP(VppTestCase): epg_220 = VppGbpEndpointGroup(self, 220, 113, rd1, gbd1, None, gbd1.bvi, "10.0.0.128", - "2001:10::128") + "2001:10::128", + VppGbpEndpointRetention(2)) epg_220.add_vpp_config() # the BVIs have the subnets applied ... diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py index 9635aa5859b..c21d8c2a8b0 100644 --- a/test/vpp_papi_provider.py +++ b/test/vpp_papi_provider.py @@ -3576,7 +3576,8 @@ class VppPapiProvider(object): {'_no_type_conversion': True}) def gbp_endpoint_group_add(self, epg, sclass, bd, - rd, uplink_sw_if_index): + rd, uplink_sw_if_index, + retention): """ GBP endpoint group Add """ return self.api(self.papi.gbp_endpoint_group_add, {'epg': @@ -3585,7 +3586,8 @@ class VppPapiProvider(object): 'bd_id': bd, 'rd_id': rd, 'epg_id': epg, - 'sclass': sclass + 'sclass': sclass, + 'retention': retention }}) def gbp_endpoint_group_del(self, epg): @@ -3709,11 +3711,6 @@ class VppPapiProvider(object): """ GBP contract Dump """ return self.api(self.papi.gbp_contract_dump, {}) - def gbp_endpoint_learn_set_inactive_threshold(self, threshold): - """ GBP set inactive threshold """ - return self.api(self.papi.gbp_endpoint_learn_set_inactive_threshold, - {'threshold': threshold}) - def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode): """ GBP VXLAN tunnel add """ return self.api(self.papi.gbp_vxlan_tunnel_add, -- 2.16.6