Terminating BGP sessions

To terminate BGP sessions, delete the associated resource, such as the Cloud VPN tunnel or VLAN attachment. After you delete the resource, the session is automatically terminated.

You can terminate BGP sessions manually by using the gcloud command-line tool or the API. If you do, the tunnel or VLAN attachment remains, but Cloud Router doesn't advertise routes over them.

gcloud

Run the remove-bgp-peer command, as shown in the following example:

gcloud compute routers remove-bgp-peer my-router --peer-name my-bgp-peer

API

To terminate BGP sessions, remove BGP peers from a Cloud Router by using the routers.patch method to update the bgpPeers[] field.

The bgpPeers[] field accepts an array of BGP peers. When you PATCH this field, you overwrite the existing array of BGP peers with the new array included in your request.

  1. Send a GET request to get the current array of BGP peers for the router. See Viewing a Cloud Router configuration.

  2. Send a PATCH request with an new array of BGP peers. Use the array from the GET request in the previous step and remove any BGP peers that you do not want on the router.

    PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/routers/ROUTER_NAME
    {
      "bgpPeers": [
        BGP_PEERS
      ]
    }
    

    Replace the following values:

    • PROJECT_ID: the project that contains the Cloud Router
    • REGION: the region where the Cloud Router is located
    • ROUTER_NAME: the name of the Cloud Router
    • BGP_PEERS: the contents of the new array of BGP peers.

      See the following example, which contains two BGP peers:

      {
        "name": "peer-1",
        "interfaceName": "if-peer-1",
        "ipAddress": "169.254.10.1",
        "peerIpAddress": "169.254.10.2",
        "peerAsn": 64512,
        "advertisedRoutePriority": 100,
        "advertiseMode": "DEFAULT"
      },
      {
        "name": "peer-2",
        "interfaceName": "if-peer-2",
        "ipAddress": "169.254.20.1",
        "peerIpAddress": "169.254.20.2",
        "peerAsn": 64513,
        "advertisedRoutePriority": 100,
        "advertiseMode": "DEFAULT"
      }