Configure multi-path routing with MED

Updated at:
Copy as MD

When Transit Routers (TRs) in multiple regions are connected to an Express Connect Router (ECR), traffic might follow suboptimal paths, resulting in detours. To resolve this, you can set a specific TR as the default path on the ECR to define a preferred route and prevent these detours.

Basic route selection rules

The Multi-Exit Discriminator (MED) is a key attribute of the Border Gateway Protocol (BGP). A lower MED value indicates a higher priority, meaning the corresponding route is preferred.

Alibaba Cloud defines three MED values: 1000 for an intra-region connection between an ECR and a TR, 2000 for a TR manually set as the default path on the ECR, and 3000 for a cross-region connection between an ECR and a TR.

Outbound route selection

Outbound traffic is routed based on the routes in a Transit Router (TR).

When a TR learns multiple routes to the same destination from ECRs and other TRs, it selects the best path based on TR route priorities. The TR forwards traffic using the route with the higher-priority attribute. If attributes are identical, the TR compares the next attribute in the sequence.

The route selection priorities are listed in the following table:

Note

The route attribute priorities are, from highest to lowest: P1 > P2 > P3 > P4.

Route attribute priority

Route attribute

Description

P1

AS_Path

The system compares the AS_Path of routes to the same destination.

A shorter AS_Path is preferred. If AS_Path lengths are the same, the system compares the local preference attribute.

P2

local preference

An intra-region next hop is preferred over a cross-region next hop.

  • If the next hop options include both an ECR and a cross-region TR, the ECR is preferred.

  • If all next hop options are TRs, the system compares the MED attribute.

P3

MED

When local preference is not the deciding factor, the MED value is compared. A lower MED value is preferred. You can set the MED of a target TR to the default value on the ECR to influence the path selection for outbound traffic. For more information, see Procedure.

If routes to the same destination have the same MED value, the system compares the byte order attribute.

P4

byte order

The system compares the region IDs of routes to the same destination. Region IDs are sorted alphabetically. The route from the region whose ID is first alphabetically receives higher priority.

For example, a route from the China (Beijing) (cn-beijing) region is preferred over a route from the China (Hangzhou) (cn-hangzhou) region.

Inbound route selection

Inbound traffic is routed based on the routes in an ECR.

When an ECR learns multiple routes to the same destination from TRs and other ECRs, it selects the best path by comparing the attributes of each route in descending order of priority. The ECR forwards traffic using the route with the higher-priority attribute. If attributes are identical, the ECR compares the next attribute in the sequence.

The route selection priorities are listed in the following table:

Note

The route attribute priorities are, from highest to lowest: P1 > P2 > P3 > P4.

Route attribute priority

Route attribute

Description

P1

MED

When an ECR learns routes to the same destination from TR instances, the MED is 1000 for routes from a TR in the same region, and 3000 for routes from a TR in a different region.

If all learned routes to the same destination are from cross-region TRs, their MED values are all 3000, so the system then compares the local preference attribute.

P2

local preference

If the region of a Virtual Border Router (VBR) has ECR and TR connections, traffic preferentially enters the cloud through the connections in the VBR's region.

If the VBR's region does not have ECR and TR connections, the system compares the default egress attribute.

P3

default egress

If the region of a VBR does not have ECR and TR connections, the system tags routes received from the TR that is set as the default egress. This ensures that the tagged route is preferred.

If no received TR route is tagged, the system compares the byte order attribute.

P4

byte order

The system compares the region IDs of routes to the same destination. Region IDs are sorted alphabetically. The route from the region whose ID is first alphabetically receives higher priority.

For example, a route from the China (Beijing) (cn-beijing) region is preferred over a route from the China (Hangzhou) (cn-hangzhou) region.

Use cases

The following three scenarios, progressing from simple to complex, explain route selection between TRs and ECRs and demonstrate how to modify traffic paths. All scenarios assume that the AS_Path lengths are the same.

Scenario 1

In this scenario, a company's on-premises data center is connected to a Virtual Border Router (VBR) in the China (Hangzhou) region. The company has services deployed in Virtual Private Clouds (VPCs) in both the China (Hangzhou) and China (Shanghai) regions.

The company uses a VBR, an ECR, and TRs to connect the on-premises data center and the cloud VPCs. A cross-region connection exists between TR1 in Hangzhou and TR2 in Shanghai. The ECR connects to both TR1 and the VBR in Hangzhou.

1. Route propagation to VPCs

  • A: The data center advertises routes to the VBR.

  • B: The VBR advertises routes to the ECR.

  • C: The ECR advertises routes to the TR.

  • D: Routes are propagated between TRs. TR1 propagates the routes from the ECR to TR2.

2. Route propagation to data center

  • A: VPCs advertise routes to TRs. route learning must be enabled for the TRs.

  • B: Routes are propagated between TRs and to the ECR. TR1 propagates the routes from TR2 to the ECR.

  • C: The ECR advertises routes to the VBR.

  • D: The VBR advertises routes to the data center.

3. Traffic paths

Because there is only one path between the VBR and VPC1, and only one path between the VBR and VPC2, no route selection is necessary.

Scenario 2

In this scenario, a company has an on-premises data center in the China (Hangzhou) region, with services deployed in VPCs in the China (Hangzhou) and China (Shanghai) regions.

The company connects its on-premises data center and cloud VPCs by using a VBR, an ECR, and TRs. A cross-region connection links the TR in Hangzhou and the TR in Shanghai. The ECR connects to TR1 in Hangzhou, TR2 in Shanghai, and the VBR in Hangzhou, creating a fully interconnected network.

1. Route propagation to VPCs

  • A: The data center advertises routes to the VBR.

  • B: The VBR advertises routes to the ECR.

  • C: The ECR advertises routes to TR1 and TR2. The ECR sets the MED attribute on the routes before sending them to the two TRs.

    When the source VBR and the destination TR are in the same region, the MED is set to 1000. When they are in different regions, the MED is set to 3000. Therefore:

    • Since the VBR and TR1 are in the same region, the ECR sets the MED of the route to 1000 before propagating it to TR1.

    • Since the VBR and TR2 are in different regions, the ECR sets the MED of the route to 3000 before propagating it to TR2.

  • D: Routes are propagated between TRs. After propagation, each TR determines its active routes as follows:

    • TR1 is directly connected to the ECR. The local preference rule prioritizes the route from the ECR. When outbound traffic from VPC1 accesses the VBR, TR1 selects the ECR as the next hop.

    • TR2 is also directly connected to the ECR. The local preference rule prioritizes the route from the ECR. When outbound traffic from VPC2 accesses the VBR, TR2 selects the ECR as the next hop.

2. Route propagation to data center

  • A: Routes are propagated between TRs.

  • B: TR1 and TR2 advertise routes to the ECR. The TRs set the MED attribute on the routes before sending them.

    When the source VPC and the current TR are in the same region, the MED is set to 1000. When they are in different regions, the MED is set to 3000.

    • For routes originating from VPC1:

      • VPC1 and TR1 are in the same region. TR1 sets the MED to 1000 before propagating the route to the ECR.

      • VPC1 and TR2 are in different regions. TR2 sets the MED to 3000 before propagating the route to the ECR.

      • After the ECR receives the routes, it prefers the route from TR1 because it has a lower MED value. When inbound traffic accesses VPC1, the ECR selects TR1 as the next hop.

    • For routes originating from VPC2: The same logic applies. The ECR prefers the route from TR2. When inbound traffic accesses VPC2, the ECR selects TR2 as the next hop.

  • C: The ECR advertises routes to the VBR.

  • D: The VBR advertises routes to the data center.

3. Traffic paths

Based on the preceding route analysis:

  • Outbound traffic: On the TRs, since both are directly connected to the ECR, the local preference rule applies, and routes from the ECR are preferred. Therefore, each TR directly selects the ECR as its next hop, and traffic goes directly from the local TR to the ECR.

  • Inbound traffic: On the ECR, routes from the TR in the same region as the VPC are preferred. Therefore, traffic preferentially enters the cloud through the TR located in the same region as the destination VPC.

Scenario 3

In this scenario, a company has connected three on-premises data centers to VBRs in the China (Beijing), China (Shanghai), and China (Hangzhou) regions, respectively. Services are deployed in VPCs in these three regions.

The company has connected all three VBRs to an ECR, and has also connected TR1 and TR2 to the ECR. Cross-region connections link all three TRs.

1. Route propagation to VPCs

  • A: The data centers advertise routes to the VBRs.

  • B: The VBRs advertise routes to the ECR.

  • C: The ECR advertises routes to TR1 and TR2. The ECR sets the MED attribute on the routes before sending them.

    When the source VBR and the destination TR are in the same region, the MED is set to 1000. When they are in different regions, the MED is set to 3000.

    For a route originating from VBR1:

    • VBR1 and TR1 are in the same region. The ECR sets the MED to 1000 before propagating the route to TR1.

    • VBR1 and TR2 are in different regions. The ECR sets the MED to 3000 before propagating the route to TR2.

  • D: Routes are propagated between TRs. After propagation, each TR determines its active routes as follows:

    • TR1 and TR2 are directly connected to the ECR. This is the same as Scenario 2. Based on the local preference rule, the route from the ECR is preferred.

    • TR3 is not directly connected to the ECR. The logic is as follows:

      • When receiving routes originating from VBR1:

        • The route from TR1 has an MED of 1000.

        • The route from TR2 has an MED of 3000.

        • The route with an MED of 1000 is preferred. Therefore, the route from TR1 becomes active. When outbound traffic from VPC3 accesses VBR1, TR3 selects TR1 as the next hop.

      • When receiving routes originating from VBR2: The same logic applies. The route from TR2 becomes active. When outbound traffic from VPC3 accesses VBR2, TR3 selects TR2 as the next hop.

      • When receiving routes originating from VBR3:

        • For the route from TR1: The source VBR3 is in the China (Hangzhou) region, and TR1 is in the China (Beijing) region. This is a cross-region connection, so the MED is 3000.

        • For the route from TR2: The source VBR3 is in the China (Hangzhou) region, and TR2 is in the China (Shanghai) region. This is a cross-region connection, so the MED is 3000.

        • Because the MED values are the same, the byte order rule serves as a tie-breaker. The route from TR1 is prioritized because its region ID, cn-beijing, comes before cn-hangzhou alphabetically. When outbound traffic from VPC3 accesses VBR3, TR3 selects TR1 as the next hop.

Based on these routing rules, the outbound traffic paths from each VPC are as follows:

VPC1 outbound path

VPC2 outbound path

VPC3 outbound path

2. Route propagation to data centers

  • A: VPCs advertise routes to TRs.

  • B: Routes are propagated between TRs and to the ECR. The TRs set the MED attribute on the routes before sending them to the ECR.

    When the source VPC and the current TR are in the same region, the MED is set to 1000. When they are in different regions, the MED is set to 3000.

    • For routes originating from VPC1:

      • VPC1 and TR1 are in the same region. TR1 sets the MED to 1000 before propagating the route to the ECR.

      • VPC1 and TR2 are in different regions. TR2 sets the MED to 3000 before propagating the route to the ECR.

      • After the ECR receives the routes, it prefers the route from TR1 because it has a lower MED value. When inbound traffic accesses VPC1, the ECR selects TR1 as the next hop.

    • For routes originating from VPC2: The same logic applies. The ECR prefers the route from TR2. When inbound traffic accesses VPC2, the ECR selects TR2 as the next hop.

    • For routes originating from VPC3:

      • VPC3 and TR1 are in different regions. TR1 sets the MED to 3000 before propagating the route to the ECR.

      • VPC3 and TR2 are in different regions. TR2 sets the MED to 3000 before propagating the route to the ECR.

      • Because the MED values of the routes received by the ECR are the same, the local preference rule applies:

        • The TR in the same region as VBR1 is TR1, which is directly connected to the ECR. Therefore, for inbound traffic from VBR1 to VPC3, the ECR selects TR1 as the next hop.

        • The TR in the same region as VBR2 is TR2, which is directly connected to the ECR. Therefore, for inbound traffic from VBR2 to VPC3, the ECR selects TR2 as the next hop.

        • The TR in the same region as VBR3 is TR3, which is not directly connected to the ECR. The byte order rule is used as a tie-breaker:

          The cn-beijing region ID comes before cn-hangzhou alphabetically, which prioritizes the route from TR1. For inbound traffic from VBR3 to VPC3, the ECR selects TR1 as the next hop.

  • C: The ECR advertises routes to the VBRs.

  • D: The VBRs advertise routes to the data centers.

Based on these routing rules, the inbound traffic paths from the data centers to the three VPCs are as follows:

VPC1 inbound path

VPC2 inbound path

VPC3 inbound path

3. Change the traffic path

You can set TR2 as the default path on the ECR to change the path for traffic between VPC3 and data center 3:

  • Change the outbound traffic path:

    After TR2 is set as the default path, the ECR sets the MED attribute to 2000 for all routes sent to TR2. When TR2 propagates these routes to TR3, TR3 prefers the routes from TR2. This changes the outbound traffic egress for VPC3 from TR1 to TR2.

  • Change the inbound traffic path:

    After TR2 is set as the default path, the default egress rule applies. Inbound traffic preferentially selects the TR set as default (TR2) as the next hop. Now, when inbound traffic from VBR3 accesses VPC3, the ECR selects TR2 as the next hop.

Path before MED change

Path after MED change

The following table summarizes the traffic paths between the three VPCs and their corresponding data centers.

MED status

VPC1-DC1 path

VPC2-DC2 path

VPC3-DC3 path

Before the change

After the change

Path unchanged

Path unchanged

Limitations

  • If an ECR is associated with only one Cloud Enterprise Network (CEN) instance, you can set only one TR in that CEN instance as the default path. You cannot set another TR in the same CEN instance as the default path.

  • If an ECR is associated with multiple CEN instances, you can set one TR in each CEN instance as the default path. You cannot set another TR in the same CEN instance as the default path.

Prerequisites

Procedure

In cross-region scenarios where multiple TRs connect to an ECR without full interconnection, traffic detours can occur. To resolve this, set a TR in a specific region as the default path on the ECR:

Go to the Basic Information page of the target ECR. Find the target TR and in the Set as Default column, click Set as Default.