Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allow to add port to .1Q bridge while router port deletion is not completed #2669

Merged
merged 5 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4879,6 +4879,12 @@ bool PortsOrch::addBridgePort(Port &port)
return true;
}

if (port.m_rif_id != 0)
{
SWSS_LOG_NOTICE("Interface %s is a router port", port.m_alias.c_str());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please add more context in the log message and change it to warning since we are returning here in a failure scenario?
"Cannot create bridge port. Interface %s is a router port"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@liorghub I recommend changing it to "WARN" log instead of notice since here are returning here in a failure scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dgsudharsan this is actually a retry mechanism (not failure).
When we print this message we also return false in the next line, DB change is not consumed and we will try again till success.

return false;
}

sai_attribute_t attr;
vector<sai_attribute_t> attrs;

Expand Down
34 changes: 34 additions & 0 deletions tests/mock_tests/mock_sai_bridge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Define classes and functions to mock SAI bridge functions.
#pragma once

#include <gmock/gmock.h>

extern "C"
{
#include "sai.h"
}

// Mock class including mock functions mapping to SAI bridge functions.
class MockSaiBridge
{
public:
MOCK_METHOD4(create_bridge_port, sai_status_t(sai_object_id_t *bridge_port_id,
sai_object_id_t switch_id,
uint32_t attr_count,
const sai_attribute_t *attr_list));
};

// Note that before mock functions below are used, mock_sai_bridge must be
// initialized to point to an instance of MockSaiBridge.
MockSaiBridge *mock_sai_bridge;

sai_status_t mock_create_bridge_port(sai_object_id_t *bridge_port_id,
sai_object_id_t switch_id,
uint32_t attr_count,
const sai_attribute_t *attr_list)
{
return mock_sai_bridge->create_bridge_port(bridge_port_id, switch_id, attr_count, attr_list);
}



60 changes: 60 additions & 0 deletions tests/mock_tests/portsorch_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
#include "mock_orchagent_main.h"
#include "mock_table.h"
#include "notifier.h"
#include "mock_sai_bridge.h"
#define private public
#include "pfcactionhandler.h"
#undef private

#include <sstream>

extern redisReply *mockReply;
using ::testing::_;
using ::testing::StrictMock;

namespace portsorch_test
{
Expand Down Expand Up @@ -116,6 +119,21 @@ namespace portsorch_test
sai_queue_api = pold_sai_queue_api;
}

sai_bridge_api_t ut_sai_bridge_api;
sai_bridge_api_t *org_sai_bridge_api;

void _hook_sai_bridge_api()
{
ut_sai_bridge_api = *sai_bridge_api;
org_sai_bridge_api = sai_bridge_api;
sai_bridge_api = &ut_sai_bridge_api;
}

void _unhook_sai_bridge_api()
{
sai_bridge_api = org_sai_bridge_api;
}

struct PortsOrchTest : public ::testing::Test
{
shared_ptr<swss::DBConnector> m_app_db;
Expand Down Expand Up @@ -310,6 +328,48 @@ namespace portsorch_test
ASSERT_FALSE(gPortsOrch->getPort(port.m_port_id, port));
}

/**
* Test case: PortsOrch::addBridgePort() does not add router port to .1Q bridge
*/
TEST_F(PortsOrchTest, addBridgePortOnRouterPort)
{
_hook_sai_bridge_api();

StrictMock<MockSaiBridge> mock_sai_bridge_;
mock_sai_bridge = &mock_sai_bridge_;
sai_bridge_api->create_bridge_port = mock_create_bridge_port;

Table portTable = Table(m_app_db.get(), APP_PORT_TABLE_NAME);

// Get SAI default ports to populate DB
auto ports = ut_helper::getInitialSaiPorts();

// Populate port table with SAI ports
for (const auto &it : ports)
{
portTable.set(it.first, it.second);
}

// Set PortConfigDone, PortInitDone
portTable.set("PortConfigDone", { { "count", to_string(ports.size()) } });
portTable.set("PortInitDone", { { "lanes", "0" } });

// refill consumer
gPortsOrch->addExistingData(&portTable);
// Apply configuration : create ports
static_cast<Orch *>(gPortsOrch)->doTask();

// Get first port and set its rif id to simulate it is router port
Port port;
gPortsOrch->getPort("Ethernet0", port);
port.m_rif_id = 1;

ASSERT_FALSE(gPortsOrch->addBridgePort(port));
EXPECT_CALL(mock_sai_bridge_, create_bridge_port(_, _, _, _)).Times(0);

_unhook_sai_bridge_api();
}

TEST_F(PortsOrchTest, PortSupportedFecModes)
{
_hook_sai_port_api();
Expand Down