From db45b9226d531ece95178e555cea1b02a9f60df7 Mon Sep 17 00:00:00 2001 From: LIU Yulong Date: Wed, 12 May 2021 10:57:48 +0800 Subject: [PATCH] Adds API extension for QoS rule type pps This patch adds new API extension for QoS rule type packet per second(pps). Related-bug: #1912460 Change-Id: I4148fb3c0da6c45f24ddd4d640c2ad0d34778e51 --- api-ref/source/v2/parameters.yaml | 68 ++++++ api-ref/source/v2/qos.inc | 213 ++++++++++++++++++ ...packet_rate_limit_rule-create-request.json | 6 + ...acket_rate_limit_rule-create-response.json | 8 + .../packet_rate_limit_rule-show-response.json | 8 + ...packet_rate_limit_rule-update-request.json | 6 + ...acket_rate_limit_rule-update-response.json | 8 + ...packet_rate_limit_rules-list-response.json | 10 + neutron_lib/api/definitions/__init__.py | 2 + neutron_lib/api/definitions/qos_pps_rule.py | 76 +++++++ neutron_lib/services/qos/constants.py | 4 + .../unit/api/definitions/test_qos_pps_rule.py | 33 +++ ...qos_pps_rule_api_def-dae7c6e67904781b.yaml | 5 + 13 files changed, 447 insertions(+) create mode 100644 api-ref/source/v2/samples/qos/packet_rate_limit_rule-create-request.json create mode 100644 api-ref/source/v2/samples/qos/packet_rate_limit_rule-create-response.json create mode 100644 api-ref/source/v2/samples/qos/packet_rate_limit_rule-show-response.json create mode 100644 api-ref/source/v2/samples/qos/packet_rate_limit_rule-update-request.json create mode 100644 api-ref/source/v2/samples/qos/packet_rate_limit_rule-update-response.json create mode 100644 api-ref/source/v2/samples/qos/packet_rate_limit_rules-list-response.json create mode 100644 neutron_lib/api/definitions/qos_pps_rule.py create mode 100644 neutron_lib/tests/unit/api/definitions/test_qos_pps_rule.py create mode 100644 releasenotes/notes/add_qos_pps_rule_api_def-dae7c6e67904781b.yaml diff --git a/api-ref/source/v2/parameters.yaml b/api-ref/source/v2/parameters.yaml index b020c2f52..10a699e8f 100644 --- a/api-ref/source/v2/parameters.yaml +++ b/api-ref/source/v2/parameters.yaml @@ -699,12 +699,24 @@ max_burst_kbps-query: in: query required: false type: integer +max_burst_kpps-query: + description: | + Filter the list result by the max burst kpps (kilo packets per second) value. + in: query + required: false + type: integer max_kbps-response-query: description: | Filter the list result by the maximum KBPS (kilobits per second) value. in: query required: false type: integer +max_kpps-query: + description: | + Filter the list result by the max kpps (kilo packets per second) value. + in: query + required: false + type: integer max_prefixlen-query: description: | Filter the subnet pool list result by the maximum prefix size that can be @@ -1096,6 +1108,19 @@ qos_minimum_bandwidth_rule-sort_key: in: query required: false type: string +qos_packet_rate_limit_rule-sort_key: + description: | + Sorts by a packet rate limit rule attribute. You can specify multiple pairs + of sort key and sort direction query parameters. The sort keys are limited + to: + + - ``direction`` + - ``id`` + - ``max_kpps`` + - ``max_burst_kpps`` + in: query + required: false + type: string rbac-sort_key: description: | Sorts by a RBAC policy attribute. You can specify multiple pairs of sort @@ -3826,6 +3851,18 @@ max_burst_kbps-response: in: body required: true type: integer +max_burst_kpps: + description: | + The max burst kpps (kilo packets per second) value. + in: body + required: true + type: integer +max_burst_kpps-response: + description: | + The max burst kpps (kilo packets per second) value. + in: body + required: true + type: integer max_kbps: description: | The maximum KBPS (kilobits per second) value. If you specify this @@ -3840,6 +3877,18 @@ max_kbps-response: in: body required: true type: integer +max_kpps: + description: | + The max kpps (kilo packets per second) value. + in: body + required: true + type: integer +max_kpps-response: + description: | + The max kpps (kilo packets per second) value. + in: body + required: true + type: integer max_prefixlen: description: | The maximum prefix size that can be allocated @@ -4254,6 +4303,19 @@ object_type: in: body required: true type: string +packet_rate_limit_rule: + description: | + A ``packet_rate_limit_rule`` object. + in: body + required: true + type: object +packet_rate_limit_rules: + description: | + A list of ``packet_rate_limit_rule`` objects associated with + the QoS policy. + in: body + required: true + type: array peer_address: description: | The peer gateway public IPv4 or IPv6 address or @@ -4759,6 +4821,12 @@ qos_network_policy_id-port-response: in: body required: true type: string +qos_packet_rate_limit_rule-id: + description: | + The ID of the QoS packet rate limit rule. + in: body + required: true + type: string qos_policy-name: description: | Human-readable name of the resource. diff --git a/api-ref/source/v2/qos.inc b/api-ref/source/v2/qos.inc index bac67fc8f..236030920 100644 --- a/api-ref/source/v2/qos.inc +++ b/api-ref/source/v2/qos.inc @@ -978,6 +978,219 @@ Response There is no body content for the response of a successful DELETE request. +=========================== +QoS packet rate limit rules +=========================== + +Lists, creates, deletes, shows information for, and updates QoS packet rate limit rules. + +List packet rate limit rules for QoS policy +=========================================== + +.. rest_method:: GET /v2.0/qos/policies/{policy_id}/packet_rate_limit_rules + +Lists all packet rate limit rules for a QoS policy. + +The list might be empty. + +You can control which response parameters are returned by using the +fields query parameter. For information, see `Filtering and column +selection `__. + +Normal response codes: 200 + +Error response codes: 401, 404 + +Request +------- + +.. rest_parameters:: parameters.yaml + + - policy_id: qos-policy-id-path + - max_kpps: max_kpps-query + - max_burst_kpps: max_burst_kpps-query + - id: id-query + - direction: qos-rule-direction-query + - sort_dir: sort_dir + - sort_key: qos_packet_rate_limit_rule-sort_key + +Response Parameters +------------------- + +.. rest_parameters:: parameters.yaml + + - packet_rate_limit_rules: packet_rate_limit_rules + - max_kpps: max_kpps-response + - max_burst_kpps: max_burst_kpps-response + - id: qos_packet_rate_limit_rule-id + - direction: qos-rule-direction-response + - tags: tags + +Response Example +---------------- + +.. literalinclude:: samples/qos/packet_rate_limit_rules-list-response.json + :language: javascript + +Create packet rate limit rule +============================= + +.. rest_method:: POST /v2.0/qos/policies/{policy_id}/packet_rate_limit_rules + +Creates a packet rate limit rule for a QoS policy. + +Normal response codes: 201 + +Error response codes: 400, 401, 404, 409 + +Request +------- + +.. rest_parameters:: parameters.yaml + + - policy_id: qos-policy-id-path + - packet_rate_limit_rule: packet_rate_limit_rule + - max_kpps: max_kpps + - max_burst_kpps: max_burst_kpps + - direction: qos-rule-direction + +Request Example +--------------- + +.. literalinclude:: samples/qos/packet_rate_limit_rule-create-request.json + :language: javascript + +Response Parameters +------------------- + +.. rest_parameters:: parameters.yaml + + - packet_rate_limit_rule: packet_rate_limit_rule + - max_kpps: max_kpps-response + - max_burst_kpps: max_burst_kpps-response + - id: qos_packet_rate_limit_rule-id + - direction: qos-rule-direction-response + - tags: tags + +Response Example +---------------- + +.. literalinclude:: samples/qos/packet_rate_limit_rule-create-response.json + :language: javascript + +Show packet rate limit rule details +=================================== + +.. rest_method:: GET /v2.0/qos/policies/{policy_id}/packet_rate_limit_rules/{rule_id} + +Shows details for a packet rate limit rule for a QoS policy. + +Normal response codes: 200 + +Error response codes: 401, 404 + +Request +------- + +.. rest_parameters:: parameters.yaml + + - policy_id: qos-policy-id-path + - rule_id: qos-rule_id + +Response Parameters +------------------- + +.. rest_parameters:: parameters.yaml + + - packet_rate_limit_rule: packet_rate_limit_rule + - max_kpps: max_kpps-response + - max_burst_kpps: max_burst_kpps-response + - id: qos_packet_rate_limit_rule-id + - direction: qos-rule-direction-response + - tags: tags + +Response Example +---------------- + +.. literalinclude:: samples/qos/packet_rate_limit_rule-show-response.json + :language: javascript + +Update packet rate limit rule +============================= + +.. rest_method:: PUT /v2.0/qos/policies/{policy_id}/packet_rate_limit_rules/{rule_id} + +Updates a packet rate limit rule for a QoS policy. + +If the request is valid, the service returns the ``Accepted (202)`` +response code. + +Normal response codes: 202 + +Error response codes: 400, 401, 404 + +Request +------- + +.. rest_parameters:: parameters.yaml + + - policy_id: qos-policy-id-path + - rule_id: qos-rule_id + - packet_rate_limit_rule: packet_rate_limit_rule + - max_kpps: max_kpps + - max_burst_kpps: max_burst_kpps + - direction: qos-rule-direction-update + +Request Example +--------------- + +.. literalinclude:: samples/qos/packet_rate_limit_rule-update-request.json + :language: javascript + +Response Parameters +------------------- + +.. rest_parameters:: parameters.yaml + + - packet_rate_limit_rule: packet_rate_limit_rule + - max_kpps: max_kpps-response + - max_burst_kpps: max_burst_kpps-response + - id: qos_packet_rate_limit_rule-id + - direction: qos-rule-direction-update-response + - tags: tags + +Response Example +---------------- + +.. literalinclude:: samples/qos/packet_rate_limit_rule-update-response.json + :language: javascript + +Delete packet rate limit rule +============================= + +.. rest_method:: DELETE /v2.0/qos/policies/{policy_id}/packet_rate_limit_rules/{rule_id} + +Deletes a packet rate limit rule for a QoS policy. + +Normal response codes: 204 + +Error response codes: 400, 401, 404 + +Request +------- + +.. rest_parameters:: parameters.yaml + + - policy_id: qos-policy-id-path + - rule_id: qos-rule_id + +Response +-------- + +There is no body content for the response of a successful DELETE request. + ================================== Quality of Service rules alias API ================================== diff --git a/api-ref/source/v2/samples/qos/packet_rate_limit_rule-create-request.json b/api-ref/source/v2/samples/qos/packet_rate_limit_rule-create-request.json new file mode 100644 index 000000000..9c6f87be1 --- /dev/null +++ b/api-ref/source/v2/samples/qos/packet_rate_limit_rule-create-request.json @@ -0,0 +1,6 @@ +{ + "packet_rate_limit_rule": { + "max_kpps": "10000", + "max_burst_kpps": "10000" + } +} diff --git a/api-ref/source/v2/samples/qos/packet_rate_limit_rule-create-response.json b/api-ref/source/v2/samples/qos/packet_rate_limit_rule-create-response.json new file mode 100644 index 000000000..7fb07ed1a --- /dev/null +++ b/api-ref/source/v2/samples/qos/packet_rate_limit_rule-create-response.json @@ -0,0 +1,8 @@ +{ + "packet_rate_limit_rule": { + "id": "1eddf7af-0b4c-42c5-8ae1-390b32f1de08", + "max_kpps": 10000, + "max_burst_kpps": 10000, + "direction": "egress" + } +} diff --git a/api-ref/source/v2/samples/qos/packet_rate_limit_rule-show-response.json b/api-ref/source/v2/samples/qos/packet_rate_limit_rule-show-response.json new file mode 100644 index 000000000..7fb07ed1a --- /dev/null +++ b/api-ref/source/v2/samples/qos/packet_rate_limit_rule-show-response.json @@ -0,0 +1,8 @@ +{ + "packet_rate_limit_rule": { + "id": "1eddf7af-0b4c-42c5-8ae1-390b32f1de08", + "max_kpps": 10000, + "max_burst_kpps": 10000, + "direction": "egress" + } +} diff --git a/api-ref/source/v2/samples/qos/packet_rate_limit_rule-update-request.json b/api-ref/source/v2/samples/qos/packet_rate_limit_rule-update-request.json new file mode 100644 index 000000000..a8120ae79 --- /dev/null +++ b/api-ref/source/v2/samples/qos/packet_rate_limit_rule-update-request.json @@ -0,0 +1,6 @@ +{ + "packet_rate_limit_rule": { + "max_kpps": "20000", + "max_burst_kpps": "20000" + } +} diff --git a/api-ref/source/v2/samples/qos/packet_rate_limit_rule-update-response.json b/api-ref/source/v2/samples/qos/packet_rate_limit_rule-update-response.json new file mode 100644 index 000000000..cefe67a09 --- /dev/null +++ b/api-ref/source/v2/samples/qos/packet_rate_limit_rule-update-response.json @@ -0,0 +1,8 @@ +{ + "packet_rate_limit_rule": { + "id": "1eddf7af-0b4c-42c5-8ae1-390b32f1de08", + "max_kpps": 20000, + "max_burst_kpps": 20000, + "direction": "egress" + } +} diff --git a/api-ref/source/v2/samples/qos/packet_rate_limit_rules-list-response.json b/api-ref/source/v2/samples/qos/packet_rate_limit_rules-list-response.json new file mode 100644 index 000000000..141662cc0 --- /dev/null +++ b/api-ref/source/v2/samples/qos/packet_rate_limit_rules-list-response.json @@ -0,0 +1,10 @@ +{ + "packet_rate_limit_rules": [ + { + "id": "1eddf7af-0b4c-42c5-8ae1-390b32f1de08", + "max_kpps": 10000, + "max_burst_kpps": 10000, + "direction": "egress" + } + ] +} diff --git a/neutron_lib/api/definitions/__init__.py b/neutron_lib/api/definitions/__init__.py index 8d1838716..83a456051 100644 --- a/neutron_lib/api/definitions/__init__.py +++ b/neutron_lib/api/definitions/__init__.py @@ -89,6 +89,7 @@ from neutron_lib.api.definitions import qos_bw_minimum_ingress from neutron_lib.api.definitions import qos_default from neutron_lib.api.definitions import qos_gateway_ip from neutron_lib.api.definitions import qos_port_network_policy +from neutron_lib.api.definitions import qos_pps_rule from neutron_lib.api.definitions import qos_rule_type_details from neutron_lib.api.definitions import qos_rules_alias from neutron_lib.api.definitions import rbac_address_groups @@ -209,6 +210,7 @@ _ALL_API_DEFINITIONS = { qos_default, qos_gateway_ip, qos_port_network_policy, + qos_pps_rule, qos_rule_type_details, qos_rules_alias, rbac_address_groups, diff --git a/neutron_lib/api/definitions/qos_pps_rule.py b/neutron_lib/api/definitions/qos_pps_rule.py new file mode 100644 index 000000000..8a322d91d --- /dev/null +++ b/neutron_lib/api/definitions/qos_pps_rule.py @@ -0,0 +1,76 @@ +# Copyright (c) 2021 China Unicom Cloud Data Co.,Ltd. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import copy + +from neutron_lib.api import converters +from neutron_lib.api.definitions import qos as qos_apidef +from neutron_lib import constants +from neutron_lib.db import constants as db_const +from neutron_lib.services.qos import constants as qos_const + + +ALIAS = 'qos-pps' +IS_SHIM_EXTENSION = False +IS_STANDARD_ATTR_EXTENSION = False +NAME = 'QoS Rule Type Packet per Second Extension' +API_PREFIX = '' +DESCRIPTION = 'Add QoS Rule Type Packet per Second' +UPDATED_TIMESTAMP = '2021-05-12T10:00:00-00:00' +RESOURCE_ATTRIBUTE_MAP = {} +PACKET_RATE_LIMIT_RULES = 'packet_rate_limit_rules' +SUB_RES_ATTR_MAP = copy.deepcopy( + qos_apidef.SUB_RESOURCE_ATTRIBUTE_MAP) +SUB_RES_ATTR_MAP.update({ + PACKET_RATE_LIMIT_RULES: { + 'parent': qos_apidef._PARENT, + 'parameters': dict( + qos_apidef._QOS_RULE_COMMON_FIELDS, + **{qos_const.MAX_KPPS: { + 'allow_post': True, 'allow_put': True, + 'convert_to': converters.convert_to_int, + 'is_visible': True, + 'is_filter': True, + 'is_sort_key': True, + 'validate': { + 'type:range': [0, db_const.DB_INTEGER_MAX_VALUE]} + }, + qos_const.MAX_BURST_KPPS: { + 'allow_post': True, 'allow_put': True, + 'is_visible': True, 'default': 0, + 'is_filter': True, + 'is_sort_key': True, + 'convert_to': converters.convert_to_int, + 'validate': { + 'type:range': [0, db_const.DB_INTEGER_MAX_VALUE]} + }, + qos_const.DIRECTION: { + 'allow_post': True, + 'allow_put': True, + 'is_visible': True, + 'is_filter': True, + 'is_sort_key': True, + 'default': constants.EGRESS_DIRECTION, + 'validate': { + 'type:values': constants.VALID_DIRECTIONS} + } + }), + } +}) +SUB_RESOURCE_ATTRIBUTE_MAP = SUB_RES_ATTR_MAP +ACTION_MAP = {} +REQUIRED_EXTENSIONS = [qos_apidef.ALIAS] +OPTIONAL_EXTENSIONS = [] +ACTION_STATUS = {} diff --git a/neutron_lib/services/qos/constants.py b/neutron_lib/services/qos/constants.py index b585c8b2c..49e9e745a 100644 --- a/neutron_lib/services/qos/constants.py +++ b/neutron_lib/services/qos/constants.py @@ -28,6 +28,10 @@ MIN_KBPS = "min_kbps" DIRECTION = "direction" DSCP_MARK = "dscp_mark" +# Names of pps rules' attributes +MAX_KPPS = "max_kpps" +MAX_BURST_KPPS = "max_burst_kpps" + QOS_POLICY_ID = 'qos_policy_id' QOS_NETWORK_POLICY_ID = 'qos_network_policy_id' diff --git a/neutron_lib/tests/unit/api/definitions/test_qos_pps_rule.py b/neutron_lib/tests/unit/api/definitions/test_qos_pps_rule.py new file mode 100644 index 000000000..b339faf59 --- /dev/null +++ b/neutron_lib/tests/unit/api/definitions/test_qos_pps_rule.py @@ -0,0 +1,33 @@ +# Copyright (c) 2021 China Unicom Cloud Data Co.,Ltd. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from neutron_lib.api.definitions import qos as qos_apidef +from neutron_lib.api.definitions import qos_pps_rule +from neutron_lib.services.qos import constants as qos_const +from neutron_lib.tests.unit.api.definitions import base + + +class QoSPPSRuleDefinitionTestCase(base.DefinitionBaseTestCase): + extension_module = qos_pps_rule + + extension_resources = (qos_apidef.POLICIES,) + extension_subresources = (qos_apidef.BANDWIDTH_LIMIT_RULES, + qos_apidef.DSCP_MARKING_RULES, + qos_apidef.MIN_BANDWIDTH_RULES, + qos_pps_rule.PACKET_RATE_LIMIT_RULES) + extension_attributes = (qos_const.MAX_KPPS, qos_const.MAX_BURST_KPPS, + qos_const.DIRECTION, qos_const.MAX_BURST, 'type', + qos_const.DSCP_MARK, qos_const.MIN_KBPS, 'rules', + qos_const.MAX_KBPS, qos_const.QOS_POLICY_ID) diff --git a/releasenotes/notes/add_qos_pps_rule_api_def-dae7c6e67904781b.yaml b/releasenotes/notes/add_qos_pps_rule_api_def-dae7c6e67904781b.yaml new file mode 100644 index 000000000..cc80877d1 --- /dev/null +++ b/releasenotes/notes/add_qos_pps_rule_api_def-dae7c6e67904781b.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Adding new API extension for QoS service plugin to allow + CURD actions for packet rate limit (packet per second) rule.