From 866028ea9c595d6e8bd4c94fa71062573d6ea6a9 Mon Sep 17 00:00:00 2001 From: Kyle Sugrue Date: Tue, 25 Jul 2023 22:25:39 -0700 Subject: [PATCH] add support to specify the default vrf name Summary: Adding the option to specify the default VRF Open/R should return to after starting a thrift instance on a non-default VRF. Reviewed By: xiangxu1121 Differential Revision: D47784714 fbshipit-source-id: 0911f462daa1d416f94c1eb98dc77b41893425b1 --- openr/config/Config.h | 5 +++++ openr/config/tests/ConfigTest.cpp | 26 ++++++++++++++++++++++++++ openr/if/OpenrConfig.thrift | 6 ++++++ 3 files changed, 37 insertions(+) diff --git a/openr/config/Config.h b/openr/config/Config.h index 09ac119c0dc..5a65de8c6e9 100644 --- a/openr/config/Config.h +++ b/openr/config/Config.h @@ -300,6 +300,11 @@ class Config { return *getThriftServerConfig().vrf_names(); } + const std::string + getDefaultVrfName() const { + return getThriftServerConfig().default_vrf_name().value_or(""); + } + const std::string getSSLCertPath() const { auto certPath = getThriftServerConfig().x509_cert_path(); diff --git a/openr/config/tests/ConfigTest.cpp b/openr/config/tests/ConfigTest.cpp index 226bf917a4d..cb38c1e068e 100644 --- a/openr/config/tests/ConfigTest.cpp +++ b/openr/config/tests/ConfigTest.cpp @@ -615,4 +615,30 @@ TEST(ConfigTest, NonDefaultVrfConfigGetter) { EXPECT_EQ(1, vrfs.size()); EXPECT_EQ(mgmtVrf, vrfs.front()); } + +TEST(ConfigTest, DefaultVrfConfigGetter) { + std::string defaultVrf{"defaultVrf"}; + thrift::ThriftServerConfig thrift_server_config; + thrift_server_config.default_vrf_name() = defaultVrf; + + auto tConfig = getBasicOpenrConfig(); + tConfig.thrift_server() = thrift_server_config; + + // no soft-drained flag + auto config = Config(tConfig); + const auto vrf = config.getDefaultVrfName(); + EXPECT_EQ(defaultVrf, vrf); +} + +TEST(ConfigTest, DefaultVrfConfigGetterUnsetValue) { + thrift::ThriftServerConfig thrift_server_config; + + auto tConfig = getBasicOpenrConfig(); + tConfig.thrift_server() = thrift_server_config; + + // no soft-drained flag + auto config = Config(tConfig); + const auto vrf = config.getDefaultVrfName(); + EXPECT_EQ("", vrf); +} } // namespace openr diff --git a/openr/if/OpenrConfig.thrift b/openr/if/OpenrConfig.thrift index 3eb93c891ee..71b868339ed 100644 --- a/openr/if/OpenrConfig.thrift +++ b/openr/if/OpenrConfig.thrift @@ -342,6 +342,12 @@ struct ThriftServerConfig { * `enable_non_default_vrf_thrift_server = true` */ 13: list vrf_names = []; + + /** + * User specified default vrf name to pivot the thrift server to. + * This VRF is only used when pivoting back from a non-default VRF + */ + 14: optional string default_vrf_name; } struct ThriftClientConfig {