Skip to content

Route application examples

Amy Buck edited this page Nov 28, 2018 · 6 revisions

This information contains route application example, including verification. cps_config_route.py contains examples for creating a route, and deleting a route (see cps_config_route.py).

NOTE: Refer to the dell-base-route.yang model which defines the route object and attributes before you configure route settings.

Create route using Python

1. Import the CPS and CPS object Python library.

import cps_utils
import socket
import netaddr as net

2. Define the protocol version, route prefix, and prefix length of the route attributes.

version = 'ipv4'
route_ip = '70.5.5.0'
obj = cps_utils.CPSObject('base-route/obj/entry')
obj.add_attr("vrf-id", 0)
if version == 'ipv4':
  obj.add_attr("af", socket.AF_INET)
elif version == 'ipv6':
  obj.add_attr("af", socket.AF_INET6) ip = net.IPNetwork(route_ip)
obj.add_attr_type("route-prefix", version)
obj.add_attr("route-prefix", str(ip.network))
obj.add_attr("prefix-len", int(ip.prefixlen))

3. Define the next-hop attributes and create the CPS object. Add multiple next-hop attributes to create ECMP entries.

nh_addr = '1.1.1.2'
lst = ["nh-list", "0", "nh-addr"]
obj.add_embed_attr(lst, nh_addr)
obj.add_attr("nh-count", 1)

4. Create the CPS object.

cps_update = ('create', obj.get())
transaction = cps_utils.CPSTransaction([cps_update])

5. Verify the return value.

ret = transaction.commit()
if not ret:
  raise RuntimeError ("Error creating Route")

See route_create.py to view the Python application example.

Verify route creation using Linux

$ ip route
1.1.1.0/24 dev e101-001-0 proto kernel scope link src 1.1.1.1
70.5.5.0 via 1.1.1.2 dev e101-001-0 proto none

Delete route using Python

1. Import the CPS and CPS object Python library.

import cps_utils
import socket
import netaddr as net

2. Define the protocol version, route prefix, and prefix length of the route attributes.

version = 'ipv4'
route_ip = '70.5.5.0'
obj = cps_utils.CPSObject('base-route/obj/entry')
obj.add_attr("vrf-id", 0)
if version == 'ipv4':
obj.add_attr("af", socket.AF_INET)
elif version == 'ipv6':
obj.add_attr("af", socket.AF_INET6)
ip = net.IPNetwork(route_ip)

obj.add_attr_type("route-prefix", version)
obj.add_attr("route-prefix", str(ip.network))
obj.add_attr("prefix-len", int(ip.prefixlen))

3. Define the CPS object and create the transaction.

cps_update = ('delete', obj.get())
transaction = cps_utils.CPSTransaction([cps_update])

4. Verify the return value.

ret = transaction.commit()
if not ret:
  raise RuntimeError ("Error creating Route")

See route_delete.py to view the Python application example.

Verify route deletion using Linux

$ ip route
1.1.1.0/24 dev e101-001-0 proto kernel scope link src 1.1.1.1
70.5.5.0 via 1.1.1.2 dev e101-001-0 proto none

$ python route-delete
{'data': {'base-route/obj/entry/prefix-len': bytearray(b' \x00\x00\x00'), 'base-route/obj/entry/vrf-id': bytearray(b'\x00\x00\x00\x00'), 'base-route/obj/entry/af': bytearray(b'\x02\x00\x00\x00'), 'base- route/obj/entry/route-prefix': 'F\x05\x05\x00'}, 'key':'1.26.1704016.1703992.1703995.1703980.1703978.1703979.'}

$ ip route
1.1.1.0/24 dev e101-001-0 proto kernel scope link src 1.1.1.1
Clone this wiki locally