-
Notifications
You must be signed in to change notification settings - Fork 35
Route application examples
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.
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.
$ 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
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.
$ 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
© 2019 OpenSwitch project. All information is contributed to and made available by OPX under the Creative Commons Attribution 4.0 International License (available at http://creativecommons.org/licenses/by/4.0/).
- Home
- System overview
- Software releases
- Hardware support
- FAQs
- Install
- Build
- Configure
- Develop
- Administer
- Troubleshoot
- Software compatibility
- Contribute
- DevOps
- Join