Skip to content

Commit

Permalink
[DASH] Add meter rule bulk support and test to syncd
Browse files Browse the repository at this point in the history
Signed-off-by: Mukesh MV <mukesh@pensando.io>
  • Loading branch information
mukeshmv committed Nov 7, 2024
1 parent fe650bb commit ea567b9
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
8 changes: 8 additions & 0 deletions syncd/VendorSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,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 @@ -577,6 +581,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
84 changes: 84 additions & 0 deletions tests/TestDash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1639,3 +1639,87 @@ 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();

const uint32_t meter_rules_count = 2;
const uint32_t meter_rule_attrs_count = 4;

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[meter_rule_attrs_count] = {
{.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}},
};

sai_attribute_t attrs1[meter_rule_attrs_count] = {
{.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}},
};

const sai_attribute_t *attr_list[meter_rules_count] = {
attrs0,
attrs1,
};

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_vnet_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 < entries_count; i++) {
ASSERT_SUCCESS(statuses[i]);
}

for (uint32_t i = 0; i < entries_count; i++) {
sai_attribute_t attrs[] = {
{.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 = {}},
};

ASSERT_SUCCESS(dash_api->get_meter_rule_attribute(&meter_rules[i], sizeof(attrs)/sizeof(sai_attribute_t), 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_SUCCESS(dash_vnet_api->remove_meter_rules(meter_rules_count, meter_rules, SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, statuses));
for (uint32_t i = 0; i < entries_count; i++) {
ASSERT_SUCCESS(statuses[i]);
}

ASSERT_SUCCESS(dash_api->remove_meter_policy(meter_policy0));
ASSERT_SUCCESS(dash_api->remove_meter_policy(meter_policy1));
}

0 comments on commit ea567b9

Please sign in to comment.