Skip to content

Commit

Permalink
[portsorch]: Set default hostif TX queue (sonic-net#2697)
Browse files Browse the repository at this point in the history
* [portsorch]: Set default hostif TX queue

* To avoid data and control packets sharing the same TX queue and possibly
  leading to control packet losses, pin control traffic to queue 7 by default.

* Use querySwitchCapability from SwitchOrch to check if SAI_HOSTIF_ATTR_QUEUE is supported

* Add a vstest

Signed-off-by: Prabhat Aravind <paravind@microsoft.com>
  • Loading branch information
prabhataravind authored Apr 20, 2023
1 parent 5bedf4e commit 04f84fc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
37 changes: 37 additions & 0 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "countercheckorch.h"
#include "notifier.h"
#include "fdborch.h"
#include "switchorch.h"
#include "stringutility.h"
#include "subscriberstatetable.h"

Expand All @@ -49,6 +50,7 @@ extern NeighOrch *gNeighOrch;
extern CrmOrch *gCrmOrch;
extern BufferOrch *gBufferOrch;
extern FdbOrch *gFdbOrch;
extern SwitchOrch *gSwitchOrch;
extern Directory<Orch*> gDirectory;
extern sai_system_port_api_t *sai_system_port_api;
extern string gMySwitchType;
Expand All @@ -61,6 +63,7 @@ extern event_handle_t g_events_handle;
#define VLAN_PREFIX "Vlan"
#define DEFAULT_VLAN_ID 1
#define MAX_VALID_VLAN_ID 4094
#define DEFAULT_HOSTIF_TX_QUEUE 7

#define PORT_SPEED_LIST_DEFAULT_SIZE 16
#define PORT_STATE_POLLING_SEC 5
Expand Down Expand Up @@ -2599,6 +2602,23 @@ bool PortsOrch::createVlanHostIntf(Port& vl, string hostif_name)
attr.value.chardata[SAI_HOSTIF_NAME_SIZE - 1] = '\0';
attrs.push_back(attr);

bool set_hostif_tx_queue = false;
if (gSwitchOrch->querySwitchCapability(SAI_OBJECT_TYPE_HOSTIF, SAI_HOSTIF_ATTR_QUEUE))
{
set_hostif_tx_queue = true;
}
else
{
SWSS_LOG_WARN("Hostif queue attribute not supported");
}

if (set_hostif_tx_queue)
{
attr.id = SAI_HOSTIF_ATTR_QUEUE;
attr.value.u32 = DEFAULT_HOSTIF_TX_QUEUE;
attrs.push_back(attr);
}

sai_status_t status = sai_hostif_api->create_hostif(&vl.m_vlan_info.host_intf_id, gSwitchId, (uint32_t)attrs.size(), attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
Expand Down Expand Up @@ -4842,6 +4862,23 @@ bool PortsOrch::addHostIntfs(Port &port, string alias, sai_object_id_t &host_int
attr.value.chardata[SAI_HOSTIF_NAME_SIZE - 1] = '\0';
attrs.push_back(attr);

bool set_hostif_tx_queue = false;
if (gSwitchOrch->querySwitchCapability(SAI_OBJECT_TYPE_HOSTIF, SAI_HOSTIF_ATTR_QUEUE))
{
set_hostif_tx_queue = true;
}
else
{
SWSS_LOG_WARN("Hostif queue attribute not supported");
}

if (set_hostif_tx_queue)
{
attr.id = SAI_HOSTIF_ATTR_QUEUE;
attr.value.u32 = DEFAULT_HOSTIF_TX_QUEUE;
attrs.push_back(attr);
}

sai_status_t status = sai_hostif_api->create_hostif(&host_intfs_id, gSwitchId, (uint32_t)attrs.size(), attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
Expand Down
1 change: 1 addition & 0 deletions tests/dvslib/dvs_vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def verify_vlan_hostif(self, hostif_name, hostifs_oid, vlan_oid):
assert hostif.get("SAI_HOSTIF_ATTR_TYPE") == "SAI_HOSTIF_TYPE_NETDEV"
assert hostif.get("SAI_HOSTIF_ATTR_OBJ_ID") == vlan_oid
assert hostif.get("SAI_HOSTIF_ATTR_NAME") == hostif_name
assert hostif.get("SAI_HOSTIF_ATTR_QUEUE") == "7"

def get_and_verify_vlan_hostif_ids(self, expected_num, polling_config=PollingConfig()):
hostif_entries = self.asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF",
Expand Down
11 changes: 11 additions & 0 deletions tests/test_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,17 @@ def test_PortIpredriver(self, dvs, testlog):
if fv[0] == "SAI_PORT_ATTR_SERDES_IPREDRIVER":
assert fv[1] == ipre_val_asic

def test_PortHostif(self, dvs):
adb = swsscommon.DBConnector(1, dvs.redis_sock, 0)
atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF")
host_intfs = atbl.getKeys()
for intf in host_intfs:
status, fvs = atbl.get(intf)
assert status, "Error getting value for key"
attributes = dict(fvs)
hostif_queue = attributes.get("SAI_HOSTIF_ATTR_QUEUE")
assert hostif_queue == "7"


# Add Dummy always-pass test at end as workaroud
# for issue when Flaky fail on final test it invokes module tear-down before retrying
Expand Down

0 comments on commit 04f84fc

Please sign in to comment.