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

[DASH] Add meter rule bulk support in syncd #1456

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions syncd/VendorSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ sai_status_t VendorSai::bulkCreate(
ptr = m_apis.dash_acl_api->create_dash_acl_rules;
break;

case SAI_OBJECT_TYPE_METER_RULE:
ptr = m_apis.dash_meter_api->create_meter_rules;
break;

default:
SWSS_LOG_ERROR("not implemented %s, FIXME", sai_serialize_object_type(object_type).c_str());
return SAI_STATUS_NOT_IMPLEMENTED;
Expand Down Expand Up @@ -572,6 +576,10 @@ sai_status_t VendorSai::bulkRemove(
ptr = m_apis.dash_acl_api->remove_dash_acl_rules;
break;

case SAI_OBJECT_TYPE_METER_RULE:
ptr = m_apis.dash_meter_api->remove_meter_rules;
break;

default:
SWSS_LOG_ERROR("not implemented %s, FIXME", sai_serialize_object_type(object_type).c_str());
return SAI_STATUS_NOT_IMPLEMENTED;
Expand Down
85 changes: 85 additions & 0 deletions tests/TestDash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1639,3 +1639,88 @@ TEST(APIBulk, outbound_ca_to_pa_entry)
ASSERT_SUCCESS(counter_api->remove_counter(counter0));
ASSERT_SUCCESS(counter_api->remove_counter(counter1));
}

TEST(APIBulk, meter_rule)
{
SWSS_LOG_ENTER();

auto switchid = TestDashEnv::instance()->getSwitchOid();

sai_dash_meter_api_t *dash_meter_api = nullptr;
ASSERT_SUCCESS(sai_api_query((sai_api_t)SAI_API_DASH_METER, (void**)&dash_meter_api));

sai_attribute_t attr;
sai_object_id_t meter_policy0, meter_policy1;
attr.id = SAI_METER_POLICY_ATTR_IP_ADDR_FAMILY;
attr.value.s32 = SAI_IP_ADDR_FAMILY_IPV4;
ASSERT_SUCCESS(dash_meter_api->create_meter_policy(&meter_policy0, switchid, 1, &attr));
ASSERT_SUCCESS(dash_meter_api->create_meter_policy(&meter_policy1, switchid, 1, &attr));


sai_ip_address_t dst0 = {};
sai_ip_address_t mask0 = {};
sai_ip_address_t dst1 = {};
sai_ip_address_t mask1 = {};
dst0.addr_family = dst1.addr_family = mask0.addr_family = mask1.addr_family = SAI_IP_ADDR_FAMILY_IPV4;
inet_pton(AF_INET, "192.1.1.0", &dst0.addr.ip4);
inet_pton(AF_INET, "255.255.255.0", &mask0.addr.ip4);
inet_pton(AF_INET, "192.15.0.0", &dst1.addr.ip4);
inet_pton(AF_INET, "255.255.0.0", &mask1.addr.ip4);

sai_attribute_t attrs0[] = {
{.id = SAI_METER_RULE_ATTR_METER_POLICY_ID, .value = (sai_attribute_value_t){.oid = meter_policy0}},
{.id = SAI_METER_RULE_ATTR_DIP, .value = (sai_attribute_value_t){.ipaddr = dst0}},
{.id = SAI_METER_RULE_ATTR_DIP_MASK, .value = (sai_attribute_value_t){.ipaddr = mask0}},
{.id = SAI_METER_RULE_ATTR_METER_CLASS, .value = (sai_attribute_value_t){.u32 = 100}},
{.id = SAI_METER_RULE_ATTR_PRIORITY, .value = (sai_attribute_value_t){.u32 = 1}},
};

sai_attribute_t attrs1[] = {
{.id = SAI_METER_RULE_ATTR_METER_POLICY_ID, .value = (sai_attribute_value_t){.oid = meter_policy1}},
{.id = SAI_METER_RULE_ATTR_DIP, .value = (sai_attribute_value_t){.ipaddr = dst1}},
{.id = SAI_METER_RULE_ATTR_DIP_MASK, .value = (sai_attribute_value_t){.ipaddr = mask1}},
{.id = SAI_METER_RULE_ATTR_METER_CLASS, .value = (sai_attribute_value_t){.u32 = 200}},
{.id = SAI_METER_RULE_ATTR_PRIORITY, .value = (sai_attribute_value_t){.u32 = 2}},
};

const sai_attribute_t *attr_list[] = {
attrs0,
attrs1,
};
constexpr uint32_t meter_rules_count = sizeof(attr_list) / sizeof(sai_attribute_t*);
constexpr uint32_t meter_rule_attrs_count = sizeof(attrs0) / sizeof(sai_attribute_t);

uint32_t attr_count[meter_rules_count] = {meter_rule_attrs_count, meter_rule_attrs_count};
sai_object_id_t meter_rules[meter_rules_count];
sai_status_t statuses[meter_rules_count] = {};

ASSERT_SUCCESS(dash_meter_api->create_meter_rules(switchid, meter_rules_count, attr_count, attr_list, SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, meter_rules, statuses));
for (uint32_t i = 0; i < meter_rules_count; i++) {
ASSERT_SUCCESS(statuses[i]);
}

for (uint32_t i = 0; i < meter_rules_count; i++) {
sai_attribute_t attrs[meter_rule_attrs_count] = {
{.id = SAI_METER_RULE_ATTR_METER_POLICY_ID, .value = {}},
{.id = SAI_METER_RULE_ATTR_DIP, .value = {}},
{.id = SAI_METER_RULE_ATTR_DIP_MASK, .value = {}},
{.id = SAI_METER_RULE_ATTR_METER_CLASS, .value = {}},
{.id = SAI_METER_RULE_ATTR_PRIORITY, .value = {}},
};

ASSERT_SUCCESS(dash_meter_api->get_meter_rule_attribute(meter_rules[i], meter_rule_attrs_count, attrs));
ASSERT_EQ(attrs[0].value.oid, attr_list[i][0].value.oid);
ASSERT_EQ(attrs[1].value.ipaddr, attr_list[i][1].value.ipaddr);
ASSERT_EQ(attrs[2].value.ipaddr, attr_list[i][2].value.ipaddr);
ASSERT_EQ(attrs[3].value.u32, attr_list[i][3].value.u32);
ASSERT_EQ(attrs[4].value.u32, attr_list[i][4].value.u32);
}

ASSERT_SUCCESS(dash_meter_api->remove_meter_rules(meter_rules_count, meter_rules, SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, statuses));
for (uint32_t i = 0; i < meter_rules_count; i++) {
ASSERT_SUCCESS(statuses[i]);
}

ASSERT_SUCCESS(dash_meter_api->remove_meter_policy(meter_policy0));
ASSERT_SUCCESS(dash_meter_api->remove_meter_policy(meter_policy1));
}
65 changes: 65 additions & 0 deletions unittest/syncd/TestVendorSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1478,3 +1478,68 @@ TEST_F(VendorSaiTest, bulk_meter_bucket_entry)
EXPECT_EQ(SAI_STATUS_NOT_SUPPORTED,
m_vsai->bulkSet(0, e, nullptr, SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, nullptr));
}

TEST(VendorSai, bulk_meter_rules)
{
VendorSai sai;
sai.apiInitialize(0, &test_services);

sai_object_id_t switchid = create_switch(sai);

sai_attribute_t attr;
sai_object_id_t meter_policy0, meter_policy1;
attr.id = SAI_METER_POLICY_ATTR_IP_ADDR_FAMILY;
attr.value.s32 = SAI_IP_ADDR_FAMILY_IPV4;
EXPECT_EQ(SAI_STATUS_SUCCESS, sai.create((sai_object_type_t)SAI_OBJECT_TYPE_METER_POLICY, &meter_policy0, switchid, 1, &attr));
EXPECT_EQ(SAI_STATUS_SUCCESS, sai.create((sai_object_type_t)SAI_OBJECT_TYPE_METER_POLICY, &meter_policy1, switchid, 1, &attr));

sai_ip_address_t dst0 = {};
sai_ip_address_t mask0 = {};
sai_ip_address_t dst1 = {};
sai_ip_address_t mask1 = {};
dst0.addr_family = dst1.addr_family = mask0.addr_family = mask1.addr_family = SAI_IP_ADDR_FAMILY_IPV4;
inet_pton(AF_INET, "192.1.1.0", &dst0.addr.ip4);
inet_pton(AF_INET, "255.255.255.0", &mask0.addr.ip4);
inet_pton(AF_INET, "192.15.0.0", &dst1.addr.ip4);
inet_pton(AF_INET, "255.255.0.0", &mask1.addr.ip4);

sai_attribute_t attrs0[] = {
{.id = SAI_METER_RULE_ATTR_METER_POLICY_ID, .value = (sai_attribute_value_t){.oid = meter_policy0}},
{.id = SAI_METER_RULE_ATTR_DIP, .value = (sai_attribute_value_t){.ipaddr = dst0}},
{.id = SAI_METER_RULE_ATTR_DIP_MASK, .value = (sai_attribute_value_t){.ipaddr = mask0}},
{.id = SAI_METER_RULE_ATTR_METER_CLASS, .value = (sai_attribute_value_t){.u32 = 100}},
{.id = SAI_METER_RULE_ATTR_PRIORITY, .value = (sai_attribute_value_t){.u32 = 1}},
};

sai_attribute_t attrs1[] = {
{.id = SAI_METER_RULE_ATTR_METER_POLICY_ID, .value = (sai_attribute_value_t){.oid = meter_policy1}},
{.id = SAI_METER_RULE_ATTR_DIP, .value = (sai_attribute_value_t){.ipaddr = dst1}},
{.id = SAI_METER_RULE_ATTR_DIP_MASK, .value = (sai_attribute_value_t){.ipaddr = mask1}},
{.id = SAI_METER_RULE_ATTR_METER_CLASS, .value = (sai_attribute_value_t){.u32 = 200}},
{.id = SAI_METER_RULE_ATTR_PRIORITY, .value = (sai_attribute_value_t){.u32 = 2}},
};

const sai_attribute_t *attr_list[] = {
attrs0,
attrs1,
};
constexpr uint32_t meter_rules_count = sizeof(attr_list) / sizeof(sai_attribute_t*);
constexpr uint32_t meter_rule_attrs_count = sizeof(attrs0) / sizeof(sai_attribute_t);

uint32_t attr_count[meter_rules_count] = {meter_rule_attrs_count, meter_rule_attrs_count};
sai_object_id_t meter_rules[meter_rules_count];
sai_status_t statuses[meter_rules_count] = {};

EXPECT_EQ(SAI_STATUS_SUCCESS, sai.bulkCreate((sai_object_type_t)SAI_OBJECT_TYPE_METER_RULE, switchid, meter_rules_count, attr_count, attr_list, SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, meter_rules, statuses));
for (uint32_t i = 0; i < meter_rules_count; i++) {
EXPECT_EQ(SAI_STATUS_SUCCESS, statuses[i]);
}

EXPECT_EQ(SAI_STATUS_SUCCESS, sai.bulkRemove((sai_object_type_t)SAI_OBJECT_TYPE_METER_RULE, meter_rules_count, meter_rules, SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, statuses));
for (uint32_t i = 0; i < meter_rules_count; i++) {
EXPECT_EQ(SAI_STATUS_SUCCESS, statuses[i]);
}

EXPECT_EQ(SAI_STATUS_SUCCESS, sai.remove((sai_object_type_t)SAI_OBJECT_TYPE_METER_POLICY, meter_policy0));
EXPECT_EQ(SAI_STATUS_SUCCESS, sai.remove((sai_object_type_t)SAI_OBJECT_TYPE_METER_POLICY, meter_policy1));
}
Loading