Skip to content

LAB5 - swss work for lab#1

Open
abelamit wants to merge 1 commit intomasterfrom
master_amabel_swss_lab5
Open

LAB5 - swss work for lab#1
abelamit wants to merge 1 commit intomasterfrom
master_amabel_swss_lab5

Conversation

@abelamit
Copy link
Owner

What I did

Why I did it

How I verified it

Details if related

@abelamit abelamit force-pushed the master_amabel_swss_lab5 branch 2 times, most recently from 5e13a5b to 6345b1b Compare July 30, 2025 12:01
fieldValue = std::to_string(TX_ERROR_CHECK_THRESHOLD_DEFAULT);
}

mcUpdateThreshold(std::stoul(fieldValue));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abelamit suggest replacing with sonic-swss-common/common/converter.h

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

fieldValue = std::to_string(TX_ERROR_CHECK_POLL_TIMEOUT_SEC_DEFAULT);
}

mcUpdateTimePeriod(std::stoul(fieldValue));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abelamit suggest replacing with sonic-swss-common/common/converter.h

{
if (op == DEL_COMMAND)
{
fieldValue = std::to_string(TX_ERROR_CHECK_THRESHOLD_DEFAULT);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abelamit FYI. Usually we do no do like this, only in a very rare cases. Different vendors may want to have different defaults

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. So how will you define default values? Since we need to upload our system with some default before user is configuring. Basically it is not mandatory to support this in DB_CONFIG


#define TX_ERROR_PORT_STATE_FIELD "tx_error_port_state"
#define TX_ERROR_PORT_STATE_ERROR "error"
#define TX_ERROR_PORT_STATE_OK "ok"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abelamit it is better to avoid having define in the main header (.h) which you include everywhere. A dedicated stuff which is used mostly under the hood better to move to the compilation unit (.cpp). This will result in a scope limitation and better encapsulation

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -0,0 +1,50 @@
#ifndef TXERRORCHECKORCH_H
#define TXERRORCHECKORCH_H

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abelamit this is a good style but # pragma once is preferred

class TxErrorCheckOrch: public Orch
{
public:
TxErrorCheckOrch(swss::DBConnector *db, std::string tableName);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abelamit having const std::string &tableName would be better. Also, suggest trying some tool for a static code analysis. That might be helpful to learn a new stuff

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. I will check out the static analysis tool


swss::Table portStateTable(m_stateDb.get(), STATE_PORT_TABLE_NAME);
portStateTable.hset(port_name, TX_ERROR_PORT_STATE_FIELD, (isTxErrorState ? TX_ERROR_PORT_STATE_ERROR : TX_ERROR_PORT_STATE_OK));
} No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abelamit do not forget about new line at the end of each file

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

continue;
}

uint32_t outErrorsCount = static_cast<uint32_t>(std::stoul(outErrors));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abelamit suggest replacing with sonic-swss-common/common/converter.h


std::stringstream ss;
ss << "oid:0x" << std::hex << portOid; // Set output format to hexadecimal and insert the value
std::string portOidStr = ss.str(); // Extract the string

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abelamit consider using sai_serialize_object_id from sonic-sairedis/meta/sai_serialize.h

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very valid point! I was looking for this function without success. Thanks!
Fixed


TxErrorCheckOrch::TxErrorCheckOrch(swss::DBConnector *db, std::string tableName):
Orch(db, std::vector<string>{tableName}),
m_countersDb(new swss::DBConnector("COUNTERS_DB", 0)),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abelamit a good practice is also to use make_shared and make_unique

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@abelamit abelamit force-pushed the master_amabel_swss_lab5 branch from 6345b1b to 3d575f4 Compare August 11, 2025 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants