From 3052fb5f25fea0ba2f60ad17c294e6da8b9eb70a Mon Sep 17 00:00:00 2001 From: abdosi <58047199+abdosi@users.noreply.github.com> Date: Sat, 8 Aug 2020 15:58:34 -0700 Subject: [PATCH] Added Max Nexthopgroup/ECMP Count supported by device into State DB. (#1383) * Added Max Nexthopgroup/ECMP Count supported by device to State DB as part of Swicth Capability Table. Motivation for adding this to StateDB was to make sure we can query this value (n) from external test case and make sure we add (n) number of ECMP Group successfully and (n+1) should fail without termination orchagent. Since we are using SWITCH_CAPABILTY Table moved the setting of table field from aclorch to switchorch Signed-off-by: Abhishek Dosi * Fix * Fix VS mock_tables gtest failure. --- orchagent/aclorch.cpp | 10 +++++----- orchagent/aclorch.h | 5 +++-- orchagent/orchdaemon.cpp | 8 ++++---- orchagent/routeorch.cpp | 7 ++++++- orchagent/routeorch.h | 4 +++- orchagent/switchorch.cpp | 8 +++++++- orchagent/switchorch.h | 5 +++-- tests/mock_tests/aclorch_ut.cpp | 17 +++++++++++------ 8 files changed, 42 insertions(+), 22 deletions(-) diff --git a/orchagent/aclorch.cpp b/orchagent/aclorch.cpp index 214b91d2d077..4d5d39e017fe 100644 --- a/orchagent/aclorch.cpp +++ b/orchagent/aclorch.cpp @@ -2220,7 +2220,7 @@ void AclOrch::init(vector& connectors, PortsOrch *portOrch, Mirr break; } } - m_switchTable.set("switch", fvVector); + m_switchOrch->set_switch_capability(fvVector); sai_attribute_t attrs[2]; attrs[0].id = SAI_SWITCH_ATTR_ACL_ENTRY_MINIMUM_PRIORITY; @@ -2362,7 +2362,7 @@ void AclOrch::putAclActionCapabilityInDB(acl_stage_type_t stage) } fvVector.emplace_back(field, acl_action_value_stream.str()); - m_switchTable.set("switch", fvVector); + m_switchOrch->set_switch_capability(fvVector); } void AclOrch::initDefaultAclActionCapabilities(acl_stage_type_t stage) @@ -2464,7 +2464,7 @@ void AclOrch::queryAclActionAttrEnumValues(const string &action_name, fvVector.emplace_back(field, acl_action_value_stream.str()); } - m_switchTable.set("switch", fvVector); + m_switchOrch->set_switch_capability(fvVector); } sai_acl_action_type_t AclOrch::getAclActionFromAclEntry(sai_acl_entry_attr_t attr) @@ -2477,10 +2477,10 @@ sai_acl_action_type_t AclOrch::getAclActionFromAclEntry(sai_acl_entry_attr_t att return static_cast(attr - SAI_ACL_ENTRY_ATTR_ACTION_START); }; -AclOrch::AclOrch(vector& connectors, TableConnector switchTable, +AclOrch::AclOrch(vector& connectors, SwitchOrch *switchOrch, PortsOrch *portOrch, MirrorOrch *mirrorOrch, NeighOrch *neighOrch, RouteOrch *routeOrch, DTelOrch *dtelOrch) : Orch(connectors), - m_switchTable(switchTable.first, switchTable.second), + m_switchOrch(switchOrch), m_mirrorOrch(mirrorOrch), m_neighOrch(neighOrch), m_routeOrch(routeOrch), diff --git a/orchagent/aclorch.h b/orchagent/aclorch.h index d7c8a759cf2f..262cf3adfa93 100644 --- a/orchagent/aclorch.h +++ b/orchagent/aclorch.h @@ -9,6 +9,7 @@ #include #include #include "orch.h" +#include "switchorch.h" #include "portsorch.h" #include "mirrororch.h" #include "dtelorch.h" @@ -391,7 +392,7 @@ class AclOrch : public Orch, public Observer { public: AclOrch(vector& connectors, - TableConnector switchTable, + SwitchOrch *m_switchOrch, PortsOrch *portOrch, MirrorOrch *mirrorOrch, NeighOrch *neighOrch, @@ -408,7 +409,6 @@ class AclOrch : public Orch, public Observer return m_countersTable; } - Table m_switchTable; // FIXME: Add getters for them? I'd better to add a common directory of orch objects and use it everywhere MirrorOrch *m_mirrorOrch; @@ -432,6 +432,7 @@ class AclOrch : public Orch, public Observer static sai_acl_action_type_t getAclActionFromAclEntry(sai_acl_entry_attr_t attr); private: + SwitchOrch *m_switchOrch; void doTask(Consumer &consumer); void doAclTableTask(Consumer &consumer); void doAclRuleTask(Consumer &consumer); diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index 26ff1f030113..99fbc0a7f6e3 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -71,8 +71,9 @@ bool OrchDaemon::init() SWSS_LOG_ENTER(); string platform = getenv("platform") ? getenv("platform") : ""; + TableConnector stateDbSwitchTable(m_stateDb, "SWITCH_CAPABILITY"); - gSwitchOrch = new SwitchOrch(m_applDb, APP_SWITCH_TABLE_NAME); + gSwitchOrch = new SwitchOrch(m_applDb, APP_SWITCH_TABLE_NAME, stateDbSwitchTable); const int portsorch_base_pri = 40; @@ -125,7 +126,7 @@ bool OrchDaemon::init() gIntfsOrch = new IntfsOrch(m_applDb, APP_INTF_TABLE_NAME, vrf_orch); gNeighOrch = new NeighOrch(m_applDb, APP_NEIGH_TABLE_NAME, gIntfsOrch); - gRouteOrch = new RouteOrch(m_applDb, APP_ROUTE_TABLE_NAME, gNeighOrch, gIntfsOrch, vrf_orch); + gRouteOrch = new RouteOrch(m_applDb, APP_ROUTE_TABLE_NAME, gSwitchOrch, gNeighOrch, gIntfsOrch, vrf_orch); TableConnector confDbSflowTable(m_configDb, CFG_SFLOW_TABLE_NAME); TableConnector appCoppTable(m_applDb, APP_COPP_TABLE_NAME); @@ -267,8 +268,7 @@ bool OrchDaemon::init() dtel_orch = new DTelOrch(m_configDb, dtel_tables, gPortsOrch); m_orchList.push_back(dtel_orch); } - TableConnector stateDbSwitchTable(m_stateDb, "SWITCH_CAPABILITY"); - gAclOrch = new AclOrch(acl_table_connectors, stateDbSwitchTable, gPortsOrch, mirror_orch, gNeighOrch, gRouteOrch, dtel_orch); + gAclOrch = new AclOrch(acl_table_connectors, gSwitchOrch, gPortsOrch, mirror_orch, gNeighOrch, gRouteOrch, dtel_orch); m_orchList.push_back(gFdbOrch); m_orchList.push_back(mirror_orch); diff --git a/orchagent/routeorch.cpp b/orchagent/routeorch.cpp index bc9174be9399..66a0c86aaf39 100644 --- a/orchagent/routeorch.cpp +++ b/orchagent/routeorch.cpp @@ -22,10 +22,11 @@ extern CrmOrch *gCrmOrch; const int routeorch_pri = 5; -RouteOrch::RouteOrch(DBConnector *db, string tableName, NeighOrch *neighOrch, IntfsOrch *intfsOrch, VRFOrch *vrfOrch) : +RouteOrch::RouteOrch(DBConnector *db, string tableName, SwitchOrch *switchOrch, NeighOrch *neighOrch, IntfsOrch *intfsOrch, VRFOrch *vrfOrch) : gRouteBulker(sai_route_api), gNextHopGroupMemberBulker(sai_next_hop_group_api, gSwitchId), Orch(db, tableName, routeorch_pri), + m_switchOrch(switchOrch), m_neighOrch(neighOrch), m_intfsOrch(intfsOrch), m_vrfOrch(vrfOrch), @@ -63,6 +64,10 @@ RouteOrch::RouteOrch(DBConnector *db, string tableName, NeighOrch *neighOrch, In m_maxNextHopGroupCount /= DEFAULT_MAX_ECMP_GROUP_SIZE; } } + vector fvTuple; + fvTuple.emplace_back("MAX_NEXTHOP_GROUP_COUNT", to_string(m_maxNextHopGroupCount)); + m_switchOrch->set_switch_capability(fvTuple); + SWSS_LOG_NOTICE("Maximum number of ECMP groups supported is %d", m_maxNextHopGroupCount); IpPrefix default_ip_prefix("0.0.0.0/0"); diff --git a/orchagent/routeorch.h b/orchagent/routeorch.h index 8cd71aee27d2..82bcd35d7194 100644 --- a/orchagent/routeorch.h +++ b/orchagent/routeorch.h @@ -3,6 +3,7 @@ #include "orch.h" #include "observer.h" +#include "switchorch.h" #include "intfsorch.h" #include "neighorch.h" @@ -88,7 +89,7 @@ struct RouteBulkContext class RouteOrch : public Orch, public Subject { public: - RouteOrch(DBConnector *db, string tableName, NeighOrch *neighOrch, IntfsOrch *intfsOrch, VRFOrch *vrfOrch); + RouteOrch(DBConnector *db, string tableName, SwitchOrch *switchOrch, NeighOrch *neighOrch, IntfsOrch *intfsOrch, VRFOrch *vrfOrch); bool hasNextHopGroup(const NextHopGroupKey&) const; sai_object_id_t getNextHopGroupId(const NextHopGroupKey&); @@ -108,6 +109,7 @@ class RouteOrch : public Orch, public Subject void notifyNextHopChangeObservers(sai_object_id_t, const IpPrefix&, const NextHopGroupKey&, bool); private: + SwitchOrch *m_switchOrch; NeighOrch *m_neighOrch; IntfsOrch *m_intfsOrch; VRFOrch *m_vrfOrch; diff --git a/orchagent/switchorch.cpp b/orchagent/switchorch.cpp index 2a9341acff91..bac2c9a3af03 100644 --- a/orchagent/switchorch.cpp +++ b/orchagent/switchorch.cpp @@ -33,8 +33,9 @@ const map packet_action_map = {"trap", SAI_PACKET_ACTION_TRAP} }; -SwitchOrch::SwitchOrch(DBConnector *db, string tableName) : +SwitchOrch::SwitchOrch(DBConnector *db, string tableName, TableConnector switchTable): Orch(db, tableName), + m_switchTable(switchTable.first, switchTable.second), m_db(db) { m_restartCheckNotificationConsumer = new NotificationConsumer(db, "RESTARTCHECK"); @@ -207,3 +208,8 @@ bool SwitchOrch::setAgingFDB(uint32_t sec) SWSS_LOG_NOTICE("Set switch %" PRIx64 " fdb_aging_time %u sec", gSwitchId, sec); return true; } + +void SwitchOrch::set_switch_capability(const std::vector& values) +{ + m_switchTable.set("switch", values); +} diff --git a/orchagent/switchorch.h b/orchagent/switchorch.h index 594226dc3d4d..579447ee19f3 100644 --- a/orchagent/switchorch.h +++ b/orchagent/switchorch.h @@ -12,20 +12,21 @@ struct WarmRestartCheck class SwitchOrch : public Orch { public: - SwitchOrch(swss::DBConnector *db, std::string tableName); - + SwitchOrch(swss::DBConnector *db, std::string tableName, TableConnector switchTable); bool checkRestartReady() { return m_warmRestartCheck.checkRestartReadyState; } bool checkRestartNoFreeze() { return m_warmRestartCheck.noFreeze; } bool skipPendingTaskCheck() { return m_warmRestartCheck.skipPendingTaskCheck; } void checkRestartReadyDone() { m_warmRestartCheck.checkRestartReadyState = false; } void restartCheckReply(const std::string &op, const std::string &data, std::vector &values); bool setAgingFDB(uint32_t sec); + void set_switch_capability(const std::vector& values); private: void doTask(Consumer &consumer); swss::NotificationConsumer* m_restartCheckNotificationConsumer; void doTask(swss::NotificationConsumer& consumer); swss::DBConnector *m_db; + swss::Table m_switchTable; // Information contained in the request from // external program for orchagent pre-shutdown state check diff --git a/tests/mock_tests/aclorch_ut.cpp b/tests/mock_tests/aclorch_ut.cpp index b7c057fce0ab..65c1862e8c35 100644 --- a/tests/mock_tests/aclorch_ut.cpp +++ b/tests/mock_tests/aclorch_ut.cpp @@ -2,6 +2,7 @@ extern sai_object_id_t gSwitchId; +extern SwitchOrch *gSwitchOrch; extern CrmOrch *gCrmOrch; extern PortsOrch *gPortsOrch; extern RouteOrch *gRouteOrch; @@ -122,7 +123,7 @@ namespace aclorch_test AclOrch *m_aclOrch; swss::DBConnector *config_db; - MockAclOrch(swss::DBConnector *config_db, swss::DBConnector *state_db, + MockAclOrch(swss::DBConnector *config_db, swss::DBConnector *state_db, SwitchOrch *switchOrch, PortsOrch *portsOrch, MirrorOrch *mirrorOrch, NeighOrch *neighOrch, RouteOrch *routeOrch) : config_db(config_db) { @@ -131,9 +132,7 @@ namespace aclorch_test vector acl_table_connectors = { confDbAclTable, confDbAclRuleTable }; - TableConnector stateDbSwitchTable(state_db, "SWITCH_CAPABILITY"); - - m_aclOrch = new AclOrch(acl_table_connectors, stateDbSwitchTable, portsOrch, mirrorOrch, + m_aclOrch = new AclOrch(acl_table_connectors, switchOrch, portsOrch, mirrorOrch, neighOrch, routeOrch); } @@ -285,6 +284,10 @@ namespace aclorch_test gVirtualRouterId = attr.value.oid; + TableConnector stateDbSwitchTable(m_state_db.get(), "SWITCH_CAPABILITY"); + ASSERT_EQ(gSwitchOrch, nullptr); + gSwitchOrch = new SwitchOrch(m_app_db.get(), APP_SWITCH_TABLE_NAME, stateDbSwitchTable); + // Create dependencies ... const int portsorch_base_pri = 40; @@ -313,7 +316,7 @@ namespace aclorch_test gNeighOrch = new NeighOrch(m_app_db.get(), APP_NEIGH_TABLE_NAME, gIntfsOrch); ASSERT_EQ(gRouteOrch, nullptr); - gRouteOrch = new RouteOrch(m_app_db.get(), APP_ROUTE_TABLE_NAME, gNeighOrch, gIntfsOrch, gVrfOrch); + gRouteOrch = new RouteOrch(m_app_db.get(), APP_ROUTE_TABLE_NAME, gSwitchOrch, gNeighOrch, gIntfsOrch, gVrfOrch); TableConnector applDbFdb(m_app_db.get(), APP_FDB_TABLE_NAME); TableConnector stateDbFdb(m_state_db.get(), STATE_FDB_TABLE_NAME); @@ -341,6 +344,8 @@ namespace aclorch_test { AclTestBase::TearDown(); + delete gSwitchOrch; + gSwitchOrch = nullptr; delete gFdbOrch; gFdbOrch = nullptr; delete gMirrorOrch; @@ -374,7 +379,7 @@ namespace aclorch_test shared_ptr createAclOrch() { - return make_shared(m_config_db.get(), m_state_db.get(), gPortsOrch, gMirrorOrch, + return make_shared(m_config_db.get(), m_state_db.get(), gSwitchOrch, gPortsOrch, gMirrorOrch, gNeighOrch, gRouteOrch); }