X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FPolicer.py;h=37b1c7f7456eb79570a4c727ab4667661d0ef281;hp=abf6090cf39ac28cc6a948ca4d39797f11664e1d;hb=HEAD;hpb=9902cc2a3610661110c66753554be12520e9c334 diff --git a/resources/libraries/python/Policer.py b/resources/libraries/python/Policer.py index abf6090cf3..28ed0b0aa9 100644 --- a/resources/libraries/python/Policer.py +++ b/resources/libraries/python/Policer.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020 Cisco and/or its affiliates. +# Copyright (c) 2024 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -16,6 +16,7 @@ from enum import IntEnum from resources.libraries.python.Constants import Constants +from resources.libraries.python.IPUtil import IpDscp from resources.libraries.python.PapiExecutor import PapiSocketExecutor from resources.libraries.python.topology import Topology @@ -59,28 +60,6 @@ class PolicerPreColor(IntEnum): VIOLATE_COLOR = 2 -class DSCP(IntEnum): - """DSCP for mark-and-transmit action.""" - D_CS0 = 0 - D_CS1 = 8 - D_CS2 = 16 - D_CS3 = 24 - D_CS4 = 32 - D_vCS5 = 40 - D_CS6 = 48 - D_CS7 = 56 - D_AF11 = 10 - D_AF12 = 12 - D_AF13 = 14 - D_AF21 = 18 - D_AF22 = 20 - D_AF23 = 22 - D_AF31 = 26 - D_AF32 = 28 - D_AF33 = 30 - D_EF = 46 - - class Policer: """Policer utilities.""" @@ -93,7 +72,7 @@ class Policer: def policer_set_configuration( node, policer_name, cir, eir, cbs, ebs, rate_type, round_type, policer_type, conform_action_type, exceed_action_type, - violate_action_type, color_aware, is_add=True, conform_dscp=None, + violate_action_type, color_aware, conform_dscp=None, exceed_dscp=None, violate_dscp=None): """Configure policer on VPP node. @@ -110,7 +89,6 @@ class Policer: :param exceed_action_type: Exceed action type. :param violate_action_type: Violate action type. :param color_aware: Color-blind (cb) or color-aware (ca). - :param is_add: Add policer if True, else delete. :param conform_dscp: DSCP for conform mark_and_transmit action. :param exceed_dscp: DSCP for exceed mark_and_transmit action. :param violate_dscp: DSCP for vilate mark_and_transmit action. @@ -127,7 +105,6 @@ class Policer: :type exceed_action_type: str :type violate_action_type: str :type color_aware: str - :type is_add: bool :type conform_dscp: str :type exceed_dscp: str :type violate_dscp: str @@ -151,10 +128,8 @@ class Policer: else 0 ) - cmd = u"policer_add_del" - args = dict( - is_add=is_add, - name=str(policer_name), + cmd = u"policer_add" + infos = dict( cir=int(cir), eir=int(eir), cb=int(cbs), @@ -165,10 +140,14 @@ class Policer: ).value, type=getattr(PolicerType, f"TYPE_{policer_type.upper()}").value, conform_action=conform_action, - exceed_action = exceed_action, - violate_action = violate_action, + exceed_action=exceed_action, + violate_action=violate_action, color_aware=bool(color_aware == u"'ca'") ) + args = dict( + name=str(policer_name), + infos=infos, + ) err_msg = f"Failed to configure policer {policer_name} " \ f"on host {node['host']}" @@ -240,4 +219,4 @@ class Policer: :returns: DSCP numeric value. :rtype: int """ - return getattr(DSCP, f"D_{dscp.upper()}").value + return getattr(IpDscp, f"IP_API_DSCP_{dscp.upper()}").value