diff --git a/syncd/VendorSai.cpp b/syncd/VendorSai.cpp index ed4580df2..6e083ab0b 100644 --- a/syncd/VendorSai.cpp +++ b/syncd/VendorSai.cpp @@ -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; @@ -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; diff --git a/tests/TestDash.cpp b/tests/TestDash.cpp index 623d64712..5f1d78bb0 100644 --- a/tests/TestDash.cpp +++ b/tests/TestDash.cpp @@ -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)); +} +