
# 查询流量镜像筛选规则列表 - ListTrafficMirrorFilterRules
#### 功能介绍
当您的流量镜像筛选规则创建成功后，您可以通过该接口查询所有流量镜像筛选规则的信息，包括流量镜像筛选规则的源/目的地址、源/目的端口等。
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-vpc/vpc_api00_0007.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-vpc/vpc_permission_0000.html)。
- 如果使用身份策略授权，需具备如下身份策略权限。
  
  | 授权项                               | 访问级别 | 资源类型（\*为必须）                | 条件键 | 别名 | 依赖的授权项 |
  |:---|:---|:---|:---|:---|:---|
  | vpc:trafficMirrorFilterRules:list | List | trafficMirrorFilterRule \* | -   | -  | -      |
     
  
 
#### URI
GET /v3/{project_id}/vpc/traffic-mirror-filter-rules
表1路径参数 
| 参数         | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
|:---|:---|:---|:---|
| project_id | 是    | String | **参数解释**： 流量镜像筛选规则所属的项目ID。获取方式请参见[获取项目ID](https://support.huaweicloud.com/api-vpc/vpc_api_0011.html)。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。 |
   
表2Query参数 
| 参数                       | 是否必选 | 参数类型              | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
|:---|:---|:---|:---|
| id                       | 否    | Array of strings  | **参数解释**： 流量镜像筛选规则的资源ID，可以通过此字段精确过滤流量镜像筛选规则，支持传入多个ID过滤。 **取值范围**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| action                   | 否    | Array of strings  | **参数解释**： 流量镜像筛选规则的策略，可以通过此字段过滤流量镜像筛选规则，支持传入多个策略过滤。 **取值范围**： accept，reject                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| description              | 否    | Array of strings  | **参数解释**： 流量镜像筛选规则的描述信息，可以通过此字段过滤流量镜像筛选规则，支持传入多个描述信息进行过滤。 **取值范围**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| destination_cidr_block   | 否    | Array of strings  | **参数解释**： 流量镜像筛选规则的目的地址，可以通过此字段过滤流量镜像筛选规则，支持传入多个地址进行过滤。 **取值范围**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| destination_port_range   | 否    | Array of strings  | **参数解释**： 流量镜像筛选规则的目的端口范围，可以通过此字段过滤流量镜像筛选规则，支持传入多个端口范围进行过滤。 **取值范围**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| direction                | 否    | Array of strings  | **参数解释**： 流量镜像筛选规则的流量方向，可以通过此字段过滤流量镜像筛选规则，支持传入多个方向进行过滤。 **取值范围**： - ingress：入方向。   - egress：出方向。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| priority                 | 否    | Array of integers | **参数解释**： 流量镜像筛选规则的优先级，可以通过此字段过滤流量镜像筛选规则，支持传入多个优先级进行过滤。 **取值范围**： 1\~65535                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| protocol                 | 否    | Array of strings  | **参数解释**： 流量支持的网络协议类型，可以通过此字段过滤流量镜像筛选规则，支持传入多个协议类型进行过滤。 **取值范围**： - tcp：过滤出支持TCP协议的流量镜像筛选规则。   - udp：过滤出支持UDP协议的流量镜像筛选规则。   - icmp：过滤出支持ICMP协议的流量镜像筛选规则。   - icmpv6：过滤出支持ICMPV6协议的流量镜像筛选规则。   - all：过滤出支持全部协议的流量镜像筛选规则。    |
| source_cidr_block        | 否    | Array of strings  | **参数解释**： 流量镜像筛选规则的源地址，可以通过此字段过滤流量镜像筛选规则，支持传入多个地址进行过滤。 **取值范围**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| source_port_range        | 否    | Array of strings  | **参数解释**： 流量镜像筛选规则的源端口范围，可以通过此字段过滤流量镜像筛选规则，支持传入多个端口范围进行过滤。 **取值范围**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| traffic_mirror_filter_id | 否    | Array of strings  | **参数解释**： 流量镜像筛选规则所在流量镜像筛选条件的ID，可以通过此字段过滤流量镜像筛选规则，支持传入多个ID进行过滤。 **取值范围**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
   
#### 请求参数
无
#### 响应参数
**状态码：200**
表3响应Body参数 
| 参数                          | 参数类型                                                                                                        | 描述                                                                                                                                                                                         |
|:---|:---|:---|
| traffic_mirror_filter_rules | Array of [TrafficMirrorFilterRule] objects | **参数解释**： 查询流量镜像筛选规则列表的响应体。 **取值范围**： 不涉及。 |
| page_info                   | [PageInfo] object                                         | **参数解释**： 分页信息。 **取值范围**： 不涉及。             |
| request_id                  | String                                                                                                      | **参数解释**： 请求ID。 **取值范围**： 不涉及。             |
   
 表4TrafficMirrorFilterRule 
| 参数                       | 参数类型    | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
|:---|:---|:---|
| id                       | String  | **参数解释**： 流量镜像筛选规则的资源ID。 **取值范围**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| project_id               | String  | **参数解释**： 流量镜像筛选规则所属的项目ID。 **取值范围**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| description              | String  | **参数解释**： 流量镜像筛选规则的描述信息。 **取值范围**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| traffic_mirror_filter_id | String  | **参数解释**： 流量镜像筛选规则所在流量镜像筛选条件的ID。 **取值范围**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| direction                | String  | **参数解释**： 流量镜像筛选规则的流量方向。 **取值范围**： - ingress：入方向。   - egress：出方向。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| source_cidr_block        | String  | **参数解释**： 流量镜像筛选规则的源地址。 **取值范围**： - 单个IP地址：IP地址/掩码。 - 单个IPv4地址示例为192.168.10.10/32。   - 单个IPv6地址示例为2002:50::44/128。     - IP网段：IP地址/掩码。 - IPv4网段示例为192.168.52.0/24。   - IPv6网段示例为2407:c080:802:469::/64。     - 所有IP地址： - 0.0.0.0/0表示匹配所有IPv4地址。   - ::/0表示匹配所有IPv6地址。       |
| destination_cidr_block   | String  | **参数解释**： 流量镜像筛选规则的目的地址。 **取值范围**： - 单个IP地址：IP地址/掩码。 - 单个IPv4地址示例为192.168.10.10/32。   - 单个IPv6地址示例为2002:50::44/128。     - IP网段：IP地址/掩码。 - IPv4网段示例为192.168.52.0/24。   - IPv6网段示例为2407:c080:802:469::/64。     - 所有IP地址： - 0.0.0.0/0表示匹配所有IPv4地址。   - ::/0表示匹配所有IPv6地址。      |
| source_port_range        | String  | **参数解释**： 流量镜像筛选规则的源端口范围。 **取值范围**： 1\~65535                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| destination_port_range   | String  | **参数解释**： 流量镜像筛选规则的目的端口范围。 **取值范围**： 1\~65535                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ethertype                | String  | **参数解释**： 流量支持的IP地址类型。 **取值范围**： - IPv4   - IPv6                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| protocol                 | String  | **参数解释**： 流量镜像支持的网络协议类型。 **取值范围**： - tcp：选择TCP协议，可以自定义源端口范围和目的端口范围。   - udp：选择UDP协议，可以自定义源端口范围和目的端口范围。   - icmp："IP类型"选择"IPv4"时，可选择ICMP协议，源端口范围和目的端口范围默认为全部端口。   - icmpv6："IP类型"选择"IPv6"时，可选择ICMPV6协议，源端口范围和目的端口范围默认为全部端口。   - all：表示支持全部网络协议，源端口范围和目的端口范围默认为全部端口。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| action                   | String  | **参数解释**： 流量镜像筛选规则的流量采集策略。 **取值范围**： - accept：采集。   - reject：不采集。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| priority                 | Integer | **参数解释**： 流量镜像筛选规则的优先级。 **取值范围**： 1\~65535，数字越小，优先级越高。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| created_at               | String  | **参数解释**： 流量镜像筛选规则的创建时间。 **取值范围**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| updated_at               | String  | **参数解释**： 流量镜像筛选规则的更新时间。 **取值范围**： 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
   
 表5PageInfo 
| 参数              | 参数类型    | 描述                                                                                                                                                                                                       |
|:---|:---|:---|
| previous_marker | String  | **参数解释**： 当前页的第一条记录。 **取值范围**： 不涉及。                      |
| current_count   | Integer | **参数解释**： 当前页的资源总数。 **取值范围**： 不涉及。                       |
| next_marker     | String  | **参数解释**： 当前页的最后一条记录，最后一页时无next_marker字段。 **取值范围**： 不涉及。 |
   
#### 请求示例
查询流量镜像筛选规则列表
```
GET http://{endpoint}/v3/{project_id}/vpc/traffic-mirror-filter-rules
```
#### 响应示例
**状态码：200**
OK
```
{
  "request_id" : "38719a68-c7c1-4fe1-bf12-4bb049349174",
  "traffic_mirror_filter_rules" : [ {
    "created_at" : "2023-02-17T08:42:44Z",
    "updated_at" : "2023-02-17T08:42:44Z",
    "id" : "3daa97b5-ad58-477d-86a5-52b65257f94b",
    "project_id" : "7365fcd452924e398ec4cc1fe39c0d12",
    "description" : "",
    "traffic_mirror_filter_id" : "b765ba87-c0b4-4f1a-9ec3-d5b1d1ddb137",
    "direction" : "ingress",
    "protocol" : "icmpv6",
    "ethertype" : "IPv4",
    "action" : "accept",
    "priority" : 16
  } ],
  "page_info" : {
    "previous_marker" : "3daa97b5-ad58-477d-86a5-52b65257f94b",
    "current_count" : 1
  }
}
```
#### SDK代码示例
SDK代码示例如下。
- [Java]
  ```
  package com.huaweicloud.sdk.test;
  import com.huaweicloud.sdk.core.auth.ICredential;
  import com.huaweicloud.sdk.core.auth.BasicCredentials;
  import com.huaweicloud.sdk.core.exception.ConnectionException;
  import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
  import com.huaweicloud.sdk.core.exception.ServiceResponseException;
  import com.huaweicloud.sdk.vpc.v3.region.VpcRegion;
  import com.huaweicloud.sdk.vpc.v3.*;
  import com.huaweicloud.sdk.vpc.v3.model.*;
  public class ListTrafficMirrorFilterRulesSolution {
      public static void main(String[] args) {
          // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
          // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
          String ak = System.getenv("CLOUD_SDK_AK");
          String sk = System.getenv("CLOUD_SDK_SK");
          String projectId = "{project_id}";
          ICredential auth = new BasicCredentials()
                  .withProjectId(projectId)
                  .withAk(ak)
                  .withSk(sk);
          VpcClient client = VpcClient.newBuilder()
                  .withCredential(auth)
                  .withRegion(VpcRegion.valueOf("<YOUR REGION>"))
                  .build();
          ListTrafficMirrorFilterRulesRequest request = new ListTrafficMirrorFilterRulesRequest();
          try {
              ListTrafficMirrorFilterRulesResponse response = client.listTrafficMirrorFilterRules(request);
              System.out.println(response.toString());
          } catch (ConnectionException e) {
              e.printStackTrace();
          } catch (RequestTimeoutException e) {
              e.printStackTrace();
          } catch (ServiceResponseException e) {
              e.printStackTrace();
              System.out.println(e.getHttpStatusCode());
              System.out.println(e.getRequestId());
              System.out.println(e.getErrorCode());
              System.out.println(e.getErrorMsg());
          }
      }
  }
  ```
- [Python]
  ```
  # coding: utf-8
  import os
  from huaweicloudsdkcore.auth.credentials import BasicCredentials
  from huaweicloudsdkvpc.v3.region.vpc_region import VpcRegion
  from huaweicloudsdkcore.exceptions import exceptions
  from huaweicloudsdkvpc.v3 import *
  if __name__ == "__main__":
      # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
      # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
      ak = os.environ["CLOUD_SDK_AK"]
      sk = os.environ["CLOUD_SDK_SK"]
      projectId = "{project_id}"
      credentials = BasicCredentials(ak, sk, projectId)
      client = VpcClient.new_builder() \
          .with_credentials(credentials) \
          .with_region(VpcRegion.value_of("<YOUR REGION>")) \
          .build()
      try:
          request = ListTrafficMirrorFilterRulesRequest()
          response = client.list_traffic_mirror_filter_rules(request)
          print(response)
      except exceptions.ClientRequestException as e:
          print(e.status_code)
          print(e.request_id)
          print(e.error_code)
          print(e.error_msg)
  ```
- [Go]
  ```
  package main
  import (
  "fmt"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
      vpc "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpc/v3"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpc/v3/model"
      region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpc/v3/region"
  )
  func main() {
      // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
      // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
      ak := os.Getenv("CLOUD_SDK_AK")
      sk := os.Getenv("CLOUD_SDK_SK")
      projectId := "{project_id}"
      auth, err := basic.NewCredentialsBuilder().
          WithAk(ak).
          WithSk(sk).
          WithProjectId(projectId).
          SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      hcClient, err := vpc.VpcClientBuilder().
           WithRegion(region.ValueOf("<YOUR REGION>")).
           WithCredential(auth).
           SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      client := vpc.NewVpcClient(hcClient)
      request := &model.ListTrafficMirrorFilterRulesRequest{}
  response, err := client.ListTrafficMirrorFilterRules(request)
  if err == nil {
          fmt.Printf("%+v\n", response)
      } else {
          fmt.Println(err)
      }
  }
  ```
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/VPC/sdk?api=ListTrafficMirrorFilterRules&version=v3)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述 |
|:---|:---|
| 200 | OK |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-vpc/vpc_api_0003.html)。
