All Products
Search
Document Center

Cloud Enterprise Network:AddTrafficMatchRuleToTrafficMarkingPolicy

Last Updated:Oct 26, 2026

Adds a traffic classification rule to a traffic marking policy.

Operation description

The AddTrafficMatchRuleToTrafficMarkingPolicy API operation is asynchronous. After you send the request, the system returns a RequestId, but the traffic classification rule is not immediately created. The creation task is still running in the background. You can call the ListTrafficMarkingPolicies API operation to query the status of the traffic classification rule.

  • If the traffic classification rule is in the Creating state, the rule is being created. In this state, you can only query the rule and cannot perform other operations.

  • If the traffic classification rule is in the Active state, the rule is created.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

cen:AddTrafficMatchRuleToTrafficMarkingPolicy

create

*All Resource

*

None None

Request parameters

Parameter

Type

Required

Description

Example

ClientToken

string

No

The client token that is used to ensure the idempotence of the request.

You can use the client to generate the value, but you must ensure that it is unique among different requests. The client token can contain only ASCII characters.

Note

If you do not specify this parameter, the system automatically uses the RequestId of the API request as the ClientToken. The RequestId of each API request may be different.

123e4567-e89b-12d3-a456-426****

DryRun

boolean

No

Specifies whether to only precheck the request. Valid values:

  • true: prechecks the request without adding the traffic classification rule to the traffic marking policy. The system checks whether required parameters are specified, the request format, and service limits. If the request fails the precheck, the corresponding error is returned. If the request passes the precheck, the DryRunOperation error code is returned.

  • false (default): sends the request. After the request passes the precheck, the traffic classification rule is added to the traffic marking policy.

false

TrafficMarkingPolicyId

string

Yes

The ID of the traffic marking policy.

tm-u9nxup5kww5po8****

TrafficMatchRules

array<object>

No

The list of traffic classification rules.

You can add up to 50 traffic classification rules at a time.

object

No

The information about the traffic classification rule.

MatchDscp

integer

No

The Differentiated Services Code Point (DSCP) value of the traffic packet. Valid values: 0 to 63.

The traffic classification rule matches traffic that contains the specified DSCP value. If you do not specify this parameter, the rule matches traffic with any DSCP value.

Note

The DSCP value refers to the DSCP value carried by the traffic packet before it enters the inter-region connection.

5

DstCidr

string

No

The destination CIDR block of the traffic packet.

The traffic classification rule matches traffic whose destination IP address falls within the destination CIDR block. If you do not specify this parameter, the rule matches traffic with any destination IP address.

10.10.10.0/24

TrafficMatchRuleDescription

string

No

The description of the traffic classification rule.

The description can be empty or 1 to 256 characters in length. It cannot start with http:// or https://.

desctest

Protocol

string

No

The protocol type of the traffic packet.

The traffic classification rule supports matching traffic of various protocol types, such as HTTP, HTTPS, TCP, UDP, SSH, and Telnet. For more protocol types, log on to the Cloud Enterprise Network (CEN) console.

Some protocols use fixed ports. Click to view port details.

  • If the protocol type is ICMP, set the destination port number to -1.

  • If the protocol type is GRE, set the destination port number to -1.

  • If the protocol type is SSH, set the destination port number to 22.

  • If the protocol type is Telnet, set the destination port number to 23.

  • If the protocol type is HTTP, set the destination port number to 80.

  • If the protocol type is HTTPS, set the destination port number to 443.

  • If the protocol type is MS SQL, set the destination port number to 1443.

  • If the protocol type is Oracle, set the destination port number to 1521.

  • If the protocol type is Mysql, set the destination port number to 3306.

  • If the protocol type is RDP, set the destination port number to 3389.

  • If the protocol type is Postgre SQL, set the destination port number to 5432.

  • If the protocol type is Redis, set the destination port number to 6379.

HTTP

DstPortRange

array

No

The destination port of the traffic packet. Valid values: -1 and 1 to 65535.

The traffic classification rule matches traffic whose destination port number falls within the destination port range. If you do not specify this parameter, the rule matches traffic with any destination port number.

You can enter up to two port numbers for this parameter. The input format is described as follows:

  • If you enter only one port number, such as 1, the system matches traffic whose destination port is 1 by default. If you enter -1, the system matches traffic with any destination port.

  • If you enter two port numbers, such as 1 and 200, the system matches traffic whose destination port is in the range of 1 to 200 by default.

  • If you enter two port numbers and one of them is -1, the other port number must also be -1, which indicates that traffic with any destination port is matched.

integer

No

The destination port of the traffic packet. Valid values: -1 and 1 to 65535.

The traffic classification rule matches traffic whose destination port number falls within the destination port range. If you do not specify this parameter, the rule matches traffic with any destination port number.

You can enter up to two port numbers for this parameter. The input format is described as follows:

  • If you enter only one port number, such as 1, the system matches traffic whose destination port is 1 by default.

  • If you enter two port numbers, such as 1 and 200, the system matches traffic whose destination port is in the range of 1 to 200 by default.

  • If you enter two port numbers and one of them is -1, the other port number must also be -1, which indicates that traffic with any destination port is matched.

80

SrcCidr

string

No

The source CIDR block of the traffic packet.

The traffic classification rule matches traffic whose source IP address falls within the source CIDR block. If you do not specify this parameter, the rule matches traffic with any source IP address.

192.168.10.0/24

AddressFamily

string

No

The address family. Valid values: IPv4, IPv6, or empty.

IPv4

SrcPortRange

array

No

The source port of the traffic packet. Valid values: -1 and 1 to 65535.

The traffic classification rule matches traffic whose source port number falls within the source port range. If you do not specify this parameter, the rule matches traffic with any source port number.

You can enter up to two port numbers for this parameter. The input format is described as follows:

  • If you enter only one port number, such as 1, the system matches traffic whose source port is 1 by default. If you enter -1, the system matches traffic with any source port.

  • If you enter two port numbers, such as 1 and 200, the system matches traffic whose source port is in the range of 1 to 200 by default.

  • If you enter two port numbers and one of them is -1, the other port number must also be -1, which indicates that traffic with any source port is matched.

integer

No

The source port of the traffic packet. Valid values: -1 and 1 to 65535.

The traffic classification rule matches traffic whose source port number falls within the source port range. If you do not specify this parameter, the rule matches traffic with any source port number.

You can enter up to two port numbers for this parameter. The input format is described as follows:

  • If you enter only one port number, such as 1, the system matches traffic whose source port is 1 by default.

  • If you enter two port numbers, such as 1 and 200, the system matches traffic whose source port is in the range of 1 to 200 by default.

  • If you enter two port numbers and one of them is -1, the other port number must also be -1, which indicates that traffic with any source port is matched.

200

TrafficMatchRuleName

string

No

The name of the traffic classification rule.

The name can be empty or 1 to 128 characters in length. It cannot start with http:// or https://.

nametest

Response elements

Element

Type

Description

Example

object

The response.

RequestId

string

The request ID.

0876E54E-3E36-5C31-89F0-9EE8A9266F9A

Examples

Success response

JSON format

{
  "RequestId": "0876E54E-3E36-5C31-89F0-9EE8A9266F9A"
}

Error codes

HTTP status code

Error code

Error message

Description

400 InvalidTrafficMarkingPolicyId.NotFound Operation is failed because traffic marking policy id is not found. The error message returned because the specified traffic marking policy ID (TrafficMarkingPolicyId) does not exist.
400 IllegalParam.SrcCidr The specified SrcCidr is invalid. The error message returned because the specified source CIDR block is invalid.
400 IncorrectStatus.TrafficMarkingPolicy The status of TrafficMarkingPolicy is incorrect. The error message returned because the status of the traffic marking policy does not support this operation. Try again later.
400 IllegalParam.DstCidr The specified DstCidr is invalid. The error message returned because the specified destination CIDR block (DstCidr) is invalid.
400 IllegalParam.Protocol The specified Protocol is invalid. The error message returned because the specified protocol is invalid.
400 Duplicated.TrafficMatchRules The parameter AddTrafficMatchRules are duplicated. The TrafficMatchRules entries specified in the parameter are duplicated.
400 InstanceExist.TrafficMatchRules The instance already exists. The error message returned because the specified traffic match rules (TrafficMatchRules) already exist.
400 MissingParam.TrafficMatchRules The parameter TrafficMatchRules is empty. The specified traffic classification rules are empty.
400 IllegalParam.SrcPortRange The specified SrcPortRange is illegal. The source port is invalid.
400 IllegalParam.DstPortRange The specified DstPortRange is illegal. The specified DstPortRange is illegal.
400 AttrMismatching.CidrAddressFamily Attribute SrcCidr or DstCidr of TrafficMarkRule does not match AddressFamily. Attribute SrcCidr or DstCidr of TrafficMarkRule does not match AddressFamily.
400 IllegalParam.AddressFamily AddressFamily is illegal. The AddressFamily value of the request parameter is invalid. Valid values are IPv4 or IPv6.
400 AttrMismatching.SrcCidrDstCidr Attribute SrcCidr of TrafficMarkRule does not match DstCidr. Attribute SrcCidr of TrafficMarkRule does not match DstCidr.
400 AttrMismatching.CidrProtocol Attribute SrcCidr or DstCidr of TrafficMarkRule does not match Protocol. Attribute SrcCidr or DstCidr of TrafficMarkRule does not match Protocol.
400 InvalidTransitRouterMode.NeedUpgrade TransitRouter need to upgrade. The error message returned because the specified transit router mode is not supported.
400 OperationUnsupported.SrcPortRange Current TR version does not support setting source port range. Current TR version does not support setting source port range
400 OperationUnsupported.DstPortRange Current TR version does not support setting destination port range. Current TR version does not support setting destination port range.
400 OperationUnsupported.IPv6Cidr The traffic marking policy for current TR type does not support IPv6 CIDR. The flow classification rules in the flow marking policy of the basic version forwarding router do not support IPv6 network segments.
400 InvalidParameter Invalid parameter. The error message returned because the parameter is set to an invalid value.
400 Unauthorized The AccessKeyId is unauthorized. The error message returned because you do not have the permissions to perform this operation.
400 MissingParam.TrafficMarkingPolicyId The parameter TrafficMarkingPolicyId is mandatory. The parameter TrafficMarkingPolicyId is mandatory.
400 InvalidParameter.TrafficMarkingPolicyId The specified parameter TrafficMarkingPolicyId is invalid. The parameter TrafficMarkingPolicyId entered is illegal.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.