本文介绍如何添加静态路由。
package com.volcengine.directconnect.examples; import com.volcengine.ApiClient; import com.volcengine.ApiException; import com.volcengine.sign.Credentials; import com.volcengine.directconnect.DirectconnectApi; import com.volcengine.directconnect.model.*; public class TestCreateDirectConnectGatewayRoute { public static void main(String[] args) throws Exception { // 设置您的AK信息。 String ak = "Your AK"; // 设置您的SK信息。 String sk = "Your SK"; // 设置您要访问的地域。 String region = "Your Region"; // 初始化apiclient。 ApiClient apiClient = new ApiClient() .setCredentials(Credentials.getCredentials(ak, sk)) .setRegion(region); DirectconnectApi api = new DirectconnectApi(apiClient); // 配置待添加静态路由的参数。 CreateDirectConnectGatewayRouteRequest createDirectConnectGatewayRouteRequest = new CreateDirectConnectGatewayRouteRequest(); createDirectConnectGatewayRouteRequest.setDestinationCidrBlock("172.XX.XX.0/24"); // 设置专线网关路由的目的网段。 createDirectConnectGatewayRouteRequest.setDirectConnectGatewayId("dcg-2fe3zsmkshs59g****"); // 设置待添加静态路由的专线网关的ID。 createDirectConnectGatewayRouteRequest.setNextHopId("dcv-7qthudw0ll6jmc****"); // 设置专线网关路由下一跳虚拟接口的ID。 // 发起请求并处理返回或异常。 try { CreateDirectConnectGatewayRouteResponse response = api.createDirectConnectGatewayRoute(createDirectConnectGatewayRouteRequest); System.out.println(response); } catch (ApiException e) { System.out.println(e.getResponseBody()); } } }