Skip to content

Commit 48650dc

Browse files
[P4Orch] Add support for SUBPORT in router_interface_manager. (#3891)
What I did Added a new feature to the router_interface_manager that allows it to support SUBPORT interfaces. Why I did it This was done to make the system more flexible.
1 parent 059ffc6 commit 48650dc

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

orchagent/p4orch/router_interface_manager.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,16 @@ ReturnCodeOr<std::vector<sai_attribute_t>> getSaiAttrs(const P4RouterInterfaceEn
104104
attr.id = SAI_ROUTER_INTERFACE_ATTR_VLAN_ID;
105105
attr.value.oid = port.m_vlan_info.vlan_oid;
106106
break;
107-
// TODO: add support for PORT::SUBPORT
107+
case Port::SUBPORT:
108+
attr.value.s32 = SAI_ROUTER_INTERFACE_TYPE_SUB_PORT;
109+
attrs.push_back(attr);
110+
attr.id = SAI_ROUTER_INTERFACE_ATTR_PORT_ID;
111+
attr.value.oid = port.m_port_id;
112+
attrs.push_back(attr);
113+
attr.id = SAI_ROUTER_INTERFACE_ATTR_OUTER_VLAN_ID;
114+
attr.value.oid = port.m_vlan_info.vlan_oid;
115+
break;
116+
108117
default:
109118
LOG_ERROR_AND_RETURN(ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM) << "Unsupported port type: " << port.m_type);
110119
}

orchagent/p4orch/tests/router_interface_manager_test.cpp

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ constexpr char *kPortName2 = "Ethernet2";
4141
constexpr sai_object_id_t kPortOid2 = 0x1fed3;
4242
constexpr uint32_t kMtu2 = 4500;
4343

44+
constexpr char* kPortName10 = "Ethernet10";
45+
constexpr sai_object_id_t kPortOid10 = 0xabcfff;
46+
constexpr uint32_t kMtu10 = 9100;
47+
4448
constexpr char *kRouterInterfaceId1 = "intf-3/4";
4549
constexpr sai_object_id_t kRouterInterfaceOid1 = 0x295100;
4650
const swss::MacAddress kMacAddress1("00:01:02:03:04:05");
4751

4852
constexpr char *kRouterInterfaceId2 = "Ethernet20";
4953
constexpr sai_object_id_t kRouterInterfaceOid2 = 0x51411;
54+
constexpr sai_object_id_t kVlanOid2 = 0xffffff;
5055
const swss::MacAddress kMacAddress2("00:ff:ee:dd:cc:bb");
5156

5257
const swss::MacAddress kZeroMacAddress("00:00:00:00:00:00");
@@ -55,7 +60,7 @@ constexpr char *kRouterIntfAppDbKey = R"({"match/router_interface_id":"intf-3/4"
5560

5661
std::unordered_map<sai_attr_id_t, sai_attribute_value_t> CreateRouterInterfaceAttributeList(
5762
const sai_object_id_t &virtual_router_oid, const swss::MacAddress mac_address, const sai_object_id_t &port_oid,
58-
const uint32_t mtu)
63+
const uint32_t mtu, const bool sub_port = false, const sai_object_id_t& vlan_oid = 0)
5964
{
6065
std::unordered_map<sai_attr_id_t, sai_attribute_value_t> attr_list;
6166
sai_attribute_value_t attr_value;
@@ -69,7 +74,15 @@ std::unordered_map<sai_attr_id_t, sai_attribute_value_t> CreateRouterInterfaceAt
6974
attr_list[SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS] = attr_value;
7075
}
7176

72-
attr_value.s32 = SAI_ROUTER_INTERFACE_TYPE_PORT;
77+
if (sub_port)
78+
{
79+
attr_value.oid = vlan_oid;
80+
attr_list[SAI_ROUTER_INTERFACE_ATTR_OUTER_VLAN_ID] = attr_value;
81+
82+
attr_value.s32 = SAI_ROUTER_INTERFACE_TYPE_SUB_PORT;
83+
} else
84+
attr_value.s32 = SAI_ROUTER_INTERFACE_TYPE_PORT;
85+
7386
attr_list[SAI_ROUTER_INTERFACE_ATTR_TYPE] = attr_value;
7487

7588
attr_value.oid = port_oid;
@@ -135,6 +148,15 @@ bool MatchCreateRouterInterfaceAttributeList(
135148
matched_attr_num++;
136149
break;
137150

151+
case SAI_ROUTER_INTERFACE_ATTR_OUTER_VLAN_ID:
152+
if (attr_list[i].value.oid !=
153+
expected_attr_list.at(SAI_ROUTER_INTERFACE_ATTR_OUTER_VLAN_ID)
154+
.oid) {
155+
return false;
156+
}
157+
matched_attr_num++;
158+
break;
159+
138160
default:
139161
// Unexpected attribute present in attribute list
140162
return false;
@@ -248,14 +270,14 @@ class RouterInterfaceManagerTest : public ::testing::Test
248270
}
249271

250272
void AddRouterInterfaceEntry(P4RouterInterfaceEntry &router_intf_entry, const sai_object_id_t port_oid,
251-
const uint32_t mtu)
273+
const uint32_t mtu, const bool sub_port = false, const sai_object_id_t vlan_oid = 0)
252274
{
253275
EXPECT_CALL(mock_sai_router_intf_,
254276
create_router_interface(
255-
::testing::NotNull(), Eq(gSwitchId), Eq(5),
277+
::testing::NotNull(), Eq(gSwitchId), sub_port ? Eq(6) : Eq(5),
256278
Truly(std::bind(MatchCreateRouterInterfaceAttributeList, std::placeholders::_1,
257279
CreateRouterInterfaceAttributeList(
258-
gVirtualRouterId, router_intf_entry.src_mac_address, port_oid, mtu)))))
280+
gVirtualRouterId, router_intf_entry.src_mac_address, port_oid, mtu, sub_port, vlan_oid)))))
259281
.WillOnce(DoAll(SetArgPointee<0>(router_intf_entry.router_interface_oid), Return(SAI_STATUS_SUCCESS)));
260282

261283
const std::string router_intf_key =
@@ -277,6 +299,16 @@ TEST_F(RouterInterfaceManagerTest, CreateRouterInterfaceValidAttributes)
277299
ValidateRouterInterfaceEntry(router_intf_entry);
278300
}
279301

302+
TEST_F(RouterInterfaceManagerTest, CreateRouterInterfaceWithSubport)
303+
{
304+
P4RouterInterfaceEntry router_intf_entry(kRouterInterfaceId1, kPortName10,
305+
kMacAddress1);
306+
AddRouterInterfaceEntry(router_intf_entry, kPortOid10, kMtu10, true,
307+
kVlanOid2);
308+
309+
ValidateRouterInterfaceEntry(router_intf_entry);
310+
}
311+
280312
TEST_F(RouterInterfaceManagerTest, CreateRouterInterfaceEntryExistsInManager)
281313
{
282314
P4RouterInterfaceEntry router_intf_entry(kRouterInterfaceId1, kPortName1, kMacAddress1);

orchagent/p4orch/tests/test_main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ using ::testing::StrictMock;
115115

116116
void CreatePort(const std::string port_name, const uint32_t speed, const uint32_t mtu, const sai_object_id_t port_oid,
117117
Port::Type port_type = Port::PHY, const sai_port_oper_status_t oper_status = SAI_PORT_OPER_STATUS_DOWN,
118+
const sai_object_id_t vlan_oid = 0,
118119
const sai_object_id_t vrouter_id = gVirtualRouterId, const bool admin_state_up = true)
119120
{
120121
Port port(port_name, port_type);
@@ -131,6 +132,7 @@ void CreatePort(const std::string port_name, const uint32_t speed, const uint32_
131132
port.m_vr_id = vrouter_id;
132133
port.m_admin_state_up = admin_state_up;
133134
port.m_oper_status = oper_status;
135+
if (port_type == Port::SUBPORT) port.m_vlan_info.vlan_oid = vlan_oid;
134136

135137
gPortsOrch->setPort(port_name, port);
136138
}
@@ -155,6 +157,9 @@ void SetupPorts()
155157
/*mtu=*/9100, /*port_oid=*/0x5678, /*port_type*/ Port::MGMT);
156158
CreatePort(/*port_name=*/"Ethernet9", /*speed=*/50000,
157159
/*mtu=*/9100, /*port_oid=*/0x56789abcfff, Port::PHY, SAI_PORT_OPER_STATUS_UNKNOWN);
160+
CreatePort(/*port_name=*/"Ethernet10", /*speed=*/50000,
161+
/*mtu=*/9100, /*port_oid=*/0xabcfff, Port::SUBPORT, SAI_PORT_OPER_STATUS_DOWN,
162+
/*vlan_oid=*/0xffffff);
158163
}
159164

160165
void AddVrf()

0 commit comments

Comments
 (0)