Skip to content

Commit

Permalink
Fix build error
Browse files Browse the repository at this point in the history
Signed-off-by: Prince George <prgeor@microsoft.com>
  • Loading branch information
prgeor committed Nov 7, 2024
1 parent edd733c commit 6955d48
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 33 deletions.
5 changes: 1 addition & 4 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8081,6 +8081,7 @@ void PortsOrch::doTask(NotificationConsumer &consumer)

for (uint32_t i = 0; i < count; i++)
{
Port port;
sai_object_id_t id = portoperstatus[i].port_id;
sai_port_oper_status_t status = portoperstatus[i].port_state;
sai_port_error_status_t port_oper_err = portoperstatus[i].port_error_status;
Expand All @@ -8089,10 +8090,6 @@ void PortsOrch::doTask(NotificationConsumer &consumer)
"oper_error_status:0x%" PRIx32,
id, status, port_oper_err);

//port_oper_err = static_cast<sai_port_error_status_t>(SAI_PORT_ERROR_STATUS_MAC_LOCAL_FAULT | SAI_PORT_ERROR_STATUS_MAC_REMOTE_FAULT);

Port port;

if (!getPort(id, port))
{
SWSS_LOG_NOTICE("Got port state change for port id 0x%" PRIx64 " which does not exist, possibly outdated event", id);
Expand Down
113 changes: 84 additions & 29 deletions tests/mock_tests/portsorch_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,31 +710,48 @@ namespace portsorch_test
Port port;
gPortsOrch->getPort("Ethernet0", port);
ASSERT_TRUE(port.m_oper_status != SAI_PORT_OPER_STATUS_UP);
ASSERT_TRUE(port.m_oper_error_status == SAI_PORT_ERROR_STATUS_CLEAR);
ASSERT_TRUE(port.m_flap_count == 0);

auto exec = static_cast<Notifier *>(gPortsOrch->getExecutor("PORT_STATUS_NOTIFICATIONS"));
auto consumer = exec->getNotificationConsumer();

std::vector<sai_port_error_status_t> errors = {
SAI_PORT_ERROR_STATUS_CLEAR,
SAI_PORT_ERROR_STATUS_MAC_LOCAL_FAULT,
SAI_PORT_ERROR_STATUS_CLEAR,
SAI_PORT_ERROR_STATUS_MAC_REMOTE_FAULT,
SAI_PORT_ERROR_STATUS_CLEAR,
SAI_PORT_ERROR_STATUS_MAC_LOCAL_FAULT | SAI_PORT_ERROR_STATUS_MAC_REMOTE_FAULT
static_cast<sai_port_error_status_t>(
SAI_PORT_ERROR_STATUS_FEC_SYNC_LOSS |
SAI_PORT_ERROR_STATUS_MAC_LOCAL_FAULT),
static_cast<sai_port_error_status_t>(
SAI_PORT_ERROR_STATUS_FEC_LOSS_ALIGNMENT_MARKER |
SAI_PORT_ERROR_STATUS_HIGH_SER |
SAI_PORT_ERROR_STATUS_HIGH_BER |
SAI_PORT_ERROR_STATUS_CRC_RATE),
SAI_PORT_ERROR_STATUS_DATA_UNIT_CRC_ERROR,
static_cast<sai_port_error_status_t>(
SAI_PORT_ERROR_STATUS_FEC_SYNC_LOSS |
SAI_PORT_ERROR_STATUS_DATA_UNIT_SIZE |
SAI_PORT_ERROR_STATUS_DATA_UNIT_MISALIGNMENT_ERROR),
static_cast<sai_port_error_status_t>(
SAI_PORT_ERROR_STATUS_CODE_GROUP_ERROR |
SAI_PORT_ERROR_STATUS_SIGNAL_LOCAL_ERROR |
SAI_PORT_ERROR_STATUS_NO_RX_REACHABILITY),
static_cast<sai_port_error_status_t>(
SAI_PORT_ERROR_STATUS_FEC_SYNC_LOSS |
SAI_PORT_ERROR_STATUS_MAC_REMOTE_FAULT)
};

// mock a redis reply for notification, it notifies that Ehernet0 is going to up
for (uint32_t count=0; count < 6; count++) {
sai_port_oper_status_t oper_status = (count % 2 == 0) ? SAI_PORT_OPER_STATUS_UP : SAI_PORT_OPER_STATUS_DOWN;
for (uint32_t count=0; count < errors.size(); count++) {
sai_port_oper_status_t oper_status = SAI_PORT_OPER_STATUS_DOWN;
mockReply = (redisReply *)calloc(sizeof(redisReply), 1);
mockReply->type = REDIS_REPLY_ARRAY;
mockReply->elements = 3; // REDIS_PUBLISH_MESSAGE_ELEMNTS
mockReply->element = (redisReply **)calloc(sizeof(redisReply *), mockReply->elements);
mockReply->element[2] = (redisReply *)calloc(sizeof(redisReply), 1);
mockReply->element[2]->type = REDIS_REPLY_STRING;
sai_port_oper_status_notification_t port_oper_status;
port_oper_status.port_error_status = errors[count]
memset(&port_oper_status, 0, sizeof(port_oper_status));
port_oper_status.port_error_status = errors[count];
port_oper_status.port_state = oper_status;
port_oper_status.port_id = port.m_port_id;
std::string data = sai_serialize_port_oper_status_ntf(1, &port_oper_status);
Expand All @@ -749,33 +766,71 @@ namespace portsorch_test
consumer->readData();
gPortsOrch->doTask(*consumer);
mockReply = nullptr;

gPortsOrch->getPort("Ethernet0", port);
ASSERT_TRUE(port.m_oper_status == oper_status);
if (port.m_oper_status == SAI_PORT_OPER_STATUS_UP)
gPortsOrch->updatePortErrorStatus(port, errors[count]);
ASSERT_TRUE(port.m_oper_error_status == errors[count]);
}

std::vector<FieldValueTuple> values;
portTableOpErrState.get("Ethernet0", values);

for (auto &valueTuple : values)
{
if (fvField(valueTuple) == "mac_local_fault_count")
{
ASSERT_TRUE(port.m_oper_error_status == SAI_PORT_ERROR_STATUS_CLEAR);
ASSERT_TRUE(fvValue(valueTuple) == "2");
}
else
else if (fvField(valueTuple) == "mac_remote_fault_count")
{
ASSERT_TRUE(port.m_oper_error_status == errors[count]);
ASSERT_TRUE(fvValue(valueTuple) == "2");
}
std::vector<FieldValueTuple> values;
statePortTable.get("Ethernet0", values);
for (auto &valueTuple : values)
else if (fvField(valueTuple) == "oper_error_status")
{
if (fvField(valueTuple) == "mac_local_fault_count")
{
ASSERT_TRUE(fvValue(valueTuple) == 3);
}
else if (fvField(valueTuple) == "mac_remote_fault_count")
{
ASSERT_TRUE(fvValue(valueTuple) == 2);
}
else if (fvField(valueTuple) == "oper_error_status")
{
ASSERT_TRUE(fvValue(valueTuple) == 0x3);
}
ASSERT_TRUE(fvValue(valueTuple) == "3");
}
else if (fvField(valueTuple) == "fec_sync_loss_count")
{
ASSERT_TRUE(fvValue(valueTuple) == "3");
}
else if (fvField(valueTuple) == "fec_alignment_loss_count")
{
ASSERT_TRUE(fvValue(valueTuple) == "1");
}
else if (fvField(valueTuple) == "high_ser_error_count")
{
ASSERT_TRUE(fvValue(valueTuple) == "1");
}
else if (fvField(valueTuple) == "high ber_error_count")
{
ASSERT_TRUE(fvValue(valueTuple) == "1");
}
else if (fvField(valueTuple) == "crc_rate_count")
{
ASSERT_TRUE(fvValue(valueTuple) == "1");
}
else if (fvField(valueTuple) == "data_unit_crc_error_count")
{
ASSERT_TRUE(fvValue(valueTuple) == "1");
}
else if (fvField(valueTuple) == "data_unit_size_count")
{
ASSERT_TRUE(fvValue(valueTuple) == "1");
}
else if (fvField(valueTuple) == "data_unit_misalignment_error_count")
{
ASSERT_TRUE(fvValue(valueTuple) == "1");
}
else if (fvField(valueTuple) == "code_group_error_count")
{
ASSERT_TRUE(fvValue(valueTuple) == "1");
}
else if (fvField(valueTuple) == "signal_local_error_count")
{
ASSERT_TRUE(fvValue(valueTuple) == "1");
}
else if (fvField(valueTuple) == "no_rx_reachability_count")
{
ASSERT_TRUE(fvValue(valueTuple) == "1");
}
}

Expand Down

0 comments on commit 6955d48

Please sign in to comment.