Goal

This tutorial shows you how to apply a custom application "bulk" QoS policy to the network element.

The Policy Service Set enables onePK applications to perform multiple policy operations within a single "bulk" message. The service set includes both synchronous and asynchronous APIs, enabling high scalability and full construction of objects in a single message.

The policy object is a top-level object in a hierarchy of objects that defines class, and other objects for applying QoS policies to interface targets. A policy object is associated with a target or interface. A policy may have a child policy.

The primary data structures are:

  • policy map
  • class map
  • entry
  • match (AKA filter)
  • action
  • table capabilities

Tutorial Code

The code used in this tutorial is available in the BulkQoSPolicyTutorial.py file in <SDK Location>/python/tutorials/tutorials/policy.

NOTE: The Policy Service Set is supported on NX-OS and IOS-XR platforms only

Requirements/Prerequisites

These steps assume the application can connect properly to a network element. Please see the Connecting to a Network Element tutorial for information on how to make the initial connection.

Steps in Detail

Create Bulk Service

Create a BulkService object on the current network element.

bulkService = bulk.BulkService(tutorial.network_element)

Create Capability

Create a capability object by querying the capabilities of the current network element.

for tbl in caps.get_table_capabilities(tutorial.network_element):
    if match.MatchType.MATCH_IP_DSCP in tbl.matches:
        logger.info("TABLE NAME "+ tbl.name + "\n")

Create Class Map

Create a class map based on the current network element and match any filters that are to be applied to this class map.

self.class_map1 = bulkService.create_class(tbl.type, tutorial.network_element)
if tbl.persistent:
    self.class_map1.storage_type = StorageType.PERSISTENT
self.class_map1.match_all = True

Add Match

Next, add matches to the class map.

self.class_map1.add_match(match.DSCP(OnepConstants.OnepDscp.ONEP_DSCP_EF))

Submit Class Map

Submit the class map to the service that you created earlier and get back the results.

bulkService.submit_class_map(self.class_map1)
logger.info("After Create class map: Result Text = " 
            + self.class_map1.result_text)
classMap1Handle = self.class_map1.handle
logger.info("CMapHandle - " + str(classMap1Handle) + "\n")

Create Policy Map

Create a policy map based on the current network element and match any actions that are to be applied to this class map.

for tbl in caps.get_table_capabilities(tutorial.network_element):
    if match.MatchType.MATCH_IP_DSCP in tbl.matches and \
       action.ActionType.SET_DSCP in tbl.actions:
        self.policy_map1 = bulkService.create_policy(tbl.type, tutorial.network_element)
        if tbl.persistent:
            self.policy_map1.storage_type = StorageType.PERSISTENT

Create Entry and Add Match

Next, create an entry in the policy map at the end of the list, create an activation holder and add actions to the activation holder.

self.entry1 = self.policy_map1.create_entry(self.class_map1)
self.entry1.add_action(action_mark1)

Submit Policy Map

Submit the policy map to the service that you created earlier and get back the results.

logger.info("Submitting policy map...")
bulkService.submit_policy_map(self.policy_map1)
logger.info("After Create policy map: Result Text = "
            + self.policy_map1.result_text)
policyMap1Handle = self.policy_map1.handle
logger.info("PMapHandle - " + str(policyMap1Handle) + "\n")

Create Target

Next, create a new target that will be applied to the current network element interface.

t1 = Target(intf, Target.TargetLocation.HARDWARE_DEFINED_INPUT)

Activate Policy on Interface

Activate the policy to its targets that are specified in the ActivationHolder list.

self.activationHolder = bulkService.create_activation_holder(self.policy_map1, t1)

Remove QoS

Then you can remove all the maps and the activation holders.

if not self.policy_map1==None:
    logger.info("\nDeactivating policy")
    bulkService.deactivate_policy(self.activationHolder)
    logger.info("Deleting policy map")
    bulkService.delete_policy_map(self.policy_map1)
if not self.class_map1==None:  
    logger.info("Deleting class map1")
    bulkService.delete_class_map(self.class_map1)

Result

Congratulations! Now you know how to apply a custom Bulk QoS policy to the network element.