NSX for vSphere: Add Floating Static Routes to NSX Edge via REST API

Recently I have been engaged in a NSX-v PSO engagement where we need to make sure all the best practices are applied to the environment. Trust me, with every engagement, you learn something new as it is always the business requirements that drive technical solutions.

Use Case

As the customer have iBGP routing configured between DLR and NSX edges, and eBGP between NSX edges and the L3 leaf switches, we need to ensure that all ECMP-enabled edges can reach the logical switches via DLR in case DLR-Edges BGP neighborship is down (if DLR control VM is down). So, one of the changes that were needed to be done was to make sure floating static routes are added to the NSX edges as backup routes.

Having about 160 discontiguous subnets attached to the UDLR and 4 edges in each datacenter in an active/standby multi-site deployment, makes it a nightmare to add all these subnets individually to each NSX edge through the GUI. REST API comes into rescue in such case.

This approach makes it feasible to add all 160 routes to each NSX edge in one REST API call.

In this post, we gonna see how we can add a floating static route to an NSX edge via REST API.

Procedure

Download and install a REST client such as postman.

This image has an empty alt attribute; its file name is image-1024x458.png

Configure basic authentication with your NSX manager and supply admin credentials. Make sure you are able to connect to your NSX manager as we need to get the NSX edge ID to make our changes.

To get the ID of your corresponding edge, you can use the below API call: GET https://<NSX-Mgr Name>/api/4.0/edges/

First let’s get the static routes currently configured on your NSX edge (if any) using the below API call: Get https://<NSX-Mgr Name>/api/4.0/edges/<edge-ID>/routing/config/static

From the above screenshot, you can notice that there are no static routes configured on edge-1.

As we are going to use NSX-v 6.x API PUT methods to inject the static routes, we need to make sure that encoding specified in the headers is configured with application/xml. Key: Content-Type, Value: application/xml

We will add the below 2 static routes as an example. The same logic can be followed to add N static routes.

Route1: Exit interface=vNIC 1, Logical Subnet=10.14.101.0/24, Next Hop=192.168.5.2, AD=240
Route2: Exit interface=vNIC 1, Logical Subnet=192.168.10.0/24, Next Hop=192.168.5.2, AD=240

Static Route AD 240 > iBGP AD 200 is used to make sure the static route acts as backup route only if BGP is down.

vNIC1 is the NSX edge transit interface connected to the downstream DLR
Next Hop IP address 192.168.5.2 is the DLR transit interface facing the NSX edge

To do so, the below API request and body will be used.

Request:
PUT https://<NSX-Mgr Name>/api/4.0/edges/<edge-ID>/routing/config/static

Body:
<staticRouting>
<staticRoutes>
<route>
<description>route1</description>
<vnic>1</vnic>
<network>10.14.101.0/24</network>
<nextHop>192.168.5.2</nextHop>
<mtu>1500</mtu> <adminDistance>240</adminDistance>
<type>user</type>
</route>
<route>
<description>route2</description>
<vnic>1</vnic>
<network>192.168.10.0/24</network>
<nextHop>192.168.5.2</nextHop>
<mtu>1500</mtu>
<adminDistance>240</adminDistance>
<type>user</type>
</route>
<staticRouting>
<staticRoutes>

After you execute the above API call, you should get a “204 No Content” response if all went OK.

Now, let’s verify our work and check if our static routes have been added to the NSX edge.

via API:

via GUI:

Hope this post is informative,

Thanks for reading,

Mohamad Alhussein

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

3316total visits,11visits today

Leave a Reply

Your email address will not be published. Required fields are marked *