Skip to content

Commit

Permalink
Merge branch 'master' into feat_poe
Browse files Browse the repository at this point in the history
  • Loading branch information
SerhiyBoikoPLV authored Oct 31, 2024
2 parents 143edcc + 93f7c15 commit 3bbd09b
Show file tree
Hide file tree
Showing 20 changed files with 141 additions and 66 deletions.
2 changes: 0 additions & 2 deletions orchagent/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ INCLUDES = -I $(top_srcdir)/lib \
-I pbh \
-I nhg

if GCOV_ENABLED
SUBDIRS = p4orch/tests
endif

CFLAGS_SAI = -I /usr/include/sai

Expand Down
49 changes: 40 additions & 9 deletions orchagent/dash/dashorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace swss;

extern Directory<Orch*> gDirectory;
extern std::unordered_map<std::string, sai_object_id_t> gVnetNameToId;
extern sai_dash_appliance_api_t* sai_dash_appliance_api;
extern sai_dash_vip_api_t* sai_dash_vip_api;
extern sai_dash_direction_lookup_api_t* sai_dash_direction_lookup_api;
extern sai_dash_eni_api_t* sai_dash_eni_api;
Expand Down Expand Up @@ -66,15 +67,31 @@ bool DashOrch::addApplianceEntry(const string& appliance_id, const dash::applian
}

uint32_t attr_count = 1;
sai_attribute_t appliance_attr;
sai_status_t status;

// NOTE: DASH Appliance object should be the first object pushed to SAI
sai_object_id_t sai_appliance_id = 0UL;
appliance_attr.id = SAI_DASH_APPLIANCE_ATTR_LOCAL_REGION_ID;
appliance_attr.value.u32 = entry.local_region_id();
status = sai_dash_appliance_api->create_dash_appliance(&sai_appliance_id, gSwitchId,
attr_count, &appliance_attr);
if (status != SAI_STATUS_SUCCESS && status != SAI_STATUS_NOT_IMPLEMENTED)
{
SWSS_LOG_ERROR("Failed to create dash appliance object in SAI for %s", appliance_id.c_str());
task_process_status handle_status = handleSaiCreateStatus((sai_api_t) SAI_API_DASH_APPLIANCE, status);
if (handle_status != task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}

sai_vip_entry_t vip_entry;
vip_entry.switch_id = gSwitchId;
if (!to_sai(entry.sip(), vip_entry.vip))
{
return false;
}
sai_attribute_t appliance_attr;
vector<sai_attribute_t> appliance_attrs;
sai_status_t status;
appliance_attr.id = SAI_VIP_ENTRY_ATTR_ACTION;
appliance_attr.value.u32 = SAI_VIP_ENTRY_ACTION_ACCEPT;
status = sai_dash_vip_api->create_vip_entry(&vip_entry, attr_count, &appliance_attr);
Expand Down Expand Up @@ -103,8 +120,8 @@ bool DashOrch::addApplianceEntry(const string& appliance_id, const dash::applian
return parseHandleSaiStatusFailure(handle_status);
}
}
appliance_entries_[appliance_id] = entry;
SWSS_LOG_NOTICE("Created vip and direction lookup entries for %s", appliance_id.c_str());
appliance_entries_[appliance_id] = ApplianceEntry { sai_appliance_id, entry };
SWSS_LOG_NOTICE("Created appliance, vip and direction lookup entries for %s", appliance_id.c_str());

return true;
}
Expand All @@ -114,15 +131,14 @@ bool DashOrch::removeApplianceEntry(const string& appliance_id)
SWSS_LOG_ENTER();

sai_status_t status;
dash::appliance::Appliance entry;

if (appliance_entries_.find(appliance_id) == appliance_entries_.end())
{
SWSS_LOG_WARN("Appliance id does not exist: %s", appliance_id.c_str());
return true;
}

entry = appliance_entries_[appliance_id];
const auto& entry = appliance_entries_[appliance_id].metadata;
sai_vip_entry_t vip_entry;
vip_entry.switch_id = gSwitchId;
if (!to_sai(entry.sip(), vip_entry.vip))
Expand Down Expand Up @@ -153,8 +169,23 @@ bool DashOrch::removeApplianceEntry(const string& appliance_id)
return parseHandleSaiStatusFailure(handle_status);
}
}

auto sai_appliance_id = appliance_entries_[appliance_id].appliance_id;
if (sai_appliance_id != 0UL)
{
status = sai_dash_appliance_api->remove_dash_appliance(sai_appliance_id);
if (status != SAI_STATUS_SUCCESS && status != SAI_STATUS_NOT_IMPLEMENTED)
{
SWSS_LOG_ERROR("Failed to remove dash appliance object in SAI for %s", appliance_id.c_str());
task_process_status handle_status = handleSaiRemoveStatus((sai_api_t) SAI_API_DASH_APPLIANCE, status);
if (handle_status != task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}
}
appliance_entries_.erase(appliance_id);
SWSS_LOG_NOTICE("Removed vip and direction lookup entries for %s", appliance_id.c_str());
SWSS_LOG_NOTICE("Removed appliance, vip and direction lookup entries for %s", appliance_id.c_str());

return true;
}
Expand Down Expand Up @@ -383,7 +414,7 @@ bool DashOrch::addEniObject(const string& eni, EniEntry& entry)
eni_attrs.push_back(eni_attr);

eni_attr.id = SAI_ENI_ATTR_VM_VNI;
auto app_entry = appliance_entries_.begin()->second;
auto& app_entry = appliance_entries_.begin()->second.metadata;
eni_attr.value.u32 = app_entry.vm_vni();
eni_attrs.push_back(eni_attr);

Expand Down
8 changes: 7 additions & 1 deletion orchagent/dash/dashorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ struct EniEntry
dash::eni::Eni metadata;
};

typedef std::map<std::string, dash::appliance::Appliance> ApplianceTable;
struct ApplianceEntry
{
sai_object_id_t appliance_id;
dash::appliance::Appliance metadata;
};

typedef std::map<std::string, ApplianceEntry> ApplianceTable;
typedef std::map<dash::route_type::RoutingType, dash::route_type::RouteType> RoutingTypeTable;
typedef std::map<std::string, EniEntry> EniTable;
typedef std::map<std::string, dash::qos::Qos> QosTable;
Expand Down
22 changes: 11 additions & 11 deletions orchagent/dash/dashvnetorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void DashVnetOrch::doTaskVnetTable(ConsumerBase& consumer)
}
}

void DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt)
bool DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt)
{
SWSS_LOG_ENTER();

Expand All @@ -291,6 +291,7 @@ void DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt
if (!dash_orch->getRouteTypeActions(ctxt.metadata.routing_type(), route_type_actions))
{
SWSS_LOG_INFO("Failed to get route type actions for %s", key.c_str());
return false;
}

for (auto action: route_type_actions.items())
Expand All @@ -309,7 +310,7 @@ void DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt
else
{
SWSS_LOG_ERROR("Invalid encap type %d for %s", action.encap_type(), key.c_str());
return;
return false;
}
outbound_ca_to_pa_attrs.push_back(outbound_ca_to_pa_attr);

Expand Down Expand Up @@ -359,9 +360,10 @@ void DashVnetOrch::addOutboundCaToPa(const string& key, VnetMapBulkContext& ctxt
object_statuses.emplace_back();
outbound_ca_to_pa_bulker_.create_entry(&object_statuses.back(), &outbound_ca_to_pa_entry,
(uint32_t)outbound_ca_to_pa_attrs.size(), outbound_ca_to_pa_attrs.data());
return true;
}

void DashVnetOrch::addPaValidation(const string& key, VnetMapBulkContext& ctxt)
bool DashVnetOrch::addPaValidation(const string& key, VnetMapBulkContext& ctxt)
{
SWSS_LOG_ENTER();

Expand All @@ -380,7 +382,7 @@ void DashVnetOrch::addPaValidation(const string& key, VnetMapBulkContext& ctxt)
SWSS_LOG_INFO("Increment PA refcount to %u for PA IP %s",
pa_refcount_table_[pa_ref_key],
underlay_ip_str.c_str());
return;
return true;
}

uint32_t attr_count = 1;
Expand All @@ -399,6 +401,7 @@ void DashVnetOrch::addPaValidation(const string& key, VnetMapBulkContext& ctxt)
pa_refcount_table_[pa_ref_key] = 1;
SWSS_LOG_INFO("Initialize PA refcount to 1 for PA IP %s",
underlay_ip_str.c_str());
return true;
}

bool DashVnetOrch::addVnetMap(const string& key, VnetMapBulkContext& ctxt)
Expand All @@ -408,17 +411,14 @@ bool DashVnetOrch::addVnetMap(const string& key, VnetMapBulkContext& ctxt)
bool exists = (vnet_map_table_.find(key) != vnet_map_table_.end());
if (!exists)
{

bool vnet_exists = (gVnetNameToId.find(ctxt.vnet_name) != gVnetNameToId.end());
if (vnet_exists)
{
addOutboundCaToPa(key, ctxt);
addPaValidation(key, ctxt);
}
else
if (!vnet_exists)
{
SWSS_LOG_INFO("Not creating VNET map for %s since VNET %s doesn't exist", key.c_str(), ctxt.vnet_name.c_str());
return false;
}
return false;
return addOutboundCaToPa(key, ctxt) && addPaValidation(key, ctxt);
}
/*
* If the VNET map is already added, don't add it to the bulker and
Expand Down
4 changes: 2 additions & 2 deletions orchagent/dash/dashvnetorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ class DashVnetOrch : public ZmqOrch
bool addVnetPost(const std::string& key, const DashVnetBulkContext& ctxt);
bool removeVnet(const std::string& key, DashVnetBulkContext& ctxt);
bool removeVnetPost(const std::string& key, const DashVnetBulkContext& ctxt);
void addOutboundCaToPa(const std::string& key, VnetMapBulkContext& ctxt);
bool addOutboundCaToPa(const std::string& key, VnetMapBulkContext& ctxt);
bool addOutboundCaToPaPost(const std::string& key, const VnetMapBulkContext& ctxt);
void removeOutboundCaToPa(const std::string& key, VnetMapBulkContext& ctxt);
bool removeOutboundCaToPaPost(const std::string& key, const VnetMapBulkContext& ctxt);
void addPaValidation(const std::string& key, VnetMapBulkContext& ctxt);
bool addPaValidation(const std::string& key, VnetMapBulkContext& ctxt);
bool addPaValidationPost(const std::string& key, const VnetMapBulkContext& ctxt);
void removePaValidation(const std::string& key, VnetMapBulkContext& ctxt);
bool removePaValidationPost(const std::string& key, const VnetMapBulkContext& ctxt);
Expand Down
16 changes: 12 additions & 4 deletions orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ uint32_t create_switch_timeout = 0;

void usage()
{
cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-f swss_rec_filename] [-j sairedis_rec_filename] [-b batch_size] [-m MAC] [-i INST_ID] [-s] [-z mode] [-k bulk_size] [-q zmq_server_address] [-c mode] [-t create_switch_timeout]" << endl;
cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-f swss_rec_filename] [-j sairedis_rec_filename] [-b batch_size] [-m MAC] [-i INST_ID] [-s] [-z mode] [-k bulk_size] [-q zmq_server_address] [-c mode] [-t create_switch_timeout] [-v VRF]" << endl;
cout << " -h: display this message" << endl;
cout << " -r record_type: record orchagent logs with type (default 3)" << endl;
cout << " Bit 0: sairedis.rec, Bit 1: swss.rec, Bit 2: responsepublisher.rec. For example:" << endl;
Expand All @@ -96,6 +96,7 @@ void usage()
cout << " -q zmq_server_address: ZMQ server address (default disable ZMQ)" << endl;
cout << " -c counter mode (traditional|asic_db), default: asic_db" << endl;
cout << " -t Override create switch timeout, in sec" << endl;
cout << " -v vrf: VRF name (default empty)" << endl;
}

void sighup_handler(int signo)
Expand Down Expand Up @@ -374,11 +375,12 @@ int main(int argc, char **argv)
string swss_rec_filename = Recorder::SWSS_FNAME;
string sairedis_rec_filename = Recorder::SAIREDIS_FNAME;
string zmq_server_address = "tcp://127.0.0.1:" + to_string(ORCH_ZMQ_PORT);
string vrf;
bool enable_zmq = false;
string responsepublisher_rec_filename = Recorder::RESPPUB_FNAME;
int record_type = 3; // Only swss and sairedis recordings enabled by default.

while ((opt = getopt(argc, argv, "b:m:r:f:j:d:i:hsz:k:q:c:t:")) != -1)
while ((opt = getopt(argc, argv, "b:m:r:f:j:d:i:hsz:k:q:c:t:v:")) != -1)
{
switch (opt)
{
Expand Down Expand Up @@ -472,6 +474,12 @@ int main(int argc, char **argv)
case 't':
create_switch_timeout = atoi(optarg);
break;
case 'v':
if (optarg)
{
vrf = optarg;
}
break;
default: /* '?' */
exit(EXIT_FAILURE);
}
Expand Down Expand Up @@ -516,8 +524,8 @@ int main(int argc, char **argv)
shared_ptr<ZmqServer> zmq_server = nullptr;
if (enable_zmq)
{
SWSS_LOG_NOTICE("Instantiate ZMQ server : %s", zmq_server_address.c_str());
zmq_server = make_shared<ZmqServer>(zmq_server_address.c_str());
SWSS_LOG_NOTICE("Instantiate ZMQ server : %s, %s", zmq_server_address.c_str(), vrf.c_str());
zmq_server = make_shared<ZmqServer>(zmq_server_address.c_str(), vrf.c_str());
}
else
{
Expand Down
33 changes: 5 additions & 28 deletions orchagent/p4orch/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ INCLUDES = -I $(top_srcdir) -I $(ORCHAGENT_DIR) -I $(P4ORCH_DIR) -I $(top_srcdir

CFLAGS_SAI = -I /usr/include/sai

TESTS = p4orch_tests p4orch_tests_asan p4orch_tests_tsan p4orch_tests_usan
TESTS = p4orch_tests

noinst_PROGRAMS = p4orch_tests p4orch_tests_asan p4orch_tests_tsan p4orch_tests_usan
noinst_PROGRAMS = p4orch_tests

if DEBUG
DBGFLAGS = -ggdb -DDEBUG
Expand All @@ -16,11 +16,6 @@ endif

CFLAGS_GTEST =
LDADD_GTEST = -lgtest -lgtest_main -lgmock -lgmock_main
CFLAGS_COVERAGE = --coverage -fprofile-arcs -ftest-coverage
LDADD_COVERAGE = -lgcov
CFLAGS_ASAN = -fsanitize=address
CFLAGS_TSAN = -fsanitize=thread
CFLAGS_USAN = -fsanitize=undefined

p4orch_tests_SOURCES = $(ORCHAGENT_DIR)/orch.cpp \
$(ORCHAGENT_DIR)/vrforch.cpp \
Expand Down Expand Up @@ -83,24 +78,6 @@ p4orch_tests_SOURCES = $(ORCHAGENT_DIR)/orch.cpp \
mock_sai_switch.cpp \
mock_sai_udf.cpp

p4orch_tests_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_COVERAGE) $(CFLAGS_SAI)
p4orch_tests_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_COVERAGE) $(CFLAGS_SAI)
p4orch_tests_LDADD = $(LDADD_GTEST) $(LDADD_COVERAGE) -lpthread -lsairedis -lswsscommon -lsaimeta -lsaimetadata -lzmq

p4orch_tests_asan_SOURCES = $(p4orch_tests_SOURCES)
p4orch_tests_asan_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_ASAN) $(CFLAGS_SAI)
p4orch_tests_asan_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_ASAN) $(CFLAGS_SAI)
p4orch_tests_asan_LDFLAGS = $(CFLAGS_ASAN)
p4orch_tests_asan_LDADD = $(LDADD_GTEST) -lpthread -lsairedis -lswsscommon -lsaimeta -lsaimetadata -lzmq

p4orch_tests_tsan_SOURCES = $(p4orch_tests_SOURCES)
p4orch_tests_tsan_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_TSAN) $(CFLAGS_SAI)
p4orch_tests_tsan_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_TSAN) $(CFLAGS_SAI)
p4orch_tests_tsan_LDFLAGS = $(CFLAGS_TSAN)
p4orch_tests_tsan_LDADD = $(LDADD_GTEST) -lpthread -lsairedis -lswsscommon -lsaimeta -lsaimetadata -lzmq

p4orch_tests_usan_SOURCES = $(p4orch_tests_SOURCES)
p4orch_tests_usan_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_USAN) $(CFLAGS_SAI)
p4orch_tests_usan_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_USAN) $(CFLAGS_SAI)
p4orch_tests_usan_LDFLAGS = $(CFLAGS_USAN)
p4orch_tests_usan_LDADD = $(LDADD_GTEST) -lpthread -lsairedis -lswsscommon -lsaimeta -lsaimetadata -lzmq
p4orch_tests_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI) $(CFLAGS_ASAN)
p4orch_tests_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI) $(CFLAGS_ASAN)
p4orch_tests_LDADD = $(LDADD_GTEST) $(LDFLAGS_ASAN) -lpthread -lsairedis -lswsscommon -lsaimeta -lsaimetadata -lzmq
8 changes: 8 additions & 0 deletions orchagent/p4orch/tests/acl_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2849,6 +2849,8 @@ TEST_F(AclManagerTest, AclRuleWithColorPacketActionsButNoRateLimit)
acl_rule->action_fvs[SAI_ACL_ENTRY_ATTR_ACTION_SET_USER_TRAP_ID].aclaction.parameter.oid);
}

#pragma GCC diagnostic warning "-Wdisabled-optimization"

TEST_F(AclManagerTest, AclRuleWithValidAction)
{
ASSERT_NO_FATAL_FAILURE(AddDefaultIngressTable());
Expand Down Expand Up @@ -3201,6 +3203,8 @@ TEST_F(AclManagerTest, AclRuleWithValidAction)
EXPECT_EQ(nullptr, GetAclRule(kAclIngressTableName, acl_rule_key));
}

#pragma GCC diagnostic pop

TEST_F(AclManagerTest, AclRuleWithVrfAction)
{
ASSERT_NO_FATAL_FAILURE(AddDefaultIngressTable());
Expand Down Expand Up @@ -3410,6 +3414,8 @@ TEST_F(AclManagerTest, AclRuleWithIpTypeBitEncoding)
ASSERT_EQ(nullptr, acl_rule);
}

#pragma GCC diagnostic warning "-Wdisabled-optimization"

TEST_F(AclManagerTest, UpdateAclRuleWithActionMeterChange)
{
ASSERT_NO_FATAL_FAILURE(AddDefaultIngressTable());
Expand Down Expand Up @@ -3834,6 +3840,8 @@ TEST_F(AclManagerTest, UpdateAclRuleWithActionMeterChange)
acl_rule->action_fvs[SAI_ACL_ENTRY_ATTR_ACTION_SET_USER_TRAP_ID].aclaction.parameter.oid);
}

#pragma GCC diagnostic pop

TEST_F(AclManagerTest, UpdateAclRuleWithVrfActionChange)
{
ASSERT_NO_FATAL_FAILURE(AddDefaultIngressTable());
Expand Down
6 changes: 3 additions & 3 deletions orchagent/p4orch/tests/wcmp_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2291,7 +2291,7 @@ TEST_F(WcmpManagerTest, WatchportStateChangetoOperDownSucceeds)
// Verify that the next hop member associated with the port is pruned.
std::string op = "port_state_change";
std::string data = "[{\"port_id\":\"oid:0x56789abcdff\",\"port_state\":\"SAI_PORT_OPER_"
"STATUS_DOWN\"}]";
"STATUS_DOWN\",\"port_error_status\":\"0\"}]";
EXPECT_CALL(mock_sai_next_hop_group_, remove_next_hop_group_member(Eq(kWcmpGroupMemberOid1)))
.WillOnce(Return(SAI_STATUS_SUCCESS));
HandlePortStatusChangeNotification(op, data);
Expand All @@ -2314,7 +2314,7 @@ TEST_F(WcmpManagerTest, WatchportStateChangeToOperUpSucceeds)
// restored.
std::string op = "port_state_change";
std::string data = "[{\"port_id\":\"oid:0x112233\",\"port_state\":\"SAI_PORT_OPER_"
"STATUS_UP\"}]";
"STATUS_UP\",\"port_error_status\":\"0\"}]";
EXPECT_CALL(mock_sai_next_hop_group_,
create_next_hop_group_member(_, Eq(gSwitchId), Eq(3),
Truly(std::bind(MatchSaiNextHopGroupMemberAttribute, kNexthopOid1, 2,
Expand All @@ -2339,7 +2339,7 @@ TEST_F(WcmpManagerTest, WatchportStateChangeFromOperUnknownToDownPrunesMemberOnl
// Verify that the pruned next hop member is not pruned again.
std::string op = "port_state_change";
std::string data = "[{\"port_id\":\"oid:0x56789abcfff\",\"port_state\":\"SAI_PORT_OPER_"
"STATUS_DOWN\"}]";
"STATUS_DOWN\",\"port_error_status\":\"0\"}]";
HandlePortStatusChangeNotification(op, data);
EXPECT_TRUE(VerifyWcmpGroupMemberInPortMap(app_db_entry.wcmp_group_members[0], true, 1));
EXPECT_TRUE(app_db_entry.wcmp_group_members[0]->pruned);
Expand Down
Loading

0 comments on commit 3bbd09b

Please sign in to comment.